From: John W. <joe...@us...> - 2004-07-28 09:19:43
|
Update of /cvsroot/javabdd/JavaBDD In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7639 Modified Files: NQueens.java Log Message: Refactored for use in test cases. Index: NQueens.java =================================================================== RCS file: /cvsroot/javabdd/JavaBDD/NQueens.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** NQueens.java 28 Jul 2004 08:39:12 -0000 1.13 --- NQueens.java 28 Jul 2004 09:19:29 -0000 1.14 *************** *** 7,13 **** --- 7,15 ---- public static BDDFactory B; + public static boolean TRACE; public static int N; /* Size of the chess board */ public static BDD[][] X; /* BDD variable array */ public static BDD queen; /* N-queen problem expressed as a BDD */ + public static BDD solution; /* One solution */ public static void main(String[] args) { *************** *** 21,43 **** return; } ! long time = System.currentTimeMillis(); ! /* Initialize with reasonable nodes and cache size and NxN variables */ ! String numOfNodes = System.getProperty("bddnodes"); ! int numberOfNodes; ! if (numOfNodes == null) ! numberOfNodes = (int) (Math.pow(4.42, N-6))*1000; ! else ! numberOfNodes = Integer.parseInt(numOfNodes); ! String cache = System.getProperty("bddcache"); ! int cacheSize; ! if (cache == null) ! cacheSize = 1000; ! else ! cacheSize = Integer.parseInt(cache); ! numberOfNodes = Math.max(1000, numberOfNodes); ! B = BDDFactory.init(numberOfNodes, cacheSize); ! B.setVarNum(N * N); queen = B.one(); --- 23,57 ---- return; } ! ! TRACE = true; long time = System.currentTimeMillis(); + runTest(); + freeAll(); + time = System.currentTimeMillis() - time; + System.out.println("Time: "+time/1000.+" seconds"); + B.done(); + B = null; + } ! public static double runTest() { ! ! if (B == null) { ! /* Initialize with reasonable nodes and cache size and NxN variables */ ! String numOfNodes = System.getProperty("bddnodes"); ! int numberOfNodes; ! if (numOfNodes == null) ! numberOfNodes = (int) (Math.pow(4.42, N-6))*1000; ! else ! numberOfNodes = Integer.parseInt(numOfNodes); ! String cache = System.getProperty("bddcache"); ! int cacheSize; ! if (cache == null) ! cacheSize = 1000; ! else ! cacheSize = Integer.parseInt(cache); ! numberOfNodes = Math.max(1000, numberOfNodes); ! B = BDDFactory.init(numberOfNodes, cacheSize); ! } ! if (B.varNum() < N * N) B.setVarNum(N * N); queen = B.one(); *************** *** 63,92 **** for (i = 0; i < N; i++) for (j = 0; j < N; j++) { ! System.out.print("Adding position " + i + "," + j+" \r"); build(i, j); } /* Print the results */ ! System.out.println("There are " + (long) queen.satCount() + " solutions."); ! BDD solution = queen.satOne(); ! System.out.println("Here is "+(long) solution.satCount() + " solution:"); ! solution.printSet(); ! System.out.println(); ! ! solution.free(); ! freeAll(); ! B.done(); ! time = System.currentTimeMillis() - time; ! System.out.println("Time: "+time/1000.+" seconds"); } ! static void freeAll() { ! queen.free(); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) X[i][j].free(); } ! static void build(int i, int j) { BDD a = B.one(), b = B.one(), c = B.one(), d = B.one(); --- 77,107 ---- for (i = 0; i < N; i++) for (j = 0; j < N; j++) { ! if (TRACE) System.out.print("Adding position " + i + "," + j+" \r"); build(i, j); } + solution = queen.satOne(); + + double result = queen.satCount(); /* Print the results */ ! if (TRACE) { ! System.out.println("There are " + (long) result + " solutions."); ! double result2 = solution.satCount(); ! System.out.println("Here is "+(long) result2 + " solution:"); ! solution.printSet(); ! System.out.println(); ! } ! return result; } ! public static void freeAll() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) X[i][j].free(); + queen.free(); + solution.free(); } ! static void build(int i, int j) { BDD a = B.one(), b = B.one(), c = B.one(), d = B.one(); |