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 グラフ チュートリアルを使用すると、機能に必要な出力を少なくとも 1 つ提供するライブラリを見つけることができます。

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

これは [('lA',), ('lB',)] を返します。機能へのパスが少なくとも 1 つあるライブラリを見つけているだけだからです。

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 に答える