[Javabdd-checkins] JavaBDD/net/sf/javabdd CALFactory.java,1.3,1.4 TestBDDFactory.java,1.3,1.4 JFacto
Brought to you by:
joewhaley
From: John W. <joe...@us...> - 2004-10-19 11:11:48
|
Update of /cvsroot/javabdd/JavaBDD/net/sf/javabdd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28180/net/sf/javabdd Modified Files: CALFactory.java TestBDDFactory.java JFactory.java JDDFactory.java BuDDyFactory.java CUDDFactory.java BDDFactory.java TypedBDDFactory.java BDD.java Log Message: Updates to support more features. Index: BDD.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/BDD.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BDD.java 16 Oct 2004 02:58:57 -0000 1.1 --- BDD.java 19 Oct 2004 11:11:35 -0000 1.2 *************** *** 6,15 **** import java.util.Arrays; import java.util.HashMap; - import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; - import java.util.Random; - import java.util.Set; import java.io.PrintStream; import java.math.BigInteger; --- 6,12 ---- *************** *** 692,696 **** * @return array of levels */ ! static int[] varset2levels(BDD r) { int size = 0; BDD p = r.id(); --- 689,693 ---- * @return array of levels */ ! private static int[] varset2levels(BDD r) { int size = 0; BDD p = r.id(); *************** *** 1363,1370 **** } ! static void fdd_printset_helper(OutputBuffer sb, ! BigInteger value, int i, ! int[] set, int[] var, ! int maxSkip) { if (i == maxSkip) { //_assert(set[var[i]] == 0); --- 1360,1367 ---- } ! private static void fdd_printset_helper(OutputBuffer sb, ! BigInteger value, int i, ! int[] set, int[] var, ! int maxSkip) { if (i == maxSkip) { //_assert(set[var[i]] == 0); *************** *** 1381,1385 **** } ! static void fdd_printset_rec(BDDFactory bdd, StringBuffer sb, BDDToString ts, BDD r, int[] set) { int fdvarnum = bdd.numberOfDomains(); --- 1378,1382 ---- } ! private static void fdd_printset_rec(BDDFactory bdd, StringBuffer sb, BDDToString ts, BDD r, int[] set) { int fdvarnum = bdd.numberOfDomains(); *************** *** 1515,1576 **** protected BDD() { } - public static void main(String[] args) { - BDDFactory bdd = BDDFactory.init(1000, 1000); - int domainSize = 1024; - bdd.extDomain(new int[] { domainSize, domainSize }); - BDDDomain d = bdd.getDomain(0); - BDDDomain d2 = bdd.getDomain(1); - Random r = new Random(); - int times = 1000; - int combine = 400; - for (int i = 0; i < times; ++i) { - int count = r.nextInt(combine); - BDD b = bdd.zero(); - for (int j = 0; j < count; ++j) { - int varNum = r.nextInt(domainSize); - BDD c = d.ithVar(varNum); //.andWith(d2.ithVar(domainSize - varNum - 1)); - b.orWith(c); - } - BDD var = d.set(); - Iterator i1 = b.iterator(var); - Iterator i2 = b.iterator2(var); - b.free(); - Set s1 = new HashSet(); - Set s2 = new HashSet(); - while (i1.hasNext()) { - BDD b1 = (BDD) i1.next(); - double sc = b1.satCount(var); - if (sc != 1.) { - System.out.println("Error, iterator() returned BDD with satcount "+sc+" : "+b1); - } - s1.add(b1); - } - while (i2.hasNext()) { - BDD b2 = (BDD) i2.next(); - double sc = b2.satCount(var); - if (sc != 1.) { - System.out.println("Error, iterator2() returned BDD with satcount "+sc+" : "+b2); - } - s2.add(b2); - } - var.free(); - if (!s1.equals(s2)) { - Set s1_minus_s2 = new HashSet(s1); - s1_minus_s2.removeAll(s2); - Set s2_minus_s1 = new HashSet(s2); - s2_minus_s1.removeAll(s1); - System.out.println("iterator() contains these extras: "+s1_minus_s2); - System.out.println("iterator2() contains these extras: "+s2_minus_s1); - } - for (Iterator k = s1.iterator(); k.hasNext(); ) { - BDD q = (BDD) k.next(); - q.free(); - } - for (Iterator k = s2.iterator(); k.hasNext(); ) { - BDD q = (BDD) k.next(); - q.free(); - } - } - } - } --- 1512,1514 ---- Index: TestBDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/TestBDDFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TestBDDFactory.java 18 Oct 2004 09:45:43 -0000 1.3 --- TestBDDFactory.java 19 Oct 2004 11:11:35 -0000 1.4 *************** *** 862,865 **** --- 862,875 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + int r1 = f1.getCacheSize(); + int r2 = f2.getCacheSize(); + assertSame(r1 == r2, "getCacheSize"); + return r1; + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#reorderGain() */ Index: JFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/JFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JFactory.java 19 Oct 2004 04:34:48 -0000 1.4 --- JFactory.java 19 Oct 2004 11:11:35 -0000 1.5 *************** *** 41,47 **** */ public static BDDFactory init(int nodenum, int cachesize) { ! BDDFactory INSTANCE = new JFactory(); ! INSTANCE.initialize(nodenum, cachesize); ! return INSTANCE; } --- 41,47 ---- */ public static BDDFactory init(int nodenum, int cachesize) { ! BDDFactory f = new JFactory(); ! f.initialize(nodenum, cachesize); ! return f; } *************** *** 2981,2986 **** } - newsize = bdd_prime_lte(newsize); - return doResize(doRehash, oldsize, newsize); } --- 2981,2984 ---- *************** *** 2997,3003 **** int doResize(boolean doRehash, int oldsize, int newsize) { ! if (oldsize > newsize) { ! return bdd_error(BDD_RANGE); ! } bddnodesize = newsize; --- 2995,3001 ---- int doResize(boolean doRehash, int oldsize, int newsize) { ! newsize = bdd_prime_lte(newsize); ! ! if (oldsize > newsize) return 0; bddnodesize = newsize; *************** *** 5453,5456 **** --- 5451,5461 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + return cachesize; + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#reorderGain() */ Index: BDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/BDDFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BDDFactory.java 19 Oct 2004 04:34:48 -0000 1.3 --- BDDFactory.java 19 Oct 2004 11:11:35 -0000 1.4 *************** *** 160,165 **** protected BDDFactory() { String s = this.getClass().toString(); ! s = s.substring(s.lastIndexOf('.')+1); ! System.out.println("Using BDD package: "+s); } --- 160,167 ---- protected BDDFactory() { String s = this.getClass().toString(); ! if (false) { ! s = s.substring(s.lastIndexOf('.')+1); ! System.out.println("Using BDD package: "+s); ! } } *************** *** 257,262 **** /** ! * <p>Resets the BDD package. This function frees all memory used by the BDD ! * package and resets the package to its initial state.</p> * * <p>Compare to bdd_done.</p> --- 259,277 ---- /** ! * <p>Reset the BDD factory to its initial state. Everything ! * is reallocated from scratch. This is like calling done() ! * followed by initialize().</p> ! */ ! public void reset() { ! int nodes = getNodeTableSize(); ! int cache = getCacheSize(); ! done(); ! initialize(nodes, cache); ! } ! ! /** ! * <p>This function frees all memory used by the BDD ! * package and resets the package to its uninitialized state. ! * The BDD package is no longer usable after this call.</p> * * <p>Compare to bdd_done.</p> *************** *** 977,980 **** --- 992,1002 ---- /** + * <p>Get the current size of the cache, in entries.</p> + * + * @return size of cache + */ + public abstract int getCacheSize(); + + /** * <p>Calculate the gain in size after a reordering. The value returned is * (100*(A-B))/A, where A is previous number of used nodes and B is current Index: TypedBDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/TypedBDDFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TypedBDDFactory.java 18 Oct 2004 09:45:43 -0000 1.3 --- TypedBDDFactory.java 19 Oct 2004 11:11:35 -0000 1.4 *************** *** 364,367 **** --- 364,374 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + return factory.getCacheSize(); + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#reorderGain() */ Index: JDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/JDDFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JDDFactory.java 18 Oct 2004 09:38:18 -0000 1.3 --- JDDFactory.java 19 Oct 2004 11:11:35 -0000 1.4 *************** *** 31,36 **** */ public static BDDFactory init(int nodenum, int cachesize) { ! BDDFactory INSTANCE = new JDDFactory(nodenum, cachesize); ! return INSTANCE; } --- 31,36 ---- */ public static BDDFactory init(int nodenum, int cachesize) { ! BDDFactory f = new JDDFactory(nodenum, cachesize); ! return f; } *************** *** 605,608 **** --- 605,616 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + // TODO Implement this. + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#setCacheRatio(int) */ Index: BuDDyFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/BuDDyFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BuDDyFactory.java 19 Oct 2004 09:13:59 -0000 1.4 --- BuDDyFactory.java 19 Oct 2004 11:11:35 -0000 1.5 *************** *** 8,11 **** --- 8,15 ---- import java.util.Iterator; import java.util.List; + import java.io.File; + import java.io.FileInputStream; + import java.io.FileOutputStream; + import java.io.IOException; import java.math.BigInteger; *************** *** 36,47 **** public static BDDFactory init(int nodenum, int cachesize) { ! if (INSTANCE != null) { ! throw new InternalError("Error: BDDFactory already initialized."); ! } ! INSTANCE = new BuDDyFactory(); ! INSTANCE.initialize(nodenum, cachesize); ! return INSTANCE; } private static BuDDyFactory INSTANCE; --- 40,51 ---- public static BDDFactory init(int nodenum, int cachesize) { ! BuDDyFactory f = new BuDDyFactory(); ! f.initialize(nodenum, cachesize); ! return f; } + /** + * Single factory instance. Only one factory object is enabled at a time. + */ private static BuDDyFactory INSTANCE; *************** *** 55,68 **** String currentdir = System.getProperty("user.dir"); String sep = System.getProperty("file.separator"); ! System.load(currentdir+sep+libname); } registerNatives(); } private static native void registerNatives(); private BuDDyFactory() {} ! static final boolean USE_FINALIZER = false; private static BuDDyBDD makeBDD(int id) { --- 59,100 ---- String currentdir = System.getProperty("user.dir"); String sep = System.getProperty("file.separator"); ! String filename = currentdir+sep+libname; ! try { ! System.load(filename); ! } catch (java.lang.UnsatisfiedLinkError y) { ! File f = new File(filename); ! if (!f.exists()) throw y; ! // Try to make a copy and use that. ! try { ! File f2 = File.createTempFile("buddy", ".dll"); ! copyFile(f, f2); ! f2.deleteOnExit(); ! System.out.println("buddy.dll is in use, linking temporary copy "+f2); ! System.load(f2.getAbsolutePath()); ! } catch (IOException z) { ! throw y; ! } ! } } registerNatives(); } + private static void copyFile(File in, File out) throws IOException { + FileInputStream fis = new FileInputStream(in); + FileOutputStream fos = new FileOutputStream(out); + byte[] buf = new byte[1024]; + int i = 0; + while ((i = fis.read(buf)) != -1) { + fos.write(buf, 0, i); + } + fis.close(); + fos.close(); + } + private static native void registerNatives(); private BuDDyFactory() {} ! private static final boolean USE_FINALIZER = false; private static BuDDyBDD makeBDD(int id) { *************** *** 139,142 **** --- 171,177 ---- */ protected void initialize(int nodenum, int cachesize) { + if (INSTANCE != null) + throw new InternalError("Error: BDDFactory already initialized."); + INSTANCE = this; initialize0(nodenum, cachesize); } *************** *** 165,168 **** --- 200,214 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#reset() + */ + public void reset() { + if (USE_FINALIZER) { + System.gc(); + System.runFinalization(); + } + super.reset(); + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#setError(int) */ *************** *** 488,491 **** --- 534,545 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + return getCacheSize0(); + } + private static native int getCacheSize0(); + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#getNodeNum() */ Index: CUDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/CUDDFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CUDDFactory.java 18 Oct 2004 09:45:43 -0000 1.3 --- CUDDFactory.java 19 Oct 2004 11:11:35 -0000 1.4 *************** *** 39,48 **** public static BDDFactory init(int nodenum, int cachesize) { ! if (INSTANCE != null) { ! throw new InternalError("Error: CUDDFactory already initialized."); ! } ! INSTANCE = new CUDDFactory(); ! INSTANCE.initialize(nodenum/256, cachesize); ! return INSTANCE; } --- 39,45 ---- public static BDDFactory init(int nodenum, int cachesize) { ! CUDDFactory f = new CUDDFactory(); ! f.initialize(nodenum/256, cachesize); ! return f; } *************** *** 88,91 **** --- 85,92 ---- */ protected void initialize(int nodenum, int cachesize) { + if (INSTANCE != null) { + throw new InternalError("Error: CUDDFactory already initialized."); + } + INSTANCE = this; initialize0(nodenum, cachesize); } *************** *** 404,407 **** --- 405,416 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + // TODO Implement this. + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#reorderGain() */ Index: CALFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/net/sf/javabdd/CALFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CALFactory.java 18 Oct 2004 09:45:43 -0000 1.3 --- CALFactory.java 19 Oct 2004 11:11:34 -0000 1.4 *************** *** 39,48 **** public static BDDFactory init(int nodenum, int cachesize) { ! if (INSTANCE != null) { ! throw new InternalError("Error: CALFactory already initialized."); ! } ! INSTANCE = new CALFactory(); ! INSTANCE.initialize(nodenum/256, cachesize); ! return INSTANCE; } --- 39,45 ---- public static BDDFactory init(int nodenum, int cachesize) { ! CALFactory f = new CALFactory(); ! f.initialize(nodenum/256, cachesize); ! return f; } *************** *** 88,91 **** --- 85,92 ---- */ protected void initialize(int nodenum, int cachesize) { + if (INSTANCE != null) { + throw new InternalError("Error: CALFactory already initialized."); + } + INSTANCE = this; initialize0(nodenum, cachesize); } *************** *** 369,372 **** --- 370,381 ---- /* (non-Javadoc) + * @see net.sf.javabdd.BDDFactory#getCacheSize() + */ + public int getCacheSize() { + // TODO Implement this. + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#getNodeNum() */ |