0

我正在尝试使用pyDatalog来确定是否满足各种功能的依赖关系。某些库 (lA,lB,...) 提供功能 (fX,fY,...) 所需的输出 (1,2,...)。

例如:

+has("lA", 1)   #Library A has output 1
+has("lA", 2)   #Library A has output 2
+has("lB", 2)   #Library B has output 2
+needs("fX", 1) #Feature X needs output 1
+needs("fX", 2) #Feature X needs output 2
+needs("fY", 2) #Feature Y needs output 2

使用 pyDatalog 图形教程,我可以找到至少提供功能所需输出之一的库:

lib_supports_feature(X, Z) <= has(X, Y) & needs(Z, Y)
lib_supports_feature(X,"fX")

这将返回: [('lA',), ('lB',)] 因为它只是查找具有至少一个特征路径的任何库。

有没有一种好方法可以使用 pyDatalog 仅返回满足该功能所有需求的库?

4

2 回答 2

1

您需要使用双重否定:

missing(X,Y,Z) <= ( # Y is a missing output of X, and is needed by Z
               needs(Z, Y) 
               & has(X, Y1) # needed only if X is not bound
               & ~ has(X, Y))

lib_full_supports_feature(X,Z) <= ( # like supports, but there is no missing output
               has(X,Y) 
               & needs(Z,Y) 
               & ~ missing(X, Y1, Z))
于 2015-04-02T16:43:28.843 回答
1

您可以计算supported_and_needed 功能的数量,并将它们与所需功能的数量进行比较。如果它们相等,则满足所有功能需求。

(lib_num_supported_and_needed_features[X, Z] == len_(Y)) <= (has(X, Y) & needs(Z, Y))
(num_needed_features[Z] == len_(Y)) <= (needs(Z, Y))
lib_full_supports_features(X, Z) <= (num_needed_features[Z] == lib_num_supported_and_needed_features[X, Z])
于 2015-07-06T11:39:36.050 回答