首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以使用pyDatalog来检查是否满足所有数据依赖?

是否可以使用pyDatalog来检查是否满足所有数据依赖?
EN

Stack Overflow用户
提问于 2015-04-02 08:07:19
回答 2查看 130关注 0票数 0

我试图使用pyDatalog来确定各种特性的依赖关系是否得到满足。一些图书馆(lA,lB,.)提供产出(1,2,.)这是特性(fX,fY,.)需要的。

例如:

代码语言:javascript
复制
+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图形教程,我可以找到至少提供一个特性所需输出的库:

代码语言:javascript
复制
lib_supports_feature(X, Z) <= has(X, Y) & needs(Z, Y)
lib_supports_feature(X,"fX")

这会返回:('lA',),('lB‘),因为它只是找到至少有一个路径的任何库。

是否有一种使用pyDatalog只返回满足该特性所有需求的库的好方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-04-02 16:43:28

您需要使用双重否定:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2015-07-06 11:39:36

您可以计算supported_and_needed特性的数量,并将它们与所需特性的数量进行比较。如果它们是平等的,那么所有的功能需求都会得到满足。

代码语言:javascript
复制
(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])
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29407979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档