我正在尝试使用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有没有一种方法只返回满足所有需要的库?
答案 0 :(得分: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))
答案 1 :(得分: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])