Reputation: 148
I am trying to use pyDatalog to determine if the dependencies for various features are satisfied. Some library (lA,lB,...) provides outputs (1,2,...) which are needed by features (fX,fY,...).
For example:
+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
Using the pyDatalog graph tutorials I can find libraries that provide at least one of the outputs required for a feature:
lib_supports_feature(X, Z) <= has(X, Y) & needs(Z, Y)
lib_supports_feature(X,"fX")
This returns: [('lA',), ('lB',)] because it is merely finding any library with at least one path to the feature.
Is there a good way to return only the libraries that meet all the needs of that feature using pyDatalog?
Upvotes: 0
Views: 138
Reputation: 145
You can count the number of supported_and_needed features and compare them with the number of needed features. If they are equal all feature needs are meet.
(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])
Upvotes: 1
Reputation: 2625
You need to use a double negation :
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))
Upvotes: 1