Esempio n. 1
0
 /**
  * Convert a BDD that to a list of indices of this domain. Same as getVarIndices(BDD), except only
  * 'max' indices are extracted.
  *
  * @param bdd bdd that is the disjunction of domain indices
  * @param max maximum number of entries to be returned
  * @see #ithVar(long)
  */
 public BigInteger[] getVarIndices(BDD bdd, int max) {
   BDDVarSet myvarset = set(); // can't use var here, must respect subclass a factory may provide
   int n = (int) bdd.satCount(myvarset);
   if (max != -1 && n > max) n = max;
   BigInteger[] res = new BigInteger[n];
   BDDIterator it = bdd.iterator(myvarset);
   myvarset.free();
   for (int i = 0; i < n; i++) {
     res[i] = it.nextValue(this);
   }
   return res;
 }
Esempio n. 2
0
  static Set<Integer> setOf(BDD bdd, BDDDomain dom) {
    if (bdd == null) return null;

    Set<Integer> set = new HashSet<Integer>();
    if (bdd.isZero()) return set;

    BDDIterator itr = bdd.iterator(dom.set());
    while (itr.hasNext()) {
      BDD a = itr.nextBDD();
      set.add(a.scanVar(dom).intValue());
      a.free();
    }
    return set;
  }
Esempio n. 3
0
  /** Bug in JavaBDD. The method varRange does not work correctly. */
  @Test
  public void testVarRange() {
    BDDFactory factory = BDDFactory.init("cudd", 10000, 10000);
    BDDDomain[] doms = factory.extDomain(new long[] {8});

    BDD bdd = doms[0].varRange(2, 5);
    System.out.println(bdd.toStringWithDomains());

    HashSet<Integer> set = new HashSet<Integer>(Arrays.asList(2, 3, 4, 5));
    BDDIterator itr = bdd.iterator(doms[0].var);
    while (itr.hasNext()) {
      BDD tmp = itr.nextBDD();
      Assert.assertTrue(set.contains(tmp.scanVar(doms[0]).longValue()));
    }
    bdd.free();
    factory.done();
  }