From: John W. <joe...@us...> - 2004-07-29 03:43:34
|
Update of /cvsroot/javabdd/JavaBDD/org/sf/javabdd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23721/org/sf/javabdd Modified Files: JFactory.java BDDFactory.java FindBestOrder.java Log Message: Change to buffered IO Index: FindBestOrder.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/org/sf/javabdd/FindBestOrder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FindBestOrder.java 27 Jul 2004 23:20:03 -0000 1.8 --- FindBestOrder.java 29 Jul 2004 03:43:21 -0000 1.9 *************** *** 5,14 **** import java.util.StringTokenizer; - import java.io.BufferedReader; ! import java.io.DataOutputStream; import java.io.File; - import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.math.BigInteger; --- 5,13 ---- import java.util.StringTokenizer; import java.io.BufferedReader; ! import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; + import java.io.FileWriter; import java.io.IOException; import java.math.BigInteger; *************** *** 91,100 **** public void writeBDDConfig(BDDFactory bdd, String fileName) throws IOException { ! DataOutputStream dos = null; try { ! dos = new DataOutputStream(new FileOutputStream(fileName)); for (int i = 0; i < bdd.numberOfDomains(); ++i) { BDDDomain d = bdd.getDomain(i); ! dos.writeBytes(d.getName()+" "+d.size()+"\n"); } } finally { --- 90,99 ---- public void writeBDDConfig(BDDFactory bdd, String fileName) throws IOException { ! BufferedWriter dos = null; try { ! dos = new BufferedWriter(new FileWriter(fileName)); for (int i = 0; i < bdd.numberOfDomains(); ++i) { BDDDomain d = bdd.getDomain(i); ! dos.write(d.getName()+" "+d.size()+"\n"); } } finally { Index: BDDFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/org/sf/javabdd/BDDFactory.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** BDDFactory.java 28 Jul 2004 09:36:57 -0000 1.24 --- BDDFactory.java 29 Jul 2004 03:43:21 -0000 1.25 *************** *** 8,17 **** import java.util.Map; import java.util.StringTokenizer; ! import java.io.DataInput; ! import java.io.DataInputStream; ! import java.io.DataOutput; ! import java.io.DataOutputStream; ! import java.io.FileInputStream; ! import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; --- 8,15 ---- import java.util.Map; import java.util.StringTokenizer; ! import java.io.BufferedReader; ! import java.io.BufferedWriter; ! import java.io.FileReader; ! import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.InvocationTargetException; *************** *** 364,379 **** */ public BDD load(String filename) throws IOException { ! DataInputStream is = null; try { ! is = new DataInputStream(new FileInputStream(filename)); ! BDD result = load(is); return result; } finally { ! if (is != null) try { is.close(); } catch (IOException _) { } } } // TODO: error code from bdd_load (?) ! public BDD load(DataInput ifile) throws IOException { tokenizer = null; --- 362,377 ---- */ public BDD load(String filename) throws IOException { ! BufferedReader r = null; try { ! r = new BufferedReader(new FileReader(filename)); ! BDD result = load(r); return result; } finally { ! if (r != null) try { r.close(); } catch (IOException _) { } } } // TODO: error code from bdd_load (?) ! public BDD load(BufferedReader ifile) throws IOException { tokenizer = null; *************** *** 448,452 **** StringTokenizer tokenizer; ! String readNext(DataInput ifile) throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String s = ifile.readLine(); --- 446,450 ---- StringTokenizer tokenizer; ! String readNext(BufferedReader ifile) throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String s = ifile.readLine(); *************** *** 486,492 **** */ public void save(String filename, BDD var) throws IOException { ! DataOutputStream is = null; try { ! is = new DataOutputStream(new FileOutputStream(filename)); save(is, var); } finally { --- 484,490 ---- */ public void save(String filename, BDD var) throws IOException { ! BufferedWriter is = null; try { ! is = new BufferedWriter(new FileWriter(filename)); save(is, var); } finally { *************** *** 496,510 **** // TODO: error code from bdd_save (?) ! public void save(DataOutput out, BDD r) throws IOException { if (r.isOne() || r.isZero()) { ! out.writeBytes("0 0 " + (r.isOne()?1:0) + "\n"); return; } ! out.writeBytes(r.nodeCount() + " " + varNum() + "\n"); for (int x = 0; x < varNum(); x++) ! out.writeBytes(var2Level(x) + " "); ! out.writeBytes("\n"); Map visited = new HashMap(); --- 494,508 ---- // TODO: error code from bdd_save (?) ! public void save(BufferedWriter out, BDD r) throws IOException { if (r.isOne() || r.isZero()) { ! out.write("0 0 " + (r.isOne()?1:0) + "\n"); return; } ! out.write(r.nodeCount() + " " + varNum() + "\n"); for (int x = 0; x < varNum(); x++) ! out.write(var2Level(x) + " "); ! out.write("\n"); Map visited = new HashMap(); *************** *** 517,521 **** } ! protected int save_rec(DataOutput out, Map visited, BDD root) throws IOException { if (root.isZero()) { root.free(); --- 515,519 ---- } ! protected int save_rec(BufferedWriter out, Map visited, BDD root) throws IOException { if (root.isZero()) { root.free(); *************** *** 540,547 **** int hi = save_rec(out, visited, h); ! out.writeBytes(v + " "); ! out.writeBytes(root.var() + " "); ! out.writeBytes(lo + " "); ! out.writeBytes(hi + "\n"); return v; --- 538,545 ---- int hi = save_rec(out, visited, h); ! out.write(v + " "); ! out.write(root.var() + " "); ! out.write(lo + " "); ! out.write(hi + "\n"); return v; Index: JFactory.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/org/sf/javabdd/JFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JFactory.java 28 Jul 2004 01:58:06 -0000 1.4 --- JFactory.java 29 Jul 2004 03:43:21 -0000 1.5 *************** *** 12,17 **** import java.util.Random; import java.util.StringTokenizer; ! import java.io.DataInput; ! import java.io.DataOutput; import java.io.IOException; import java.io.PrintStream; --- 12,17 ---- import java.util.Random; import java.util.StringTokenizer; ! import java.io.BufferedReader; ! import java.io.BufferedWriter; import java.io.IOException; import java.io.PrintStream; *************** *** 623,627 **** int[] bddvar2level; /* Variable -> level table */ int[] bddlevel2var; /* Level -> variable table */ ! int bddresized; /* Flag indicating a resize of the nodetable */ int minfreenodes = 20; --- 623,627 ---- int[] bddvar2level; /* Variable -> level table */ int[] bddlevel2var; /* Level -> variable table */ ! boolean bddresized; /* Flag indicating a resize of the nodetable */ int minfreenodes = 20; *************** *** 808,814 **** void checkresize() { ! if (bddresized != 0) bdd_operator_noderesize(); ! bddresized = 0; } --- 808,814 ---- void checkresize() { ! if (bddresized) bdd_operator_noderesize(); ! bddresized = false; } *************** *** 1268,1271 **** --- 1268,1335 ---- } + int relprod_rec(int l, int r) { + BddCacheDataI entry; + int res; + + if (l == 0 || r == 0) + return 0; + if (l == r) + return quant_rec(l); + if (l == 1) + return quant_rec(r); + if (r == 1) + return quant_rec(l); + + int LEVEL_l = LEVEL(l); + int LEVEL_r = LEVEL(r); + if (LEVEL_l > quantlast && LEVEL_r > quantlast) { + int oldop = applyop; + applyop = appexop; + res = apply_rec(l, r); + applyop = oldop; + } else { + entry = BddCache_lookupI(appexcache, APPEXHASH(l, r, appexop)); + if (entry.a == l && entry.b == r && entry.c == appexid) { + if (CACHESTATS) + bddcachestats.opHit++; + return entry.res; + } + if (CACHESTATS) + bddcachestats.opMiss++; + + if (LEVEL_l == LEVEL_r) { + PUSHREF(relprod_rec(LOW(l), LOW(r))); + PUSHREF(relprod_rec(HIGH(l), HIGH(r))); + if (INVARSET(LEVEL_l)) + res = apply_rec(READREF(2), READREF(1)); + else + res = bdd_makenode(LEVEL_l, READREF(2), READREF(1)); + } else if (LEVEL_l < LEVEL_r) { + PUSHREF(relprod_rec(LOW(l), r)); + PUSHREF(relprod_rec(HIGH(l), r)); + if (INVARSET(LEVEL_l)) + res = apply_rec(READREF(2), READREF(1)); + else + res = bdd_makenode(LEVEL_l, READREF(2), READREF(1)); + } else { + PUSHREF(relprod_rec(l, LOW(r))); + PUSHREF(relprod_rec(l, HIGH(r))); + if (INVARSET(LEVEL_r)) + res = apply_rec(READREF(2), READREF(1)); + else + res = bdd_makenode(LEVEL_r, READREF(2), READREF(1)); + } + + POPREF(2); + + entry.a = l; + entry.b = r; + entry.c = appexid; + entry.res = res; + } + + return res; + } + int bdd_relprod(int a, int b, int var) { return bdd_appex(a, b, bddop_and, var); *************** *** 1301,1305 **** if (firstReorder == 0) bdd_disable_reorder(); ! res = appquant_rec(l, r); if (firstReorder == 0) bdd_enable_reorder(); --- 1365,1369 ---- if (firstReorder == 0) bdd_disable_reorder(); ! res = opr == -1 ? relprod_rec(l, r) : appquant_rec(l, r); if (firstReorder == 0) bdd_enable_reorder(); *************** *** 2872,2876 **** bdd_gbc_rehash(); ! bddresized = 1; return 0; --- 2936,2940 ---- bdd_gbc_rehash(); ! bddresized = true; return 0; *************** *** 2890,2894 **** bddnodes = new int[bddnodesize*__node_size]; ! bddresized = 0; for (n = 0; n < bddnodesize; n++) { --- 2954,2958 ---- bddnodes = new int[bddnodesize*__node_size]; ! bddresized = false; for (n = 0; n < bddnodesize; n++) { *************** *** 4291,4297 **** /* (non-Javadoc) ! * @see org.sf.javabdd.BDDFactory#load(java.io.DataInput) */ ! public BDD load(DataInput in) throws IOException { int result = bdd_load(in); return new bdd(result); --- 4355,4361 ---- /* (non-Javadoc) ! * @see org.sf.javabdd.BDDFactory#load(java.io.BufferedReader) */ ! public BDD load(BufferedReader in) throws IOException { int result = bdd_load(in); return new bdd(result); *************** *** 4299,4305 **** /* (non-Javadoc) ! * @see org.sf.javabdd.BDDFactory#save(java.io.DataOutput, org.sf.javabdd.BDD) */ ! public void save(DataOutput out, BDD b) throws IOException { int x = ((bdd) b)._index; bdd_save(out, x); --- 4363,4369 ---- /* (non-Javadoc) ! * @see org.sf.javabdd.BDDFactory#save(java.io.BufferedWriter, org.sf.javabdd.BDD) */ ! public void save(BufferedWriter out, BDD b) throws IOException { int x = ((bdd) b)._index; bdd_save(out, x); *************** *** 5385,5389 **** StringTokenizer tokenizer; ! String readNext(DataInput ifile) throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String s = ifile.readLine(); --- 5449,5453 ---- StringTokenizer tokenizer; ! String readNext(BufferedReader ifile) throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String s = ifile.readLine(); *************** *** 5395,5399 **** } ! int bdd_load(DataInput ifile) throws IOException { int n, vnum, tmproot; int root; --- 5459,5463 ---- } ! int bdd_load(BufferedReader ifile) throws IOException { int n, vnum, tmproot; int root; *************** *** 5448,5452 **** } ! int bdd_loaddata(DataInput ifile) throws IOException { int key, var, low, high, root = 0, n; --- 5512,5516 ---- } ! int bdd_loaddata(BufferedReader ifile) throws IOException { int key, var, low, high, root = 0, n; *************** *** 5496,5504 **** } ! void bdd_save(DataOutput out, int r) throws IOException { int[] n = new int[1]; if (r < 2) { ! out.writeBytes("0 0 " + r + "\n"); return; } --- 5560,5568 ---- } ! void bdd_save(BufferedWriter out, int r) throws IOException { int[] n = new int[1]; if (r < 2) { ! out.write("0 0 " + r + "\n"); return; } *************** *** 5506,5514 **** bdd_markcount(r, n); bdd_unmark(r); ! out.writeBytes(n[0] + " " + bddvarnum + "\n"); for (int x = 0; x < bddvarnum; x++) ! out.writeBytes(bddvar2level[x] + " "); ! out.writeBytes("\n"); bdd_save_rec(out, r); --- 5570,5578 ---- bdd_markcount(r, n); bdd_unmark(r); ! out.write(n[0] + " " + bddvarnum + "\n"); for (int x = 0; x < bddvarnum; x++) ! out.write(bddvar2level[x] + " "); ! out.write("\n"); bdd_save_rec(out, r); *************** *** 5518,5522 **** } ! void bdd_save_rec(DataOutput out, int root) throws IOException { if (root < 2) --- 5582,5586 ---- } ! void bdd_save_rec(BufferedWriter out, int root) throws IOException { if (root < 2) *************** *** 5530,5537 **** bdd_save_rec(out, HIGH(root)); ! out.writeBytes(root + " "); ! out.writeBytes(bddlevel2var[LEVEL(root)] + " "); ! out.writeBytes(LOW(root) + " "); ! out.writeBytes(HIGH(root) + "\n"); return; --- 5594,5601 ---- bdd_save_rec(out, HIGH(root)); ! out.write(root + " "); ! out.write(bddlevel2var[LEVEL(root)] + " "); ! out.write(LOW(root) + " "); ! out.write(HIGH(root) + "\n"); return; |