我试图使用pyDatalog来确定各种特性的依赖关系是否得到满足。一些图书馆(lA,lB,.)提供产出(1,2,.)这是特性(fX,fY,.)需要的。
例如:
+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只返回满足该特性所有需求的库的好方法?
发布于 2015-04-02 16:43:28
您需要使用双重否定:
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-07-06 11:39:36
您可以计算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])https://stackoverflow.com/questions/29407979
复制相似问题