Пример #1
0
  public static void main(String[] args) {
    BDDFactory bdd = init(1000000, 100000);

    System.out.println("One: " + CUDDFactory.one);
    System.out.println("Zero: " + CUDDFactory.zero);

    BDDDomain[] doms = bdd.extDomain(new int[] {50, 10, 15, 20, 15});

    BDD b = bdd.one();
    for (int i = 0; i < doms.length - 1; ++i) {
      b.andWith(doms[i].ithVar(i));
    }

    for (int i = 0; i < bdd.numberOfDomains(); ++i) {
      BDDDomain d = bdd.getDomain(i);
      int[] ivar = d.vars();
      System.out.print("Domain #" + i + ":");
      for (int j = 0; j < ivar.length; ++j) {
        System.out.print(' ');
        System.out.print(j);
        System.out.print(':');
        System.out.print(ivar[j]);
      }
      System.out.println();
    }

    BDDPairing p = bdd.makePair(doms[2], doms[doms.length - 1]);
    System.out.println("Pairing: " + p);

    System.out.println("Before replace(): " + b);
    BDD c = b.replace(p);
    System.out.println("After replace(): " + c);

    c.printDot();
  }
Пример #2
0
  /**
   * Builds a BDD which is true for all the possible assignments to the variable blocks that makes
   * the blocks equal.
   *
   * <p>Compare to fdd_equals/fdd_equ.
   *
   * @param that
   * @return BDD
   */
  public BDD buildEquals(BDDDomain that) {
    if (!this.size().equals(that.size())) {
      throw new BDDException(
          "Size of "
              + this
              + " != size of that "
              + that
              + "( "
              + this.size()
              + " vs "
              + that.size()
              + ")");
    }

    BDDFactory factory = getFactory();
    BDD e = factory.universe();

    int[] this_ivar = this.vars();
    int[] that_ivar = that.vars();

    for (int n = 0; n < this.varNum(); n++) {
      BDD a = factory.ithVar(this_ivar[n]);
      BDD b = factory.ithVar(that_ivar[n]);
      a.biimpWith(b);
      e.andWith(a);
    }

    return e;
  }
Пример #3
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;
  }
Пример #4
0
  public BDD buildAdd(BDDDomain that, int bits, long value) {
    if (bits > this.varNum() || bits > that.varNum())
      throw new BDDException(
          "Number of bits requested ("
              + bits
              + ") is larger than domain sizes "
              + this.varNum()
              + ","
              + that.varNum());

    BDDFactory bdd = getFactory();

    if (value == 0L) {
      BDD result = bdd.universe();
      int n;
      for (n = 0; n < bits; n++) {
        BDD b = bdd.ithVar(this.ivar[n]);
        b.biimpWith(bdd.ithVar(that.ivar[n]));
        result.andWith(b);
      }
      for (; n < Math.max(this.varNum(), that.varNum()); n++) {
        BDD b = (n < this.varNum()) ? bdd.nithVar(this.ivar[n]) : bdd.one();
        b.andWith((n < that.varNum()) ? bdd.nithVar(that.ivar[n]) : bdd.one());
        result.andWith(b);
      }
      return result;
    }

    int[] vars = new int[bits];
    System.arraycopy(this.ivar, 0, vars, 0, vars.length);
    BDDBitVector y = bdd.buildVector(vars);
    BDDBitVector v = bdd.constantVector(bits, value);
    BDDBitVector z = y.add(v);

    int[] thatvars = new int[bits];
    System.arraycopy(that.ivar, 0, thatvars, 0, thatvars.length);
    BDDBitVector x = bdd.buildVector(thatvars);
    BDD result = bdd.one();
    int n;
    for (n = 0; n < x.size(); n++) {
      BDD b = x.bitvec[n].biimp(z.bitvec[n]);
      result.andWith(b);
    }
    for (; n < Math.max(this.varNum(), that.varNum()); n++) {
      BDD b = (n < this.varNum()) ? bdd.nithVar(this.ivar[n]) : bdd.one();
      b.andWith((n < that.varNum()) ? bdd.nithVar(that.ivar[n]) : bdd.one());
      result.andWith(b);
    }
    x.free();
    y.free();
    z.free();
    v.free();
    return result;
  }
Пример #5
0
  @Test
  public void testIthVar() {
    BDDFactory factory = BDDFactory.init("cudd", 10000, 10000);
    BDDDomain[] doms = factory.extDomain(new long[] {4, 4});
    BDDDomain dom = doms[0];

    try {
      dom.ithVar(4);
    } catch (BDDException e) {
      System.out.println("falls through");
    }

    BDD a = dom.ithVar(0);
    Assert.assertEquals(1, setOf(a, dom).size());
    Assert.assertTrue(setOf(a, dom).contains(0));
    //		Assert.assertEquals(1, doms[0].usedbits);

    BDD b = dom.ithVar(1);
    //		Assert.assertEquals(1, doms[0].usedbits);

    BDD c = dom.ithVar(2);
    System.out.println(setOf(a, dom));
    Assert.assertEquals(1, setOf(a, dom).size()); // Wrong
    Assert.assertTrue(setOf(a, dom).contains(0));
    Assert.assertEquals(1, setOf(c, dom).size());
    Assert.assertTrue(setOf(c, dom).contains(2));
    //		Assert.assertEquals(2, doms[0].usedbits);

    BDD d = dom.ithVar(3);
    //		Assert.assertEquals(2, doms[0].usedbits);

    //		doms[0].extendCapacity(4);
    //		Assert.assertEquals(4, doms[0].ithVar(4).scanVar(doms[0]).intValue());
    //		Assert.assertEquals(4, doms[0].varNum());
    //
    //		doms[0].extendCapacity(50);
    //		Assert.assertEquals(50, doms[0].ithVar(50).scanVar(doms[0]).intValue());
    //		Assert.assertEquals(7, doms[0].varNum());
  }
Пример #6
0
 public BDD buildAdd(BDDDomain that, long value) {
   if (this.varNum() != that.varNum()) throw new BDDException();
   return buildAdd(that, this.varNum(), value);
 }