使用CUDD交叉两个BDD

时间:2016-08-19 03:03:55

标签: binary-decision-diagram cudd

我想为以下两个布尔函数找到两个BDD的交集:

F=A'B'C'D'=1
G=A XOR B XOR C XOR D=1

这是我的代码:

 int main (int argc, char *argv[])
    {
        char filename[30];
        DdManager *gbm; /* Global BDD manager. */
        gbm = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); /* Initialize a new BDD manager. */
        DdNode *bdd, *var, *tmp_neg, *tmp,*f,*g;
        int i;
        bdd = Cudd_ReadOne(gbm); /*Returns the logic one constant of the manager*/
        Cudd_Ref(bdd); /*Increases the reference count of a node*/

        for (i = 3; i >= 0; i--) {
          var = Cudd_bddIthVar(gbm,i); /*Create a new BDD variable*/
          tmp_neg = Cudd_Not(var); /*Perform NOT Boolean operation*/
          tmp = Cudd_bddAnd(gbm, tmp_neg, bdd); /*Perform AND Boolean operation*/
          Cudd_Ref(tmp);
          Cudd_RecursiveDeref(gbm,bdd);
          f = tmp;
        }

        for (i = 3; i >= 0; i--) {
          var = Cudd_bddIthVar(gbm,i); /*Create a new BDD variable*/
          tmp = Cudd_bddXor(gbm, var, bdd); /*Perform AND Boolean operation*/
          Cudd_Ref(tmp);
          Cudd_RecursiveDeref(gbm,bdd);
          g = tmp;
        }
        bdd= Cudd_bddIntersect(gbm,f,g);/*Intersection between F and G */
        bdd = Cudd_BddToAdd(gbm, bdd); /*Convert BDD to ADD for display purpose*/
    print_dd (gbm, bdd, 2,4); /*Print the dd to standard output*/
    sprintf(filename, "./bdd/graph.dot"); /*Write .dot filename to a string*/
    write_dd(gbm, bdd, filename);  /*Write the resulting cascade dd to a file*/
    Cudd_Quit(gbm);
    return 0; 
}

这是我得到的结果:

DdManager nodes: 7 | DdManager vars: 4 | DdManager reorderings: 0 | DdManager memory: 8949888 
: 3 nodes 2 leaves 2 minterms
ID =  0xaa40f   index = 0   T = 0           E =  1        

0---  1

正如你在这里看到的那样,交叉点给出A = 0并且不关心B,C和D.我期待A,B,C和D的值满足F和G的要求。但显然A = 0不是F和G的解决方案。例如,某人可以选择A = 0,B = 1,其中函数F为0.这里有什么问题?

1 个答案:

答案 0 :(得分:1)

此回复非常晚,但只是为了解决问题,问题是Cudd_bddAndCudd_bddXor的最后一个操作数是bdd而不是fg。当然,fg都应该正确初始化(bdd当前初始化的方式)。以这种方式修复代码也将处理bdd的多个解引用,如果垃圾收集开始,这将导致悲痛。

此外,Cudd_bddIntersect不计算两个BDD的AND,而是计算AND的函数。如果想要证明两个BDD的连接没有计算整个结果(然后可能从中提取证据),就会使用它。

最后,bdd用作Cudd_BddToAdd的操作数和返回值的目标。这可以保证“泄漏”BDD节点。