From: John W. <joe...@us...> - 2005-05-21 09:55:06
|
Update of /cvsroot/javabdd/JavaBDD/net/sf/javabdd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19127/net/sf/javabdd Modified Files: BDD.java Log Message: Added tuple support to iterator. Index: BDD.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/BDD.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** BDD.java 21 May 2005 08:44:06 -0000 1.8 --- BDD.java 21 May 2005 09:54:46 -0000 1.9 *************** *** 608,615 **** } ! /* (non-Javadoc) ! * @see java.util.Iterator#next() */ ! public Object next() { if (allsatProfile == null) throw new NoSuchElementException(); --- 608,617 ---- } ! /** ! * Return the next satisfying var setting. ! * ! * @return byte[] */ ! public byte[] nextSat() { if (allsatProfile == null) throw new NoSuchElementException(); *************** *** 619,622 **** --- 621,631 ---- return b; } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() { + return nextSat(); + } /* (non-Javadoc) *************** *** 918,929 **** --- 927,1027 ---- } + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ public boolean hasNext() { return a != null; } + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ public Object next() { return nextBDD(); } + /** + * Return the next tuple of domain values in the iteration. + * + * @return the next tuple of domain values in the iteration. + */ + public BigInteger[] nextTuple() { + if (a == null) { + throw new NoSuchElementException(); + } + lastReturned = null; + BigInteger[] result = new BigInteger[f.numberOfDomains()]; + for (int i = 0; i < result.length; ++i) { + BDDDomain dom = f.getDomain(i); + int[] ivar = dom.vars(); + BigInteger val = BigInteger.ZERO; + for (int m = dom.varNum() - 1; m >= 0; m--) { + val = val.shiftLeft(1); + int level = f.var2Level(ivar[m]); + int k = Arrays.binarySearch(v, level); + if (k < 0) { + val = null; + break; + } + if (b[k]) { + val = val.add(BigInteger.ONE); + } + } + result[i] = val; + } + if (!gotoNextA()) { + gotoNext(); + } + return result; + } + + /** + * An alternate implementation of nextTuple(). + * This may be slightly faster than the default if there are many domains. + * + * @return the next tuple of domain values in the iteration. + */ + public BigInteger[] nextTuple2() { + boolean[] store = nextSat(); + BigInteger[] result = new BigInteger[f.numberOfDomains()]; + for (int i = 0; i < result.length; ++i) { + BDDDomain dom = f.getDomain(i); + int[] ivar = dom.vars(); + BigInteger val = BigInteger.ZERO; + for (int m = dom.varNum() - 1; m >= 0; m--) { + val = val.shiftLeft(1); + if (store[ivar[m]]) + val = val.add(BigInteger.ONE); + } + result[i] = val; + } + return result; + } + + /** + * Return the next single satisfying assignment in the iteration. + * + * @return the next single satisfying assignment in the iteration. + */ + public boolean[] nextSat() { + if (a == null) { + throw new NoSuchElementException(); + } + lastReturned = null; + boolean[] result = new boolean[f.varNum()]; + for (int i = 0; i < b.length; ++i) { + result[f.level2Var(v[i])] = b[i]; + } + if (!gotoNextA()) { + gotoNext(); + } + return result; + } + + /** + * Return the next BDD in the iteration. + * + * @return the next BDD in the iteration + */ public BDD nextBDD() { if (a == null) { *************** *** 995,999 **** int level = f.var2Level(var); int i = Arrays.binarySearch(v, level); ! if (i == -1 || a[i] != -1) throw new BDDException(); b[i] = true; --- 1093,1097 ---- int level = f.var2Level(var); int i = Arrays.binarySearch(v, level); ! if (i < 0 || a[i] != -1) throw new BDDException(); b[i] = true; |