是否可以使用 pyDatalog 检查是否满足所有数据依赖性?
Can pyDatalog be used to check if all data dependencies are satisfied?
我正在尝试使用 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")
这个 returns: [('lA',), ('lB',)] 因为它只是在寻找至少有一个特征路径的任何库。
是否有一种好方法 return 仅使用 pyDatalog 满足 所有 该功能需求的库?
你需要使用双重否定:
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))
您可以计算 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])
我正在尝试使用 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")
这个 returns: [('lA',), ('lB',)] 因为它只是在寻找至少有一个特征路径的任何库。
是否有一种好方法 return 仅使用 pyDatalog 满足 所有 该功能需求的库?
你需要使用双重否定:
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))
您可以计算 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])