带有变量子集的JavaBDD sat计数

带有变量子集的JavaBDD sat计数,java,binary-decision-diagram,Java,Binary Decision Diagram,我正在使用JavaBDD对BDD进行一些计算。 我有一个非常大的BDD,它包含许多变量,我想计算有多少方法可以满足这些变量的一小部分 我当前的尝试如下所示: // var 1,2,3 are BDDVarSets with 1 variable. BDDVarSet union = var1; union = union.union(var2); union = union.union(var3); BDD varSet restOfVars = allVars.minus(union); B

我正在使用JavaBDD对BDD进行一些计算。 我有一个非常大的BDD,它包含许多变量,我想计算有多少方法可以满足这些变量的一小部分

我当前的尝试如下所示:

// var 1,2,3 are BDDVarSets with 1 variable.
BDDVarSet union = var1;
union = union.union(var2);
union = union.union(var3);

BDD varSet restOfVars = allVars.minus(union);
BDD result = largeBdd.exist(restOfVars);

double sats = result.satCount(); // Returns a very large number (way too large).
double partSats = result.satCount(union) // Returns an inccorrect number. It is documented that this should not work.

exist()的用法不正确吗?

经过一番尝试,我明白了我的问题所在

double partSats = result.satCount(union);
是否返回正确答案。它所做的是计算有多少可能的解,并将解除以2^(#变量在集合中)

我认为
satCount(union)
不起作用的原因是代码中其他地方错误使用了
exist()

以下是SATCONND(varSet)的实现,以供参考:

  /**
   * <p>Calculates the number of satisfying variable assignments to the variables
   * in the given varset.  ASSUMES THAT THE BDD DOES NOT HAVE ANY ASSIGNMENTS TO
   * VARIABLES THAT ARE NOT IN VARSET.  You will need to quantify out the other
   * variables first.</p>
   * 
   * <p>Compare to bdd_satcountset.</p>
   * 
   * @return the number of satisfying variable assignments
   */
  public double satCount(BDDVarSet varset) {
    BDDFactory factory = getFactory();

    if (varset.isEmpty() || isZero()) /* empty set */
      return 0.;

    double unused = factory.varNum();
    unused -= varset.size();
    unused = satCount() / Math.pow(2.0, unused);

    return unused >= 1.0 ? unused : 1.0;
  }
/**
*计算满足变量分配的变量数
*在给定的变量集中。假设BDD没有任何分配给
*不在变量集中的变量。你需要量化出另一个
*首先是变量

* *与bdd_satcountset比较

* *@返回满足的变量赋值数 */ 公共双satCount(BDDVarSet varset){ BDDFactory factory=getFactory(); if(varset.isEmpty()| | isZero())/*空集*/ 返回0。; double unused=factory.varNum(); 未使用-=varset.size(); unused=satCount()/Math.pow(2.0,unused); 返回未使用>=1.0?未使用:1.0; }
玩了一会儿之后,我明白了我的问题所在

double partSats = result.satCount(union);
是否返回正确答案。它所做的是计算有多少可能的解,并将解除以2^(#变量在集合中)

我认为
satCount(union)
不起作用的原因是代码中其他地方错误使用了
exist()

以下是SATCONND(varSet)的实现,以供参考:

  /**
   * <p>Calculates the number of satisfying variable assignments to the variables
   * in the given varset.  ASSUMES THAT THE BDD DOES NOT HAVE ANY ASSIGNMENTS TO
   * VARIABLES THAT ARE NOT IN VARSET.  You will need to quantify out the other
   * variables first.</p>
   * 
   * <p>Compare to bdd_satcountset.</p>
   * 
   * @return the number of satisfying variable assignments
   */
  public double satCount(BDDVarSet varset) {
    BDDFactory factory = getFactory();

    if (varset.isEmpty() || isZero()) /* empty set */
      return 0.;

    double unused = factory.varNum();
    unused -= varset.size();
    unused = satCount() / Math.pow(2.0, unused);

    return unused >= 1.0 ? unused : 1.0;
  }
/**
*计算满足变量分配的变量数
*在给定的变量集中。假设BDD没有任何分配给
*不在变量集中的变量。你需要量化出另一个
*首先是变量

* *与bdd_satcountset比较

* *@返回满足的变量赋值数 */ 公共双satCount(BDDVarSet varset){ BDDFactory factory=getFactory(); if(varset.isEmpty()| | isZero())/*空集*/ 返回0。; double unused=factory.varNum(); 未使用-=varset.size(); unused=satCount()/Math.pow(2.0,unused); 返回未使用>=1.0?未使用:1.0; }