javabdd-checkins Mailing List for JavaBDD
Brought to you by:
joewhaley
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(4) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
|
Feb
|
Mar
(6) |
Apr
(6) |
May
(4) |
Jun
(31) |
Jul
(64) |
Aug
(19) |
Sep
(28) |
Oct
(50) |
Nov
(25) |
Dec
|
| 2005 |
Jan
(44) |
Feb
(8) |
Mar
(2) |
Apr
(15) |
May
(48) |
Jun
(8) |
Jul
(7) |
Aug
|
Sep
(1) |
Oct
(3) |
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(2) |
Jul
(14) |
Aug
|
Sep
|
Oct
|
Nov
(6) |
Dec
(4) |
| 2007 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2011 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Sarn U. <pol...@ya...> - 2019-04-18 15:20:59
|
My name is Mr. Sarn Richard Ursell. I am currently a student at Victoria University, a famous University here in Wellington, (I currently study mathematics, first year, level-100), -and I wish to learn programming in, as I have some WONDERFUL ideas for manipulating sound and picture information using Java. I am told that this is a beautiful language, and, I can truly believe this. Is it alright with you if I collaborate with you about these projects, and can you please help me with some algorithms, that I need-and-wish to use to apply to sound and picture information? I can explain in more depth if you so desire, Many thanks, Sincerely, Mr. Sarn Richard Ursell. |
|
From: <rob...@us...> - 2011-11-24 20:02:21
|
Revision: 483
http://javabdd.svn.sourceforge.net/javabdd/?rev=483&view=rev
Author: robimalik
Date: 2011-11-24 20:02:15 +0000 (Thu, 24 Nov 2011)
Log Message:
-----------
MODIFY
No longer try to implement setCacheRatio() for CUDD.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2011-02-18 14:54:24 UTC (rev 482)
+++ trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2011-11-24 20:02:15 UTC (rev 483)
@@ -174,9 +174,9 @@
* @see net.sf.javabdd.BDDFactory#setCacheRatio(double)
*/
public double setCacheRatio(double x) {
- // TODO Implement this.
- System.err.println("Warning: setCacheRatio() not yet implemented");
- return 0;
+ // Cache size is determined automatically by CUDD.
+ // System.err.println("Warning: setCacheRatio() not yet implemented");
+ return 1.0;
}
/* (non-Javadoc)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gi...@us...> - 2011-02-18 14:54:32
|
Revision: 482
http://javabdd.svn.sourceforge.net/javabdd/?rev=482&view=rev
Author: gismo
Date: 2011-02-18 14:54:24 +0000 (Fri, 18 Feb 2011)
Log Message:
-----------
added CUDDBDD.restrict again - if the parameter is a cube, Coudert and Madre's restrict actually does exactly what we expect from the function
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2011-02-18 14:37:09 UTC (rev 481)
+++ trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2011-02-18 14:54:24 UTC (rev 482)
@@ -617,29 +617,25 @@
* @see net.sf.javabdd.BDD#restrict(net.sf.javabdd.BDD)
*/
public BDD restrict(BDD var) {
-// CUDDBDD c = (CUDDBDD) var;
-// long b = cofactor0(_ddnode_ptr, c._ddnode_ptr);
-// return new CUDDBDD(b);
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ CUDDBDD c = (CUDDBDD) var;
+ long b = restrict0(_ddnode_ptr, c._ddnode_ptr);
+ return new CUDDBDD(b);
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDD#restrictWith(net.sf.javabdd.BDD)
*/
public BDD restrictWith(BDD var) {
-// CUDDBDD c = (CUDDBDD) var;
-// long b = cofactor0(_ddnode_ptr, c._ddnode_ptr);
-// addRef(b);
-// delRef(_ddnode_ptr);
-// if (this != c) {
-// delRef(c._ddnode_ptr);
-// c._ddnode_ptr = INVALID_BDD;
-// }
-// _ddnode_ptr = b;
-// return this;
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ CUDDBDD c = (CUDDBDD) var;
+ long b = restrict0(_ddnode_ptr, c._ddnode_ptr);
+ addRef(b);
+ delRef(_ddnode_ptr);
+ if (this != c) {
+ delRef(c._ddnode_ptr);
+ c._ddnode_ptr = INVALID_BDD;
+ }
+ _ddnode_ptr = b;
+ return this;
}
// private static native long cofactor0(long b, long var);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gi...@us...> - 2011-02-18 14:37:16
|
Revision: 481
http://javabdd.svn.sourceforge.net/javabdd/?rev=481&view=rev
Author: gismo
Date: 2011-02-18 14:37:09 +0000 (Fri, 18 Feb 2011)
Log Message:
-----------
fixed BDD.simplify: It takes now a BDD instead of a BDDVarSet
fix in CUDDFactory: simplify is implemented in CUDD by the method "restrict". The JavaBDD restrict method is called cofactor in CUDD. I fixed simplify and set restrict to unimplemented. I will add the required method in cudd_jni.c shortly.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/BDD.java
trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
trunk/JavaBDD/net/sf/javabdd/CALFactory.java
trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
trunk/JavaBDD/net/sf/javabdd/TypedBDDFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/BDD.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDD.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/BDD.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -404,7 +404,7 @@
* @param d BDDVarSet containing the variables in the domain
* @return the result of the simplify operation
*/
- public abstract BDD simplify(BDDVarSet d);
+ public abstract BDD simplify(BDD d);
/**
* <p>Returns the variable support of this BDD. The support is all the
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -179,7 +179,7 @@
public BDD satOne(BDDVarSet var, boolean pol) {
return makeBDD(satOne_impl2(v, unwrap(var), pol));
}
- public BDD simplify(BDDVarSet d) {
+ public BDD simplify(BDD d) {
return makeBDD(simplify_impl(v, unwrap(d)));
}
public BDDVarSet support() {
Modified: trunk/JavaBDD/net/sf/javabdd/CALFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/CALFactory.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/CALFactory.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -586,7 +586,7 @@
/* (non-Javadoc)
* @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet)
*/
- public BDD simplify(BDDVarSet d) {
+ public BDD simplify(BDD d) {
// TODO Implement this.
throw new UnsupportedOperationException();
}
Modified: trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -617,35 +617,43 @@
* @see net.sf.javabdd.BDD#restrict(net.sf.javabdd.BDD)
*/
public BDD restrict(BDD var) {
- CUDDBDD c = (CUDDBDD) var;
- long b = restrict0(_ddnode_ptr, c._ddnode_ptr);
- return new CUDDBDD(b);
+// CUDDBDD c = (CUDDBDD) var;
+// long b = cofactor0(_ddnode_ptr, c._ddnode_ptr);
+// return new CUDDBDD(b);
+ // TODO Implement this.
+ throw new UnsupportedOperationException();
}
- private static native long restrict0(long b, long var);
/* (non-Javadoc)
* @see net.sf.javabdd.BDD#restrictWith(net.sf.javabdd.BDD)
*/
public BDD restrictWith(BDD var) {
- CUDDBDD c = (CUDDBDD) var;
- long b = restrict0(_ddnode_ptr, c._ddnode_ptr);
- addRef(b);
- delRef(_ddnode_ptr);
- if (this != c) {
- delRef(c._ddnode_ptr);
- c._ddnode_ptr = INVALID_BDD;
- }
- _ddnode_ptr = b;
- return this;
+// CUDDBDD c = (CUDDBDD) var;
+// long b = cofactor0(_ddnode_ptr, c._ddnode_ptr);
+// addRef(b);
+// delRef(_ddnode_ptr);
+// if (this != c) {
+// delRef(c._ddnode_ptr);
+// c._ddnode_ptr = INVALID_BDD;
+// }
+// _ddnode_ptr = b;
+// return this;
+ // TODO Implement this.
+ throw new UnsupportedOperationException();
}
+// private static native long cofactor0(long b, long var);
- /* (non-Javadoc)
+ /** Coudert and Mardre's restrict function. Note that this function
+ * is called restrict in CUDD, While the JavaBDD's restrict function is
+ * called cofactor in CUDD. (the generalized cofactor is constrain)
* @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet)
*/
- public BDD simplify(BDDVarSet d) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ public BDD simplify(BDD d) {
+ CUDDBDD c = (CUDDBDD) d;
+ long b = restrict0(_ddnode_ptr, c._ddnode_ptr);
+ return new CUDDBDD(b);
}
+ private static native long restrict0(long b, long var);
/* (non-Javadoc)
* @see net.sf.javabdd.BDD#support()
Modified: trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -326,9 +326,9 @@
*
* @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet)
*/
- public BDD simplify(BDDVarSet d) {
- BDDVarSet c1 = ((TestBDDVarSet) d).b1;
- BDDVarSet c2 = ((TestBDDVarSet) d).b2;
+ public BDD simplify(BDD d) {
+ BDD c1 = ((TestBDD) d).b1;
+ BDD c2 = ((TestBDD) d).b2;
BDD r1 = b1.simplify(c1);
BDD r2 = b2.simplify(c2);
return new TestBDD(r1, r2);
Modified: trunk/JavaBDD/net/sf/javabdd/TypedBDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/TypedBDDFactory.java 2010-11-16 01:29:49 UTC (rev 480)
+++ trunk/JavaBDD/net/sf/javabdd/TypedBDDFactory.java 2011-02-18 14:37:09 UTC (rev 481)
@@ -755,8 +755,8 @@
/* (non-Javadoc)
* @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet)
*/
- public BDD simplify(BDDVarSet d) {
- TypedBDDVarSet bdd1 = (TypedBDDVarSet) d;
+ public BDD simplify(BDD d) {
+ TypedBDD bdd1 = (TypedBDD) d;
// TODO How does this change the domains?
Set newDom = makeSet();
newDom.addAll(dom);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rob...@us...> - 2010-11-16 01:29:55
|
Revision: 480
http://javabdd.svn.sourceforge.net/javabdd/?rev=480&view=rev
Author: robimalik
Date: 2010-11-16 01:29:49 +0000 (Tue, 16 Nov 2010)
Log Message:
-----------
Fix reordering bugs.
Modified Paths:
--------------
trunk/JavaBDD/cudd_jni.c
trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
Modified: trunk/JavaBDD/cudd_jni.c
===================================================================
--- trunk/JavaBDD/cudd_jni.c 2010-10-14 01:42:49 UTC (rev 479)
+++ trunk/JavaBDD/cudd_jni.c 2010-11-16 01:29:49 UTC (rev 480)
@@ -1,5 +1,6 @@
#include <jni.h>
#include <stdlib.h>
+
#include "util.h"
#include "cudd.h"
#include "cuddInt.h"
@@ -369,7 +370,11 @@
{
Cudd_ReorderingType cuddmethod = getCUDDReorderMethod(env, javamethod);
if (!(*env)->ExceptionOccurred(env)) {
- Cudd_AutodynEnable(manager, cuddmethod);
+ if (cuddmethod == CUDD_REORDER_NONE) {
+ Cudd_AutodynDisable(manager);
+ } else {
+ Cudd_AutodynEnable(manager, cuddmethod);
+ }
}
}
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2010-10-14 01:42:49 UTC (rev 479)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2010-11-16 01:29:49 UTC (rev 480)
@@ -66,46 +66,51 @@
* @param cachesize operation cache size
* @return BDD factory object
*/
- public static BDDFactory init(String bddpackage, int nodenum, int cachesize) {
- try {
- if (bddpackage.equals("buddy"))
- return BuDDyFactory.init(nodenum, cachesize);
- if (bddpackage.equals("cudd"))
- return CUDDFactory.init(nodenum, cachesize);
- if (bddpackage.equals("cal"))
- return CALFactory.init(nodenum, cachesize);
- if (bddpackage.equals("j") || bddpackage.equals("java"))
- return JFactory.init(nodenum, cachesize);
- if (bddpackage.equals("u"))
- return UberMicroFactory.init(nodenum, cachesize);
- if (bddpackage.equals("micro"))
- return MicroFactory.init(nodenum, cachesize);
- if (bddpackage.equals("jdd"))
- return JDDFactory.init(nodenum, cachesize);
- if (bddpackage.equals("test"))
- return TestBDDFactory.init(nodenum, cachesize);
- if (bddpackage.equals("typed"))
- return TypedBDDFactory.init(nodenum, cachesize);
- if (bddpackage.equals("zdd")) {
- BDDFactory bdd = JFactory.init(nodenum, cachesize);
- ((JFactory)bdd).ZDD = true;
- return bdd;
- }
- } catch (LinkageError e) {
- System.out.println("Could not load BDD package "+bddpackage+": "+e.getLocalizedMessage());
- }
- try {
- Class c = Class.forName(bddpackage);
- Method m = c.getMethod("init", new Class[] { int.class, int.class });
- return (BDDFactory) m.invoke(null, new Object[] { new Integer(nodenum), new Integer(cachesize) });
- }
- catch (ClassNotFoundException _) {}
- catch (NoSuchMethodException _) {}
- catch (IllegalAccessException _) {}
- catch (InvocationTargetException _) {}
- // falling back to default java implementation.
- return JFactory.init(nodenum, cachesize);
+ public static BDDFactory init(String bddpackage, int nodenum, int cachesize)
+ {
+ try {
+ if (bddpackage.equals("buddy")) {
+ return BuDDyFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("cudd")) {
+ return CUDDFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("cal")) {
+ return CALFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("j") || bddpackage.equals("java")) {
+ return JFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("u")) {
+ return UberMicroFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("micro")) {
+ return MicroFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("jdd")) {
+ return JDDFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("test")) {
+ return TestBDDFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("typed")) {
+ return TypedBDDFactory.init(nodenum, cachesize);
+ } else if (bddpackage.equals("zdd")) {
+ BDDFactory bdd = JFactory.init(nodenum, cachesize);
+ ((JFactory)bdd).ZDD = true;
+ return bdd;
+ } else {
+ System.err.println("Unknown BDD package: " + bddpackage);
+ }
+ } catch (LinkageError e) {
+ System.err.println("Could not load BDD package "+ bddpackage +
+ ": " + e.getLocalizedMessage());
}
+ try {
+ Class c = Class.forName(bddpackage);
+ Method m = c.getMethod("init", new Class[] { int.class, int.class });
+ return (BDDFactory) m.invoke(null, new Object[]
+ { new Integer(nodenum), new Integer(cachesize) });
+ }
+ catch (ClassNotFoundException _) {}
+ catch (NoSuchMethodException _) {}
+ catch (IllegalAccessException _) {}
+ catch (InvocationTargetException _) {}
+ // falling back to default java implementation.
+ return JFactory.init(nodenum, cachesize);
+ }
/**
* Logical 'and'.
Modified: trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2010-10-14 01:42:49 UTC (rev 479)
+++ trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2010-11-16 01:29:49 UTC (rev 480)
@@ -205,7 +205,7 @@
private static native void enableReorder0();
public int reorderVerbose(int v) { return reorderVerbose0(v); }
private static native int reorderVerbose0(int v);
- public void reorder(ReorderMethod m) { reorder0(m.id); }
+ public void reorder(ReorderMethod m) { if (varNum() > 1) reorder0(m.id); }
private static native void reorder0(int method);
public void autoReorder(ReorderMethod method) { autoReorder0(method.id); }
private static native void autoReorder0(int method);
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2010-10-14 01:42:49 UTC (rev 479)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2010-11-16 01:29:49 UTC (rev 480)
@@ -227,7 +227,7 @@
public void disableReorder() { bdd_disable_reorder(); }
public void enableReorder() { bdd_enable_reorder(); }
public int reorderVerbose(int v) { return bdd_reorder_verbose(v); }
- public void reorder(ReorderMethod m) { bdd_reorder(m.id); }
+ public void reorder(ReorderMethod m) { if (varNum() > 1) bdd_reorder(m.id); }
public void autoReorder(ReorderMethod method) { bdd_autoreorder(method.id); }
public void autoReorder(ReorderMethod method, int max) { bdd_autoreorder_times(method.id, max); }
public void swapVar(int v1, int v2) { bdd_swapvar(v1, v2); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rob...@us...> - 2010-10-14 01:42:55
|
Revision: 479
http://javabdd.svn.sourceforge.net/javabdd/?rev=479&view=rev
Author: robimalik
Date: 2010-10-14 01:42:49 +0000 (Thu, 14 Oct 2010)
Log Message:
-----------
Enable variable reordering and variable groups for CUDD.
Modified Paths:
--------------
trunk/JavaBDD/cudd_jni.c
trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
Modified: trunk/JavaBDD/cudd_jni.c
===================================================================
--- trunk/JavaBDD/cudd_jni.c 2007-06-15 22:22:53 UTC (rev 478)
+++ trunk/JavaBDD/cudd_jni.c 2010-10-14 01:42:49 UTC (rev 479)
@@ -46,6 +46,84 @@
(*env)->DeleteLocalRef(env, cls);
}
+
+/***************************************************************************
+ * Auxiliary Methods
+ */
+
+const char* BDDFACTORY_CLASS_NAME = "net/sf/javabdd/BDDFactory";
+
+jfieldID JAVA_REORDER_NONE;
+jfieldID JAVA_REORDER_RANDOM;
+jfieldID JAVA_REORDER_SIFT;
+jfieldID JAVA_REORDER_SIFTITE;
+jfieldID JAVA_REORDER_WIN2;
+jfieldID JAVA_REORDER_WIN2ITE;
+jfieldID JAVA_REORDER_WIN3;
+jfieldID JAVA_REORDER_WIN3ITE;
+
+
+static jboolean isJavaReorderMethod(JNIEnv *env, jclass cls,
+ jfieldID id, jobject method)
+{
+ jobject field = (*env)->GetStaticObjectField(env, cls, id);
+ return (*env)->IsSameObject(env, field, method);
+}
+
+
+static Cudd_ReorderingType getCUDDReorderMethod(JNIEnv *env,
+ jobject javamethod)
+{
+ jclass cls = (*env)->FindClass(env, BDDFACTORY_CLASS_NAME);
+ if (isJavaReorderMethod(env, cls, JAVA_REORDER_NONE, javamethod)) {
+ return CUDD_REORDER_NONE;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_RANDOM, javamethod)) {
+ return CUDD_REORDER_RANDOM;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_SIFT, javamethod)) {
+ return CUDD_REORDER_SIFT;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_SIFTITE, javamethod)) {
+ return CUDD_REORDER_SIFT_CONVERGE;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_WIN2, javamethod)) {
+ return CUDD_REORDER_WINDOW2;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_WIN2ITE, javamethod)) {
+ return CUDD_REORDER_WINDOW2_CONV;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_WIN3, javamethod)) {
+ return CUDD_REORDER_WINDOW3;
+ } else if (isJavaReorderMethod(env, cls, JAVA_REORDER_WIN3ITE, javamethod)) {
+ return CUDD_REORDER_WINDOW3_CONV;
+ } else {
+ die(env, "Unknown Java reorder method!");
+ return 0;
+ }
+}
+
+static jfieldID getJavaReorderMethodId(JNIEnv *env,
+ Cudd_ReorderingType cuddmethod)
+{
+ switch (cuddmethod) {
+ case CUDD_REORDER_NONE:
+ return JAVA_REORDER_NONE;
+ case CUDD_REORDER_RANDOM:
+ return JAVA_REORDER_RANDOM;
+ case CUDD_REORDER_SIFT:
+ return JAVA_REORDER_SIFT;
+ case CUDD_REORDER_SIFT_CONVERGE:
+ return JAVA_REORDER_SIFTITE;
+ case CUDD_REORDER_WINDOW2:
+ return JAVA_REORDER_WIN2;
+ case CUDD_REORDER_WINDOW2_CONV:
+ return JAVA_REORDER_WIN2ITE;
+ case CUDD_REORDER_WINDOW3:
+ return JAVA_REORDER_WIN3;
+ case CUDD_REORDER_WINDOW3_CONV:
+ return JAVA_REORDER_WIN3ITE;
+ default:
+ die(env, "Unknown reorder method in CUDD!");
+ return 0;
+ }
+}
+
+
/**** START OF NATIVE METHOD IMPLEMENTATIONS ****/
/*
@@ -56,6 +134,24 @@
JNIEXPORT void JNICALL Java_net_sf_javabdd_CUDDFactory_registerNatives
(JNIEnv *env, jclass cl)
{
+ jclass cls = (*env)->FindClass(env, BDDFACTORY_CLASS_NAME);
+ const char* type = "Lnet/sf/javabdd/BDDFactory$ReorderMethod;";
+ JAVA_REORDER_NONE =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_NONE", type);
+ JAVA_REORDER_RANDOM =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_RANDOM", type);;
+ JAVA_REORDER_SIFT =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_SIFT", type);
+ JAVA_REORDER_SIFTITE =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_SIFTITE", type);
+ JAVA_REORDER_WIN2 =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_WIN2", type);
+ JAVA_REORDER_WIN2ITE =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_WIN2ITE", type);
+ JAVA_REORDER_WIN3 =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_WIN3", type);
+ JAVA_REORDER_WIN3ITE =
+ (*env)->GetStaticFieldID(env, cls, "REORDER_WIN3ITE", type);
}
typedef struct CuddPairing {
@@ -146,12 +242,15 @@
Cudd_Deref((DdNode *)(intptr_cast_type) bdd_one);
Cudd_Deref((DdNode *)(intptr_cast_type) bdd_zero);
-
+ /*
fprintf(stderr, "Garbage collections: %d Time spent: %ldms\n",
- Cudd_ReadGarbageCollections(manager), Cudd_ReadGarbageCollectionTime(manager));
-
+ Cudd_ReadGarbageCollections(manager),
+ Cudd_ReadGarbageCollectionTime(manager));
bdds = Cudd_CheckZeroRef(manager);
- if (bdds > 0) fprintf(stderr, "Note: %d BDDs still in memory when terminating\n", bdds);
+ if (bdds > 0)
+ fprintf(stderr, "Note: %d BDDs still in memory when terminating\n",
+ bdds);
+ */
m = manager;
manager = NULL; // race condition with delRef
Cudd_Quit(m);
@@ -248,6 +347,34 @@
/*
* Class: net_sf_javabdd_CUDDFactory
+ * Method: reorder0
+ * Signature: (Lnet/sf/javabdd/BDDFactory/ReorderMethod;)V
+ */
+JNIEXPORT void JNICALL Java_net_sf_javabdd_CUDDFactory_reorder0
+ (JNIEnv *env, jclass cl, jobject javamethod)
+{
+ Cudd_ReorderingType cuddmethod = getCUDDReorderMethod(env, javamethod);
+ if (!(*env)->ExceptionOccurred(env)) {
+ Cudd_ReduceHeap(manager, cuddmethod, INT_MAX);
+ }
+}
+
+/*
+ * Class: net_sf_javabdd_CUDDFactory
+ * Method: autoreorder0
+ * Signature: (Lnet/sf/javabdd/BDDFactory/ReorderMethod;)V
+ */
+JNIEXPORT void JNICALL Java_net_sf_javabdd_CUDDFactory_autoreorder0
+ (JNIEnv *env, jclass cl, jobject javamethod)
+{
+ Cudd_ReorderingType cuddmethod = getCUDDReorderMethod(env, javamethod);
+ if (!(*env)->ExceptionOccurred(env)) {
+ Cudd_AutodynEnable(manager, cuddmethod);
+ }
+}
+
+/*
+ * Class: net_sf_javabdd_CUDDFactory
* Method: setVarOrder0
* Signature: ([I)V
*/
@@ -271,6 +398,35 @@
/*
* Class: net_sf_javabdd_CUDDFactory
+ * Method: addVarBlock0
+ * Signature: (IIZ)V
+ */
+JNIEXPORT void JNICALL Java_net_sf_javabdd_CUDDFactory_addVarBlock0
+ (JNIEnv *env, jclass cl, jint first, jint last, jboolean fixed)
+{
+ int firstp = Cudd_ReadPerm(manager, first);
+ int lastp = Cudd_ReadPerm(manager, last);
+ if (firstp <= lastp) {
+ int len = lastp - firstp + 1;
+ Cudd_MakeTreeNode(manager, first, len, fixed ? MTR_FIXED : MTR_DEFAULT);
+ } else {
+ die(env, "Bad indexes in variable block!");
+ }
+}
+
+/*
+ * Class: net_sf_javabdd_CUDDFactory
+ * Method: clearVarBlocks0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_net_sf_javabdd_CUDDFactory_clearVarBlocks0
+ (JNIEnv *env, jclass cl)
+{
+ Cudd_FreeTree(manager);
+}
+
+/*
+ * Class: net_sf_javabdd_CUDDFactory
* Method: getAllocNum0
* Signature: ()I
*/
Modified: trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2007-06-15 22:22:53 UTC (rev 478)
+++ trunk/JavaBDD/net/sf/javabdd/CUDDFactory.java 2010-10-14 01:42:49 UTC (rev 479)
@@ -1,6 +1,9 @@
+//# -*- tab-width: 4 indent-tabs-mode: nil c-basic-offset: 4 -*-
+
// CUDDFactory.java, created Jan 29, 2003 9:50:57 PM by jwhaley
// Copyright (C) 2003 John Whaley
// Licensed under the terms of the GNU LGPL; see COPYING for details.
+
package net.sf.javabdd;
import java.util.Collection;
@@ -277,57 +280,55 @@
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#reorder(net.sf.javabdd.BDDFactory.ReorderMethod)
*/
- public void reorder(ReorderMethod m) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ public void reorder(final ReorderMethod method)
+ {
+ reorder0(method);
}
+ private static native void reorder0(ReorderMethod method);
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod)
*/
- public void autoReorder(ReorderMethod method) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ public void autoReorder(final ReorderMethod method)
+ {
+ mAutoReorderMethod = method;
+ autoreorder0(method);
}
+ private static native void autoreorder0(ReorderMethod method);
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod, int)
*/
public void autoReorder(ReorderMethod method, int max) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ autoReorder(method);
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#getReorderMethod()
*/
public ReorderMethod getReorderMethod() {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ return mAutoReorderMethod;
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#getReorderTimes()
*/
public int getReorderTimes() {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ return Integer.MAX_VALUE;
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#disableReorder()
*/
public void disableReorder() {
- // TODO Implement this.
- System.err.println("Warning: disableReorder() not yet implemented");
+ autoReorder(BDDFactory.REORDER_NONE);
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#enableReorder()
*/
public void enableReorder() {
- // TODO Implement this.
- System.err.println("Warning: enableReorder() not yet implemented");
+ autoReorder(mAutoReorderMethod);
}
/* (non-Javadoc)
@@ -349,34 +350,56 @@
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#addVarBlock(net.sf.javabdd.BDD, boolean)
*/
- public void addVarBlock(BDD var, boolean fixed) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ public void addVarBlock(BDD vars, final boolean fixed)
+ {
+ if (vars.isZero()) {
+ return;
+ } else if (vars.isOne()) {
+ throw new IllegalArgumentException
+ ("Bad cube in CUDDFactory.addVarBlock()!");
+ } else {
+ final int first = vars.var();
+ int last;
+ do {
+ last = vars.var();
+ vars = vars.high();
+ if (vars.isZero()) {
+ throw new IllegalArgumentException
+ ("Bad cube in CUDDFactory.addVarBlock()!");
+ }
+ } while (!vars.isOne());
+ addVarBlock(first, last, fixed);
+ }
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#addVarBlock(int, int, boolean)
*/
- public void addVarBlock(int first, int last, boolean fixed) {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ public void addVarBlock
+ (final int first, final int last, final boolean fixed)
+ {
+ addVarBlock0(first, last, fixed);
}
+ private static native void addVarBlock0
+ (int first, int last, boolean fixed);
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#varBlockAll()
*/
public void varBlockAll() {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ final int varnum = varNum();
+ for (int i = 0; i < varnum; i++) {
+ addVarBlock(i, i, false);
+ }
}
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#clearVarBlocks()
*/
public void clearVarBlocks() {
- // TODO Implement this.
- throw new UnsupportedOperationException();
+ clearVarBlocks0();
}
+ private static native void clearVarBlocks0();
/* (non-Javadoc)
* @see net.sf.javabdd.BDDFactory#printOrder()
@@ -954,5 +977,9 @@
public String getVersion() {
return "CUDD "+REVISION.substring(11, REVISION.length()-2);
}
-
+
+
+ private static BDDFactory.ReorderMethod mAutoReorderMethod =
+ BDDFactory.REORDER_NONE;
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2007-06-15 22:22:54
|
Revision: 478
http://svn.sourceforge.net/javabdd/?rev=478&view=rev
Author: joewhaley
Date: 2007-06-15 15:22:53 -0700 (Fri, 15 Jun 2007)
Log Message:
-----------
Added Google Analytics.
Modified Paths:
--------------
trunk/JavaBDD/project.properties
trunk/JavaBDD/xdocs/navigation.xml
Modified: trunk/JavaBDD/project.properties
===================================================================
--- trunk/JavaBDD/project.properties 2007-03-06 07:31:44 UTC (rev 477)
+++ trunk/JavaBDD/project.properties 2007-06-15 22:22:53 UTC (rev 478)
@@ -2,8 +2,10 @@
# Where to find source code, used by tasklist plugin.
#maven.src.dir = .
-maven.compile.source = 1.3
-maven.compile.target = 1.3
+#maven.compile.source = 1.3
+#maven.compile.target = 1.3
+maven.compile.source = 1.5
+maven.compile.target = 1.5
# The string to look for in TODO tags, used by tasklist plugin.
#maven.tasklist.taskTag = TODO
Modified: trunk/JavaBDD/xdocs/navigation.xml
===================================================================
--- trunk/JavaBDD/xdocs/navigation.xml 2007-03-06 07:31:44 UTC (rev 477)
+++ trunk/JavaBDD/xdocs/navigation.xml 2007-06-15 22:22:53 UTC (rev 478)
@@ -35,5 +35,13 @@
<item name="JavaBDD Source code"
href="http://prdownloads.sourceforge.net/javabdd/javabdd_src_1.0b2.tar.gz"/>
</menu>
+ <footer>
+<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
+</script>
+<script type="text/javascript">
+_uacct = "UA-72567-3";
+urchinTracker();
+</script>
+ </footer>
</body>
</project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2007-03-06 07:31:45
|
Revision: 477
http://svn.sourceforge.net/javabdd/?rev=477&view=rev
Author: joewhaley
Date: 2007-03-05 23:31:44 -0800 (Mon, 05 Mar 2007)
Log Message:
-----------
Turn off some debugging junk.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java 2007-03-06 06:08:40 UTC (rev 476)
+++ trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java 2007-03-06 07:31:44 UTC (rev 477)
@@ -34,10 +34,11 @@
public static boolean FLUSH_CACHE_ON_GC = true;
- static final boolean VERIFY_ASSERTIONS = true;
+ static final boolean VERIFY_ASSERTIONS = false;
static final boolean ORDER_CACHE = false;
static final int CACHESTATS = 0;
static final boolean SWAPCOUNT = false;
+ static final boolean TRACE_REORDER = false;
public static final String REVISION = "$Revision: 465 $";
@@ -506,7 +507,7 @@
float HASHFACTOR = 1.5f;
void HASH_RESET() {
- System.out.println("Resetting hash table");
+ if (false) System.out.println("Resetting hash table");
if (bddhash == null || bddhash.length < bddnodesize * HASHFACTOR) {
int newSize = (int)(bddnodesize * HASHFACTOR);
if (POWEROF2)
@@ -533,7 +534,7 @@
}
final void HASH_RESET(int h) {
- System.out.println("Resetting hash entry "+h);
+ if (false) System.out.println("Resetting hash entry "+h);
bddhash[h] = HASH_EMPTY;
}
@@ -667,7 +668,7 @@
newBegin = 2;
}
- System.out.println("Moving level "+var0+" from ("+oldBegin+".."+oldEnd+") to ("+newBegin+".."+newEnd+")");
+ if (TRACE_REORDER) System.out.println("Moving level "+var0+" from ("+oldBegin+".."+oldEnd+") to ("+newBegin+".."+newEnd+")");
if (newEnd > bddhash.length) {
// grow the table!
@@ -748,7 +749,7 @@
//System.out.println("Rehashing "+r+" from hashloc "+k);
bddhash[k] = HASH_EMPTY;
int h = rehash_helper(var0, r);
- if (true)
+ if (TRACE_REORDER)
System.out.println("Rehashed "+r+" from hashloc "+k+" to hashloc "+h);
}
}
@@ -791,7 +792,7 @@
return h;
}
if (x < 0 || x == HASH_EMPTY) {
- System.out.println("Rehashing node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" into hash slot "+h);
+ if (TRACE_REORDER) System.out.println("Rehashing node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" into hash slot "+h);
if (VERIFY_ASSERTIONS) _assert(x != HASH_SENTINEL);
bddhash[h] = v;
if (x != HASH_EMPTY && -x != v) {
@@ -826,7 +827,7 @@
if (VERIFY_ASSERTIONS) _assert(HASH_GETVAL(h) != v);
int x = bddhash[h];
if (x == HASH_EMPTY || x == HASH_SENTINEL) {
- System.out.println("Inserting node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" into hash slot "+h);
+ if (TRACE_REORDER) System.out.println("Inserting node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" into hash slot "+h);
bddhash[h] = v;
return h;
} else {
@@ -843,7 +844,7 @@
h -= l.size;
}
- System.out.println("Inserting node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" failed, resizing hash and trying again");
+ if (TRACE_REORDER) System.out.println("Inserting node "+v+"("+VARr(v)+","+LOW(v)+","+HIGH(v)+") rc="+refcounts.get(v)+" failed, resizing hash and trying again");
HASHr_RESIZE(var);
@@ -5609,10 +5610,10 @@
k += levels[n].size;
if (levels[n].size >= 4)
levels[n].size = bdd_prime_lte(levels[n].size);
- System.out.println("Var "+n+": "+levels[n].nodenum+" nodes, hash="+levels[n].start+"..."+(levels[n].start+levels[n].size));
+ if (TRACE_REORDER) System.out.println("Var "+n+": "+levels[n].nodenum+" nodes, hash="+levels[n].start+"..."+(levels[n].start+levels[n].size));
total += levels[n].nodenum;
}
- System.out.println("total nodes="+total);
+ if (TRACE_REORDER) System.out.println("total nodes="+total);
}
// Reference counts.
@@ -5704,7 +5705,7 @@
int size1 = levels[var1].size;
int n;
- System.out.println("Doing local GC for var "+var1+" ("+vl1+"..."+(vl1+size1)+")");
+ if (TRACE_REORDER) System.out.println("Doing local GC for var "+var1+" ("+vl1+"..."+(vl1+size1)+")");
for (n = 0; n < size1; ++n) {
int hash = n + vl1;
@@ -5712,7 +5713,7 @@
int r = HASH_GETVAL(hash);
if (!refcounts.hasref(r)) {
- System.out.println("No longer referenced, freeing: "+r+"("+VARr(r)+","+LOW(r)+","+HIGH(r)+") rc="+refcounts.get(r)+" hash="+hash);
+ if (TRACE_REORDER) System.out.println("No longer referenced, freeing: "+r+"("+VARr(r)+","+LOW(r)+","+HIGH(r)+") rc="+refcounts.get(r)+" hash="+hash);
HASHr_SETSENTINEL(hash);
if (VERIFY_ASSERTIONS) _assert(VARr(r) == var1);
refcounts.dec(LOW(r));
@@ -5760,7 +5761,7 @@
int size0 = levels[var0].size;
int n;
- System.out.println("Exchanging v"+var0+" and v"+var1+" ("+levels[var0].nodenum+" nodes) hashloc "+vl0+"..."+(vl0+size0));
+ if (TRACE_REORDER) System.out.println("Exchanging v"+var0+" and v"+var1+" ("+levels[var0].nodenum+" nodes) hashloc "+vl0+"..."+(vl0+size0));
toBeProcessed.init(levels[var0].nodenum);
@@ -5768,11 +5769,11 @@
for (n = 0; n < size0; ++n) {
int hash = n + vl0;
- System.out.println(" hashloc "+hash+" = "+bddhash[hash]);
+ if (TRACE_REORDER) System.out.println(" hashloc "+hash+" = "+bddhash[hash]);
if (!HASHr_HASVAL(hash)) continue;
int r = HASHr_GETVAL(hash);
- System.out.println("Inspecting node "+r+"("+VARr(r)+","+LOW(r)+","+HIGH(r)+") rc="+refcounts.get(r));
+ if (TRACE_REORDER) System.out.println("Inspecting node "+r+"("+VARr(r)+","+LOW(r)+","+HIGH(r)+") rc="+refcounts.get(r));
if (VERIFY_ASSERTIONS) _assert(VARr(r) == var0);
if (VARr(LOW(r)) != var1 && VARr(HIGH(r)) != var1) {
@@ -5787,7 +5788,7 @@
}
}
- System.out.println("Exchanging v"+var0+": "+toBeProcessed.numtoprocess+" nodes have v"+var1+
+ if (TRACE_REORDER) System.out.println("Exchanging v"+var0+": "+toBeProcessed.numtoprocess+" nodes have v"+var1+
" as a successor, "+levels[var0].nodenum+" do not");
return toBeProcessed;
@@ -5817,7 +5818,7 @@
} else
f10 = f11 = f1;
- System.out.println("Pushing down node "+t+"("+var0+","+f0+","+f1+") rc="+refcounts.get(t));
+ if (TRACE_REORDER) System.out.println("Pushing down node "+t+"("+var0+","+f0+","+f1+") rc="+refcounts.get(t));
// Note: makenode does refcou.
f0 = reorder_makenode(var0, f00, f10);
@@ -5833,8 +5834,8 @@
refcounts.dec(LOW(t));
refcounts.dec(HIGH(t));
- System.out.println("Old low child node: "+LOW(t)+"("+VARr(LOW(t))+","+LOW(LOW(t))+","+HIGH(LOW(t))+") rc="+refcounts.get(LOW(t)));
- System.out.println("Old high child node: "+HIGH(t)+"("+VARr(HIGH(t))+","+LOW(HIGH(t))+","+HIGH(HIGH(t))+") rc="+refcounts.get(HIGH(t)));
+ if (TRACE_REORDER) System.out.println("Old low child node: "+LOW(t)+"("+VARr(LOW(t))+","+LOW(LOW(t))+","+HIGH(LOW(t))+") rc="+refcounts.get(LOW(t)));
+ if (TRACE_REORDER) System.out.println("Old high child node: "+HIGH(t)+"("+VARr(HIGH(t))+","+LOW(HIGH(t))+","+HIGH(HIGH(t))+") rc="+refcounts.get(HIGH(t)));
// Update in-place
SETVARr(t, var1);
@@ -5843,8 +5844,8 @@
levels[var1].nodenum++;
- System.out.println("New low child node: "+LOW(t)+"("+VARr(LOW(t))+","+LOW(LOW(t))+","+HIGH(LOW(t))+") rc="+refcounts.get(LOW(t)));
- System.out.println("New high child node: "+HIGH(t)+"("+VARr(HIGH(t))+","+LOW(HIGH(t))+","+HIGH(HIGH(t))+") rc="+refcounts.get(HIGH(t)));
+ if (TRACE_REORDER) System.out.println("New low child node: "+LOW(t)+"("+VARr(LOW(t))+","+LOW(LOW(t))+","+HIGH(LOW(t))+") rc="+refcounts.get(LOW(t)));
+ if (TRACE_REORDER) System.out.println("New high child node: "+HIGH(t)+"("+VARr(HIGH(t))+","+LOW(HIGH(t))+","+HIGH(HIGH(t))+") rc="+refcounts.get(HIGH(t)));
// Rehash the node since it has new children
hash = NODEHASHr(var1, f0, f1);
@@ -5919,13 +5920,10 @@
return res;
}
- double[] reordercheck;
-
int reorder_init() {
int n;
reorder_handler(true, reorderstats);
- reordercheck = allSatCounts();
levels = new levelData[bddvarnum];
@@ -6073,9 +6071,6 @@
// Garbage collect to rehash blocks.
bdd_gbc();
- compare(reordercheck, allSatCounts());
- reordercheck = null;
-
reorder_handler(false, reorderstats);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2007-03-06 06:08:41
|
Revision: 476
http://svn.sourceforge.net/javabdd/?rev=476&view=rev
Author: joewhaley
Date: 2007-03-05 22:08:40 -0800 (Mon, 05 Mar 2007)
Log Message:
-----------
Added new UberMicroFactory.
Fixed setCacheRatio().
Added Intel compiler flag to optimize for Core 2 Duo processors.
Other small cleanups.
Modified Paths:
--------------
trunk/JavaBDD/Makefile
trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java
trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
Added Paths:
-----------
trunk/JavaBDD/net/sf/javabdd/BitString.java
trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java
Modified: trunk/JavaBDD/Makefile
===================================================================
--- trunk/JavaBDD/Makefile 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/Makefile 2007-03-06 06:08:40 UTC (rev 476)
@@ -35,7 +35,7 @@
CUDD_DLL_NAME = cudd.dll
CAL_DLL_NAME = cal.dll
ifeq (${CC},icl) # Intel Windows compiler
- CFLAGS = -DSPECIALIZE_RELPROD -DSPECIALIZE_OR -DSPECIALIZE_AND -DSMALL_NODES /O2 /Ob2 $(EXTRA_CFLAGS)
+ CFLAGS = -DSPECIALIZE_RELPROD -DSPECIALIZE_OR -DSPECIALIZE_AND -DSMALL_NODES /O2 /Ob2 /QxT $(EXTRA_CFLAGS)
CUDD_CFLAGS = $(CFLAGS) -DHAVE_SYS_RESOURCE_H=0
CAL_CFLAGS = $(CFLAGS) -DCLOCK_RESOLUTION=60 -DRLIMIT_DATA_DEFAULT=16777216 -DNDEBUG=1 -DSTDC_HEADERS=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_UNISTD_H=0 -DHAVE_ERRNO_H=1 -DHAVE_ASSERT_H=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_PWD_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_SYS_TIME_H=0 -DHAVE_SYS_RESOURCE_H=0 -DHAVE_STDARG_H=1 -DSIZEOF_VOID_P=4 -DSIZEOF_INT=4 -DHAVE_IEEE_754=1 -DPAGE_SIZE=4096 -DLG_PAGE_SIZE=12 -DRETSIGTYPE=void -DHAVE_STRCOLL=1 -DHAVE_SYSCONF=1 -DHAVE_GETHOSTNAME=1 -DHAVE_STRCSPN=1 -DHAVE_STRERROR=1 -DHAVE_STRSPN=1 -DHAVE_STRSTR=1 -DHAVE_GETENV=1 -DHAVE_STRCHR=1 -DHAVE_GETRLIMIT=1 -DHAVE_GETRUSAGE=1 -DHAVE_VALLOC=0
OBJECT_OUTPUT_OPTION = -Fo
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -76,7 +76,9 @@
return CALFactory.init(nodenum, cachesize);
if (bddpackage.equals("j") || bddpackage.equals("java"))
return JFactory.init(nodenum, cachesize);
- if (bddpackage.equals("u") || bddpackage.equals("micro"))
+ if (bddpackage.equals("u"))
+ return UberMicroFactory.init(nodenum, cachesize);
+ if (bddpackage.equals("micro"))
return MicroFactory.init(nodenum, cachesize);
if (bddpackage.equals("jdd"))
return JDDFactory.init(nodenum, cachesize);
@@ -1278,6 +1280,12 @@
sb.append("Unique Chain: ");
sb.append(uniqueChain);
sb.append(newLine);
+ sb.append("=> Ave. chain = ");
+ if (uniqueAccess > 0)
+ sb.append(((float) uniqueChain) / ((float) uniqueAccess));
+ else
+ sb.append((float)0);
+ sb.append(newLine);
sb.append("Unique Hit: ");
sb.append(uniqueHit);
sb.append(newLine);
@@ -1830,7 +1838,11 @@
}
protected static void bdd_default_gbchandler(boolean pre, GCStats s) {
- if (!pre) {
+ if (pre) {
+ if (s.freenodes != 0)
+ System.err.println("Starting GC cycle #"+(s.num+1)+
+ ": "+s.nodes+" nodes / "+s.freenodes+" free");
+ } else {
System.err.println(s.toString());
}
}
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -209,12 +209,10 @@
protected void finalize() throws Throwable {
super.finalize();
- if (USE_FINALIZER) {
- if (false && v != invalid_bdd_impl()) {
- System.out.println("BDD not freed! "+System.identityHashCode(this));
- }
- deferredFree(v);
+ if (false && v != invalid_bdd_impl()) {
+ System.out.println("BDD not freed! "+System.identityHashCode(this));
}
+ deferredFree(v);
}
}
@@ -347,12 +345,10 @@
protected void finalize() throws Throwable {
super.finalize();
- if (USE_FINALIZER) {
- if (false && v != invalid_bdd_impl()) {
- System.out.println("BDD not freed! "+System.identityHashCode(this));
- }
- deferredFree(v);
+ if (false && v != invalid_bdd_impl()) {
+ System.out.println("BDD not freed! "+System.identityHashCode(this));
}
+ deferredFree(v);
}
}
@@ -524,6 +520,8 @@
protected /*bdd*/int[] to_free = new /*bdd*/int[8];
protected /*bdd*/int to_free_length = 0;
public void deferredFree(int v) {
+ if (v == invalid_bdd_impl())
+ return;
synchronized(to_free) {
if (to_free_length == to_free.length) {
/*bdd*/int[] t = new /*bdd*/int[to_free.length * 2];
Modified: trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -34,7 +34,16 @@
public abstract int[] toLevelArray();
public String toString() {
- return Arrays.toString(toArray());
+ //return Arrays.toString(toArray());
+ int[] a = toArray();
+ StringBuffer sb = new StringBuffer(a.length * 4 + 2);
+ sb.append('[');
+ for (int i = 0; i < a.length; ++i) {
+ if (i != 0) sb.append(',');
+ sb.append(a[i]);
+ }
+ sb.append(']');
+ return sb.toString();
}
/**
Added: trunk/JavaBDD/net/sf/javabdd/BitString.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BitString.java (rev 0)
+++ trunk/JavaBDD/net/sf/javabdd/BitString.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -0,0 +1,805 @@
+// BitString.java, created Wed May 16 17:26:33 2001 by joewhaley
+// Copyright (C) 2001-3 John Whaley <jw...@al...>
+// Licensed under the terms of the GNU LGPL; see COPYING for details.
+package net.sf.javabdd;
+
+import java.util.Iterator;
+
+/**
+ * <code>BitString</code> implements a vector of bits much like <code>java.util.BitSet</code>,
+ * except that this implementation actually works. Also, <code>BitString</code>
+ * has some groovy features which <code>BitSet</code> doesn't; mostly related to
+ * efficient iteration over <code>true</code> and <code>false</code> components.
+ * <p>
+ * Each component of the <code>BitString</code> has a boolean value.
+ * The bits of a <code>BitString</code> are indexed by non-negative
+ * integers (that means they are zero-based, of course). Individual
+ * indexed bits can be examined, set, or cleared. One
+ * <code>BitString</code> may be used to modify the contents of another
+ * <code>BitString</code> through logical AND, logical inclusive OR,
+ * and logical exclusive OR operations.
+ * <p>
+ * By default, all bits in the set initially have the value
+ * <code>false</code>.
+ * <p>
+ * Every bit set has a current size, which is the number of bits of
+ * space currently in use by the bit set. Note that the size is related
+ * to the implementation of a bit set, so it may change with implementation.
+ * The length of a bit set related to the logical length of a bit set
+ * and is defined independently of implementation.
+ *
+ * @author John Whaley <jw...@al...>
+ * @version $Id: BitString.java 2279 2005-05-28 10:24:54Z joewhaley $
+ */
+public final class BitString implements Cloneable, java.io.Serializable {
+
+ /**
+ * Version ID for serialization.
+ */
+ private static final long serialVersionUID = 3257570590025265971L;
+
+ /* There are 2^BITS_PER_UNIT bits in each unit (int) */
+ private static final int BITS_PER_UNIT = 5;
+ private static final int MASK = (1 << BITS_PER_UNIT) - 1;
+ private int[] bits;
+
+ /**
+ * Convert bitIndex to a subscript into the bits[] array.
+ */
+ private static int subscript(int bitIndex) {
+ return bitIndex >> BITS_PER_UNIT;
+ }
+
+ /**
+ * Creates an empty string with the specified size.
+ * @param nbits the size of the string
+ */
+ public BitString(int nbits) {
+ /* subscript(nbits + MASK) is the length of the array needed to hold
+ * nbits. Can also be written 1+subscript(nbits-1). */
+ bits = new int[subscript(nbits + MASK)];
+ }
+
+ /**
+ * Returns the first index in the bit string which is set, or
+ * -1 if there is no such index.
+ */
+ public int firstSet() {
+ return firstSet(-1);
+ }
+
+ /**
+ * Returns the first index greater than <code>where</code> in the
+ * bit string which is set, or -1 if there is no such index.
+ * @param where the starting point for the search. May be negative.
+ */
+ public int firstSet(int where) {
+ // convert exclusive starting point to inclusive starting point
+ where = (where < -1) ? 0 : (where + 1);
+ // search in first unit is masked.
+ int mask = (~0) << (where & MASK);
+ // search through units
+ for (int i = subscript(where); i < bits.length; i++, mask = ~0) {
+ int unit = bits[i] & mask;
+ if (unit != 0) return (i << BITS_PER_UNIT) + (bsf(unit) - 1);
+ }
+ return -1;
+ }
+
+ /**
+ * Utility function to return the number of 1 bits in the given integer
+ * value.
+ *
+ * @param b value to check
+ * @return byte number of one bits
+ */
+ public static final byte popcount(int b) {
+ int t, x;
+ x = b;
+ x = x - ((x >> 1) & 0x55555555);
+ t = ((x >> 2) & 0x33333333);
+ x = (x & 0x33333333) + t;
+ x = (x + (x >> 4)) & 0x0F0F0F0F;
+ x = x + (x >> 8);
+ x = x + (x >> 16);
+ return (byte) x;
+ }
+
+ /**
+ * Utility function to return the number of 1 bits in the given long value.
+ *
+ * @param b value to check
+ * @return byte number of one bits
+ */
+ public static final byte popcount(long b) {
+ long t, x;
+ x = b;
+ x = x - ((x >> 1) & 0x5555555555555555L);
+ t = ((x >> 2) & 0x3333333333333333L);
+ x = (x & 0x3333333333333333L) + t;
+ x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FL;
+ x = x + (x >> 8);
+ x = x + (x >> 16);
+ x = x + (x >> 32);
+ return (byte) x;
+ }
+
+ /**
+ * Utility function to return the index of the first (lowest-order) one bit
+ * in the given integer. Returns zero if the given number is zero.
+ *
+ * @param b value to check
+ * @return byte index of first one bit, or zero if the number is zero
+ */
+ public static final int bsf(int b) {
+ int t = ~(b | -b);
+ return popcount(t);
+ }
+
+ /**
+ * Utility function to return the index of the last one bit in the given
+ * integer. Returns zero if the given number is zero.
+ *
+ * @param v value to check
+ * @return byte index of first one bit, or zero if the number is zero
+ */
+ public static final int bsr(int v) {
+ if ((v & 0xFFFF0000) != 0) {
+ if ((v & 0xFF000000) != 0)
+ return 24 + bytemsb[(v >> 24) & 0xFF];
+ else
+ return 16 + bytemsb[v >> 16];
+ }
+ if ((v & 0x0000FF00) != 0)
+ return 8 + bytemsb[v >> 8];
+ else
+ return bytemsb[v];
+ }
+
+ /** Highest bit set in a byte. */
+ private static final byte bytemsb[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 /* 256 */};
+
+ /**
+ * Returns the last index less than <code>where</code> in the
+ * bit string which is set, or -1 if there is no such index.
+ * @param where the starting point for the search.
+ */
+ public int lastSet(int where) {
+ // convert exclusive starting point to inclusive starting point
+ if (--where < 0) return -1;
+ int start = (bits.length - 1), mask = ~0;
+ if (subscript(where) < bits.length) {
+ // search in first unit is masked.
+ start = subscript(where);
+ mask = (~0) >>> (MASK - (where & mask));
+ }
+ // search through units
+ for (int i = start; i >= 0; i--, mask = ~0) {
+ int unit = bits[i] & mask;
+ if (unit != 0) return (i << BITS_PER_UNIT) + (bsr(unit) - 1);
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the last index in the bit string which is set, or
+ * -1 if there is no such index.
+ */
+ public int lastSet() {
+ return lastSet(size());
+ }
+
+ /**
+ * Sets all bits.
+ */
+ public void setAll() {
+ int i = bits.length;
+ while (i-- > 0) {
+ bits[i] = ~0;
+ }
+ }
+
+ /**
+ * Sets all bits up to and including the given bit.
+ * @param bit the bit to be set up to (zero-based)
+ */
+ public void setUpTo(int bit) {
+ int where = subscript(bit);
+ /* preaddition of 1 to bit is a clever hack to avoid long arithmetic */
+ bits[where] |= ((1 << ((bit + 1) & MASK)) - 1);
+ while (where-- > 0) {
+ bits[where] = ~0;
+ }
+ }
+
+ public void setRange(int lo, int hi) {
+ int where1 = subscript(lo);
+ int where2 = subscript(hi);
+ if (where1 == where2) {
+ for ( ; lo <= hi; ++lo)
+ bits[where1] |= (1 << (lo & MASK));
+ } else {
+ /* preaddition of 1 to bit is a clever hack to avoid long arithmetic */
+ bits[where2] |= ((1 << ((hi + 1) & MASK)) - 1);
+ while (--where2 > where1) {
+ bits[where2] = ~0;
+ }
+ bits[where1] |= -(1 << (lo & MASK));
+ }
+ }
+
+ /**
+ * Sets a bit.
+ * @param bit the bit to be set (zero-based)
+ */
+ public void set(int bit) {
+ bits[subscript(bit)] |= (1 << (bit & MASK));
+ }
+
+ /**
+ * Clears all bits.
+ */
+ public void clearAll() {
+ int i = bits.length;
+ while (i-- > 0) {
+ bits[i] = 0;
+ }
+ }
+
+ /**
+ * Clears all bits up to and including the given bit.
+ * @param bit the bit to be set up to (zero-based)
+ */
+ public void clearUpTo(int bit) {
+ int where = subscript(bit);
+ /* preaddition of 1 to bit is a clever hack to avoid long arithmetic */
+ bits[where] &= ~((1 << ((bit + 1) & MASK)) - 1);
+ while (where-- > 0) {
+ bits[where] = 0;
+ }
+ }
+
+ /**
+ * Clears a bit.
+ * @param bit the bit to be cleared (zero-based)
+ */
+ public void clear(int bit) {
+ bits[subscript(bit)] &= ~(1 << (bit & MASK));
+ }
+
+ /**
+ * Gets a bit.
+ * @param bit the bit to be gotten (zero-based)
+ */
+ public boolean get(int bit) {
+ int n = subscript(bit);
+ return ((bits[n] & (1 << (bit & MASK))) != 0);
+ }
+
+ /**
+ * Logically ANDs this bit set with the specified set of bits.
+ * Returns <code>true</code> if <code>this</code> was modified in
+ * response to the operation.
+ * @param set the bit set to be ANDed with
+ */
+ public boolean and(BitString set) {
+ if (this == set) { // should help alias analysis
+ return false;
+ }
+ int n = bits.length;
+ boolean changed = false;
+ for (int i = n; i-- > 0;) {
+ int old = bits[i];
+ bits[i] &= set.bits[i];
+ changed |= (old != bits[i]);
+ }
+ return changed;
+ }
+
+ /**
+ * Logically ORs this bit set with the specified set of bits.
+ * Returns <code>true</code> if <code>this</code> was modified in
+ * response to the operation.
+ * @param set the bit set to be ORed with
+ */
+ public boolean or(BitString set) {
+ if (this == set) { // should help alias analysis
+ return false;
+ }
+ int setLength = set.bits.length;
+ boolean changed = false;
+ for (int i = setLength; i-- > 0;) {
+ int old = bits[i];
+ bits[i] |= set.bits[i];
+ changed |= (old != bits[i]);
+ }
+ return changed;
+ }
+
+ /**
+ * Logically ORs this bit set with the specified set of bits.
+ * Returns <code>true</code> if <code>this</code> was modified in
+ * response to the operation.
+ * @param set the bit set to be ORed with
+ */
+ public boolean or_upTo(BitString set, int bit) {
+ if (this == set) { // should help alias analysis
+ return false;
+ }
+ boolean result;
+ int where = subscript(bit);
+ int old = bits[where];
+ bits[where] |= (set.bits[where] & ((1 << ((bit + 1) & MASK)) - 1));
+ result = (bits[where] != old);
+ while (where-- > 0) {
+ old = bits[where];
+ bits[where] |= set.bits[where];
+ result |= (bits[where] != old);
+ }
+ return result;
+ }
+
+ /**
+ * Logically XORs this bit set with the specified set of bits.
+ * Returns <code>true</code> if <code>this</code> was modified in
+ * response to the operation.
+ * @param set the bit set to be XORed with
+ */
+ public boolean xor(BitString set) {
+ int setLength = set.bits.length;
+ boolean changed = false;
+ for (int i = setLength; i-- > 0;) {
+ int old = bits[i];
+ bits[i] ^= set.bits[i];
+ changed |= (old != bits[i]);
+ }
+ return changed;
+ }
+
+ /**
+ * Logically subtracts this bit set with the specified set of bits.
+ * Returns <code>true</code> if <code>this</code> was modified in
+ * response to the operation.
+ * @param set the bit set to subtract
+ */
+ public boolean minus(BitString set) {
+ int n = bits.length;
+ boolean changed = false;
+ for (int i = n; i-- > 0;) {
+ int old = bits[i];
+ bits[i] &= ~set.bits[i];
+ changed |= (old != bits[i]);
+ }
+ return changed;
+ }
+
+ /**
+ * Check if the intersection of the two sets is empty
+ * @param other the set to check intersection with
+ */
+ public boolean intersectionEmpty(BitString other) {
+ int n = bits.length;
+ for (int i = n; i-- > 0;) {
+ if ((bits[i] & other.bits[i]) != 0) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Check if this set contains all bits of the given set.
+ * @param other the set to check containment with
+ */
+ public boolean contains(BitString other) {
+ int n = bits.length;
+ for (int i = n; i-- > 0;) {
+ if ((bits[i] & other.bits[i]) != other.bits[i]) return false;
+ }
+ return true;
+ }
+
+ private static void shld(int[] bits, int i1, int i2, int amt) {
+ //Assert._assert(amt >= 0 && amt < BITS_PER_UNIT);
+ bits[i1] = (bits[i1] << amt) | ((bits[i2] << (BITS_PER_UNIT - amt)) >> (BITS_PER_UNIT - amt));
+ }
+
+ /**
+ * Performs a left-shift operation.
+ * @param amt number of bits to shift, can be negative
+ */
+ public void shl(int amt) {
+ final int div = amt >> BITS_PER_UNIT;
+ final int mod = amt & MASK;
+ final int size = bits.length;
+ if (amt < 0) {
+ shr(-amt); return;
+ }
+ // big moves
+ if (div > 0) {
+ System.arraycopy(bits, 0, bits, div, size - div);
+ for (int i = 0; i < div; ++i)
+ bits[i] = 0;
+ /*
+ int i;
+ for (i = size - 1; i >= div; --i) {
+ bits[i] = bits[i - div];
+ }
+ for (; i >= 0; --i) {
+ bits[i] = 0;
+ }
+ */
+ }
+ // small moves
+ if (mod > 0) {
+ int i;
+ for (i = size - 1; i > div; --i) {
+ shld(bits, i, i - 1, mod);
+ }
+ bits[i] <<= mod;
+ }
+ }
+
+ private static void shrd(int[] bits, int i1, int i2, int amt) {
+ //Assert._assert(amt >= 0 && amt < BITS_PER_UNIT);
+ bits[i1] = (bits[i1] >>> amt) | ((bits[i2] >>> (BITS_PER_UNIT - amt)) << (BITS_PER_UNIT - amt));
+ }
+
+ /**
+ * Performs a right-shift operation.
+ * @param amt number of bits to shift
+ */
+ public void shr(int amt) {
+ final int div = amt >> BITS_PER_UNIT;
+ final int mod = amt & MASK;
+ final int size = bits.length;
+ // big moves
+ if (div > 0) {
+ System.arraycopy(bits, div, bits, 0, size - div);
+ for (int i = size-div; i < size; ++i)
+ bits[i] = 0;
+ /*
+ int i;
+ for (i = 0; i < size - div; ++i) {
+ bits[i] = bits[i + div];
+ }
+ for (; i < size; ++i) {
+ bits[i] = 0;
+ }
+ */
+ }
+ // small moves
+ if (mod > 0) {
+ int i;
+ for (i = 0; i < size - div - 1; ++i) {
+ shrd(bits, i, i + 1, mod);
+ }
+ bits[i] >>>= mod;
+ }
+ }
+
+ /**
+ * Copies the values of the bits in the specified set into this set.
+ * @param set the bit set to copy the bits from
+ */
+ public void copyBits(BitString set) {
+ System.arraycopy(set.bits, 0, bits, 0, Math.min(bits.length, set.bits.length));
+ }
+
+ /**
+ * Returns a hash code value for this bit string whose value depends
+ * only on which bits have been set within this <code>BitString</code>.
+ */
+ public int hashCode() {
+ int h = 1234;
+ for (int i = bits.length; --i >= 0;) {
+ h ^= bits[i] * (i + 1);
+ }
+ return h;
+ }
+
+ /**
+ * Returns the "logical size" of this <code>BitString</code>: the
+ * index of the highest set bit in the <code>BitString</code> plus
+ * one. Returns zero if the <code>BitString</code> contains no
+ * set bits.
+ */
+ public int length() {
+ return lastSet() + 1;
+ }
+
+ /**
+ * Returns the number of bits of space actually in use by this
+ * <code>BitString</code> to represent bit values.
+ * The maximum element in the set is the size - 1st element.
+ * The minimum element in the set is the zero'th element.
+ */
+ public int size() {
+ return bits.length << BITS_PER_UNIT;
+ }
+
+ /**
+ * Compares this object against the specified object.
+ * @param obj the object to compare with
+ * @return true if the contents of the bitsets are the same; false otherwise.
+ */
+ public boolean equals(Object obj) {
+ BitString set;
+ if (obj == null) return false;
+ if (this == obj) return true; //should help alias analysis
+ try {
+ set = (BitString) obj;
+ } catch (ClassCastException e) {
+ return false;
+ }
+ if (length() != set.length()) return false;
+ int n = bits.length - 1;
+ while (n >= 0 && bits[n] == 0) n--;
+ // now n has the first non-zero entry
+ for (int i = n; i >= 0; i--) {
+ if (bits[i] != set.bits[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns whether this <code>BitString</code> is all zeroes.
+ * @return true if it is all zeroes.
+ */
+ public boolean isZero() {
+ int setLength = bits.length;
+ for (int i = setLength; i-- > 0;) {
+ if (bits[i] != 0) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the number of ones in this <code>BitString</code>.
+ * @return number of bits set.
+ */
+ public int numberOfOnes() {
+ int setLength = bits.length;
+ int number = 0;
+ for (int i = setLength; i-- > 0;) {
+ number += popcount(bits[i]);
+ }
+ return number;
+ }
+
+ /**
+ * Returns the number of ones in this <code>BitString</code> up to a given index.
+ * @return number of bits set.
+ */
+ public int numberOfOnes(int where) {
+ int setLength = subscript(where);
+ int number = 0;
+ for (int i = setLength; i-- > 0;) {
+ number += popcount(bits[i]);
+ }
+ number += popcount(bits[setLength] & ((1 << ((where + 1) & MASK)) - 1));
+ return number;
+ }
+
+ /**
+ * Clones the BitString.
+ */
+ public Object clone() {
+ BitString result = null;
+ try {
+ result = (BitString) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // this shouldn't happen, since we are Cloneable
+ throw new InternalError();
+ }
+ result.bits = new int[bits.length];
+ System.arraycopy(bits, 0, result.bits, 0, result.bits.length);
+ return result;
+ }
+
+ /**
+ * Converts the BitString to a String.
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ boolean needSeparator = false;
+ buffer.append('{');
+ for (ForwardBitStringIterator i=iterator(); i.hasNext(); ) {
+ int x = i.nextIndex();
+ if (needSeparator) {
+ buffer.append(", ");
+ } else {
+ needSeparator = true;
+ }
+ buffer.append(x);
+ }
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+ /**
+ * Returns an iterator that iterates through the bits in forward order.
+ */
+ public ForwardBitStringIterator iterator() {
+ return new ForwardBitStringIterator();
+ }
+
+ public ForwardBitStringZeroIterator zeroIterator() {
+ return new ForwardBitStringZeroIterator();
+ }
+
+ /**
+ * Returns an iterator that iterates through the bits in backward order.
+ */
+ public BackwardBitStringIterator backwardsIterator() {
+ return new BackwardBitStringIterator();
+ }
+
+ /**
+ * Returns an iterator that iterates through the bits in backward order,
+ * starting at the given index.
+ */
+ public BackwardBitStringIterator backwardsIterator(int i) {
+ return new BackwardBitStringIterator(i);
+ }
+
+ /**
+ * Abstract bit string iterator class.
+ */
+ public abstract static class BitStringIterator implements Iterator {
+
+ /**
+ * Returns the index of the next bit set.
+ */
+ public abstract int nextIndex();
+
+ /**
+ * @see java.util.Iterator#next()
+ */
+ public final Object next() {
+ return new Integer(nextIndex());
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("Unmodifiable Iterator");
+ }
+
+ }
+
+ /**
+ * Iterator for iterating through a bit string in forward order.
+ */
+ public class ForwardBitStringIterator extends BitStringIterator {
+ private int j, k, t;
+
+ ForwardBitStringIterator() {
+ j = 0;
+ k = 0;
+ t = bits[0];
+ }
+
+ /**
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ while (t == 0) {
+ if (j == bits.length - 1) return false;
+ t = bits[++j];
+ k += 1 << BITS_PER_UNIT;
+ }
+ return true;
+ }
+
+ /**
+ * @see jwutil.math.BitString.BitStringIterator#nextIndex()
+ */
+ public int nextIndex() {
+ while (t == 0) {
+ if (j == bits.length - 1) throw new java.util.NoSuchElementException();
+ t = bits[++j];
+ k += 1 << BITS_PER_UNIT;
+ }
+ int t2 = (t ^ (-t));
+ int index = 31 - popcount(t2);
+ t &= t2;
+ return k + index;
+ /*
+ int t2 = ~(t | (-t));
+ int index = popcount(t2);
+ t &= ~(t2 + 1);
+ return k + index;
+ */
+ }
+
+ }
+
+ /**
+ * Iterator for iterating through a bit string in forward order.
+ */
+ public class ForwardBitStringZeroIterator extends BitStringIterator {
+ private int j, k, t;
+
+ ForwardBitStringZeroIterator() {
+ j = 0;
+ k = 0;
+ t = ~bits[0];
+ }
+
+ /**
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ while (t == 0) {
+ if (j == bits.length - 1) return false;
+ t = ~bits[++j];
+ k += 1 << BITS_PER_UNIT;
+ }
+ return true;
+ }
+
+ /**
+ * @see jwutil.math.BitString.BitStringIterator#nextIndex()
+ */
+ public int nextIndex() {
+ while (t == 0) {
+ if (j == bits.length - 1) throw new java.util.NoSuchElementException();
+ t = ~bits[++j];
+ k += 1 << BITS_PER_UNIT;
+ }
+ int t2 = (t ^ (-t));
+ int index = 31 - popcount(t2);
+ t &= t2;
+ return k + index;
+ }
+
+ }
+
+ /**
+ * Iterator for iterating through a bit string in backward order.
+ */
+ public class BackwardBitStringIterator extends BitStringIterator {
+ private int j, k, t;
+
+ BackwardBitStringIterator(int i) {
+ j = subscript(i);
+ t = bits[j];
+ t &= (1 << ((i + 1) & MASK)) - 1;
+ k = j << BITS_PER_UNIT;
+ }
+
+ BackwardBitStringIterator() {
+ j = bits.length - 1;
+ t = bits[j];
+ k = j << BITS_PER_UNIT;
+ }
+
+ /**
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ while (t == 0) {
+ if (j == 0) {
+ return false;
+ }
+ t = bits[--j];
+ k -= 1 << BITS_PER_UNIT;
+ }
+ return true;
+ }
+
+ /**
+ * @see jwutil.math.BitString.BitStringIterator#nextIndex()
+ */
+ public int nextIndex() {
+ while (t == 0) {
+ if (j == 0) throw new java.util.NoSuchElementException();
+ t = bits[--j];
+ k -= 1 << BITS_PER_UNIT;
+ }
+ int index = bsr(t) - 1;
+ t &= ~(1 << index);
+ return k + index;
+ }
+
+ }
+}
Modified: trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -295,7 +295,7 @@
* @see net.sf.javabdd.BDDFactory#setCacheRatio(int)
*/
public double setCacheRatio(double x) {
- return setCacheRatio0((int)(x * 100.)) / 100.;
+ return setCacheRatio0((int)x);
}
private static native int setCacheRatio0(int x);
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-12-05 10:59:01 UTC (rev 475)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -214,7 +214,7 @@
public int getCacheSize() { return cachesize; }
public int reorderGain() { return bdd_reorder_gain(); }
public void printStat() { bdd_fprintstat(System.out); }
- public double setCacheRatio(double x) { return bdd_setcacheratio((int)(x * 100)) / 100.; }
+ public double setCacheRatio(double x) { return bdd_setcacheratio((int)x); }
public int varNum() { return bdd_varnum(); }
public int setVarNum(int num) { return bdd_setvarnum(num); }
public void printAll() { bdd_fprintall(System.out); }
@@ -1431,7 +1431,7 @@
}
checkresize();
- if (true) bdd_validate(res);
+ if (false) bdd_validate(res);
return res;
}
@@ -2574,7 +2574,7 @@
}
checkresize();
- if (true) bdd_validate(res);
+ if (false) bdd_validate(res);
return res;
}
@@ -5331,21 +5331,28 @@
resizedInMakenode = false;
if (imatrixDepends(iactmtx, var, bddlevel2var[level + 1])) {
+ // This var depends on the next one.
+ // (ie there is some BDD with both this var and the next one)
+
+ // Rehash this level and return a list of nodes that depend on the
+ // next level.
int toBeProcessed = reorder_downSimple(var);
levelData l = levels[var];
if (l.nodenum < (l.size) / 3
|| l.nodenum >= (l.size * 3) / 2
&& l.size < l.maxsize) {
+ // Hash table for this level is too big or too small, resize it.
reorder_swapResize(toBeProcessed, var);
reorder_localGbcResize(toBeProcessed, var);
} else {
+ // Swap the variable and do a GC pass on this level.
reorder_swap(toBeProcessed, var);
reorder_localGbc(var);
}
}
- /* Swap the var<->level tables */
+ // Swap the var<->level tables
n = bddlevel2var[level];
bddlevel2var[level] = bddlevel2var[level + 1];
bddlevel2var[level + 1] = n;
@@ -5439,13 +5446,17 @@
int reorder_downSimple(int var0) {
int toBeProcessed = 0;
+
+ // Next variable to swap with.
int var1 = bddlevel2var[bddvar2level[var0] + 1];
+
+ // Hash table range for source variable.
int vl0 = levels[var0].start;
int size0 = levels[var0].size;
int n;
+ // Rehash this level and recalculate the number of nodes.
levels[var0].nodenum = 0;
-
for (n = 0; n < size0; n++) {
int r;
@@ -5455,26 +5466,17 @@
while (r != 0) {
int next = NEXT(r);
-/***
- if (LOW(r) == -1) {
- System.out.println(r+": LOW="+LOW(r));
- }
- if (HIGH(r) == -1) {
- System.out.println(r+": HIGH="+HIGH(r));
- }
-***/
if (VARr(LOW(r)) != var1 && VARr(HIGH(r)) != var1) {
- /* Node does not depend on next var, let it stay in the chain */
+ // Node does not depend on next var, put it in the chain
SETNEXT(r, HASH(n + vl0));
SETHASH(n + vl0, r);
levels[var0].nodenum++;
} else {
- /* Node depends on next var - save it for later procesing */
+ // Node depends on next var - save it for later processing
SETNEXT(r, toBeProcessed);
toBeProcessed = r;
if (SWAPCOUNT)
cachestats.swapCount++;
-
}
r = next;
@@ -5493,7 +5495,7 @@
int f1 = HIGH(toBeProcessed);
int f00, f01, f10, f11;
- /* Find the cofactors for the new nodes */
+ // Find the cofactors for the new nodes
if (VARr(f0) == var1) {
f00 = LOW(f0);
f01 = HIGH(f0);
@@ -5520,14 +5522,14 @@
DECREF(LOW(toBeProcessed));
DECREF(HIGH(toBeProcessed));
- /* Update in-place */
+ // Update in-place
SETVARr(toBeProcessed, var1);
SETLOW(toBeProcessed, f0);
SETHIGH(toBeProcessed, f1);
levels[var1].nodenum++;
- /* Do not rehash yet since we are going to resize the hash table */
+ // Do not rehash yet since we are going to resize the hash table
toBeProcessed = next;
}
@@ -5595,13 +5597,15 @@
void reorder_swap(int toBeProcessed, int var0) {
int var1 = bddlevel2var[bddvar2level[var0] + 1];
+ // toBeProcessed is a linked list of nodes that depend on the next level.
+
while (toBeProcessed != 0) {
int next = NEXT(toBeProcessed);
int f0 = LOW(toBeProcessed);
int f1 = HIGH(toBeProcessed);
int f00, f01, f10, f11, hash;
- /* Find the cofactors for the new nodes */
+ // Find the cofactors for the new nodes
if (VARr(f0) == var1) {
f00 = LOW(f0);
f01 = HIGH(f0);
@@ -5620,22 +5624,25 @@
//node = bddnodes[toBeProcessed]; /* Might change in makenode */
/* We know that the refcou of the grandchilds of this node
- * is greater than one (these are f00...f11), so there is
- * no need to do a recursive refcou decrease. It is also
- * possible for the node.low/high nodes to come alive again,
- * so deref. of the childs is delayed until the local GBC. */
+ * is greater than one (these are f00...f11), so there is
+ * no need to do a recursive refcou decrease. It is also
+ * possible for the node.low/high nodes to come alive again,
+ * so deref. of the childs is delayed until the local GBC. */
DECREF(LOW(toBeProcessed));
DECREF(HIGH(toBeProcessed));
- /* Update in-place */
+ // Update in-place
+ // NOTE: This node may be a duplicate. However, we add this to the start
+ // of the list so we will always encounter this one first. The refcount
+ // of the node we duplicated will go to zero.
SETVARr(toBeProcessed, var1);
SETLOW(toBeProcessed, f0);
SETHIGH(toBeProcessed, f1);
levels[var1].nodenum++;
- /* Rehash the node since it got new childs */
+ // Rehash the node since it has new children
hash = NODEHASH2(VARr(toBeProcessed), LOW(toBeProcessed), HIGH(toBeProcessed));
SETNEXT(toBeProcessed, HASH(hash));
SETHASH(hash, toBeProcessed);
@@ -5658,7 +5665,7 @@
cachestats.uniqueAccess++;
/* Note: We know that low,high has a refcou greater than zero, so
- there is no need to add reference *recursively* */
+ there is no need to add reference *recursively* */
if (ZDD) {
/* check whether high child is zero */
@@ -5701,9 +5708,9 @@
return 0;
/* Try to allocate more nodes - call noderesize without
- * enabling rehashing.
+ * enabling rehashing.
* Note: if ever rehashing is allowed here, then remember to
- * update local variable "hash" */
+ * update local variable "hash" */
bdd_noderesize(false);
resizedInMakenode = true;
@@ -5740,12 +5747,18 @@
}
int reorder_init() {
+ // This method does the following:
+ // - Calculate interaction matrix "iactmtx"
+ // - Calculates the number of nodes with each variable.
+ // - Mutates each node to store the var instead of the level.
+ // - Sets refcounts for all links, including internal ones.
+
int n;
reorder_handler(true, reorderstats);
+ // Split the hash table into a separate region for each variable.
levels = new levelData[bddvarnum];
-
for (n = 0; n < bddvarnum; n++) {
levels[n] = new levelData();
levels[n].start = -1;
@@ -5753,15 +5766,15 @@
levels[n].nodenum = 0;
}
- /* First mark and recursive refcou. all roots and childs. Also do some
- * setup here for both setLevellookup and reorder_gbc */
+ // First mark and recursive refcou. all roots and childs. Also do some
+ // setup here for both setLevellookup and reorder_gbc
if (mark_roots() < 0)
return -1;
- /* Initialize the hash tables */
+ // Initialize the hash tables
reorder_setLevellookup();
- /* Garbage collect and rehash to new scheme */
+ // Garbage collect and rehash to new scheme
reorder_gbc();
return 0;
@@ -5786,14 +5799,19 @@
iactmtx = imatrixNew(bddvarnum);
+ // Loop to compute dependences and node refcounts.
for (n = 2, extrootsize = 0; n < bddnodesize; n++) {
if (MARKED(n)) {
+ // Node has an external reference.
UNMARK(n);
extroots[extrootsize++] = n;
+ // Calculate the set of variables in this BDD.
+ // Also sets refcounts on internal nodes.
for (int i = 0; i < bddvarnum; ++i)
dep[i] = false;
+
dep[VARr(n)] = true;
levels[VARr(n)].nodenum++;
@@ -5835,12 +5853,15 @@
return;
if (!HASREF(r) || MARKED(r)) {
+ // We haven't processed the node yet.
+ // Processed nodes have a refcount and are unmarked.
+
bddfreenum--;
- /* Detect variable dependencies for the interaction matrix */
+ // Detect variable dependencies for the interaction matrix
dep[VARr(r) & ~MARK_MASK] = true;
- /* Make sure the nodenum field is updated. Used in the initial GBC */
+ // Make sure the nodenum field is updated. Used in the initial GBC
levels[VARr(r) & ~MARK_MASK].nodenum++;
addref_rec(LOW(r), dep);
@@ -5848,8 +5869,8 @@
} else {
int n;
- /* Update (from previously found) variable dependencies
- * for the interaction matrix */
+ // Update (from previously found) variable dependencies
+ // for the interaction matrix
for (n = 0; n < bddvarnum; n++)
dep[n]
|= imatrixDepends(iactmtx, VARr(r) & ~MARK_MASK, n);
@@ -5913,7 +5934,7 @@
CLEARREF(n);
/* This is where we go from .var to .level again!
- * - Do NOT use the LEVEL macro here. */
+ * - Do NOT use the LEVEL macro here. */
SETLEVELANDMARK(n, bddvar2level[LEVELANDMARK(n)]);
}
Added: trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java (rev 0)
+++ trunk/JavaBDD/net/sf/javabdd/UberMicroFactory.java 2007-03-06 06:08:40 UTC (rev 476)
@@ -0,0 +1,6763 @@
+// UberMicroFactory.java, created Jan 29, 2005 8:24:17 PM by joewhaley
+// Copyright (C) 2005 John Whaley <jw...@al...>
+// Licensed under the terms of the GNU LGPL; see COPYING for details.
+package net.sf.javabdd;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Random;
+import java.util.Set;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.PrintStream;
+
+/**
+ * <p>BDD factory where each node only takes 16 bytes.
+ * This is accomplished by tightly packing the bits, eliminating
+ * the refcount, splitting out the unique table and limiting the
+ * maximum number of BDD variables to 2^11 = 2048.</p>
+ *
+ * <p>This BDD factory is not only more memory efficient than
+ * JFactory, it also seems to perform better, probably due to
+ * better memory locality. It performs cache-aware BDD node
+ * placement.</p>
+ *
+ * @author jwhaley
+ * @version $Id: UberMicroFactory.java 465 2006-07-26 16:42:44Z joewhaley $
+ */
+public class UberMicroFactory extends BDDFactoryIntImpl {
+
+ public static boolean FLUSH_CACHE_ON_GC = true;
+
+ static final boolean VERIFY_ASSERTIONS = true;
+ static final boolean ORDER_CACHE = false;
+ static final int CACHESTATS = 0;
+ static final boolean SWAPCOUNT = false;
+
+ public static final String REVISION = "$Revision: 465 $";
+
+ public String getVersion() {
+ return "UberMicroFactory "+REVISION.substring(11, REVISION.length()-2);
+ }
+
+ private UberMicroFactory() { }
+
+ /* (non-Javadoc)
+ * @see net.sf.javabdd.BDDFactory#init(int, int)
+ */
+ public static BDDFactory init(int nodenum, int cachesize) {
+ BDDFactory f = new UberMicroFactory();
+ f.initialize(nodenum, cachesize);
+ if (CACHESTATS > 0) addShutdownHook(f);
+ return f;
+ }
+
+ static void addShutdownHook(final BDDFactory f) {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ System.out.println(f.getCacheStats().toString());
+ }
+ });
+ }
+
+ protected IntBDD makeBDD(/*bdd*/int v) {
+ return new Micro5BDD(v);
+ }
+
+ static final boolean USE_WEAK_REFS = false;
+
+ Collection externalRefBDDs, externalRefVarSets;
+
+ class Micro5BDD extends BDDFactoryIntImpl.IntBDD {
+ Micro5BDD(int v) {
+ super(v);
+ if (VERIFY_ASSERTIONS) {
+ if (v == INVALID_BDD)
+ bdd_error(BDD_BREAK); /* distinctive */
+ if (v >= bddnodesize)
+ bdd_error(BDD_ILLBDD);
+ if (bddnodes[v] == 0)
+ bdd_error(BDD_ILLBDD);
+ }
+ if (USE_WEAK_REFS)
+ externalRefBDDs.add(new java.lang.ref.WeakReference(this));
+ else
+ externalRefBDDs.add(this);
+ }
+ }
+
+ protected IntBDDVarSet makeBDDVarSet(/*bdd*/int v) {
+ return new Micro5VarSet(v);
+ }
+
+ public class Micro5VarSet extends IntBDDVarSet {
+ Micro5VarSet(int v) {
+ super(v);
+ if (VERIFY_ASSERTIONS) {
+ if (v == INVALID_BDD)
+ bdd_error(BDD_BREAK); /* distinctive */
+ if (v >= bddnodesize)
+ bdd_error(BDD_ILLBDD);
+ if (bddnodes[v] == 0)
+ bdd_error(BDD_ILLBDD);
+ }
+ if (USE_WEAK_REFS)
+ externalRefVarSets.add(new java.lang.ref.WeakReference(this));
+ else
+ externalRefVarSets.add(this);
+ }
+ }
+
+ public void handleDeferredFree() {
+ to_free_length = 0;
+ }
+
+ /**
+ * Implementation of BDDPairing used by JFactory.
+ */
+ class bddPair extends BDDPairing {
+ int[] result;
+ int last;
+ int id;
+ bddPair next;
+
+ /* (non-Javadoc)
+ * @see net.sf.javabdd.BDDPairing#set(int, int)
+ */
+ public void set(int oldvar, int newvar) {
+ bdd_setpair(this, oldvar, newvar);
+ }
+ /* (non-Javadoc)
+ * @see net.sf.javabdd.BDDPairing#set(int, net.sf.javabdd.BDD)
+ */
+ public void set(int oldvar, BDD newvar) {
+ bdd_setbddpair(this, oldvar, unwrap(newvar));
+ }
+ /* (non-Javadoc)
+ * @see net.sf.javabdd.BDDPairing#reset()
+ */
+ public void reset() {
+ bdd_resetpair(this);
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append('{');
+ boolean any = false;
+ for (int i = 0; i < result.length; ++i) {
+ if (result[i] != bdd_ithvar(bddlevel2var[i])) {
+ if (any) sb.append(", ");
+ any = true;
+ sb.append(bddlevel2var[i]);
+ sb.append('=');
+ BDD b = makeBDD(result[i]);
+ sb.append(b);
+ b.free();
+ }
+ }
+ sb.append('}');
+ return sb.toString();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see net.sf.javabdd.BDDFactory#makePair()
+ */
+ public BDDPairing makePair() {
+ bddPair p = new bddPair();
+ p.result = new int[bddvarnum];
+ int n;
+ for (n = 0; n < bddvarnum; n++)
+ p.result[n] = bdd_ithvar(bddlevel2var[n]);
+
+ p.id = update_pairsid();
+ p.last = -1;
+
+ bdd_register_pair(p);
+ return p;
+ }
+
+ // Redirection functions.
+
+ protected void addref_impl(int v) { }
+ protected void delref_impl(int v) { }
+ protected int zero_impl() { return BDDZERO; }
+ protected int one_impl() { return BDDONE; }
+ protected int invalid_bdd_impl() { return INVALID_BDD; }
+ protected int var_impl(int v) { return bdd_var(v); }
+ protected int level_impl(int v) { return LEVEL(v); }
+ protected int low_impl(int v) { return bdd_low(v); }
+ protected int high_impl(int v) { return bdd_high(v); }
+ protected int ithVar_impl(int var) { return bdd_ithvar(var); }
+ protected int nithVar_impl(int var) { return bdd_nithvar(var); }
+
+ protected int makenode_impl(int lev, int lo, int hi) { return bdd_makenode(lev, lo, hi); }
+ protected int ite_impl(int v1, int v2, int v3) { return bdd_ite(v1, v2, v3); }
+ protected int apply_impl(int v1, int v2, BDDOp opr) { return bdd_apply(v1, v2, opr.id); }
+ protected int not_impl(int v1) { return bdd_not(v1); }
+ protected int applyAll_impl(int v1, int v2, BDDOp opr, int v3) { return bdd_appall(v1, v2, opr.id, v3); }
+ protected int applyEx_impl(int v1, int v2, BDDOp opr, int v3) { return bdd_appex(v1, v2, opr.id, v3); }
+ protected int applyUni_impl(int v1, int v2, BDDOp opr, int v3) { return bdd_appuni(v1, v2, opr.id, v3); }
+ protected int compose_impl(int v1, int v2, int var) { return bdd_compose(v1, v2, var); }
+ protected int constrain_impl(int v1, int v2) { return bdd_constrain(v1, v2); }
+ protected int restrict_impl(int v1, int v2) { return bdd_restrict(v1, v2); }
+ protected int simplify_impl(int v1, int v2) { return bdd_simplify(v1, v2); }
+ protected int support_impl(int v) { return bdd_support(v); }
+ protected int exist_impl(int v1, int v2) { return bdd_exist(v1, v2); }
+ protected int forAll_impl(int v1, int v2) { return bdd_forall(v1, v2); }
+ protected int unique_impl(int v1, int v2) { return bdd_unique(v1, v2); }
+ protected int fullSatOne_impl(int v) { return bdd_fullsatone(v); }
+
+ protected int replace_impl(int v, BDDPairing p) { return bdd_replace(v, (bddPair)p); }
+ protected int veccompose_impl(int v, BDDPairing p) { return bdd_veccompose(v, (bddPair)p); }
+
+ protected int nodeCount_impl(int v) { return bdd_nodecount(v); }
+ protected double pathCount_impl(int v) { return bdd_pathcount(v); }
+ protected double satCount_impl(int v) { return bdd_satcount(v); }
+ protected int satOne_impl(int v) { return bdd_satone(v); }
+ protected int satOne_impl2(int v1, int v2, boolean pol) { return bdd_satoneset(v1, v2, pol); }
+ protected int nodeCount_impl2(int[] v) { return bdd_anodecount(v); }
+ protected int[] varProfile_impl(int v) { return bdd_varprofile(v); }
+ protected void printTable_impl(int v) { bdd_fprinttable(System.out, v); }
+
+ // More redirection functions.
+
+ protected void initialize(int initnodesize, int cs) { bdd_init(initnodesize, cs); }
+ public void addVarBlock(int first, int last, boolean fixed) { bdd_intaddvarblock(first, last, fixed); }
+ public void varBlockAll() { bdd_varblockall(); }
+ public void clearVarBlocks() { bdd_clrvarblocks(); }
+ public void printOrder() { bdd_fprintorder(System.out); }
+ public int getNodeTableSize() { return bdd_getallocnum(); }
+ public int setNodeTableSize(int size) { return bdd_setallocnum(size); }
+ public int setCacheSize(int v) { return bdd_setcachesize(v); }
+ public boolean isInitialized() { return bddrunning; }
+ public void done() { super.done(); bdd_done(); }
+ public void setError(int code) { bdderrorcond = code; }
+ public void clearError() { bdderrorcond = 0; }
+ public int setMaxNodeNum(int size) { return bdd_setmaxnodenum(size); }
+ public double setMinFreeNodes(double x) { return bdd_setminfreenodes((int)(x * 100.)) / 100.; }
+ public int setMaxIncrease(int x) { return bdd_setmaxincrease(x); }
+ public double setIncreaseFactor(double x) { return bdd_setincreasefactor(x); }
+ public int getNodeNum() { return bdd_getnodenum(); }
+ public int getCacheSize() { return cachesize; }
+ public int reorderGain() { return bdd_reorder_gain(); }
+ public void printStat() { bdd_fprintstat(System.out); }
+ public double setCacheRatio(double x) { return bdd_setcacheratio((int)x); }
+ public int varNum() { return bdd_varnum(); }
+ public int setVarNum(int num) { return bdd_setvarnum(num); }
+ public void printAll() { bdd_fprintall(System.out); }
+ public BDD load(BufferedReader in, int[] translate) throws IOException { return makeBDD(bdd_load(in, translate)); }
+ public void save(BufferedWriter out, BDD b) throws IOException { bdd_save(out, unwrap(b)); }
+ public void setVarOrder(int[] neworder) { bdd_setvarorder(neworder); }
+ public int level2Var(int level) { return bddlevel2var[level]; }
+ public int var2Level(int var) { return bddvar2level[var]; }
+ public int getReorderTimes() { return bddreordertimes; }
+ public void disableReorder() { bdd_disable_reorder(); }
+ public void enableReorder() { bdd_enable_reorder(); }
+ public int reorderVerbose(int v) { return bdd_reorder_verbose(v); }
+ public void reorder(ReorderMethod m) { bdd_reorder(m.id); }
+ public void autoReorder(ReorderMethod method) { bdd_autoreorder(method.id); }
+ public void autoReorder(ReorderMethod method, int max) { bdd_autoreorder_times(method.id, max); }
+ public void swapVar(int v1, int v2) { bdd_swapvar(v1, v2); }
+
+ public ReorderMethod getReorderMethod() {
+ switch (bddreordermethod) {
+ case BDD_REORDER_NONE :
+ return REORDER_NONE;
+ case BDD_REORDER_WIN2 :
+ return REORDER_WIN2;
+ case BDD_REORDER_WIN2ITE :
+ return REORDER_WIN2ITE;
+ case BDD_REORDER_WIN3 :
+ return REORDER_WIN3;
+ case BDD_REORDER_WIN3ITE :
+ return REORDER_WIN3ITE;
+ case BDD_REORDER_SIFT :
+ return REORDER_SIFT;
+ case BDD_REORDER_SIFTITE :
+ return REORDER_SIFTITE;
+ case BDD_REORDER_RANDOM :
+ return REORDER_RANDOM;
+ default :
+ throw new BDDException();
+ }
+ }
+
+ // Experimental functions.
+
+ public void validateAll() { bdd_validate_all(); }
+ public void validateLive() { bdd_validate_live(); }
+ public void validateBDD(BDD b) { bdd_validate(unwrap(b)); }
+
+
+ /***** IMPLEMENTATION BELOW *****/
+
+ long[] bddnodes;
+
+ static final int LEV_BITS = 11;
+ static final int NODE_BITS = 26;
+ static final int LOW_SHIFT = 12;
+ static final int HIGH_SHIFT = 38;
+ static final int LEV_SHIFT = 1;
+ static final int MARK_MASK = 0x001;
+ static final int LEV_MASK = 0xffe;
+ static final long LO_MASK = 0x0000003ffffff000L;
+ static final long HI_MASK = 0xffffffc000000000L;
+ static final long LOHILEV_MASK = LO_MASK | HI_MASK | LEV_MASK;
+
+ static final int INVALID_BDD = -1;
+ static final int MAXVAR = (1 << LEV_BITS) - 1;
+ static final int MAX_PAIRSID = MAXVAR;
+ static final int NODE_MASK = (1 << NODE_BITS) - 1;
+
+ private final int LEVEL(int node) {
+ return ((int)bddnodes[node] & LEV_MASK) >> LEV_SHIFT;
+ }
+
+ private final void SETLEVEL(int node, int val) {
+ if (VERIFY_ASSERTIONS)
+ _assert(val >= 0 && val <= MAXVAR);
+ long a = bddnodes[node] & ~LEV_MASK;
+ a |= val << LEV_SHIFT;
+ bddnodes[node] = a;
+ }
+
+ private final void SETMARK(int n) {
+ bddnodes[n] |= MARK_MASK;
+ }
+
+ private final void UNMARK(int n) {
+ if (VERIFY_ASSERTIONS) _assert(n > 1);
+ bddnodes[n] &= ~MARK_MASK;
+ }
+
+ private final boolean MARKED(int n) {
+ return ((int)bddnodes[n] & MARK_MASK) != 0;
+ }
+
+ private final int LOW(int r) {
+ return (int)(bddnodes[r] >> LOW_SHIFT) & NODE_MASK;
+ }
+
+ private final void SETLOW(int r, int v) {
+ if (VERIFY_ASSERTIONS) _assert(v >= 0 && v <= NODE_MASK);
+ long a = bddnodes[r] & ~LO_MASK;
+ a |= (long)v << LOW_SHIFT;
+ bddnodes[r] = a;
+ }
+
+ private final int HIGH(int r) {
+ return (int)(bddnodes[r] >> HIGH_SHIFT) & NODE_MASK;
+ }
+
+ private final void SETHIGH(int r, int v) {
+ if (VERIFY_ASSERTIONS) _assert(v >= 0 && v <= NODE_MASK);
+ long a = bddnodes[r] & ~HI_MASK;
+ a |= (long)v << HIGH_SHIFT;
+ bddnodes[r] = a;
+ }
+
+ private static final long MAKE_NODE(int lev, int lo, int hi) {
+ long a = lev << LEV_SHIFT;
+ a |= (long)lo << LOW_SHIFT;
+ a |= (long)hi << HIGH_SHIFT;
+ return a;
+ }
+
+ private final int VARr(int node) {
+ return ((int)bddnodes[node] & LEV_MASK) >> LEV_SHIFT;
+ }
+
+ private final void SETVARr(int node, int val) {
+ if (VERIFY_ASSERTIONS)
+ _assert(val >= 0 && val <= MAXVAR);
+ long a = bddnodes[node] & ~LEV_MASK;
+ a |= val << LEV_SHIFT;
+ bddnodes[node] = a;
+ }
+
+ static final int BUCKET_SIZE = 8;
+
+ class freelist {
+ BitString fullbuckets;
+
+ void reset() {
+ if (VERIFY_ASSERTIONS) _assert((bddnodesize & -BUCKET_SIZE) == bddnodesize);
+ int b = bddnodesize / BUCKET_SIZE;
+ if (fullbuckets == null || b != fullbuckets.size())
+ fullbuckets = new BitString(b);
+ last_bucket = 0;
+ }
+
+ void resize() {
+ if (fullbuckets == null) {
+ reset();
+ } else {
+ if (VERIFY_ASSERTIONS) _assert((bddnodesize & -BUCKET_SIZE) == bddnodesize);
+ int b = bddnodesize / BUCKET_SIZE;
+ if (b !...
[truncated message content] |
|
From: <joe...@us...> - 2006-12-05 10:59:03
|
Revision: 475
http://svn.sourceforge.net/javabdd/?rev=475&view=rev
Author: joewhaley
Date: 2006-12-05 02:59:01 -0800 (Tue, 05 Dec 2006)
Log Message:
-----------
Added random relprod test.
Modified Paths:
--------------
trunk/JavaBDD_tests/bdd/IteratorTests.java
Modified: trunk/JavaBDD_tests/bdd/IteratorTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-12-05 10:58:16 UTC (rev 474)
+++ trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-12-05 10:59:01 UTC (rev 475)
@@ -13,6 +13,7 @@
import net.sf.javabdd.BDDDomain;
import net.sf.javabdd.BDDFactory;
import net.sf.javabdd.BDDVarSet;
+import net.sf.javabdd.TestBDDFactory;
/**
* IteratorTests
@@ -21,6 +22,8 @@
* @version $Id$
*/
public class IteratorTests extends BDDTestCase {
+ static Random random = new Random(1238);
+
public static void main(String[] args) {
junit.textui.TestRunner.run(IteratorTests.class);
}
@@ -84,8 +87,6 @@
}
}
- static Random random = new Random(1234);
-
static BDD randomBDD(BDDFactory f) {
BDD result = f.zero();
for (int i = 0; i < f.varNum(); ++i) {
@@ -100,6 +101,15 @@
return result;
}
+ static BDDVarSet randomBDDVarSet(BDDFactory f) {
+ BDDVarSet s = f.emptySet();
+ for (int i = 0; i < f.varNum(); ++i) {
+ if (random.nextBoolean())
+ s.unionWith(i);
+ }
+ return s;
+ }
+
static BDD betterRandomBDD(BDDFactory f) {
// Use a random truth table.
byte[] bytes = new byte[(1 << f.varNum()) / 8 + 1];
@@ -153,6 +163,25 @@
}
}
+ public void testRandomRelprod() {
+ System.setProperty("bdd1", "zdd");
+ System.setProperty("bdd2", "j");
+ BDDFactory bdd = TestBDDFactory.init(10000, 1000);
+ bdd.setVarNum(5);
+ for (int i = 0; i < 1000; ++i) {
+ BDD b = betterRandomBDD(bdd);
+ BDD c = betterRandomBDD(bdd);
+ BDDVarSet d = randomBDDVarSet(bdd);
+ BDD e = b.relprod(c, d);
+
+ BDD f = b.and(c);
+ BDD g = f.exist(d);
+ Assert.assertEquals(g, e);
+
+ b.free(); c.free(); d.free(); e.free(); f.free(); g.free();
+ }
+ }
+
public void testRandomIterator() {
reset();
Assert.assertTrue(hasNext());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-12-05 10:58:18
|
Revision: 474
http://svn.sourceforge.net/javabdd/?rev=474&view=rev
Author: joewhaley
Date: 2006-12-05 02:58:16 -0800 (Tue, 05 Dec 2006)
Log Message:
-----------
Working ZDD exists() and relprod().
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-12-03 10:34:02 UTC (rev 473)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-12-05 10:58:16 UTC (rev 474)
@@ -421,7 +421,8 @@
} else {
int k = do_unionlevel(high_impl(v), lev);
addref_impl(k);
- int result = makenode_impl(lev, zero_impl(), k);
+ int result = makenode_impl(l, zero_impl(), k);
+ delref_impl(k);
return result;
}
}
Modified: trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java 2006-12-03 10:34:02 UTC (rev 473)
+++ trunk/JavaBDD/net/sf/javabdd/BDDVarSet.java 2006-12-05 10:58:16 UTC (rev 474)
@@ -3,6 +3,8 @@
// Licensed under the terms of the GNU LGPL; see COPYING for details.
package net.sf.javabdd;
+import java.util.Arrays;
+
/**
* <p>Some BDD methods, namely <tt>exist()</tt>, <tt>forall()</tt>, <tt>unique()</tt>,
* <tt>relprod()</tt>, <tt>applyAll()</tt>, <tt>applyEx()</tt>, <tt>applyUni()</tt>,
@@ -31,6 +33,10 @@
public abstract int[] toArray();
public abstract int[] toLevelArray();
+ public String toString() {
+ return Arrays.toString(toArray());
+ }
+
/**
* <p>Scans this BDD and copies the stored variables into an array of BDDDomains.
* The domains returned are guaranteed to be in ascending order.</p>
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-12-03 10:34:02 UTC (rev 473)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-12-05 10:58:16 UTC (rev 474)
@@ -37,7 +37,7 @@
*/
public static boolean FLUSH_CACHE_ON_GC = true;
- static final boolean VERIFY_ASSERTIONS = true;
+ static final boolean VERIFY_ASSERTIONS = false;
static final boolean CACHESTATS = false;
static final boolean SWAPCOUNT = false;
@@ -1431,6 +1431,7 @@
}
checkresize();
+ if (true) bdd_validate(res);
return res;
}
@@ -1565,7 +1566,7 @@
return zand_rec(LOW(l), r);
else if (LEVEL(l) > LEVEL(r))
return zand_rec(l, LOW(r));
- _assert(!ISCONST(l) && !ISCONST(r));
+ if (VERIFY_ASSERTIONS) _assert(!ISCONST(l) && !ISCONST(r));
entry = BddCache_lookupI(applycache, APPLYHASH(l, r, bddop_and));
@@ -1591,6 +1592,82 @@
return res;
}
+ int zrelprod_rec(int l, int r, int lev) {
+ BddCacheDataI entry;
+ int res;
+
+ if (l == r)
+ return zquant_rec(l, lev);
+ if (ISZERO(l) || ISZERO(r))
+ return 0;
+
+ int LEVEL_l = LEVEL(l);
+ int LEVEL_r = LEVEL(r);
+
+ for (;;) {
+ if (lev > quantlast) {
+ applyop = bddop_and;
+ res = zand_rec(l, r);
+ applyop = bddop_or;
+ return res;
+ }
+ if (lev >= LEVEL_l || lev >= LEVEL_r)
+ break;
+ if (INVARSET(lev)) {
+ res = zrelprod_rec(l, r, lev+1);
+ PUSHREF(res);
+ res = zdd_makenode(lev, res, res);
+ POPREF(1);
+ return res;
+ }
+ ++lev;
+ }
+
+ entry = BddCache_lookupI(appexcache, APPEXHASH(l, r, bddop_and));
+ if (entry.a == l && entry.b == r && entry.c == appexid) {
+ if (CACHESTATS)
+ cachestats.opHit++;
+ return entry.res;
+ }
+ if (CACHESTATS)
+ cachestats.opMiss++;
+
+ if (LEVEL_l == LEVEL_r) {
+ if (VERIFY_ASSERTIONS) _assert(LEVEL_l == lev);
+ PUSHREF(zrelprod_rec(LOW(l), LOW(r), lev+1));
+ PUSHREF(zrelprod_rec(HIGH(l), HIGH(r), lev+1));
+ if (INVARSET(lev)) {
+ res = zor_rec(READREF(2), READREF(1));
+ POPREF(2);
+ PUSHREF(res);
+ res = zdd_makenode(lev, res, res);
+ POPREF(1);
+ } else {
+ res = zdd_makenode(lev, READREF(2), READREF(1));
+ POPREF(2);
+ }
+ } else {
+ if (LEVEL_l < LEVEL_r) {
+ if (VERIFY_ASSERTIONS) _assert(LEVEL_l == lev);
+ res = zrelprod_rec(LOW(l), r, lev+1);
+ } else {
+ if (VERIFY_ASSERTIONS) _assert(LEVEL_r == lev);
+ res = zrelprod_rec(l, LOW(r), lev+1);
+ }
+ if (INVARSET(lev)) {
+ PUSHREF(res);
+ res = zdd_makenode(lev, res, res);
+ POPREF(1);
+ }
+ }
+ entry.a = l;
+ entry.b = r;
+ entry.c = appexid;
+ entry.res = res;
+
+ return res;
+ }
+
int or_rec(int l, int r) {
BddCacheDataI entry;
int res;
@@ -1808,14 +1885,6 @@
if (var < 2) /* Empty set */
return bdd_apply(l, r, opr);
- if (ZDD) {
- // TODO: A real ZDD implementation.
- int x = bdd_addref(bdd_apply(l, r, opr));
- int y = bdd_exist(x, var);
- bdd_delref(x);
- return y;
- }
-
if (applycache == null) applycache = BddCacheI_init(cachesize);
if (appexcache == null) appexcache = BddCacheI_init(cachesize);
if (quantcache == null) quantcache = BddCacheI_init(cachesize);
@@ -1833,7 +1902,11 @@
if (numReorder == 0)
bdd_disable_reorder();
- res = opr == bddop_and ? relprod_rec(l, r) : appquant_rec(l, r);
+ if (opr == bddop_and)
+ res = ZDD ? zrelprod_rec(l, r, 0) : relprod_rec(l, r);
+ else
+ res = appquant_rec(l, r);
+
if (numReorder == 0)
bdd_enable_reorder();
} catch (ReorderException x) {
@@ -2166,13 +2239,32 @@
return res;
}
- int zquant_rec(int r) {
+ int zquant_rec(int r, int lev) {
BddCacheDataI entry;
int res;
- if (r < 2 || LEVEL(r) > quantlast)
+ for (;;) {
+ if (lev > quantlast)
+ return r;
+ if (lev == LEVEL(r))
+ break;
+ if (INVARSET(lev)) {
+ switch (applyop) {
+ case bddop_and: return 0;
+ case bddop_or:
+ PUSHREF(zquant_rec(r, lev+1));
+ res = zdd_makenode(lev, READREF(1), READREF(1));
+ POPREF(1);
+ return res;
+ default: throw new BDDException();
+ }
+ }
+ lev++;
+ }
+
+ if (r < 2)
return r;
-
+
entry = BddCache_lookupI(quantcache, QUANTHASH(r));
if (entry.a == r && entry.c == quantid) {
if (CACHESTATS)
@@ -2182,8 +2274,9 @@
if (CACHESTATS)
cachestats.opMiss++;
- PUSHREF(zquant_rec(LOW(r)));
- PUSHREF(zquant_rec(HIGH(r)));
+ int nlev = LEVEL(r) + 1;
+ PUSHREF(zquant_rec(LOW(r), nlev));
+ PUSHREF(zquant_rec(HIGH(r), nlev));
if (INVARSET(LEVEL(r))) {
int r2 = READREF(2), r1 = READREF(1);
@@ -2192,12 +2285,15 @@
case bddop_or: res = zor_rec(r2, r1); break;
default: throw new BDDException();
}
+ POPREF(2);
+ PUSHREF(res);
+ res = zdd_makenode(LEVEL(r), READREF(1), READREF(1));
+ POPREF(1);
} else {
res = zdd_makenode(LEVEL(r), READREF(2), READREF(1));
+ POPREF(2);
}
- POPREF(2);
-
entry.a = r;
entry.c = quantid;
entry.res = res;
@@ -2465,7 +2561,7 @@
if (numReorder == 0)
bdd_disable_reorder();
- res = quant_rec(r);
+ res = ZDD?zquant_rec(r, 0):quant_rec(r);
if (numReorder == 0)
bdd_enable_reorder();
} catch (ReorderException x) {
@@ -2478,6 +2574,7 @@
}
checkresize();
+ if (true) bdd_validate(res);
return res;
}
@@ -2504,7 +2601,7 @@
if (numReorder == 0)
bdd_disable_reorder();
- res = quant_rec(r);
+ res = ZDD?zquant_rec(r, 0):quant_rec(r);
if (numReorder == 0)
bdd_enable_reorder();
} catch (ReorderException x) {
@@ -2772,7 +2869,7 @@
void support_rec(int r, int[] support) {
- _assert(!ZDD);
+ if (VERIFY_ASSERTIONS) _assert(!ZDD);
if (r < 2)
return;
@@ -2793,7 +2890,7 @@
void zsupport_rec(int r, int lev, int[] support) {
- _assert(ZDD);
+ if (VERIFY_ASSERTIONS) _assert(ZDD);
if (!ISZERO(r)) {
while (lev != LEVEL(r)) {
@@ -3929,7 +4026,7 @@
break;
}
}
- _assert(newIndex != bddvarnum);
+ if (VERIFY_ASSERTIONS) _assert(newIndex != bddvarnum);
}
int tmp = pair.result[oldlev];
pair.result[oldlev] = pair.result[newIndex];
@@ -6295,7 +6392,11 @@
}
}
void bdd_validate(int k) {
- validate(k, -1);
+ try {
+ validate(k, -1);
+ } finally {
+ bdd_unmark(k);
+ }
}
void validate(int k, int lastLevel) {
if (k < 2) return;
@@ -6303,6 +6404,15 @@
//System.out.println("Level("+k+") = "+lev);
if (lev <= lastLevel)
throw new BDDException(lev+" <= "+lastLevel);
+ if (ZDD) {
+ if (HIGH(k) == 0)
+ throw new BDDException("HIGH("+k+")==0");
+ } else {
+ if (LOW(k) == HIGH(k))
+ throw new BDDException("LOW("+k+") == HIGH("+k+")");
+ }
+ if (MARKED(k)) return;
+ SETMARK(k);
//System.out.println("Low:");
validate(LOW(k), lev);
//System.out.println("High:");
Modified: trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2006-12-03 10:34:02 UTC (rev 473)
+++ trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2006-12-05 10:58:16 UTC (rev 474)
@@ -64,11 +64,19 @@
}
public static final void assertSame(BDDVarSet b1, BDDVarSet b2, String s) {
- assertSame(b1.toBDD(), b2.toBDD(), s);
+ if (!b1.toString().equals(b2.toString())) {
+ System.out.println("b1 = " + b1.toString());
+ System.out.println("b2 = " + b2.toString());
+ throw new InternalError(s);
+ }
}
public static final void assertSame(boolean b, BDDVarSet b1, BDDVarSet b2, String s) {
- assertSame(b, b1.toBDD(), b2.toBDD(), s);
+ if (!b) {
+ System.err.println("b1 = " + b1);
+ System.err.println("b2 = " + b2);
+ throw new InternalError(s);
+ }
}
private class TestBDD extends BDD {
BDD b1, b2;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-12-03 10:34:05
|
Revision: 473
http://svn.sourceforge.net/javabdd/?rev=473&view=rev
Author: joewhaley
Date: 2006-12-03 02:34:02 -0800 (Sun, 03 Dec 2006)
Log Message:
-----------
Clean up code.
Modified Paths:
--------------
trunk/JavaBDD_tests/bdd/BasicTests.java
Modified: trunk/JavaBDD_tests/bdd/BasicTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/BasicTests.java 2006-12-03 10:32:26 UTC (rev 472)
+++ trunk/JavaBDD_tests/bdd/BasicTests.java 2006-12-03 10:34:02 UTC (rev 473)
@@ -202,12 +202,6 @@
a = bdd.ithVar(0);
b = a.not();
c = bdd.nithVar(0);
- //System.out.println("First graph:");
- //a.printDot();
- //System.out.println("Second graph:");
- //b.printDot();
- //System.out.println("Third graph:");
- //c.printDot();
Assert.assertEquals(b, c);
if (!bdd.isZDD()) {
c.free();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-12-03 10:32:29
|
Revision: 472
http://svn.sourceforge.net/javabdd/?rev=472&view=rev
Author: joewhaley
Date: 2006-12-03 02:32:26 -0800 (Sun, 03 Dec 2006)
Log Message:
-----------
For ZDD: Fixed toString() and an embarrassing bug in ithVar/setvarnum.
Updated TestBDDFactory to work with ZDDs and newer APIs.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/BDD.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/BDD.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-11-30 09:23:43 UTC (rev 471)
+++ trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-12-03 10:32:26 UTC (rev 472)
@@ -546,6 +546,11 @@
protected byte[] allsatProfile;
protected final boolean useLevel;
+ protected AllSatIterator(BDDFactory factory, boolean level) {
+ f = factory;
+ useLevel = level;
+ }
+
/**
* Constructs a satisfying-assignment iterator on the given BDD.
* next() returns a byte array indexed by BDD variable number.
@@ -1289,6 +1294,8 @@
public String toString() {
BDDFactory f = this.getFactory();
int[] set = new int[f.varNum()];
+ if (f.isZDD())
+ Arrays.fill(set, 1);
StringBuffer sb = new StringBuffer();
bdd_printset_rec(f, sb, this, set);
return sb.toString();
@@ -1316,17 +1323,34 @@
}
sb.append('>');
} else {
- set[f.var2Level(r.var())] = 1;
- BDD rl = r.low();
- bdd_printset_rec(f, sb, rl, set);
- rl.free();
-
- set[f.var2Level(r.var())] = 2;
- BDD rh = r.high();
- bdd_printset_rec(f, sb, rh, set);
- rh.free();
-
- set[f.var2Level(r.var())] = 0;
+ if (f.isZDD()) {
+ if (r.low().equals(r.high())) {
+ set[f.var2Level(r.var())] = 0;
+ } else {
+ BDD rl = r.low();
+ bdd_printset_rec(f, sb, rl, set);
+ rl.free();
+
+ set[f.var2Level(r.var())] = 2;
+ }
+ BDD rl = r.high();
+ bdd_printset_rec(f, sb, rl, set);
+ rl.free();
+
+ set[f.var2Level(r.var())] = 1;
+ } else {
+ set[f.var2Level(r.var())] = 1;
+ BDD rl = r.low();
+ bdd_printset_rec(f, sb, rl, set);
+ rl.free();
+
+ set[f.var2Level(r.var())] = 2;
+ BDD rh = r.high();
+ bdd_printset_rec(f, sb, rh, set);
+ rh.free();
+
+ set[f.var2Level(r.var())] = 0;
+ }
}
}
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-30 09:23:43 UTC (rev 471)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-12-03 10:32:26 UTC (rev 472)
@@ -2943,12 +2943,12 @@
if (ISZERO(LOW(r))) {
int res = satone_rec(HIGH(r));
- int m = bdd_makenode(LEVEL(r), BDDZERO, res);
+ int m = makenode_impl(LEVEL(r), BDDZERO, res);
PUSHREF(m);
return m;
} else {
int res = satone_rec(LOW(r));
- int m = bdd_makenode(LEVEL(r), res, BDDZERO);
+ int m = makenode_impl(LEVEL(r), res, (ZDD && LOW(r)==HIGH(r))?res:BDDZERO);
PUSHREF(m);
return m;
}
@@ -5003,13 +5003,22 @@
if (ZDD) {
int res = 1, res_not = 1;
for (int k = num-1; k >= 0; --k) {
- PUSHREF(res);
- PUSHREF(res_not);
- PUSHREF(univ);
- res = zdd_makenode(k, (k == bddvarnum)?0:res, res);
- res_not = (k == bddvarnum) ? res_not : zdd_makenode(k, res_not, res_not);
- if (bdv == bddvarnum) univ = zdd_makenode(k, univ, univ);
- POPREF(3);
+ int res2 = zdd_makenode(k, (k == bddvarnum)?0:res, res);
+ INCREF(res2);
+ DECREF(res);
+ res = res2;
+
+ int res_not2 = (k == bddvarnum) ? res_not : zdd_makenode(k, res_not, res_not);
+ INCREF(res_not2);
+ DECREF(res_not);
+ res_not = res_not2;
+
+ if (bdv == bddvarnum) {
+ int univ2 = zdd_makenode(k, univ, univ);
+ INCREF(univ2);
+ DECREF(univ);
+ univ = univ2;
+ }
}
bddvarset[bddvarnum * 2] = res;
bddvarset[bddvarnum * 2 + 1] = res_not;
@@ -5040,7 +5049,7 @@
bdd_operator_varresize();
if (ZDD) {
- System.out.println("Changed number of ZDD variables, all existing ZDDs are now invalid.");
+ System.out.println("Changed number of ZDD variables to "+num+", all existing ZDDs are now invalid.");
// Need to rebuild varsets for existing domains.
for (int n = 0; n < fdvarnum; n++) {
domain[n].var.free();
Modified: trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2006-11-30 09:23:43 UTC (rev 471)
+++ trunk/JavaBDD/net/sf/javabdd/TestBDDFactory.java 2006-12-03 10:32:26 UTC (rev 472)
@@ -11,9 +11,11 @@
import java.math.BigInteger;
/**
- * <p>This BDD factory is used to test other BDD factories. It is a wrapper around
- * two BDD factories, and all operations are performed on both factories. It
- * throws an exception if the results from the two implementations do not match.</p>
+ * <p>
+ * This BDD factory is used to test other BDD factories. It is a wrapper around
+ * two BDD factories, and all operations are performed on both factories. It
+ * throws an exception if the results from the two implementations do not match.
+ * </p>
*
* @see net.sf.javabdd.BDDFactory
*
@@ -21,11 +23,11 @@
* @version $Id$
*/
public class TestBDDFactory extends BDDFactory {
-
BDDFactory f1, f2;
public TestBDDFactory(BDDFactory a, BDDFactory b) {
- f1 = a; f2 = b;
+ f1 = a;
+ f2 = b;
}
public static BDDFactory init(int nodenum, int cachesize) {
@@ -41,36 +43,34 @@
throw new InternalError(s);
}
}
-
+
public static final void assertSame(BDD b1, BDD b2, String s) {
if (!b1.toString().equals(b2.toString())) {
//if (b1.nodeCount() != b2.nodeCount()) {
- System.out.println("b1 = "+b1.nodeCount());
- System.out.println("b2 = "+b2.nodeCount());
- System.out.println("b1 = "+b1.toString());
- System.out.println("b2 = "+b2.toString());
+ System.out.println("b1 = " + b1.nodeCount());
+ System.out.println("b2 = " + b2.nodeCount());
+ System.out.println("b1 = " + b1.toString());
+ System.out.println("b2 = " + b2.toString());
throw new InternalError(s);
}
}
public static final void assertSame(boolean b, BDD b1, BDD b2, String s) {
if (!b) {
- System.err.println("b1 = "+b1);
- System.err.println("b2 = "+b2);
+ System.err.println("b1 = " + b1);
+ System.err.println("b2 = " + b2);
throw new InternalError(s);
}
}
-
+
public static final void assertSame(BDDVarSet b1, BDDVarSet b2, String s) {
assertSame(b1.toBDD(), b2.toBDD(), s);
}
-
+
public static final void assertSame(boolean b, BDDVarSet b1, BDDVarSet b2, String s) {
assertSame(b, b1.toBDD(), b2.toBDD(), s);
}
-
private class TestBDD extends BDD {
-
BDD b1, b2;
TestBDD(BDD a, BDD b) {
@@ -79,21 +79,27 @@
assertSame(a, b, "constructor");
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#getFactory()
*/
public BDDFactory getFactory() {
return TestBDDFactory.this;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#toVarSet()
*/
public BDDVarSet toVarSet() {
return new TestBDDVarSet(b1.toVarSet(), b2.toVarSet());
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#isZero()
*/
public boolean isZero() {
@@ -103,7 +109,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#isOne()
*/
public boolean isOne() {
@@ -113,7 +121,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#var()
*/
public int var() {
@@ -123,7 +133,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#high()
*/
public BDD high() {
@@ -132,7 +144,9 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#low()
*/
public BDD low() {
@@ -141,7 +155,9 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#id()
*/
public BDD id() {
@@ -150,7 +166,9 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#not()
*/
public BDD not() {
@@ -159,133 +177,158 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#ite(net.sf.javabdd.BDD, net.sf.javabdd.BDD)
*/
public BDD ite(BDD thenBDD, BDD elseBDD) {
- BDD c1 = ((TestBDD)thenBDD).b1;
- BDD c2 = ((TestBDD)thenBDD).b2;
- BDD d1 = ((TestBDD)elseBDD).b1;
- BDD d2 = ((TestBDD)elseBDD).b2;
+ BDD c1 = ((TestBDD) thenBDD).b1;
+ BDD c2 = ((TestBDD) thenBDD).b2;
+ BDD d1 = ((TestBDD) elseBDD).b1;
+ BDD d2 = ((TestBDD) elseBDD).b2;
BDD r1 = b1.ite(c1, d1);
BDD r2 = b2.ite(c2, d2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#relprod(net.sf.javabdd.BDD, net.sf.javabdd.BDDVarSet)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#relprod(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDVarSet)
*/
public BDD relprod(BDD that, BDDVarSet var) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
- BDDVarSet d1 = ((TestBDDVarSet)var).b1;
- BDDVarSet d2 = ((TestBDDVarSet)var).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
+ BDDVarSet d1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet d2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.relprod(c1, d1);
BDD r2 = b2.relprod(c2, d2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#compose(net.sf.javabdd.BDD, int)
*/
public BDD compose(BDD g, int var) {
- BDD c1 = ((TestBDD)g).b1;
- BDD c2 = ((TestBDD)g).b2;
+ BDD c1 = ((TestBDD) g).b1;
+ BDD c2 = ((TestBDD) g).b2;
BDD r1 = b1.compose(c1, var);
BDD r2 = b2.compose(c2, var);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#veccompose(net.sf.javabdd.BDDPairing)
*/
public BDD veccompose(BDDPairing pair) {
- BDDPairing c1 = ((TestBDDPairing)pair).b1;
- BDDPairing c2 = ((TestBDDPairing)pair).b2;
+ BDDPairing c1 = ((TestBDDPairing) pair).b1;
+ BDDPairing c2 = ((TestBDDPairing) pair).b2;
BDD r1 = b1.veccompose(c1);
BDD r2 = b2.veccompose(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#constrain(net.sf.javabdd.BDD)
*/
public BDD constrain(BDD that) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
BDD r1 = b1.constrain(c1);
BDD r2 = b2.constrain(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#exist(net.sf.javabdd.BDDVarSet)
*/
public BDD exist(BDDVarSet var) {
- BDDVarSet c1 = ((TestBDDVarSet)var).b1;
- BDDVarSet c2 = ((TestBDDVarSet)var).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.exist(c1);
BDD r2 = b2.exist(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#forAll(net.sf.javabdd.BDD)
*/
public BDD forAll(BDDVarSet var) {
- BDDVarSet c1 = ((TestBDDVarSet)var).b1;
- BDDVarSet c2 = ((TestBDDVarSet)var).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.forAll(c1);
BDD r2 = b2.forAll(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#unique(net.sf.javabdd.BDD)
*/
public BDD unique(BDDVarSet var) {
- BDDVarSet c1 = ((TestBDDVarSet)var).b1;
- BDDVarSet c2 = ((TestBDDVarSet)var).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.unique(c1);
BDD r2 = b2.unique(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#restrict(net.sf.javabdd.BDD)
*/
public BDD restrict(BDD var) {
- BDD c1 = ((TestBDD)var).b1;
- BDD c2 = ((TestBDD)var).b2;
+ BDD c1 = ((TestBDD) var).b1;
+ BDD c2 = ((TestBDD) var).b2;
BDD r1 = b1.restrict(c1);
BDD r2 = b2.restrict(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#restrictWith(net.sf.javabdd.BDD)
*/
public BDD restrictWith(BDD var) {
- BDD c1 = ((TestBDD)var).b1;
- BDD c2 = ((TestBDD)var).b2;
+ BDD c1 = ((TestBDD) var).b1;
+ BDD c2 = ((TestBDD) var).b2;
b1.restrictWith(c1);
b2.restrictWith(c2);
assertSame(b1, b2, "restrict");
return this;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet)
*/
public BDD simplify(BDDVarSet d) {
- BDDVarSet c1 = ((TestBDDVarSet)d).b1;
- BDDVarSet c2 = ((TestBDDVarSet)d).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) d).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) d).b2;
BDD r1 = b1.simplify(c1);
BDD r2 = b2.simplify(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#support()
*/
public BDDVarSet support() {
@@ -294,69 +337,86 @@
return new TestBDDVarSet(r1, r2);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#apply(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#apply(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDFactory.BDDOp)
*/
public BDD apply(BDD that, BDDOp opr) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
BDD r1 = b1.apply(c1, opr);
BDD r2 = b2.apply(c2, opr);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#applyWith(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#applyWith(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDFactory.BDDOp)
*/
public BDD applyWith(BDD that, BDDOp opr) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
b1.applyWith(c1, opr);
b2.applyWith(c2, opr);
- assertSame(b1, b2, "applyWith "+opr);
+ assertSame(b1, b2, "applyWith " + opr);
return this;
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#applyAll(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#applyAll(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
*/
public BDD applyAll(BDD that, BDDOp opr, BDDVarSet var) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
- BDDVarSet e1 = ((TestBDDVarSet)var).b1;
- BDDVarSet e2 = ((TestBDDVarSet)var).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
+ BDDVarSet e1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet e2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.applyAll(c1, opr, e1);
BDD r2 = b2.applyAll(c2, opr, e2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#applyEx(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#applyEx(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
*/
public BDD applyEx(BDD that, BDDOp opr, BDDVarSet var) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
- BDDVarSet e1 = ((TestBDDVarSet)var).b1;
- BDDVarSet e2 = ((TestBDDVarSet)var).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
+ BDDVarSet e1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet e2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.applyEx(c1, opr, e1);
BDD r2 = b2.applyEx(c2, opr, e2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDD#applyUni(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#applyUni(net.sf.javabdd.BDD,
+ * net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet)
*/
public BDD applyUni(BDD that, BDDOp opr, BDDVarSet var) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
- BDDVarSet e1 = ((TestBDDVarSet)var).b1;
- BDDVarSet e2 = ((TestBDDVarSet)var).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
+ BDDVarSet e1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet e2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.applyUni(c1, opr, e1);
BDD r2 = b2.applyUni(c2, opr, e2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#satOne()
*/
public BDD satOne() {
@@ -365,7 +425,9 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#fullSatOne()
*/
public BDD fullSatOne() {
@@ -374,41 +436,49 @@
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#satOne(net.sf.javabdd.BDDVarSet, boolean)
*/
public BDD satOne(BDDVarSet var, boolean pol) {
- BDDVarSet c1 = ((TestBDDVarSet)var).b1;
- BDDVarSet c2 = ((TestBDDVarSet)var).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) var).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) var).b2;
BDD r1 = b1.satOne(c1, pol);
BDD r2 = b2.satOne(c2, pol);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#replace(net.sf.javabdd.BDDPairing)
*/
public BDD replace(BDDPairing pair) {
- BDDPairing c1 = ((TestBDDPairing)pair).b1;
- BDDPairing c2 = ((TestBDDPairing)pair).b2;
+ BDDPairing c1 = ((TestBDDPairing) pair).b1;
+ BDDPairing c2 = ((TestBDDPairing) pair).b2;
BDD r1 = b1.replace(c1);
BDD r2 = b2.replace(c2);
return new TestBDD(r1, r2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#replaceWith(net.sf.javabdd.BDDPairing)
*/
public BDD replaceWith(BDDPairing pair) {
- BDDPairing c1 = ((TestBDDPairing)pair).b1;
- BDDPairing c2 = ((TestBDDPairing)pair).b2;
+ BDDPairing c1 = ((TestBDDPairing) pair).b1;
+ BDDPairing c2 = ((TestBDDPairing) pair).b2;
b1.replaceWith(c1);
b2.replaceWith(c2);
assertSame(b1, b2, "replaceWith");
return this;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#printDot()
*/
public void printDot() {
@@ -416,17 +486,81 @@
b1.printDot();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#toString()
+ */
+ public String toString() {
+ // String already checked.
+ return b1.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#toStringWithDomains(net.sf.javabdd.BDD.BDDToString)
+ */
+ public String toStringWithDomains(BDDToString ts) {
+ String s1 = b1.toStringWithDomains(ts);
+ String s2 = b2.toStringWithDomains(ts);
+ assertSame(s1.equals(s2), "toStringWithDomains");
+ return s1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#allsat()
+ */
+ public AllSatIterator allsat() {
+ return new AllSatIterator(TestBDDFactory.this, false) {
+ AllSatIterator i1 = b1.allsat();
+ AllSatIterator i2 = b2.allsat();
+
+ public boolean hasNext() {
+ boolean r1 = i1.hasNext();
+ boolean r2 = i2.hasNext();
+ assertSame(r1 == r2, b1, b2, "allsat.hasNext");
+ return r1;
+ }
+
+ public byte[] nextSat() {
+ byte[] r1 = i1.nextSat();
+ byte[] r2 = i2.nextSat();
+ assertSame(Arrays.equals(r1, r2), b1, b2, "allsat.nextSat");
+ return r1;
+ }
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDD#scanAllVar()
+ */
+ public BigInteger[] scanAllVar() {
+ BigInteger[] r1 = b1.scanAllVar();
+ BigInteger[] r2 = b2.scanAllVar();
+ assertSame(Arrays.equals(r1, r2), b1, b2, "scanAllVar");
+ return r1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#nodeCount()
*/
public int nodeCount() {
int r1 = b1.nodeCount();
int r2 = b2.nodeCount();
- assertSame(r1 == r2, b1, b2, "nodeCount");
+ if (false) assertSame(r1 == r2, b1, b2, "nodeCount");
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#pathCount()
*/
public double pathCount() {
@@ -436,7 +570,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#satCount()
*/
public double satCount() {
@@ -446,32 +582,35 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#varProfile()
*/
public int[] varProfile() {
int[] r1 = b1.varProfile();
int[] r2 = b2.varProfile();
- assertSame(r1.length == r2.length, "varProfile");
- for (int i=0; i<r1.length; ++i) {
- assertSame(r1[i] == r2[i], "varProfile");
- }
+ assertSame(Arrays.equals(r1, r2), "varProfile");
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#equals(net.sf.javabdd.BDD)
*/
public boolean equals(BDD that) {
- BDD c1 = ((TestBDD)that).b1;
- BDD c2 = ((TestBDD)that).b2;
+ BDD c1 = ((TestBDD) that).b1;
+ BDD c2 = ((TestBDD) that).b2;
boolean r1 = b1.equals(c1);
boolean r2 = b2.equals(c2);
assertSame(r1 == r2, b1, b2, "equals");
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#hashCode()
*/
public int hashCode() {
@@ -480,7 +619,9 @@
return b2.hashCode();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDD#free()
*/
public void free() {
@@ -488,9 +629,7 @@
b2.free();
}
}
-
private class TestBDDVarSet extends BDDVarSet {
-
BDDVarSet b1, b2;
TestBDDVarSet(BDDVarSet a, BDDVarSet b) {
@@ -513,7 +652,7 @@
BDD r2 = b2.toBDD();
return new TestBDD(r1, r2);
}
-
+
public BDDVarSet id() {
BDDVarSet r1 = b1.id();
BDDVarSet r2 = b2.id();
@@ -521,16 +660,16 @@
}
public BDDVarSet intersect(BDDVarSet that) {
- BDDVarSet c1 = ((TestBDDVarSet)that).b1;
- BDDVarSet c2 = ((TestBDDVarSet)that).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) that).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) that).b2;
BDDVarSet r1 = b1.intersect(c1);
BDDVarSet r2 = b2.intersect(c2);
return new TestBDDVarSet(r1, r2);
}
public BDDVarSet intersectWith(BDDVarSet that) {
- BDDVarSet c1 = ((TestBDDVarSet)that).b1;
- BDDVarSet c2 = ((TestBDDVarSet)that).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) that).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) that).b2;
b1.intersectWith(c1);
b2.intersectWith(c2);
assertSame(b1, b2, "intersectWith");
@@ -566,8 +705,8 @@
}
public BDDVarSet union(BDDVarSet that) {
- BDDVarSet c1 = ((TestBDDVarSet)that).b1;
- BDDVarSet c2 = ((TestBDDVarSet)that).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) that).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) that).b2;
BDDVarSet r1 = b1.union(c1);
BDDVarSet r2 = b2.union(c2);
return new TestBDDVarSet(r1, r2);
@@ -580,8 +719,8 @@
}
public BDDVarSet unionWith(BDDVarSet that) {
- BDDVarSet c1 = ((TestBDDVarSet)that).b1;
- BDDVarSet c2 = ((TestBDDVarSet)that).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) that).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) that).b2;
b1.unionWith(c1);
b2.unionWith(c2);
assertSame(b1, b2, "unionWith");
@@ -594,45 +733,62 @@
assertSame(b1, b2, "unionWith");
return this;
}
-
+
public int hashCode() {
// TODO Compare!
b1.hashCode();
return b2.hashCode();
}
-
+
public boolean equals(BDDVarSet that) {
- BDDVarSet c1 = ((TestBDDVarSet)that).b1;
- BDDVarSet c2 = ((TestBDDVarSet)that).b2;
+ BDDVarSet c1 = ((TestBDDVarSet) that).b1;
+ BDDVarSet c2 = ((TestBDDVarSet) that).b2;
boolean r1 = b1.equals(c1);
boolean r2 = b2.equals(c2);
assertSame(r1 == r2, b1, b2, "equals");
return r1;
}
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#zero()
*/
public BDD zero() {
return new TestBDD(f1.zero(), f2.zero());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#one()
*/
public BDD one() {
return new TestBDD(f1.one(), f2.one());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDDFactory#universe()
+ */
+ public BDD universe() {
+ return new TestBDD(f1.universe(), f2.universe());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#emptySet()
*/
public BDDVarSet emptySet() {
return new TestBDDVarSet(f1.emptySet(), f2.emptySet());
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#initialize(int, int)
*/
protected void initialize(int nodenum, int cachesize) {
@@ -640,7 +796,9 @@
f2.initialize(nodenum, cachesize);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#isInitialized()
*/
public boolean isInitialized() {
@@ -650,7 +808,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#done()
*/
public void done() {
@@ -658,23 +818,29 @@
f2.done();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setError(int)
*/
public void setError(int code) {
f1.setError(code);
f2.setError(code);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#clearError()
*/
public void clearError() {
f1.clearError();
f2.clearError();
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setMaxNodeNum(int)
*/
public int setMaxNodeNum(int size) {
@@ -684,7 +850,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setMinFreeNodes(double)
*/
public double setMinFreeNodes(double x) {
@@ -694,17 +862,21 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setIncreaseFactor(double)
*/
public double setIncreaseFactor(double x) {
double r1 = f1.setIncreaseFactor(x);
double r2 = f2.setIncreaseFactor(x);
- assertSame(r1 == r2, "setIncreaseFactor");
+ if (false) assertSame(r1 == r2, "setIncreaseFactor");
return r1;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setMaxIncrease(int)
*/
public int setMaxIncrease(int x) {
@@ -714,7 +886,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setCacheRatio(double)
*/
public double setCacheRatio(double x) {
@@ -724,17 +898,21 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setNodeTableSize(int)
*/
public int setNodeTableSize(int size) {
int r1 = f1.setNodeTableSize(size);
int r2 = f2.setNodeTableSize(size);
- assertSame(r1 == r2, "setNodeTableSize");
+ if (false) assertSame(r1 == r2, "setNodeTableSize");
return r1;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setCacheSize(int)
*/
public int setCacheSize(int size) {
@@ -743,8 +921,10 @@
assertSame(r1 == r2, "setCacheSize");
return r1;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#varNum()
*/
public int varNum() {
@@ -754,31 +934,39 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setVarNum(int)
*/
public int setVarNum(int num) {
int r1 = f1.setVarNum(num);
int r2 = f2.setVarNum(num);
- //assertSame(r1 == r2, "setVarNum");
+ // assertSame(r1 == r2, "setVarNum");
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#ithVar(int)
*/
public BDD ithVar(int var) {
return new TestBDD(f1.ithVar(var), f2.ithVar(var));
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#nithVar(int)
*/
public BDD nithVar(int var) {
return new TestBDD(f1.nithVar(var), f2.nithVar(var));
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#printAll()
*/
public void printAll() {
@@ -786,32 +974,40 @@
f1.printAll();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#printTable(net.sf.javabdd.BDD)
*/
public void printTable(BDD b) {
// TODO Compare!
- BDD b1 = ((TestBDD)b).b1;
+ BDD b1 = ((TestBDD) b).b1;
f1.printTable(b1);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#load(java.lang.String)
*/
public BDD load(String filename) throws IOException {
return new TestBDD(f1.load(filename), f2.load(filename));
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#save(java.lang.String, net.sf.javabdd.BDD)
*/
public void save(String filename, BDD var) throws IOException {
// TODO Compare!
- BDD b1 = ((TestBDD)var).b1;
+ BDD b1 = ((TestBDD) var).b1;
f1.save(filename, b1);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#level2Var(int)
*/
public int level2Var(int level) {
@@ -821,7 +1017,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#var2Level(int)
*/
public int var2Level(int var) {
@@ -831,7 +1029,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#reorder(net.sf.javabdd.BDDFactory.ReorderMethod)
*/
public void reorder(ReorderMethod m) {
@@ -839,7 +1039,9 @@
f2.reorder(m);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod)
*/
public void autoReorder(ReorderMethod method) {
@@ -847,15 +1049,20 @@
f2.autoReorder(method);
}
- /* (non-Javadoc)
- * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod, int)
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod,
+ * int)
*/
public void autoReorder(ReorderMethod method, int max) {
f1.autoReorder(method, max);
f2.autoReorder(method, max);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getReorderMethod()
*/
public ReorderMethod getReorderMethod() {
@@ -865,7 +1072,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getReorderTimes()
*/
public int getReorderTimes() {
@@ -875,7 +1084,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#disableReorder()
*/
public void disableReorder() {
@@ -883,7 +1094,9 @@
f2.disableReorder();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#enableReorder()
*/
public void enableReorder() {
@@ -891,7 +1104,9 @@
f2.enableReorder();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#reorderVerbose(int)
*/
public int reorderVerbose(int v) {
@@ -901,7 +1116,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#setVarOrder(int[])
*/
public void setVarOrder(int[] neworder) {
@@ -909,7 +1126,9 @@
f2.setVarOrder(neworder);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#addVarBlock(int, int, boolean)
*/
public void addVarBlock(int first, int last, boolean fixed) {
@@ -917,7 +1136,9 @@
f2.addVarBlock(first, last, fixed);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#varBlockAll()
*/
public void varBlockAll() {
@@ -925,7 +1146,9 @@
f2.varBlockAll();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#clearVarBlocks()
*/
public void clearVarBlocks() {
@@ -933,7 +1156,9 @@
f2.clearVarBlocks();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#printOrder()
*/
public void printOrder() {
@@ -941,14 +1166,16 @@
f1.printOrder();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#nodeCount(java.util.Collection)
*/
public int nodeCount(Collection r) {
LinkedList a1 = new LinkedList();
LinkedList a2 = new LinkedList();
- for (Iterator i=r.iterator(); i.hasNext();) {
- TestBDD b = (TestBDD)i.next();
+ for (Iterator i = r.iterator(); i.hasNext();) {
+ TestBDD b = (TestBDD) i.next();
a1.add(b.b1);
a2.add(b.b2);
}
@@ -958,7 +1185,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getNodeTableSize()
*/
public int getNodeTableSize() {
@@ -968,7 +1197,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getNodeNum()
*/
public int getNodeNum() {
@@ -978,7 +1209,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getCacheSize()
*/
public int getCacheSize() {
@@ -987,8 +1220,10 @@
assertSame(r1 == r2, "getCacheSize");
return r1;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#reorderGain()
*/
public int reorderGain() {
@@ -998,7 +1233,9 @@
return r1;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#printStat()
*/
public void printStat() {
@@ -1006,7 +1243,9 @@
f1.printStat();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#makePair()
*/
public BDDPairing makePair() {
@@ -1015,7 +1254,9 @@
return new TestBDDPairing(p1, p2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#swapVar(int, int)
*/
public void swapVar(int v1, int v2) {
@@ -1023,30 +1264,34 @@
f2.swapVar(v1, v2);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#createDomain(int, BigInteger)
*/
protected BDDDomain createDomain(int a, BigInteger b) {
return new TestBDDDomain(a, b);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#createBitVector(int)
*/
protected BDDBitVector createBitVector(int a) {
return new TestBDDBitVector(a);
}
-
private static class TestBDDPairing extends BDDPairing {
-
BDDPairing b1, b2;
-
+
TestBDDPairing(BDDPairing p1, BDDPairing p2) {
this.b1 = p1;
this.b2 = p2;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDPairing#set(int, int)
*/
public void set(int oldvar, int newvar) {
@@ -1054,7 +1299,9 @@
b2.set(oldvar, newvar);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDPairing#set(int, net.sf.javabdd.BDD)
*/
public void set(int oldvar, BDD newvar) {
@@ -1062,53 +1309,53 @@
b2.set(oldvar, newvar);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDPairing#reset()
*/
public void reset() {
b1.reset();
b2.reset();
}
-
}
-
private class TestBDDDomain extends BDDDomain {
-
private TestBDDDomain(int a, BigInteger b) {
super(a, b);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDDomain#getFactory()
*/
public BDDFactory getFactory() {
return TestBDDFactory.this;
}
-
}
-
private class TestBDDBitVector extends BDDBitVector {
-
TestBDDBitVector(int a) {
super(a);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDBitVector#getFactory()
*/
public BDDFactory getFactory() {
return TestBDDFactory.this;
}
-
}
-
public static final String REVISION = "$Revision$";
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see net.sf.javabdd.BDDFactory#getVersion()
*/
public String getVersion() {
- return "TestBDD "+REVISION.substring(11, REVISION.length()-2)+
- " of ("+f1.getVersion()+","+f2.getVersion()+")";
+ return "TestBDD " + REVISION.substring(11, REVISION.length() - 2)
+ + " of (" + f1.getVersion() + "," + f2.getVersion() + ")";
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-30 09:23:44
|
Revision: 471
http://svn.sourceforge.net/javabdd/?rev=471&view=rev
Author: joewhaley
Date: 2006-11-30 01:23:43 -0800 (Thu, 30 Nov 2006)
Log Message:
-----------
Added allsat() iterator test.
Modified Paths:
--------------
trunk/JavaBDD_tests/bdd/IteratorTests.java
Added Paths:
-----------
trunk/JavaBDD_tests/bdd/IOTests.java
Added: trunk/JavaBDD_tests/bdd/IOTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/IOTests.java (rev 0)
+++ trunk/JavaBDD_tests/bdd/IOTests.java 2006-11-30 09:23:43 UTC (rev 471)
@@ -0,0 +1,55 @@
+// IOTests.java, created Nov 20, 2006 4:55:28 PM by jwhaley
+// Copyright (C) 2006 jwhaley
+// Licensed under the terms of the GNU LGPL; see COPYING for details.
+package bdd;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import junit.framework.Assert;
+import net.sf.javabdd.BDD;
+import net.sf.javabdd.BDDFactory;
+
+/**
+ * IOTests
+ *
+ * @author jwhaley
+ * @version $Id$
+ */
+public class IOTests extends BDDTestCase {
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(IOTests.class);
+ }
+
+ public void testLoad() {
+ reset();
+ Assert.assertTrue(hasNext());
+ while (hasNext()) {
+ BDDFactory bdd = nextFactory();
+ File tmp = null;
+ Exception error = null;
+ try {
+ tmp = File.createTempFile("loadtest", "bdd");
+ tmp.deleteOnExit();
+ PrintWriter out = new PrintWriter(tmp);
+ out.println("2 3");
+ out.println("0 1 2");
+ out.println("222 1 1 0");
+ out.println("333 2 1 222");
+ out.close();
+ BDD x = bdd.load(tmp.getAbsolutePath());
+ tmp.delete();
+ //x.printDot();
+ Assert.assertEquals(6.0, x.satCount(), 0.001);
+ x.free();
+ } catch (IOException x) {
+ error = x;
+ } finally {
+ if (tmp != null) tmp.delete();
+ }
+ if (error != null)
+ Assert.fail(error.toString());
+ }
+ }
+
+}
Modified: trunk/JavaBDD_tests/bdd/IteratorTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-11-30 09:22:42 UTC (rev 470)
+++ trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-11-30 09:23:43 UTC (rev 471)
@@ -84,6 +84,75 @@
}
}
+ static Random random = new Random(1234);
+
+ static BDD randomBDD(BDDFactory f) {
+ BDD result = f.zero();
+ for (int i = 0; i < f.varNum(); ++i) {
+ BDD b = f.universe();
+ for (int j = 0; j < f.varNum(); ++j) {
+ int k = random.nextInt(3);
+ if (k == 0) b.andWith(f.nithVar(j));
+ else if (k == 1) b.andWith(f.ithVar(j));
+ }
+ result.orWith(b);
+ }
+ return result;
+ }
+
+ static BDD betterRandomBDD(BDDFactory f) {
+ // Use a random truth table.
+ byte[] bytes = new byte[(1 << f.varNum()) / 8 + 1];
+ random.nextBytes(bytes);
+ BDD result = f.zero();
+ for (int i = 0; i < (1 << f.varNum()); ++i) {
+ if ((bytes[i / 8] & (1<<(i%8))) != 0) {
+ BDD b = f.universe();
+ for (int j = 0; j < f.varNum(); ++j) {
+ if ((i & (1<<j)) != 0)
+ b.andWith(f.ithVar(j));
+ else
+ b.andWith(f.nithVar(j));
+ }
+ result.orWith(b);
+ }
+ }
+ return result;
+ }
+
+ public void testAllsatIterator() {
+ reset();
+ Assert.assertTrue(hasNext());
+ while (hasNext()) {
+ BDDFactory f = nextFactory();
+ f.setVarNum(5);
+ for (int kk = 0; kk < 10; ++kk) {
+ BDD bdd1 = ((kk&1)==0)?randomBDD(f):betterRandomBDD(f);
+ BDD bdd2 = f.zero();
+ BDD.AllSatIterator i = bdd1.allsat();
+ while (i.hasNext()) {
+ byte[] b = i.nextSat();
+ BDD t = f.universe();
+ for (int k = 0; k < b.length; ++k) {
+ if (b[k] == 0)
+ t.andWith(f.nithVar(k));
+ else if (b[k] == 1)
+ t.andWith(f.ithVar(k));
+ }
+
+ BDD overlap = bdd2.and(t);
+ Assert.assertTrue(overlap.isZero());
+ overlap.free();
+
+ bdd2.orWith(t);
+ }
+ Assert.assertEquals(bdd1, bdd2);
+ bdd2.free();
+ bdd1.free();
+ }
+ }
+ }
+
public void testRandomIterator() {
reset();
Assert.assertTrue(hasNext());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-30 09:22:44
|
Revision: 470
http://svn.sourceforge.net/javabdd/?rev=470&view=rev
Author: joewhaley
Date: 2006-11-30 01:22:42 -0800 (Thu, 30 Nov 2006)
Log Message:
-----------
Implement ZDD iterators.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/BDD.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/BDD.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-11-29 08:07:31 UTC (rev 469)
+++ trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-11-30 09:22:42 UTC (rev 470)
@@ -598,10 +598,25 @@
BDD rn = lo_empty ? r.high() : r.low();
int v = rn.isOne()||rn.isZero() ? f.varNum() - 1 : rn.level() - 1;
for ( ; v > LEVEL_r; --v) {
- allsatProfile[useLevel?v:f.level2Var(v)] = -1;
+ allsatProfile[useLevel?v:f.level2Var(v)] = f.isZDD()?(byte)0:(byte)-1;
}
if (!lo_empty) {
- hiStack.addLast(r);
+ if (f.isZDD()) {
+ // Check for dont-care bits in ZDD.
+ BDD rh = r.high();
+ boolean isDontCare = rn.equals(rh);
+ rh.free();
+ if (isDontCare) {
+ // low child == high child, this is a dont-care bit.
+ allsatProfile[useLevel?v:f.level2Var(v)] = -1;
+ r.free();
+ } else {
+ hiStack.addLast(r);
+ }
+ } else {
+ // BDD.
+ hiStack.addLast(r);
+ }
} else {
r.free();
}
@@ -965,7 +980,7 @@
throw new NoSuchElementException();
}
//if (lastReturned != null) lastReturned.free();
- lastReturned = f.one();
+ lastReturned = f.universe();
//for (int i = 0; i < v.length; ++i) {
for (int i = v.length-1; i >= 0; --i) {
int li = v[i];
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-29 08:07:31 UTC (rev 469)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-30 09:22:42 UTC (rev 470)
@@ -2978,37 +2978,42 @@
return r;
if (LEVEL(r) < LEVEL(var)) {
+ // r is not in the set
if (ISZERO(LOW(r))) {
int res = satoneset_rec(HIGH(r), var);
- int m = bdd_makenode(LEVEL(r), BDDZERO, res);
+ int m = makenode_impl(LEVEL(r), BDDZERO, res);
PUSHREF(m);
return m;
} else {
int res = satoneset_rec(LOW(r), var);
- int m = bdd_makenode(LEVEL(r), res, BDDZERO);
+ int m = makenode_impl(LEVEL(r), res, (ZDD && LOW(r) == HIGH(r))?res:BDDZERO);
PUSHREF(m);
return m;
}
} else if (LEVEL(var) < LEVEL(r)) {
int res = satoneset_rec(r, HIGH(var));
- if (satPolarity) {
- int m = bdd_makenode(LEVEL(var), BDDZERO, res);
+ if (!ZDD && satPolarity) {
+ int m = makenode_impl(LEVEL(var), BDDZERO, res);
PUSHREF(m);
return m;
} else {
- int m = bdd_makenode(LEVEL(var), res, BDDZERO);
+ int m = makenode_impl(LEVEL(var), res, BDDZERO);
PUSHREF(m);
return m;
}
} else /* LEVEL(r) == LEVEL(var) */ {
if (ISZERO(LOW(r))) {
int res = satoneset_rec(HIGH(r), HIGH(var));
- int m = bdd_makenode(LEVEL(r), BDDZERO, res);
+ int m = makenode_impl(LEVEL(r), BDDZERO, res);
PUSHREF(m);
return m;
} else {
int res = satoneset_rec(LOW(r), HIGH(var));
- int m = bdd_makenode(LEVEL(r), res, BDDZERO);
+ int m;
+ if (ZDD && satPolarity && LOW(r) == HIGH(r))
+ m = zdd_makenode(LEVEL(r), BDDZERO, res);
+ else
+ m = makenode_impl(LEVEL(r), res, BDDZERO);
PUSHREF(m);
return m;
}
@@ -3030,7 +3035,7 @@
res = fullsatone_rec(r);
for (v = LEVEL(r) - 1; v >= 0; v--) {
- res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
+ res = PUSHREF(makenode_impl(v, res, 0));
}
bdd_enable_reorder();
@@ -3048,19 +3053,19 @@
int v;
for (v = LEVEL(LOW(r)) - 1; v > LEVEL(r); v--) {
- res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
+ res = PUSHREF(makenode_impl(v, res, 0));
}
- return PUSHREF(ZDD?zdd_makenode(LEVEL(r), res, 0):bdd_makenode(LEVEL(r), res, 0));
+ return PUSHREF(makenode_impl(LEVEL(r), res, 0));
} else {
int res = fullsatone_rec(HIGH(r));
int v;
for (v = LEVEL(HIGH(r)) - 1; v > LEVEL(r); v--) {
- res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
+ res = PUSHREF(makenode_impl(v, res, 0));
}
- return PUSHREF(ZDD?zdd_makenode(LEVEL(r), 0, res):bdd_makenode(LEVEL(r), 0, res));
+ return PUSHREF(makenode_impl(LEVEL(r), 0, res));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-29 08:07:33
|
Revision: 469
http://svn.sourceforge.net/javabdd/?rev=469&view=rev
Author: joewhaley
Date: 2006-11-29 00:07:31 -0800 (Wed, 29 Nov 2006)
Log Message:
-----------
Improved ZDD support. load(), support(), quant methods now work.
Modified Paths:
--------------
trunk/JavaBDD_tests/bdd/BDDTestCase.java
trunk/JavaBDD_tests/bdd/BasicTests.java
trunk/JavaBDD_tests/bdd/IteratorTests.java
trunk/JavaBDD_tests/highlevel/NQueensTest.java
trunk/JavaBDD_tests/regression/R2.java
trunk/JavaBDD_tests/trace/TraceDriver.java
Modified: trunk/JavaBDD_tests/bdd/BDDTestCase.java
===================================================================
--- trunk/JavaBDD_tests/bdd/BDDTestCase.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/bdd/BDDTestCase.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -21,6 +21,7 @@
public static final String[] factoryNames = {
"net.sf.javabdd.JFactory",
+ "zdd",
"net.sf.javabdd.BuDDyFactory",
"net.sf.javabdd.MicroFactory",
//"net.sf.javabdd.CUDDFactory",
@@ -38,10 +39,15 @@
for (int k = 0; k < factoryNames.length; ++k) {
String bddpackage = factoryNames[k];
try {
- Class c = Class.forName(bddpackage);
- Method m = c.getMethod("init", new Class[] { int.class, int.class });
- BDDFactory b = (BDDFactory) m.invoke(null, new Object[] { new Integer(nodenum), new Integer(cachesize) });
- f.add(b);
+ if (bddpackage.indexOf('.') == -1) {
+ BDDFactory b = BDDFactory.init(bddpackage, nodenum, cachesize);
+ f.add(b);
+ } else {
+ Class c = Class.forName(bddpackage);
+ Method m = c.getMethod("init", new Class[] { int.class, int.class });
+ BDDFactory b = (BDDFactory) m.invoke(null, new Object[] { new Integer(nodenum), new Integer(cachesize) });
+ f.add(b);
+ }
}
catch (Throwable _) {
if (_ instanceof InvocationTargetException)
Modified: trunk/JavaBDD_tests/bdd/BasicTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/BasicTests.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/bdd/BasicTests.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -473,7 +473,7 @@
if (bdd.varNum() < 5) bdd.setVarNum(5);
BDD a, b, c, d, e;
a = bdd.ithVar(1);
- b = bdd.one();
+ b = bdd.universe();
c = bdd.zero();
d = a.ite(b, c);
Assert.assertEquals(a, d);
@@ -648,7 +648,7 @@
for (int i = 0; i < f.numberOfDomains(); ++i) {
list.add(f.getDomain(i));
}
- BDD result = f.one();
+ BDD result = f.universe();
for (int i = 0; i < k; ++i) {
int x = random.nextInt(f.numberOfDomains() - i);
BDDDomain d = (BDDDomain) list.remove(x);
Modified: trunk/JavaBDD_tests/bdd/IteratorTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -44,7 +44,7 @@
} catch (NoSuchElementException x) {
}
- b = bdd.one();
+ b = bdd.universe();
Iterator i1 = b.iterator(var);
Iterator i2 = new MyBDDIterator(b, var);
b.free();
Modified: trunk/JavaBDD_tests/highlevel/NQueensTest.java
===================================================================
--- trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -52,7 +52,7 @@
if (B.varNum() < N * N) B.setVarNum(N * N);
- queen = B.one();
+ queen = B.universe();
int i, j;
@@ -92,7 +92,7 @@
}
private static void build(int i, int j) {
- BDD a = B.one(), b = B.one(), c = B.one(), d = B.one();
+ BDD a = B.universe(), b = B.universe(), c = B.universe(), d = B.universe();
int k, l;
/* No one in the same column */
Modified: trunk/JavaBDD_tests/regression/R2.java
===================================================================
--- trunk/JavaBDD_tests/regression/R2.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/regression/R2.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -25,9 +25,9 @@
while (hasNext()) {
BDDFactory bdd = nextFactory();
BDD zero = bdd.zero();
- BDD one = bdd.one();
+ BDD one = bdd.universe();
Assert.assertTrue(bdd.getVersion(), zero.isZero());
- Assert.assertTrue(bdd.getVersion(), one.isOne());
+ Assert.assertTrue(bdd.getVersion(), one.isUniverse());
BDDVarSet s0 = zero.support();
BDDVarSet s1 = one.support();
Assert.assertTrue(bdd.getVersion(), s0.isEmpty());
Modified: trunk/JavaBDD_tests/trace/TraceDriver.java
===================================================================
--- trunk/JavaBDD_tests/trace/TraceDriver.java 2006-11-29 08:07:13 UTC (rev 468)
+++ trunk/JavaBDD_tests/trace/TraceDriver.java 2006-11-29 08:07:31 UTC (rev 469)
@@ -211,7 +211,7 @@
if(ops == 2) ret.bdd = op1.bdd.or(op2.bdd);
else {
for (Enumeration e = operands.elements() ; e.hasMoreElements() ;)
- if(((TracedVariable)e.nextElement()).bdd.isOne()) { ret.bdd = bdd.one(); return; }
+ if(((TracedVariable)e.nextElement()).bdd.isUniverse()) { ret.bdd = bdd.universe(); return; }
BDD tmp = bdd.zero();
for (Enumeration e = operands.elements() ; e.hasMoreElements() ;) {
@@ -230,7 +230,7 @@
for (Enumeration e = operands.elements() ; e.hasMoreElements() ;)
if(((TracedVariable)e.nextElement()).bdd.isZero()) { ret.bdd = bdd.zero(); return; }
- BDD tmp = bdd.one();
+ BDD tmp = bdd.universe();
for (Enumeration e = operands.elements() ; e.hasMoreElements() ;) {
TracedVariable v = (TracedVariable)e.nextElement();
BDD tmp2 = tmp.and(v.bdd);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-29 08:07:15
|
Revision: 468
http://svn.sourceforge.net/javabdd/?rev=468&view=rev
Author: joewhaley
Date: 2006-11-29 00:07:13 -0800 (Wed, 29 Nov 2006)
Log Message:
-----------
Improved ZDD support. load(), support(), quant methods now work.
Modified Paths:
--------------
trunk/JavaBDD/NQueens.java
trunk/JavaBDD/RubiksCube.java
trunk/JavaBDD/net/sf/javabdd/BDDDomain.java
trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
trunk/JavaBDD/net/sf/javabdd/JFactory.java
Modified: trunk/JavaBDD/NQueens.java
===================================================================
--- trunk/JavaBDD/NQueens.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/NQueens.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -58,7 +58,7 @@
}
if (B.varNum() < N * N) B.setVarNum(N * N);
- queen = B.one();
+ queen = B.universe();
int i, j;
@@ -108,7 +108,7 @@
}
static void build(int i, int j) {
- BDD a = B.one(), b = B.one(), c = B.one(), d = B.one();
+ BDD a = B.universe(), b = B.universe(), c = B.universe(), d = B.universe();
int k, l;
/* No one in the same column */
Modified: trunk/JavaBDD/RubiksCube.java
===================================================================
--- trunk/JavaBDD/RubiksCube.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/RubiksCube.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -159,7 +159,7 @@
}
static BDD buildInitial() {
- BDD b = bdd.one();
+ BDD b = bdd.universe();
for (int k=0; k<4; ++k) {
for (int i=0; i<n; ++i) {
b.andWith(bdd.getDomain(k*n + i).ithVar(k));
Modified: trunk/JavaBDD/net/sf/javabdd/BDDDomain.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDDomain.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/net/sf/javabdd/BDDDomain.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -94,7 +94,7 @@
/* Encode V<=X-1. V is the variables in 'var' and X is the domain size */
BigInteger val = size().subtract(BigInteger.ONE);
- BDD d = factory.one();
+ BDD d = factory.universe();
int[] ivar = vars();
for (int n = 0; n < this.varNum(); n++) {
if (val.testBit(0))
@@ -128,7 +128,7 @@
BDDFactory bdd = getFactory();
if (value == 0L) {
- BDD result = bdd.one();
+ BDD result = bdd.universe();
int n;
for (n = 0; n < bits; n++) {
BDD b = bdd.ithVar(this.ivar[n]);
@@ -182,7 +182,7 @@
}
BDDFactory factory = getFactory();
- BDD e = factory.one();
+ BDD e = factory.universe();
int[] this_ivar = this.vars();
int[] that_ivar = that.vars();
@@ -226,7 +226,7 @@
}
BDDFactory factory = getFactory();
- BDD v = factory.one();
+ BDD v = factory.universe();
int[] ivar = this.vars();
for (int n = 0; n < ivar.length; n++) {
if (val.testBit(0))
@@ -257,7 +257,7 @@
BDD result = factory.zero();
int[] ivar = this.vars();
while (lo.compareTo(hi) <= 0) {
- BDD v = factory.one();
+ BDD v = factory.universe();
for (int n = ivar.length - 1; ; n--) {
if (lo.testBit(n)) {
v.andWith(factory.ithVar(ivar[n]));
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -84,6 +84,11 @@
return TestBDDFactory.init(nodenum, cachesize);
if (bddpackage.equals("typed"))
return TypedBDDFactory.init(nodenum, cachesize);
+ if (bddpackage.equals("zdd")) {
+ BDDFactory bdd = JFactory.init(nodenum, cachesize);
+ ((JFactory)bdd).ZDD = true;
+ return bdd;
+ }
} catch (LinkageError e) {
System.out.println("Could not load BDD package "+bddpackage+": "+e.getLocalizedMessage());
}
@@ -218,7 +223,7 @@
* <p>Compare to bdd_buildcube.</p>
*/
public BDD buildCube(int value, List/*<BDD>*/ variables) {
- BDD result = one();
+ BDD result = universe();
Iterator i = variables.iterator();
int z = 0;
while (i.hasNext()) {
@@ -240,7 +245,7 @@
* <p>Compare to bdd_ibuildcube./p>
*/
public BDD buildCube(int value, int[] variables) {
- BDD result = one();
+ BDD result = universe();
for (int z = 0; z < variables.length; z++, value >>= 1) {
BDD v;
if ((value & 0x1) != 0)
@@ -529,7 +534,7 @@
// Check for constant true / false
if (lh_nodenum == 0 && vnum == 0) {
int r = Integer.parseInt(readNext(ifile));
- return r == 0 ? zero() : one();
+ return r == 0 ? zero() : universe();
}
// Not actually used.
@@ -631,7 +636,7 @@
protected BDD loadhash_get(LoadHash[] lh_table, int lh_nodenum, int key) {
if (key < 0) return null;
if (key == 0) return zero();
- if (key == 1) return one();
+ if (key == 1) return universe();
int hash = lh_table[key % lh_nodenum].first;
@@ -1423,6 +1428,14 @@
}
}
+ if (isZDD()) {
+ // Need to rebuild varsets for existing domains.
+ for (n = 0; n < fdvarnum; n++) {
+ domain[n].var.free();
+ domain[n].var =
+ makeSet(domain[n].ivar);
+ }
+ }
for (n = 0; n < num; n++) {
domain[n + fdvarnum].var =
makeSet(domain[n + fdvarnum].ivar);
Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -446,7 +446,7 @@
}
protected IntBDDVarSet makeBDDVarSet(/*bdd*/int v) {
- if (true || isZDD()) {
+ if (isZDD()) {
if (USE_FINALIZER)
return new IntZDDVarSetWithFinalizer(v);
else
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-13 07:25:37 UTC (rev 467)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-29 08:07:13 UTC (rev 468)
@@ -67,7 +67,7 @@
});
}
- boolean ZDD = true;
+ boolean ZDD = false;
/**
* Implementation of BDDPairing used by JFactory.
@@ -1561,14 +1561,11 @@
return l;
if (ISZERO(l) || ISZERO(r))
return 0;
- if (ISONE(l))
- return r;
- if (ISONE(r))
- return l;
if (LEVEL(l) < LEVEL(r))
return zand_rec(LOW(l), r);
else if (LEVEL(l) > LEVEL(r))
return zand_rec(l, LOW(r));
+ _assert(!ISCONST(l) && !ISCONST(r));
entry = BddCache_lookupI(applycache, APPLYHASH(l, r, bddop_and));
@@ -1811,6 +1808,14 @@
if (var < 2) /* Empty set */
return bdd_apply(l, r, opr);
+ if (ZDD) {
+ // TODO: A real ZDD implementation.
+ int x = bdd_addref(bdd_apply(l, r, opr));
+ int y = bdd_exist(x, var);
+ bdd_delref(x);
+ return y;
+ }
+
if (applycache == null) applycache = BddCacheI_init(cachesize);
if (appexcache == null) appexcache = BddCacheI_init(cachesize);
if (quantcache == null) quantcache = BddCacheI_init(cachesize);
@@ -2144,14 +2149,12 @@
if (INVARSET(LEVEL(r))) {
int r2 = READREF(2), r1 = READREF(1);
switch (applyop) {
- case bddop_and: res = ZDD ? zand_rec(r2, r1) : and_rec(r2, r1); break;
- case bddop_or: res = ZDD ? zor_rec(r2, r1) : or_rec(r2, r1); break;
+ case bddop_and: res = and_rec(r2, r1); break;
+ case bddop_or: res = or_rec(r2, r1); break;
default: res = apply_rec(r2, r1); break;
}
} else {
- res = ZDD
- ? zdd_makenode(LEVEL(r), READREF(2), READREF(1))
- : bdd_makenode(LEVEL(r), READREF(2), READREF(1));
+ res = bdd_makenode(LEVEL(r), READREF(2), READREF(1));
}
POPREF(2);
@@ -2163,6 +2166,45 @@
return res;
}
+ int zquant_rec(int r) {
+ BddCacheDataI entry;
+ int res;
+
+ if (r < 2 || LEVEL(r) > quantlast)
+ return r;
+
+ entry = BddCache_lookupI(quantcache, QUANTHASH(r));
+ if (entry.a == r && entry.c == quantid) {
+ if (CACHESTATS)
+ cachestats.opHit++;
+ return entry.res;
+ }
+ if (CACHESTATS)
+ cachestats.opMiss++;
+
+ PUSHREF(zquant_rec(LOW(r)));
+ PUSHREF(zquant_rec(HIGH(r)));
+
+ if (INVARSET(LEVEL(r))) {
+ int r2 = READREF(2), r1 = READREF(1);
+ switch (applyop) {
+ case bddop_and: res = zand_rec(r2, r1); break;
+ case bddop_or: res = zor_rec(r2, r1); break;
+ default: throw new BDDException();
+ }
+ } else {
+ res = zdd_makenode(LEVEL(r), READREF(2), READREF(1));
+ }
+
+ POPREF(2);
+
+ entry.a = r;
+ entry.c = quantid;
+ entry.res = res;
+
+ return res;
+ }
+
int bdd_constrain(int f, int c) {
int res;
int numReorder = 1;
@@ -2706,7 +2748,10 @@
supportMin = LEVEL(r);
supportMax = supportMin;
- support_rec(r, supportSet);
+ if (ZDD)
+ zsupport_rec(r, 0, supportSet);
+ else
+ support_rec(r, supportSet);
bdd_unmark(r);
bdd_disable_reorder();
@@ -2715,7 +2760,7 @@
if (supportSet[n] == supportID) {
int tmp;
bdd_addref(res);
- tmp = bdd_makenode(n, 0, res);
+ tmp = makenode_impl(n, 0, res);
bdd_delref(res);
res = tmp;
}
@@ -2727,6 +2772,8 @@
void support_rec(int r, int[] support) {
+ _assert(!ZDD);
+
if (r < 2)
return;
@@ -2744,6 +2791,41 @@
support_rec(HIGH(r), support);
}
+ void zsupport_rec(int r, int lev, int[] support) {
+
+ _assert(ZDD);
+
+ if (!ISZERO(r)) {
+ while (lev != LEVEL(r)) {
+ if (lev > supportMax)
+ supportMax = lev;
+ support[lev++] = supportID;
+ }
+ }
+
+ if (r < 2)
+ return;
+
+ if (MARKED(r) || LOW(r) == INVALID_BDD)
+ return;
+
+ if (LOW(r) == HIGH(r)) {
+ SETMARK(r);
+ zsupport_rec(LOW(r), LEVEL(r)+1, support);
+ return;
+ }
+
+ support[LEVEL(r)] = supportID;
+
+ if (LEVEL(r) > supportMax)
+ supportMax = LEVEL(r);
+
+ SETMARK(r);
+
+ zsupport_rec(LOW(r), LEVEL(r)+1, support);
+ zsupport_rec(HIGH(r), LEVEL(r)+1, support);
+ }
+
int bdd_appall(int l, int r, int opr, int var) {
int res;
int numReorder = 1;
@@ -4952,6 +5034,15 @@
bdd_pairs_resize(oldbddvarnum, bddvarnum);
bdd_operator_varresize();
+ if (ZDD) {
+ System.out.println("Changed number of ZDD variables, all existing ZDDs are now invalid.");
+ // Need to rebuild varsets for existing domains.
+ for (int n = 0; n < fdvarnum; n++) {
+ domain[n].var.free();
+ domain[n].var = makeSet(domain[n].ivar);
+ }
+ }
+
bdd_enable_reorder();
return 0;
@@ -5888,7 +5979,6 @@
int next;
}
- // TODO: revisit for zdd
int bdd_loaddata(BufferedReader ifile, int[] translate) throws IOException {
int key, var, low, high, root = 0, n;
@@ -5908,6 +5998,12 @@
if (low < 0 || high < 0 || var < 0)
return bdd_error(BDD_FORMAT);
+ if (ZDD) {
+ // The terminal "1" in BDD means universal set.
+ if (low == 1) low = univ;
+ if (high == 1) high = univ;
+ }
+
root = bdd_addref(bdd_ite(bdd_ithvar(var), high, low));
loadhash_add(key, root);
@@ -5962,6 +6058,7 @@
return;
}
+ // TODO: revisit for ZDD
void bdd_save_rec(BufferedWriter out, int root) throws IOException {
if (root < 2)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-13 16:58:32
|
Revision: 467
http://svn.sourceforge.net/javabdd/?rev=467&view=rev
Author: joewhaley
Date: 2006-11-12 23:25:37 -0800 (Sun, 12 Nov 2006)
Log Message:
-----------
More support for ZDDs.
Modified Paths:
--------------
trunk/JavaBDD_tests/bdd/BasicTests.java
trunk/JavaBDD_tests/highlevel/NQueensTest.java
trunk/JavaBDD_tests/regression/R3.java
Modified: trunk/JavaBDD_tests/bdd/BasicTests.java
===================================================================
--- trunk/JavaBDD_tests/bdd/BasicTests.java 2006-11-13 07:25:31 UTC (rev 466)
+++ trunk/JavaBDD_tests/bdd/BasicTests.java 2006-11-13 07:25:37 UTC (rev 467)
@@ -25,7 +25,6 @@
* @version $Id$
*/
public class BasicTests extends BDDTestCase {
-
public static void main(String[] args) {
junit.textui.TestRunner.run(BasicTests.class);
}
@@ -45,10 +44,12 @@
Assert.assertEquals(true, y.isOne());
Assert.assertEquals(false, z.isZero());
Assert.assertEquals(false, z.isOne());
- x.free(); y.free(); z.free();
+ x.free();
+ y.free();
+ z.free();
}
}
-
+
public void testVar() {
reset();
Assert.assertTrue(hasNext());
@@ -56,8 +57,9 @@
BDDFactory bdd = nextFactory();
if (bdd.varNum() < 5) bdd.setVarNum(5);
try {
- bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 });
- } catch (UnsupportedOperationException _) { }
+ bdd.setVarOrder(new int[]{0, 1, 2, 3, 4});
+ } catch (UnsupportedOperationException _) {
+ }
BDD a = bdd.ithVar(1);
BDD b = bdd.ithVar(2);
BDD c = bdd.ithVar(3);
@@ -71,18 +73,24 @@
try {
d.var();
Assert.fail(bdd.getVersion());
- } catch (BDDException x) { }
+ } catch (BDDException x) {
+ }
try {
e.var();
Assert.fail(bdd.getVersion());
- } catch (BDDException x) { }
+ } catch (BDDException x) {
+ }
BDD f = a.and(b);
- if (!bdd.isZDD())
- Assert.assertEquals(1, f.var());
- a.free(); b.free(); c.free(); d.free(); e.free(); f.free();
+ if (!bdd.isZDD()) Assert.assertEquals(1, f.var());
+ a.free();
+ b.free();
+ c.free();
+ d.free();
+ e.free();
+ f.free();
}
}
-
+
public void testVarOrder() {
reset();
Assert.assertTrue(hasNext());
@@ -90,9 +98,10 @@
BDDFactory bdd = nextFactory();
if (bdd.varNum() < 5) bdd.setVarNum(5);
try {
- bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 });
+ bdd.setVarOrder(new int[]{0, 1, 2, 3, 4});
} catch (UnsupportedOperationException _) {
- System.err.println("Warning: "+bdd.getVersion()+" does not support setVarOrder()");
+ System.err.println("Warning: " + bdd.getVersion()
+ + " does not support setVarOrder()");
continue;
}
BDD a = bdd.ithVar(0);
@@ -107,7 +116,7 @@
Assert.assertEquals(3, d.var());
Assert.assertEquals(4, e.var());
}
- bdd.setVarOrder(new int[] { 2, 3, 4, 0, 1 });
+ bdd.setVarOrder(new int[]{2, 3, 4, 0, 1});
if (!bdd.isZDD()) {
Assert.assertEquals(0, a.var());
Assert.assertEquals(1, b.var());
@@ -120,10 +129,14 @@
Assert.assertEquals(1, d.level());
Assert.assertEquals(2, e.level());
}
- a.free(); b.free(); c.free(); d.free(); e.free();
+ a.free();
+ b.free();
+ c.free();
+ d.free();
+ e.free();
}
}
-
+
public void testLowHigh() {
reset();
Assert.assertTrue(hasNext());
@@ -131,8 +144,9 @@
BDDFactory bdd = nextFactory();
if (bdd.varNum() < 5) bdd.setVarNum(5);
try {
- bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 });
- } catch (UnsupportedOperationException _) { }
+ bdd.setVarOrder(new int[]{0, 1, 2, 3, 4});
+ } catch (UnsupportedOperationException _) {
+ }
BDD a, b, c;
a = bdd.ithVar(0);
a.andWith(bdd.ithVar(1));
@@ -157,8 +171,7 @@
Assert.assertEquals(1, b.var());
c = b.high();
b.free();
- if (!bdd.isZDD())
- Assert.assertEquals(2, c.var());
+ if (!bdd.isZDD()) Assert.assertEquals(2, c.var());
b = c.low();
if (!bdd.isZDD()) {
Assert.assertEquals(true, b.isOne());
@@ -173,10 +186,12 @@
} catch (BDDException _) {
}
}
- a.free(); b.free(); c.free();
+ a.free();
+ b.free();
+ c.free();
}
}
-
+
public void testNot() {
reset();
Assert.assertTrue(hasNext());
@@ -187,12 +202,12 @@
a = bdd.ithVar(0);
b = a.not();
c = bdd.nithVar(0);
- System.out.println("First graph:");
- a.printDot();
- System.out.println("Second graph:");
- b.printDot();
- System.out.println("Third graph:");
- c.printDot();
+ //System.out.println("First graph:");
+ //a.printDot();
+ //System.out.println("Second graph:");
+ //b.printDot();
+ //System.out.println("Third graph:");
+ //c.printDot();
Assert.assertEquals(b, c);
if (!bdd.isZDD()) {
c.free();
@@ -202,10 +217,12 @@
c = b.low();
Assert.assertEquals(true, c.isOne());
}
- a.free(); b.free(); c.free();
+ a.free();
+ b.free();
+ c.free();
}
}
-
+
public void testId() {
reset();
Assert.assertTrue(hasNext());
@@ -218,37 +235,39 @@
a.andWith(bdd.ithVar(0));
Assert.assertTrue(!a.equals(b));
Assert.assertTrue(a.var() == 0);
- if (!bdd.isZDD())
- Assert.assertTrue(b.var() == 1);
+ if (!bdd.isZDD()) Assert.assertTrue(b.var() == 1);
b.andWith(bdd.zero());
Assert.assertTrue(b.isZero());
Assert.assertTrue(!a.isZero());
- a.free(); b.free();
+ a.free();
+ b.free();
}
}
-
- void testApply(BDDFactory bdd, BDDFactory.BDDOp op,
- boolean b1, boolean b2, boolean b3, boolean b4) {
+
+ void testApply(BDDFactory bdd, BDDFactory.BDDOp op, boolean b1, boolean b2, boolean b3,
+ boolean b4) {
BDD a;
- Assert.assertEquals(b1, (a = bdd.zero().applyWith(bdd.zero(), op)).isOne());
+ Assert.assertEquals(b1, (a = bdd.zero().applyWith(bdd.zero(), op)).isUniverse());
a.free();
- Assert.assertEquals(b2, (a = bdd.zero().applyWith(bdd.one(), op)).isOne());
+ Assert.assertEquals(b2, (a = bdd.zero().applyWith(bdd.universe(), op)).isUniverse());
a.free();
- Assert.assertEquals(b3, (a = bdd.one().applyWith(bdd.zero(), op)).isOne());
+ Assert.assertEquals(b3, (a = bdd.universe().applyWith(bdd.zero(), op)).isUniverse());
a.free();
- Assert.assertEquals(b4, (a = bdd.one().applyWith(bdd.one(), op)).isOne());
+ Assert.assertEquals(b4, (a = bdd.universe().applyWith(bdd.universe(), op)).isUniverse());
a.free();
}
-
+
static boolean isFreed(BDD b) {
return b.hashCode() == -1 || b.hashCode() == 0x07ffffff;
}
-
- void testApplyWith(BDDFactory bdd, BDDFactory.BDDOp op,
- boolean b1, boolean b2, boolean b3, boolean b4) {
+
+ void testApplyWith(BDDFactory bdd, BDDFactory.BDDOp op, boolean b1, boolean b2, boolean b3,
+ boolean b4) {
BDD a, b, c, d;
- a = bdd.zero(); b = bdd.zero();
- c = a; d = b;
+ a = bdd.zero();
+ b = bdd.zero();
+ c = a;
+ d = b;
Assert.assertTrue(!isFreed(d));
a.applyWith(b, op);
Assert.assertEquals(b1, a.isOne());
@@ -256,9 +275,10 @@
Assert.assertTrue(isFreed(b));
Assert.assertTrue(isFreed(d));
a.free();
-
- a = bdd.zero(); b = bdd.one();
- c = a; d = b;
+ a = bdd.zero();
+ b = bdd.one();
+ c = a;
+ d = b;
Assert.assertTrue(!isFreed(d));
a.applyWith(b, op);
Assert.assertEquals(b2, a.isOne());
@@ -266,9 +286,10 @@
Assert.assertTrue(isFreed(b));
Assert.assertTrue(isFreed(d));
a.free();
-
- a = bdd.one(); b = bdd.zero();
- c = a; d = b;
+ a = bdd.one();
+ b = bdd.zero();
+ c = a;
+ d = b;
Assert.assertTrue(!isFreed(d));
a.applyWith(b, op);
Assert.assertEquals(b3, a.isOne());
@@ -276,9 +297,10 @@
Assert.assertTrue(isFreed(b));
Assert.assertTrue(isFreed(d));
a.free();
-
- a = bdd.one(); b = bdd.one();
- c = a; d = b;
+ a = bdd.one();
+ b = bdd.one();
+ c = a;
+ d = b;
Assert.assertTrue(!isFreed(d));
a.applyWith(b, op);
Assert.assertEquals(b4, a.isOne());
@@ -287,7 +309,7 @@
Assert.assertTrue(isFreed(d));
a.free();
}
-
+
public void testOr() {
reset();
Assert.assertTrue(hasNext());
@@ -307,11 +329,13 @@
c = b.id();
b.orWith(b);
Assert.assertEquals(b, c);
- a.free(); b.free(); c.free();
+ a.free();
+ b.free();
+ c.free();
testApply(bdd, BDDFactory.or, false, true, true, true);
}
}
-
+
public void testXor() {
reset();
Assert.assertTrue(hasNext());
@@ -323,17 +347,19 @@
b = bdd.ithVar(2);
c = bdd.nithVar(1);
c.xorWith(a);
- Assert.assertTrue(c.isOne());
+ Assert.assertTrue(c.isUniverse());
a = bdd.zero();
a.orWith(bdd.zero());
Assert.assertTrue(a.isZero());
b.xorWith(b);
Assert.assertTrue(b.isZero());
- a.free(); b.free(); c.free();
+ a.free();
+ b.free();
+ c.free();
testApply(bdd, BDDFactory.xor, false, true, true, false);
}
}
-
+
public void testImp() {
reset();
Assert.assertTrue(hasNext());
@@ -343,7 +369,7 @@
testApply(bdd, BDDFactory.imp, true, true, false, true);
}
}
-
+
public void testBiimp() {
reset();
Assert.assertTrue(hasNext());
@@ -353,7 +379,7 @@
testApply(bdd, BDDFactory.biimp, true, false, false, true);
}
}
-
+
public void testDiff() {
reset();
Assert.assertTrue(hasNext());
@@ -363,7 +389,7 @@
testApply(bdd, BDDFactory.diff, false, false, true, false);
}
}
-
+
public void testLess() {
reset();
Assert.assertTrue(hasNext());
@@ -373,10 +399,11 @@
// TODO: more tests
try {
testApply(bdd, BDDFactory.less, false, true, false, false);
- } catch (UnsupportedOperationException _) { }
+ } catch (UnsupportedOperationException _) {
+ }
}
}
-
+
public void testInvImp() {
reset();
Assert.assertTrue(hasNext());
@@ -385,10 +412,11 @@
// TODO: more tests
try {
testApply(bdd, BDDFactory.invimp, true, false, true, true);
- } catch (UnsupportedOperationException _) { }
+ } catch (UnsupportedOperationException _) {
+ }
}
}
-
+
public void testNand() {
reset();
Assert.assertTrue(hasNext());
@@ -398,7 +426,7 @@
testApply(bdd, BDDFactory.nand, true, true, true, false);
}
}
-
+
public void testNor() {
reset();
Assert.assertTrue(hasNext());
@@ -408,7 +436,7 @@
testApply(bdd, BDDFactory.nor, true, false, false, false);
}
}
-
+
public void testApplyWith() {
reset();
Assert.assertTrue(hasNext());
@@ -424,16 +452,19 @@
testApplyWith(bdd, BDDFactory.nor, true, false, false, false);
try {
testApplyWith(bdd, BDDFactory.biimp, true, false, false, true);
- } catch (UnsupportedOperationException _) { }
+ } catch (UnsupportedOperationException _) {
+ }
try {
testApplyWith(bdd, BDDFactory.less, false, true, false, false);
- } catch (UnsupportedOperationException _) { }
+ } catch (UnsupportedOperationException _) {
+ }
try {
testApplyWith(bdd, BDDFactory.invimp, true, false, true, true);
- } catch (UnsupportedOperationException _) { }
+ } catch (UnsupportedOperationException _) {
+ }
}
}
-
+
public void testIte() {
reset();
Assert.assertTrue(hasNext());
@@ -450,15 +481,20 @@
d = a.ite(c, b);
e = d.not();
Assert.assertEquals(a, e);
- d.free(); e.free();
+ d.free();
+ e.free();
e = bdd.ithVar(2);
d = e.ite(a, a);
Assert.assertEquals(a, d);
// TODO: more tests.
- a.free(); b.free(); c.free(); d.free(); e.free();
+ a.free();
+ b.free();
+ c.free();
+ d.free();
+ e.free();
}
}
-
+
public void testReplace() {
reset();
Assert.assertTrue(hasNext());
@@ -469,7 +505,7 @@
BDDPairing p2 = bdd.makePair();
p2.set(1, 2);
BDDPairing p3 = bdd.makePair();
- p3.set(new int[] { 0, 1 }, new int[] { 1, 0 });
+ p3.set(new int[]{0, 1}, new int[]{1, 0});
BDD a, b, c, d, e, f;
a = bdd.ithVar(0);
b = bdd.ithVar(1);
@@ -491,19 +527,24 @@
Assert.assertTrue(d.isZero());
e.replaceWith(p3);
Assert.assertTrue(e.isOne());
- a.free(); b.free(); c.free(); d.free(); e.free(); f.free();
+ a.free();
+ b.free();
+ c.free();
+ d.free();
+ e.free();
+ f.free();
p1.reset();
p2.reset();
p3.reset();
}
}
-
+
void tEnsureCapacity() {
reset();
Assert.assertTrue(hasNext());
while (hasNext()) {
BDDFactory bdd = nextFactory();
- long[] domains = new long[] { 127, 17, 31, 4 };
+ long[] domains = new long[]{127, 17, 31, 4};
BDDDomain[] d = bdd.extDomain(domains);
BDD q = d[0].ithVar(7);
BDD r = d[1].ithVar(9);
@@ -512,7 +553,7 @@
BDD u = r.and(s);
BDD v = q.and(t);
BDD w = u.and(t);
- //BDD x = d[1].set();
+ // BDD x = d[1].set();
for (int i = 0; i < d.length; ++i) {
d[i].ensureCapacity(BigInteger.valueOf(150));
Assert.assertEquals(BigInteger.valueOf(7), q.scanVar(d[0]));
@@ -526,22 +567,28 @@
Assert.assertEquals(BigInteger.valueOf(9), w.scanVar(d[1]));
Assert.assertEquals(BigInteger.valueOf(4), w.scanVar(d[2]));
Assert.assertEquals(BigInteger.valueOf(2), w.scanVar(d[3]));
- //BDD y = d[1].set();
- //Assert.assertEquals(x, y);
- //y.free();
+ // BDD y = d[1].set();
+ // Assert.assertEquals(x, y);
+ // y.free();
}
- //x.free();
- w.free(); v.free(); u.free(); t.free(); s.free(); r.free(); q.free();
+ // x.free();
+ w.free();
+ v.free();
+ u.free();
+ t.free();
+ s.free();
+ r.free();
+ q.free();
}
}
-
+
void tEnsureCapacity2() throws IOException {
reset();
Assert.assertTrue(hasNext());
while (hasNext()) {
BDDFactory bdd = nextFactory();
- System.out.println("Factory "+bdd);
- long[] domainSizes = new long[] { 127, 17, 31, 4, 256, 87, 42, 666, 3405, 18 };
+ System.out.println("Factory " + bdd);
+ long[] domainSizes = new long[]{127, 17, 31, 4, 256, 87, 42, 666, 3405, 18};
while (bdd.numberOfDomains() < domainSizes.length) {
bdd.extDomain(domainSizes[bdd.numberOfDomains()]);
}
@@ -557,7 +604,7 @@
final int num = 10;
for (int i = 0; i < count; ++i) {
String order = randomOrder(d);
- //System.out.println("Random order: "+order);
+ // System.out.println("Random order: "+order);
bdd.setVarOrder(bdd.makeVarOrdering(false, order));
List bdds = new LinkedList();
for (int j = 0; j < num; ++j) {
@@ -565,32 +612,35 @@
bdds.add(b);
}
StringBuffer sb = new StringBuffer();
- for (Iterator j = bdds.iterator(); j.hasNext(); ) {
+ for (Iterator j = bdds.iterator(); j.hasNext();) {
BDD b = (BDD) j.next();
sb.append(b.toStringWithDomains());
- //bdd.save(new BufferedWriter(new PrintWriter(System.out)), b);
+ // bdd.save(new BufferedWriter(new PrintWriter(System.out)),
+ // b);
}
String before = sb.toString();
int which = random.nextInt(d.length);
int amount = random.nextInt(d[which].size().intValue() * 3);
- //System.out.println(" Ensure capacity "+d[which]+" = "+amount);
+ // System.out.println(" Ensure capacity "+d[which]+" =
+ // "+amount);
d[which].ensureCapacity(amount);
sb = new StringBuffer();
- for (Iterator j = bdds.iterator(); j.hasNext(); ) {
+ for (Iterator j = bdds.iterator(); j.hasNext();) {
BDD b = (BDD) j.next();
sb.append(b.toStringWithDomains());
- //bdd.save(new BufferedWriter(new PrintWriter(System.out)), b);
+ // bdd.save(new BufferedWriter(new PrintWriter(System.out)),
+ // b);
}
String after = sb.toString();
Assert.assertEquals(before, after);
- for (Iterator j = bdds.iterator(); j.hasNext(); ) {
+ for (Iterator j = bdds.iterator(); j.hasNext();) {
BDD b = (BDD) j.next();
b.free();
}
}
}
}
-
+
private static BDD randomBDD(BDDFactory f) {
Assert.assertTrue(f.numberOfDomains() > 0);
List list = new ArrayList(f.numberOfDomains());
@@ -600,16 +650,15 @@
}
BDD result = f.one();
for (int i = 0; i < k; ++i) {
- int x = random.nextInt(f.numberOfDomains()-i);
+ int x = random.nextInt(f.numberOfDomains() - i);
BDDDomain d = (BDDDomain) list.remove(x);
int y = random.nextInt(d.size().intValue());
result.andWith(d.ithVar(y));
}
- if (k == 0 && random.nextBoolean())
- result.andWith(f.zero());
+ if (k == 0 && random.nextBoolean()) result.andWith(f.zero());
return result;
}
-
+
private static String randomOrder(BDDDomain[] domains) {
domains = (BDDDomain[]) randomShuffle(domains);
StringBuffer sb = new StringBuffer();
@@ -623,14 +672,14 @@
}
return sb.toString();
}
-
private static Random random = new Random(System.currentTimeMillis());
+
private static Object[] randomShuffle(Object[] a) {
int n = a.length;
List list = new ArrayList(Arrays.asList(a));
Object[] result = (Object[]) a.clone();
for (int i = 0; i < n; ++i) {
- int k = random.nextInt(n-i);
+ int k = random.nextInt(n - i);
result[i] = list.remove(k);
}
Assert.assertTrue(list.isEmpty());
Modified: trunk/JavaBDD_tests/highlevel/NQueensTest.java
===================================================================
--- trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-11-13 07:25:31 UTC (rev 466)
+++ trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-11-13 07:25:37 UTC (rev 467)
@@ -77,7 +77,7 @@
build(i, j);
}
- solution = queen.satOne();
+ solution = queen.fullSatOne();
double result = queen.satCount();
return result;
Modified: trunk/JavaBDD_tests/regression/R3.java
===================================================================
--- trunk/JavaBDD_tests/regression/R3.java 2006-11-13 07:25:31 UTC (rev 466)
+++ trunk/JavaBDD_tests/regression/R3.java 2006-11-13 07:25:37 UTC (rev 467)
@@ -25,6 +25,7 @@
while (hasNext()) {
BDDFactory bdd = nextFactory();
+ if (bdd.isZDD()) continue;
BDD x0,x1,y0,y1,z0,z1,t,or,one;
BDDVarSet xs0,xs1;
bdd.setVarNum(5);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-11-13 16:58:17
|
Revision: 466
http://svn.sourceforge.net/javabdd/?rev=466&view=rev
Author: joewhaley
Date: 2006-11-12 23:25:31 -0800 (Sun, 12 Nov 2006)
Log Message:
-----------
More support for ZDDs.
Modified Paths:
--------------
trunk/JavaBDD/net/sf/javabdd/JFactory.java
Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java
===================================================================
--- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-26 16:42:44 UTC (rev 465)
+++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-11-13 07:25:31 UTC (rev 466)
@@ -102,15 +102,19 @@
sb.append('{');
boolean any = false;
for (int i = 0; i < result.length; ++i) {
- // TODO: revisit for zdd
- if (result[i] != bdd_ithvar(bddlevel2var[i])) {
+ if (result[i] != (ZDD ? zdd_makenode(i, 0, 1):bdd_ithvar(bddlevel2var[i]))) {
if (any) sb.append(", ");
any = true;
sb.append(bddlevel2var[i]);
sb.append('=');
- BDD b = makeBDD(result[i]);
- sb.append(b);
- b.free();
+ //if (ZDD)
+ // sb.append(bddlevel2var[LEVEL(result[i])]);
+ //else
+ {
+ BDD b = makeBDD(result[i]);
+ sb.append(b);
+ b.free();
+ }
}
}
sb.append('}');
@@ -125,9 +129,11 @@
bddPair p = new bddPair();
p.result = new int[bddvarnum];
int n;
- // TODO: revisit for zdd
for (n = 0; n < bddvarnum; n++)
- p.result[n] = bdd_ithvar(bddlevel2var[n]);
+ if (ZDD)
+ p.result[n] = bdd_addref(zdd_makenode(n, 0, 1));
+ else
+ p.result[n] = bdd_ithvar(bddlevel2var[n]);
p.id = update_pairsid();
p.last = -1;
@@ -1191,6 +1197,7 @@
CHECKa(r, bddfalse);
if (replacecache == null) replacecache = BddCacheI_init(cachesize);
+ if (ZDD && applycache == null) applycache = BddCacheI_init(cachesize);
again : for (;;) {
try {
@@ -1198,6 +1205,7 @@
replacepair = pair.result;
replacelast = pair.last;
replaceid = (pair.id << 2) | CACHEID_REPLACE;
+ if (ZDD) applyop = bddop_or;
if (numReorder == 0) bdd_disable_reorder();
res = replace_rec(r);
@@ -1284,32 +1292,38 @@
}
int zdd_correctify(int level, int l, int r) {
- // TODO: This function is wrong. Need to figure out how to do replace in ZDD.
int res;
-
- if (level < LEVEL(l) && level < LEVEL(r))
- return zdd_makenode(level, l, r);
-
- if (level == LEVEL(l) || level == LEVEL(r)) {
- bdd_error(BDD_REPLACE);
- return 0;
- }
-
- if (LEVEL(l) == LEVEL(r)) {
- PUSHREF(zdd_correctify(level, LOW(l), LOW(r)));
- PUSHREF(zdd_correctify(level, HIGH(l), HIGH(r)));
- res = zdd_makenode(LEVEL(l), READREF(2), READREF(1));
- } else if (LEVEL(l) < LEVEL(r)) {
- PUSHREF(zdd_correctify(level, LOW(l), r));
- PUSHREF(zdd_correctify(level, HIGH(l), r));
- res = zdd_makenode(LEVEL(l), READREF(2), READREF(1));
+
+ // Here's the idea: Flip the "level" bit on the one branch,
+ // then "or" the result with the zero branch.
+ PUSHREF(zdd_makenode(level, 0, 1));
+ PUSHREF(zdd_change(r, READREF(1)));
+ res = zor_rec(READREF(1), l);
+ POPREF(2);
+
+ return res;
+ }
+
+ // Flip zvar in r.
+ int zdd_change(int r, int zvar) {
+ int res;
+
+ if (ISZERO(r))
+ return r;
+ if (ISONE(r))
+ return zvar;
+
+ if (LEVEL(r) > LEVEL(zvar)) {
+ res = zdd_makenode(LEVEL(zvar), BDDZERO, r);
+ } else if (LEVEL(r) == LEVEL(zvar)) {
+ res = zdd_makenode(LEVEL(zvar), HIGH(r), LOW(r));
} else {
- PUSHREF(zdd_correctify(level, l, LOW(r)));
- PUSHREF(zdd_correctify(level, l, HIGH(r)));
+ PUSHREF(zdd_change(LOW(r), zvar));
+ PUSHREF(zdd_change(HIGH(r), zvar));
res = zdd_makenode(LEVEL(r), READREF(2), READREF(1));
+ POPREF(2);
}
- POPREF(2);
-
+
return res; /* FIXME: cache ? */
}
@@ -1333,11 +1347,79 @@
applyop = op;
if (numReorder == 0) bdd_disable_reorder();
- switch (op) {
- case bddop_and: res = ZDD ? zand_rec(l, r) : and_rec(l, r); break;
- case bddop_or: res = ZDD ? zor_rec(l, r) : or_rec(l, r); break;
- case bddop_diff: res = ZDD ? zdiff_rec(l, r) : apply_rec(l, r); break;
- default: res = apply_rec(l, r); break;
+ if (ZDD) {
+ switch (op) {
+ case bddop_and: res = zand_rec(l, r); break;
+ case bddop_or: res = zor_rec(l, r); break;
+ case bddop_diff: res = zdiff_rec(l, r); break;
+ case bddop_imp:
+ {
+ // TODO: A real ZDD implementation
+ int a = bdd_addref(zdiff_rec(l, r));
+ res = zdiff_rec(univ, a);
+ bdd_delref(a);
+ break;
+ }
+ case bddop_invimp:
+ {
+ // TODO: A real ZDD implementation
+ int a = bdd_addref(zdiff_rec(r, l));
+ res = zdiff_rec(univ, a);
+ bdd_delref(a);
+ break;
+ }
+ case bddop_less:
+ {
+ // TODO: A real ZDD implementation
+ res = zdiff_rec(r, l);
+ break;
+ }
+ case bddop_nand:
+ {
+ // TODO: A real ZDD implementation
+ int k = bdd_addref(zand_rec(l, r));
+ res = zdiff_rec(univ, k);
+ bdd_delref(k);
+ break;
+ }
+ case bddop_nor:
+ {
+ // TODO: A real ZDD implementation
+ int k = bdd_addref(zor_rec(l, r));
+ res = zdiff_rec(univ, k);
+ bdd_delref(k);
+ break;
+ }
+ case bddop_xor:
+ {
+ // TODO: A real ZDD implementation
+ int a = bdd_addref(zand_rec(l, r));
+ int b = bdd_addref(zor_rec(l, r));
+ res = zdiff_rec(b, a);
+ bdd_delref(a); bdd_delref(b);
+ break;
+ }
+ case bddop_biimp:
+ {
+ // TODO: A real ZDD implementation
+ int a = bdd_addref(zand_rec(l, r));
+ int b = bdd_addref(zor_rec(l, r));
+ int c = bdd_addref(zdiff_rec(b, a));
+ bdd_delref(a); bdd_delref(b);
+ res = zdiff_rec(univ, c);
+ bdd_delref(c);
+ break;
+ }
+ default:
+ // TODO: other operators
+ throw new BDDException();
+ }
+ } else {
+ switch (op) {
+ case bddop_and: res = and_rec(l, r); break;
+ case bddop_or: res = or_rec(l, r); break;
+ default: res = apply_rec(l, r); break;
+ }
}
if (numReorder == 0) bdd_enable_reorder();
} catch (ReorderException x) {
@@ -2866,7 +2948,7 @@
res = fullsatone_rec(r);
for (v = LEVEL(r) - 1; v >= 0; v--) {
- res = PUSHREF(bdd_makenode(v, res, 0));
+ res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
}
bdd_enable_reorder();
@@ -2884,19 +2966,19 @@
int v;
for (v = LEVEL(LOW(r)) - 1; v > LEVEL(r); v--) {
- res = PUSHREF(bdd_makenode(v, res, 0));
+ res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
}
- return PUSHREF(bdd_makenode(LEVEL(r), res, 0));
+ return PUSHREF(ZDD?zdd_makenode(LEVEL(r), res, 0):bdd_makenode(LEVEL(r), res, 0));
} else {
int res = fullsatone_rec(HIGH(r));
int v;
for (v = LEVEL(HIGH(r)) - 1; v > LEVEL(r); v--) {
- res = PUSHREF(bdd_makenode(v, res, 0));
+ res = PUSHREF(ZDD?zdd_makenode(v, res, 0):bdd_makenode(v, res, 0));
}
- return PUSHREF(bdd_makenode(LEVEL(r), 0, res));
+ return PUSHREF(ZDD?zdd_makenode(LEVEL(r), 0, res):bdd_makenode(LEVEL(r), 0, res));
}
}
@@ -3031,7 +3113,8 @@
if (countcache == null) countcache = BddCacheD_init(cachesize);
miscid = CACHEID_SATCOU;
- size = Math.pow(2.0, (double) LEVEL(r));
+ if (!ZDD)
+ size = Math.pow(2.0, (double) LEVEL(r));
return size * satcount_rec(r);
}
@@ -3064,12 +3147,13 @@
size = 0;
s = 1;
-
- s *= Math.pow(2.0, (float) (LEVEL(LOW(root)) - LEVEL(root) - 1));
+ if (!ZDD)
+ s *= Math.pow(2.0, (float) (LEVEL(LOW(root)) - LEVEL(root) - 1));
size += s * satcount_rec(LOW(root));
s = 1;
- s *= Math.pow(2.0, (float) (LEVEL(HIGH(root)) - LEVEL(root) - 1));
+ if (!ZDD)
+ s *= Math.pow(2.0, (float) (LEVEL(HIGH(root)) - LEVEL(root) - 1));
size += s * satcount_rec(HIGH(root));
entry.a = root;
@@ -3747,9 +3831,29 @@
if (newvar < 0 || newvar > bddvarnum - 1)
bdd_error(BDD_VAR);
- bdd_delref(pair.result[bddvar2level[oldvar]]);
- // TODO: revisit for zdd
- pair.result[bddvar2level[oldvar]] = bdd_ithvar(newvar);
+ if (ZDD) {
+ // ZDD requires a permutation, not just a pairing.
+ int oldlev = bddvar2level[oldvar], newlev = bddvar2level[newvar];
+ int newIndex = newlev;
+ if (LEVEL(pair.result[newIndex]) != newlev) {
+ // Find who points to newlev.
+ for (newIndex = 0; newIndex < bddvarnum; ++newIndex) {
+ if (LEVEL(pair.result[newIndex]) == newlev) {
+ break;
+ }
+ }
+ _assert(newIndex != bddvarnum);
+ }
+ int tmp = pair.result[oldlev];
+ pair.result[oldlev] = pair.result[newIndex];
+ pair.result[newIndex] = tmp;
+
+ if (newlev > pair.last)
+ pair.last = newlev;
+ } else {
+ bdd_delref(pair.result[bddvar2level[oldvar]]);
+ pair.result[bddvar2level[oldvar]] = bdd_ithvar(newvar);
+ }
pair.id = update_pairsid();
if (bddvar2level[oldvar] > pair.last)
@@ -3764,6 +3868,9 @@
if (pair == null)
return;
+ if (ZDD)
+ throw new BDDException("setbddpair not supported with ZDDs");
+
CHECK(newvar);
if (oldvar < 0 || oldvar >= bddvarnum)
bdd_error(BDD_VAR);
@@ -3782,9 +3889,13 @@
void bdd_resetpair(bddPair p) {
int n;
- // TODO: revisit for zdd
- for (n = 0; n < bddvarnum; n++)
- p.result[n] = bdd_ithvar(bddlevel2var[n]);
+ for (n = 0; n < bddvarnum; n++) {
+ if (ZDD) {
+ bdd_delref(p.result[n]);
+ p.result[n] = bdd_addref(zdd_makenode(n, 0, 1));
+ } else
+ p.result[n] = bdd_ithvar(bddlevel2var[n]);
+ }
p.last = 0;
}
@@ -3861,9 +3972,11 @@
System.arraycopy(p.result, 0, new_result, 0, oldsize);
p.result = new_result;
- // TODO: revisit for zdd
for (n = oldsize; n < newsize; n++)
- p.result[n] = bdd_ithvar(bddlevel2var[n]);
+ if (ZDD)
+ p.result[n] = bdd_addref(zdd_makenode(n, 0, 1));
+ else
+ p.result[n] = bdd_ithvar(bddlevel2var[n]);
}
return 0;
@@ -4688,6 +4801,8 @@
bddvarnum = 0;
bddproduced = 0;
+ univ = 1;
+
//err_handler = null;
//gbc_handler = null;
//resize_handler = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2006-07-26 19:49:45
|
Revision: 464 Author: joewhaley Date: 2006-07-26 09:42:39 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=464&view=rev Log Message: ----------- Improved ZDD support. Modified Paths: -------------- trunk/JavaBDD_tests/bdd/BasicTests.java Modified: trunk/JavaBDD_tests/bdd/BasicTests.java =================================================================== --- trunk/JavaBDD_tests/bdd/BasicTests.java 2006-07-21 16:55:23 UTC (rev 463) +++ trunk/JavaBDD_tests/bdd/BasicTests.java 2006-07-26 16:42:39 UTC (rev 464) @@ -63,9 +63,11 @@ BDD c = bdd.ithVar(3); BDD d = bdd.one(); BDD e = bdd.zero(); - Assert.assertEquals(1, a.var()); - Assert.assertEquals(2, b.var()); - Assert.assertEquals(3, c.var()); + if (!bdd.isZDD()) { + Assert.assertEquals(1, a.var()); + Assert.assertEquals(2, b.var()); + Assert.assertEquals(3, c.var()); + } try { d.var(); Assert.fail(bdd.getVersion()); @@ -75,7 +77,8 @@ Assert.fail(bdd.getVersion()); } catch (BDDException x) { } BDD f = a.and(b); - Assert.assertEquals(1, f.var()); + if (!bdd.isZDD()) + Assert.assertEquals(1, f.var()); a.free(); b.free(); c.free(); d.free(); e.free(); f.free(); } } @@ -97,22 +100,26 @@ BDD c = bdd.ithVar(2); BDD d = bdd.ithVar(3); BDD e = bdd.ithVar(4); - Assert.assertEquals(0, a.var()); - Assert.assertEquals(1, b.var()); - Assert.assertEquals(2, c.var()); - Assert.assertEquals(3, d.var()); - Assert.assertEquals(4, e.var()); + if (!bdd.isZDD()) { + Assert.assertEquals(0, a.var()); + Assert.assertEquals(1, b.var()); + Assert.assertEquals(2, c.var()); + Assert.assertEquals(3, d.var()); + Assert.assertEquals(4, e.var()); + } bdd.setVarOrder(new int[] { 2, 3, 4, 0, 1 }); - Assert.assertEquals(0, a.var()); - Assert.assertEquals(1, b.var()); - Assert.assertEquals(2, c.var()); - Assert.assertEquals(3, d.var()); - Assert.assertEquals(4, e.var()); - Assert.assertEquals(3, a.level()); - Assert.assertEquals(4, b.level()); - Assert.assertEquals(0, c.level()); - Assert.assertEquals(1, d.level()); - Assert.assertEquals(2, e.level()); + if (!bdd.isZDD()) { + Assert.assertEquals(0, a.var()); + Assert.assertEquals(1, b.var()); + Assert.assertEquals(2, c.var()); + Assert.assertEquals(3, d.var()); + Assert.assertEquals(4, e.var()); + Assert.assertEquals(3, a.level()); + Assert.assertEquals(4, b.level()); + Assert.assertEquals(0, c.level()); + Assert.assertEquals(1, d.level()); + Assert.assertEquals(2, e.level()); + } a.free(); b.free(); c.free(); d.free(); e.free(); } } @@ -132,35 +139,40 @@ a.andWith(bdd.nithVar(2)); Assert.assertEquals(0, a.var()); b = a.low(); - Assert.assertEquals(true, b.isZero()); - try { - b.low(); - Assert.fail(); - } catch (BDDException _) { + if (!bdd.isZDD()) { + Assert.assertEquals(true, b.isZero()); + try { + b.low(); + Assert.fail(); + } catch (BDDException _) { + } + try { + b.high(); + Assert.fail(); + } catch (BDDException _) { + } } - try { - b.high(); - Assert.fail(); - } catch (BDDException _) { - } b.free(); b = a.high(); Assert.assertEquals(1, b.var()); c = b.high(); b.free(); - Assert.assertEquals(2, c.var()); + if (!bdd.isZDD()) + Assert.assertEquals(2, c.var()); b = c.low(); - Assert.assertEquals(true, b.isOne()); - try { - b.low(); - Assert.fail(); - } catch (BDDException _) { + if (!bdd.isZDD()) { + Assert.assertEquals(true, b.isOne()); + try { + b.low(); + Assert.fail(); + } catch (BDDException _) { + } + try { + b.high(); + Assert.fail(); + } catch (BDDException _) { + } } - try { - b.high(); - Assert.fail(); - } catch (BDDException _) { - } a.free(); b.free(); c.free(); } } @@ -175,13 +187,21 @@ a = bdd.ithVar(0); b = a.not(); c = bdd.nithVar(0); + System.out.println("First graph:"); + a.printDot(); + System.out.println("Second graph:"); + b.printDot(); + System.out.println("Third graph:"); + c.printDot(); Assert.assertEquals(b, c); - c.free(); - c = b.high(); - Assert.assertEquals(true, c.isZero()); - c.free(); - c = b.low(); - Assert.assertEquals(true, c.isOne()); + if (!bdd.isZDD()) { + c.free(); + c = b.high(); + Assert.assertEquals(true, c.isZero()); + c.free(); + c = b.low(); + Assert.assertEquals(true, c.isOne()); + } a.free(); b.free(); c.free(); } } @@ -198,7 +218,8 @@ a.andWith(bdd.ithVar(0)); Assert.assertTrue(!a.equals(b)); Assert.assertTrue(a.var() == 0); - Assert.assertTrue(b.var() == 1); + if (!bdd.isZDD()) + Assert.assertTrue(b.var() == 1); b.andWith(bdd.zero()); Assert.assertTrue(b.isZero()); Assert.assertTrue(!a.isZero()); @@ -278,12 +299,14 @@ b = bdd.ithVar(2); c = bdd.nithVar(1); c.orWith(a); - Assert.assertTrue(c.isOne()); + Assert.assertTrue(c.isUniverse()); a = bdd.zero(); a.orWith(bdd.zero()); Assert.assertTrue(a.isZero()); + c.free(); + c = b.id(); b.orWith(b); - Assert.assertEquals(2, b.var()); + Assert.assertEquals(b, c); a.free(); b.free(); c.free(); testApply(bdd, BDDFactory.or, false, true, true, true); } @@ -346,6 +369,7 @@ Assert.assertTrue(hasNext()); while (hasNext()) { BDDFactory bdd = nextFactory(); + if (bdd.isZDD()) continue; // TODO: more tests try { testApply(bdd, BDDFactory.less, false, true, false, false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <joe...@us...> - 2006-07-26 17:46:44
|
Revision: 465 Author: joewhaley Date: 2006-07-26 09:42:44 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=465&view=rev Log Message: ----------- Improved ZDD support. Modified Paths: -------------- trunk/JavaBDD/net/sf/javabdd/BDD.java trunk/JavaBDD/net/sf/javabdd/BDDFactory.java trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java trunk/JavaBDD/net/sf/javabdd/JDDFactory.java trunk/JavaBDD/net/sf/javabdd/JFactory.java trunk/JavaBDD/net/sf/javabdd/MicroFactory.java Modified: trunk/JavaBDD/net/sf/javabdd/BDD.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-07-26 16:42:44 UTC (rev 465) @@ -48,6 +48,14 @@ public abstract boolean isOne(); /** + * <p>Returns true if this BDD is the universe BDD. + * The universal BDD differs from the one BDD in ZDD mode.</p> + * + * @return true if this BDD is the universe BDD + */ + public boolean isUniverse() { return isOne(); } + + /** * <p>Converts this BDD to a new BDDVarSet.</p> * * <p>This BDD must be a boolean function that represents the all-true minterm Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/BDDFactory.java 2006-07-26 16:42:44 UTC (rev 465) @@ -196,6 +196,14 @@ public abstract BDD one(); /** + * <p>Get the constant universe BDD. + * (The universe BDD differs from the one BDD in ZDD mode.)</p> + * + * <p>Compare to bdd_true.</p> + */ + public BDD universe() { return one(); } + + /** * <p>Get an empty BDDVarSet.</p> * * <p>Compare to bdd_true.</p> Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-26 16:42:44 UTC (rev 465) @@ -20,6 +20,7 @@ protected abstract void delref_impl(/*bdd*/int v); protected abstract /*bdd*/int zero_impl(); protected abstract /*bdd*/int one_impl(); + protected /*bdd*/int universe_impl() { return one_impl(); } protected abstract /*bdd*/int invalid_bdd_impl(); protected abstract int var_impl(/*bdd*/int v); protected abstract int level_impl(/*bdd*/int v); @@ -28,6 +29,7 @@ protected abstract /*bdd*/int ithVar_impl(int var); protected abstract /*bdd*/int nithVar_impl(int var); + protected abstract /*bdd*/int makenode_impl(int lev, /*bdd*/int lo, /*bdd*/int hi); protected abstract /*bdd*/int ite_impl(/*bdd*/int v1, /*bdd*/int v2, /*bdd*/int v3); protected abstract /*bdd*/int apply_impl(/*bdd*/int v1, /*bdd*/int v2, BDDOp opr); protected abstract /*bdd*/int not_impl(/*bdd*/int v1); @@ -121,6 +123,9 @@ public boolean isOne() { return v == one_impl(); } + public boolean isUniverse() { + return v == universe_impl(); + } public boolean isZero() { return v == zero_impl(); } @@ -236,7 +241,7 @@ public class IntBDDVarSet extends BDDVarSet { /*bdd*/int v; - private IntBDDVarSet(/*bdd*/int v) { + protected IntBDDVarSet(/*bdd*/int v) { this.v = v; addref_impl(v); } @@ -256,12 +261,15 @@ public BDDVarSet id() { return makeBDDVarSet(v); } + protected int do_intersect(int v1, int v2) { + return apply_impl(v1, v2, or); + } public BDDVarSet intersect(BDDVarSet b) { - return makeBDDVarSet(apply_impl(v, unwrap(b), or)); + return makeBDDVarSet(do_intersect(v, unwrap(b))); } public BDDVarSet intersectWith(BDDVarSet b) { /*bdd*/int v2 = unwrap(b); - /*bdd*/int v3 = apply_impl(v, v2, or); + /*bdd*/int v3 = do_intersect(v, v2); addref_impl(v3); delref_impl(v); if (this != b) @@ -300,18 +308,21 @@ } return result; } + protected int do_unionvar(int v, int var) { + return apply_impl(v, ithVar_impl(var), and); + } + protected int do_union(int v1, int v2) { + return apply_impl(v1, v2, and); + } public BDDVarSet union(BDDVarSet b) { - return makeBDDVarSet(apply_impl(v, unwrap(b), and)); + return makeBDDVarSet(do_union(v, unwrap(b))); } public BDDVarSet union(int var) { - /*bdd*/int v2 = ithVar_impl(var); - /*bdd*/int v3 = apply_impl(v, v2, and); - delref_impl(v2); - return makeBDDVarSet(v3); + return makeBDDVarSet(do_unionvar(v, var)); } public BDDVarSet unionWith(BDDVarSet b) { /*bdd*/int v2 = unwrap(b); - /*bdd*/int v3 = apply_impl(v, v2, and); + /*bdd*/int v3 = do_union(v, v2); addref_impl(v3); delref_impl(v); if (this != b) @@ -320,11 +331,9 @@ return this; } public BDDVarSet unionWith(int var) { - /*bdd*/int v2 = ithVar_impl(var); - /*bdd*/int v3 = apply_impl(v, v2, and); + /*bdd*/int v3 = do_unionvar(v, var); addref_impl(v3); delref_impl(v); - delref_impl(v2); v = v3; return this; } @@ -348,11 +357,106 @@ } + public class IntZDDVarSet extends IntBDDVarSet { + protected IntZDDVarSet(/*bdd*/int v) { + super(v); + } + protected int do_intersect(int v1, int v2) { + if (v1 == one_impl()) return v2; + if (v2 == one_impl()) return v1; + int l1, l2; + l1 = level_impl(v1); + l2 = level_impl(v2); + for (;;) { + if (v1 == v2) + return v1; + if (l1 < l2) { + v1 = high_impl(v1); + if (v1 == one_impl()) return v2; + l1 = level_impl(v1); + } else if (l1 > l2) { + v2 = high_impl(v2); + if (v2 == one_impl()) return v1; + l2 = level_impl(v2); + } else { + int k = do_intersect(high_impl(v1), high_impl(v2)); + addref_impl(k); + int result = makenode_impl(l1, zero_impl(), k); + delref_impl(k); + return result; + } + } + } + protected int do_union(int v1, int v2) { + if (v1 == v2) return v1; + if (v1 == one_impl()) return v2; + if (v2 == one_impl()) return v1; + int l1, l2; + l1 = level_impl(v1); + l2 = level_impl(v2); + int vv1 = v1, vv2 = v2, lev = l1; + if (l1 <= l2) + vv1 = high_impl(v1); + if (l1 >= l2) { + vv2 = high_impl(v2); + lev = l2; + } + int k = do_union(vv1, vv2); + addref_impl(k); + int result = makenode_impl(lev, zero_impl(), k); + delref_impl(k); + return result; + } + protected int do_unionvar(int v, int var) { + return do_unionlevel(v, var2Level(var)); + } + private int do_unionlevel(int v, int lev) { + if (v == one_impl()) + return makenode_impl(lev, zero_impl(), one_impl()); + int l = level_impl(v); + if (l == lev) { + return v; + } else if (l > lev) { + return makenode_impl(lev, zero_impl(), v); + } else { + int k = do_unionlevel(high_impl(v), lev); + addref_impl(k); + int result = makenode_impl(lev, zero_impl(), k); + return result; + } + } + } + + public class IntZDDVarSetWithFinalizer extends IntZDDVarSet { + + protected IntZDDVarSetWithFinalizer(int v) { + super(v); + } + + protected void finalize() throws Throwable { + super.finalize(); + if (USE_FINALIZER) { + if (false && v != invalid_bdd_impl()) { + System.out.println("BDD not freed! "+System.identityHashCode(this)); + } + deferredFree(v); + } + } + + } + protected IntBDDVarSet makeBDDVarSet(/*bdd*/int v) { - if (USE_FINALIZER) - return new IntBDDVarSetWithFinalizer(v); - else - return new IntBDDVarSet(v); + if (true || isZDD()) { + if (USE_FINALIZER) + return new IntZDDVarSetWithFinalizer(v); + else + return new IntZDDVarSet(v); + } else { + if (USE_FINALIZER) + return new IntBDDVarSetWithFinalizer(v); + else + return new IntBDDVarSet(v); + } } protected static final /*bdd*/int unwrap(BDDVarSet b) { @@ -387,6 +491,10 @@ return makeBDD(one_impl()); } + public BDD universe() { + return makeBDD(universe_impl()); + } + public BDDVarSet emptySet() { return makeBDDVarSet(one_impl()); } Modified: trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2006-07-26 16:42:44 UTC (rev 465) @@ -115,6 +115,7 @@ protected int nithVar_impl(int var) { return nithVar0(var); } private static native int nithVar0(int var); + protected int makenode_impl(int lev, int lo, int hi) { return ite0(ithVar_impl(level2Var0(lev)), hi, lo); } protected int ite_impl(int v1, int v2, int v3) { return ite0(v1, v2, v3); } private static native int ite0(int b, int c, int d); protected int apply_impl(int v1, int v2, BDDOp opr) { return apply0(v1, v2, opr.id); } Modified: trunk/JavaBDD/net/sf/javabdd/JDDFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-26 16:42:44 UTC (rev 465) @@ -62,6 +62,7 @@ throw new BDDException(); return bdd.not(vars[var]); } + protected int makenode_impl(int lev, int lo, int hi) { return bdd.mk(lev, lo, hi); } protected int ite_impl(int v1, int v2, int v3) { return bdd.ite(v1, v2, v3); } protected int apply_impl(int x, int y, BDDOp opr) { int r; Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-26 16:42:44 UTC (rev 465) @@ -37,7 +37,7 @@ */ public static boolean FLUSH_CACHE_ON_GC = true; - static final boolean VERIFY_ASSERTIONS = false; + static final boolean VERIFY_ASSERTIONS = true; static final boolean CACHESTATS = false; static final boolean SWAPCOUNT = false; @@ -67,7 +67,7 @@ }); } - boolean ZDD = false; + boolean ZDD = true; /** * Implementation of BDDPairing used by JFactory. @@ -102,6 +102,7 @@ sb.append('{'); boolean any = false; for (int i = 0; i < result.length; ++i) { + // TODO: revisit for zdd if (result[i] != bdd_ithvar(bddlevel2var[i])) { if (any) sb.append(", "); any = true; @@ -124,6 +125,7 @@ bddPair p = new bddPair(); p.result = new int[bddvarnum]; int n; + // TODO: revisit for zdd for (n = 0; n < bddvarnum; n++) p.result[n] = bdd_ithvar(bddlevel2var[n]); @@ -140,6 +142,7 @@ protected void delref_impl(int v) { bdd_delref(v); } protected int zero_impl() { return BDDZERO; } protected int one_impl() { return BDDONE; } + protected int universe_impl() { return univ; } protected int invalid_bdd_impl() { return INVALID_BDD; } protected int var_impl(int v) { return bdd_var(v); } protected int level_impl(int v) { return LEVEL(v); } @@ -148,6 +151,12 @@ protected int ithVar_impl(int var) { return bdd_ithvar(var); } protected int nithVar_impl(int var) { return bdd_nithvar(var); } + protected int makenode_impl(int lev, int lo, int hi) { + if (ZDD) + return zdd_makenode(lev, lo, hi); + else + return bdd_makenode(lev, lo, hi); + } protected int ite_impl(int v1, int v2, int v3) { return bdd_ite(v1, v2, v3); } protected int apply_impl(int v1, int v2, BDDOp opr) { return bdd_apply(v1, v2, opr.id); } protected int not_impl(int v1) { return bdd_not(v1); } @@ -456,7 +465,7 @@ prev_interleaved = inter; } BddTree newchild = my_vartree[0]; - _assert(newchild.prev == null); + if (VERIFY_ASSERTIONS) _assert(newchild.prev == null); //while (newchild.prev != null) newchild = newchild.prev; if (parent == null) vartree = newchild; else parent.nextlevel = newchild; @@ -492,8 +501,6 @@ return null; } - - /***** IMPLEMENTATION BELOW *****/ static final int REF_MASK = 0xFFC00000; @@ -710,6 +717,7 @@ /*=== PRIVATE KERNEL VARIABLES =========================================*/ int[] bddvarset; /* Set of defined BDD variables */ + int univ = 1; /* Universal set (used for ZDD) */ int gbcollectnum; /* Number of garbage collections */ int cachesize; /* Size of the operator caches */ long gbcclock; /* Clock ticks used in GBC */ @@ -941,8 +949,10 @@ again : for (;;) { try { INITREF(); + if (numReorder == 0) bdd_disable_reorder(); - res = ZDD ? znot_rec(r) : not_rec(r); + if (ZDD) res = zdiff_rec(univ, r); + else res = not_rec(r); if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); @@ -985,36 +995,6 @@ return res; } - int znot_rec(int r) { - BddCacheDataI entry; - int res; - - if (ISZERO(r)) - return bddtrue; - if (ISONE(r)) - return bddfalse; - - entry = BddCache_lookupI(applycache, NOTHASH(r)); - - if (entry.a == r && entry.c == bddop_not) { - if (CACHESTATS) - cachestats.opHit++; - return entry.res; - } - if (CACHESTATS) - cachestats.opMiss++; - - PUSHREF(znot_rec(LOW(r))); - res = bdd_makenode(LEVEL(r), READREF(1), HIGH(r)); - POPREF(1); - - entry.a = r; - entry.c = bddop_not; - entry.res = res; - - return res; - } - int bdd_ite(int f, int g, int h) { int res; int numReorder = 1; @@ -1136,7 +1116,7 @@ if (ISONE(g) && ISZERO(h)) return f; if (ISZERO(g) && ISONE(h)) - return znot_rec(f); + return zdiff_rec(univ, f); int v = Math.min(LEVEL(g), LEVEL(h)); if (LEVEL(f) < v) @@ -1155,43 +1135,43 @@ if (LEVEL(f) == LEVEL(h)) { PUSHREF(zite_rec(LOW(f), LOW(g), LOW(h))); PUSHREF(zite_rec(HIGH(f), HIGH(g), HIGH(h))); - res = bdd_makenode(LEVEL(f), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(f), READREF(2), READREF(1)); POPREF(2); } else if (LEVEL(f) < LEVEL(h)) { PUSHREF(zite_rec(LOW(f), LOW(g), h)); PUSHREF(zite_rec(HIGH(f), HIGH(g), 0)); - res = bdd_makenode(LEVEL(f), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(f), READREF(2), READREF(1)); POPREF(2); } else /* f > h */ { PUSHREF(zite_rec(f, g, LOW(h))); - res = bdd_makenode(LEVEL(h), HIGH(h), READREF(1)); + res = zdd_makenode(LEVEL(h), HIGH(h), READREF(1)); POPREF(1); } } else if (LEVEL(f) < LEVEL(g)) { if (LEVEL(f) == LEVEL(h)) { PUSHREF(zite_rec(LOW(f), g, LOW(h))); PUSHREF(zite_rec(HIGH(f), 0, HIGH(h))); - res = bdd_makenode(LEVEL(f), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(f), READREF(2), READREF(1)); POPREF(2); } else if (LEVEL(f) < LEVEL(h)) { res = zite_rec(LOW(f), g, h); } else /* f > h */ { PUSHREF(zite_rec(f, g, LOW(h))); - res = bdd_makenode(LEVEL(h), HIGH(h), READREF(1)); + res = zdd_makenode(LEVEL(h), HIGH(h), READREF(1)); POPREF(1); } } else /* f > g */ { if (LEVEL(g) == LEVEL(h)) { PUSHREF(zite_rec(f, LOW(g), LOW(h))); - res = bdd_makenode(LEVEL(g), HIGH(h), READREF(1)); + res = zdd_makenode(LEVEL(g), HIGH(h), READREF(1)); POPREF(1); } else if (LEVEL(g) < LEVEL(h)) { PUSHREF(zite_rec(f, LOW(g), h)); - res = bdd_makenode(LEVEL(g), 0, READREF(1)); + res = zdd_makenode(LEVEL(g), 0, READREF(1)); POPREF(1); } else /* g > h */ { PUSHREF(zite_rec(f, g, LOW(h))); - res = bdd_makenode(LEVEL(h), HIGH(h), READREF(1)); + res = zdd_makenode(LEVEL(h), HIGH(h), READREF(1)); POPREF(1); } } @@ -1253,11 +1233,18 @@ PUSHREF(replace_rec(LOW(r))); PUSHREF(replace_rec(HIGH(r))); - res = - bdd_correctify( - LEVEL(replacepair[LEVEL(r)]), - READREF(2), - READREF(1)); + if (ZDD) + res = + zdd_correctify( + LEVEL(replacepair[LEVEL(r)]), + READREF(2), + READREF(1)); + else + res = + bdd_correctify( + LEVEL(replacepair[LEVEL(r)]), + READREF(2), + READREF(1)); POPREF(2); entry.a = r; @@ -1296,6 +1283,36 @@ return res; /* FIXME: cache ? */ } + int zdd_correctify(int level, int l, int r) { + // TODO: This function is wrong. Need to figure out how to do replace in ZDD. + int res; + + if (level < LEVEL(l) && level < LEVEL(r)) + return zdd_makenode(level, l, r); + + if (level == LEVEL(l) || level == LEVEL(r)) { + bdd_error(BDD_REPLACE); + return 0; + } + + if (LEVEL(l) == LEVEL(r)) { + PUSHREF(zdd_correctify(level, LOW(l), LOW(r))); + PUSHREF(zdd_correctify(level, HIGH(l), HIGH(r))); + res = zdd_makenode(LEVEL(l), READREF(2), READREF(1)); + } else if (LEVEL(l) < LEVEL(r)) { + PUSHREF(zdd_correctify(level, LOW(l), r)); + PUSHREF(zdd_correctify(level, HIGH(l), r)); + res = zdd_makenode(LEVEL(l), READREF(2), READREF(1)); + } else { + PUSHREF(zdd_correctify(level, l, LOW(r))); + PUSHREF(zdd_correctify(level, l, HIGH(r))); + res = zdd_makenode(LEVEL(r), READREF(2), READREF(1)); + } + POPREF(2); + + return res; /* FIXME: cache ? */ + } + int bdd_apply(int l, int r, int op) { int res; int numReorder = 1; @@ -1483,7 +1500,7 @@ PUSHREF(zand_rec(LOW(l), LOW(r))); PUSHREF(zand_rec(HIGH(l), HIGH(r))); - res = bdd_makenode(LEVEL(l), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(l), READREF(2), READREF(1)); POPREF(2); @@ -1547,8 +1564,8 @@ if (l == r) return l; - if (ISONE(l) || ISONE(r)) - return 1; + //if (ISONE(l) || ISONE(r)) + // return 1; if (ISZERO(l)) return r; if (ISZERO(r)) @@ -1566,15 +1583,15 @@ if (LEVEL(l) == LEVEL(r)) { PUSHREF(zor_rec(LOW(l), LOW(r))); PUSHREF(zor_rec(HIGH(l), HIGH(r))); - res = bdd_makenode(LEVEL(l), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(l), READREF(2), READREF(1)); POPREF(2); } else { if (LEVEL(l) < LEVEL(r)) { PUSHREF(zor_rec(LOW(l), r)); - res = bdd_makenode(LEVEL(l), READREF(1), HIGH(l)); + res = zdd_makenode(LEVEL(l), READREF(1), HIGH(l)); } else { PUSHREF(zor_rec(l, LOW(r))); - res = bdd_makenode(LEVEL(r), READREF(1), HIGH(r)); + res = zdd_makenode(LEVEL(r), READREF(1), HIGH(r)); } POPREF(1); } @@ -1591,16 +1608,16 @@ BddCacheDataI entry; int res; - if (ISZERO(l) || ISONE(r) || l == r) + if (ISZERO(l) /*|| ISONE(r)*/ || l == r) return 0; if (ISZERO(r)) return l; if (LEVEL(l) > LEVEL(r)) return zdiff_rec(l, LOW(r)); - entry = BddCache_lookupI(applycache, APPLYHASH(l, r, bddop_and)); + entry = BddCache_lookupI(applycache, APPLYHASH(l, r, bddop_diff)); - if (entry.a == l && entry.b == r && entry.c == bddop_and) { + if (entry.a == l && entry.b == r && entry.c == bddop_diff) { if (CACHESTATS) cachestats.opHit++; return entry.res; @@ -1611,11 +1628,11 @@ if (LEVEL(l) == LEVEL(r)) { PUSHREF(zdiff_rec(LOW(l), LOW(r))); PUSHREF(zdiff_rec(HIGH(l), HIGH(r))); - res = bdd_makenode(LEVEL(l), READREF(2), READREF(1)); + res = zdd_makenode(LEVEL(l), READREF(2), READREF(1)); POPREF(2); } else { PUSHREF(zdiff_rec(LOW(l), r)); - res = bdd_makenode(LEVEL(l), READREF(1), HIGH(l)); + res = zdd_makenode(LEVEL(l), READREF(1), HIGH(l)); POPREF(1); } @@ -2050,7 +2067,9 @@ default: res = apply_rec(r2, r1); break; } } else { - res = bdd_makenode(LEVEL(r), READREF(2), READREF(1)); + res = ZDD + ? zdd_makenode(LEVEL(r), READREF(2), READREF(1)) + : bdd_makenode(LEVEL(r), READREF(2), READREF(1)); } POPREF(2); @@ -3207,22 +3226,36 @@ } int bdd_makenode(int level, int low, int high) { - int hash2; - int res; + if (VERIFY_ASSERTIONS) _assert(!ZDD); + + if (CACHESTATS) + cachestats.uniqueAccess++; + // check whether children are equal + if (low == high) + return low; + + return makenode(level, low, high); + } + + int zdd_makenode(int level, int low, int high) { + if (VERIFY_ASSERTIONS) _assert(ZDD); + if (CACHESTATS) cachestats.uniqueAccess++; + + // check whether high child is zero + if (high == 0) + return low; + + return makenode(level, low, high); + } + + // Don't call directly - call bdd_makenode or zdd_makenode instead. + private int makenode(int level, int low, int high) { + int hash2; + int res; - if (ZDD) { - /* check whether high child is zero */ - if (high == 0) - return low; - } else { - /* check whether childs are equal */ - if (low == high) - return low; - } - /* Try to find an existing node of this kind */ hash2 = NODEHASH(level, low, high); res = HASH(hash2); @@ -3715,6 +3748,7 @@ bdd_error(BDD_VAR); bdd_delref(pair.result[bddvar2level[oldvar]]); + // TODO: revisit for zdd pair.result[bddvar2level[oldvar]] = bdd_ithvar(newvar); pair.id = update_pairsid(); @@ -3748,6 +3782,7 @@ void bdd_resetpair(bddPair p) { int n; + // TODO: revisit for zdd for (n = 0; n < bddvarnum; n++) p.result[n] = bdd_ithvar(bddlevel2var[n]); p.last = 0; @@ -3826,6 +3861,7 @@ System.arraycopy(p.result, 0, new_result, 0, oldsize); p.result = new_result; + // TODO: revisit for zdd for (n = oldsize; n < newsize; n++) p.result[n] = bdd_ithvar(bddlevel2var[n]); } @@ -4757,16 +4793,36 @@ bddrefstack = new int[num * 2 + 1]; bddrefstacktop = 0; + if (ZDD) + bddvarnum = 0; // need to recreate all of them for ZDD + + univ = 1; for (bdv = bddvarnum; bddvarnum < num; bddvarnum++) { - bddvarset[bddvarnum * 2] = PUSHREF(bdd_makenode(bddvarnum, 0, 1)); - bddvarset[bddvarnum * 2 + 1] = bdd_makenode(bddvarnum, 1, 0); - POPREF(1); + if (ZDD) { + int res = 1, res_not = 1; + for (int k = num-1; k >= 0; --k) { + PUSHREF(res); + PUSHREF(res_not); + PUSHREF(univ); + res = zdd_makenode(k, (k == bddvarnum)?0:res, res); + res_not = (k == bddvarnum) ? res_not : zdd_makenode(k, res_not, res_not); + if (bdv == bddvarnum) univ = zdd_makenode(k, univ, univ); + POPREF(3); + } + bddvarset[bddvarnum * 2] = res; + bddvarset[bddvarnum * 2 + 1] = res_not; + SETMAXREF(univ); + } else { + bddvarset[bddvarnum * 2] = PUSHREF(bdd_makenode(bddvarnum, 0, 1)); + bddvarset[bddvarnum * 2 + 1] = bdd_makenode(bddvarnum, 1, 0); + POPREF(1); + } if (bdderrorcond != 0) { bddvarnum = bdv; return -bdderrorcond; } - + SETMAXREF(bddvarset[bddvarnum * 2]); SETMAXREF(bddvarset[bddvarnum * 2 + 1]); bddlevel2var[bddvarnum] = bddvarnum; @@ -5717,6 +5773,7 @@ int next; } + // TODO: revisit for zdd int bdd_loaddata(BufferedReader ifile, int[] translate) throws IOException { int key, var, low, high, root = 0, n; Modified: trunk/JavaBDD/net/sf/javabdd/MicroFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/MicroFactory.java 2006-07-26 16:42:39 UTC (rev 464) +++ trunk/JavaBDD/net/sf/javabdd/MicroFactory.java 2006-07-26 16:42:44 UTC (rev 465) @@ -149,6 +149,7 @@ protected int ithVar_impl(int var) { return bdd_ithvar(var); } protected int nithVar_impl(int var) { return bdd_nithvar(var); } + protected int makenode_impl(int lev, int lo, int hi) { return bdd_makenode(lev, lo, hi); } protected int ite_impl(int v1, int v2, int v3) { return bdd_ite(v1, v2, v3); } protected int apply_impl(int v1, int v2, BDDOp opr) { return bdd_apply(v1, v2, opr.id); } protected int not_impl(int v1) { return bdd_not(v1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <joe...@us...> - 2006-07-21 16:55:31
|
Revision: 463 Author: joewhaley Date: 2006-07-21 09:55:23 -0700 (Fri, 21 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=463&view=rev Log Message: ----------- Update BuDDyFactory to also use common superclass BDDFactoryIntImpl. Modified Paths: -------------- trunk/JavaBDD/Makefile trunk/JavaBDD/buddy_jni.c trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java trunk/JavaBDD/net/sf/javabdd/JDDFactory.java trunk/JavaBDD/net/sf/javabdd/JFactory.java trunk/JavaBDD/net/sf/javabdd/MicroFactory.java Modified: trunk/JavaBDD/Makefile =================================================================== --- trunk/JavaBDD/Makefile 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/Makefile 2006-07-21 16:55:23 UTC (rev 463) @@ -141,8 +141,7 @@ CUDD_CLASSFILE = net/sf/javabdd/CUDDFactory.class CAL_CLASSFILE = net/sf/javabdd/CALFactory.class BUDDY_CLASSNAMES = net.sf.javabdd.BuDDyFactory \ - net.sf.javabdd.BuDDyFactory\$$BuDDyBDD \ - net.sf.javabdd.BuDDyFactory\$$BuDDyBDDPairing + net.sf.javabdd.BuDDyFactory\$$BuDDyPairing CUDD_CLASSNAMES = net.sf.javabdd.CUDDFactory \ net.sf.javabdd.CUDDFactory\$$CUDDBDD \ net.sf.javabdd.CUDDFactory\$$CUDDBDDPairing Modified: trunk/JavaBDD/buddy_jni.c =================================================================== --- trunk/JavaBDD/buddy_jni.c 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/buddy_jni.c 2006-07-21 16:55:23 UTC (rev 463) @@ -984,10 +984,10 @@ /* * Class: net_sf_javabdd_BuDDyFactory - * Method: nodeCount0 + * Method: nodeCount1 * Signature: ([I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_nodeCount0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_nodeCount1 (JNIEnv *env, jclass cl, jintArray arr) { jint *a; @@ -1116,11 +1116,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: var0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_var0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_var0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1134,11 +1134,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: high0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_high0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_high0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1152,11 +1152,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: low0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_low0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_low0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1169,11 +1169,11 @@ return result;} /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: not0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_not0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_not0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1187,11 +1187,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: ite0 * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_ite0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_ite0 (JNIEnv *env, jclass cl, jint b, jint c, jint d) { int result; @@ -1205,11 +1205,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: relprod0 * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_relprod0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_relprod0 (JNIEnv *env, jclass cl, jint b, jint c, jint d) { int result; @@ -1223,11 +1223,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: compose0 * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_compose0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_compose0 (JNIEnv *env, jclass cl, jint b, jint c, jint v) { int result; @@ -1241,11 +1241,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: constrain0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_constrain0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_constrain0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1259,11 +1259,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: exist0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_exist0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_exist0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1277,11 +1277,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: forAll0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_forAll0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_forAll0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1295,11 +1295,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: unique0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_unique0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_unique0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1313,11 +1313,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: restrict0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_restrict0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_restrict0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1331,11 +1331,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: simplify0 * Signature: (II)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_simplify0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_simplify0 (JNIEnv *env, jclass cl, jint b, jint c) { int result; @@ -1349,11 +1349,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: support0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_support0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_support0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1367,11 +1367,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: apply0 * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_apply0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_apply0 (JNIEnv *env, jclass cl, jint b, jint c, jint operation) { int result; @@ -1385,11 +1385,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: applyAll0 * Signature: (IIII)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_applyAll0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_applyAll0 (JNIEnv *env, jclass cl, jint b, jint c, jint operation, jint d) { int result; @@ -1403,11 +1403,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: applyEx0 * Signature: (IIII)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_applyEx0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_applyEx0 (JNIEnv *env, jclass cl, jint b, jint c, jint operation, jint d) { int result; @@ -1421,11 +1421,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: applyUni0 * Signature: (IIII)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_applyUni0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_applyUni0 (JNIEnv *env, jclass cl, jint b, jint c, jint operation, jint d) { int result; @@ -1439,11 +1439,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: satOne0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_satOne0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_satOne0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1457,11 +1457,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: fullSatOne0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_fullSatOne0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_fullSatOne0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1475,11 +1475,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: satOne1 * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_satOne1 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_satOne1 (JNIEnv *env, jclass cl, jint b, jint c, jint d) { int result; @@ -1493,11 +1493,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: printSet0 * Signature: (I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_printSet0 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_printSet0 (JNIEnv *env, jclass cl, jint b) { jnienv = env; @@ -1510,11 +1510,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: printDot0 * Signature: (I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_printDot0 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_printDot0 (JNIEnv *env, jclass cl, jint b) { jnienv = env; @@ -1527,11 +1527,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: nodeCount0 * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_nodeCount0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_nodeCount0 (JNIEnv *env, jclass cl, jint b) { int result; @@ -1545,11 +1545,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: pathCount0 * Signature: (I)D */ -JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_pathCount0 +JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_pathCount0 (JNIEnv *env, jclass cl, jint b) { double result; @@ -1563,11 +1563,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: satCount0 * Signature: (I)D */ -JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_satCount0 +JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_satCount0 (JNIEnv *env, jclass cl, jint b) { double result; @@ -1581,11 +1581,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: satCount1 * Signature: (II)D */ -JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_satCount1 +JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_satCount1 (JNIEnv *env, jclass cl, jint b, jint c) { double result; @@ -1599,11 +1599,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: logSatCount0 * Signature: (I)D */ -JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_logSatCount0 +JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_logSatCount0 (JNIEnv *env, jclass cl, jint b) { double result; @@ -1617,11 +1617,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: logSatCount1 * Signature: (II)D */ -JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_logSatCount1 +JNIEXPORT jdouble JNICALL Java_net_sf_javabdd_BuDDyFactory_logSatCount1 (JNIEnv *env, jclass cl, jint b, jint c) { double result; @@ -1635,11 +1635,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: varProfile0 * Signature: (I)[I */ -JNIEXPORT jintArray JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_varProfile0 +JNIEXPORT jintArray JNICALL Java_net_sf_javabdd_BuDDyFactory_varProfile0 (JNIEnv *env, jclass cl, jint b) { jintArray result; @@ -1664,11 +1664,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: addRef * Signature: (I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_addRef +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_addRef (JNIEnv *env, jclass cl, jint b) { jnienv = env; @@ -1680,11 +1680,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDD + * Class: net_sf_javabdd_BuDDyFactory * Method: delRef * Signature: (I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_delRef +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_delRef (JNIEnv *env, jclass cl, jint b) { jnienv = env; @@ -1702,7 +1702,7 @@ * Method: veccompose0 * Signature: (IJ)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_veccompose0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_veccompose0 (JNIEnv *env, jclass cl, jint b, jlong pair) { int result; @@ -1722,7 +1722,7 @@ * Method: replace0 * Signature: (IJ)I */ -JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDD_replace0 +JNIEXPORT jint JNICALL Java_net_sf_javabdd_BuDDyFactory_replace0 (JNIEnv *env, jclass cl, jint b, jlong pair) { int result; @@ -1737,14 +1737,14 @@ return result; } -/* class net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing */ +/* class net_sf_javabdd_BuDDyFactory_BuDDyPairing */ /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: set0 * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_set0 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_set0 (JNIEnv *env, jclass cl, jlong pair, jint i, jint j) { bddPair* p; @@ -1758,11 +1758,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: set1 * Signature: (J[I[I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_set1 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_set1 (JNIEnv *env, jclass cl, jlong pair, jintArray arr1, jintArray arr2) { jint size1, size2; @@ -1795,11 +1795,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: set2 * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_set2 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_set2 (JNIEnv *env, jclass cl, jlong pair, jint b, jint c) { bddPair* p; @@ -1813,11 +1813,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: set3 * Signature: (J[I[I)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_set3 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_set3 (JNIEnv *env, jclass cl, jlong pair, jintArray arr1, jintArray arr2) { jint size1, size2; @@ -1850,11 +1850,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: reset0 * Signature: (J)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_reset0 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_reset0 (JNIEnv *env, jclass cl, jlong pair) { bddPair* p; @@ -1868,11 +1868,11 @@ } /* - * Class: net_sf_javabdd_BuDDyFactory_BuDDyBDDPairing + * Class: net_sf_javabdd_BuDDyFactory_BuDDyPairing * Method: free0 * Signature: (J)V */ -JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyBDDPairing_free0 +JNIEXPORT void JNICALL Java_net_sf_javabdd_BuDDyFactory_00024BuDDyPairing_free0 (JNIEnv *env, jclass cl, jlong pair) { bddPair* p; Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-21 16:55:23 UTC (rev 463) @@ -399,6 +399,19 @@ return makeBDD(zero_impl()); } + public void done() { + if (USE_FINALIZER) { + System.gc(); + System.runFinalization(); + handleDeferredFree(); + } + } + + protected void finalize() throws Throwable { + super.finalize(); + this.done(); + } + protected /*bdd*/int[] to_free = new /*bdd*/int[8]; protected /*bdd*/int to_free_length = 0; public void deferredFree(int v) { Modified: trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/net/sf/javabdd/BuDDyFactory.java 2006-07-21 16:55:23 UTC (rev 463) @@ -4,9 +4,6 @@ package net.sf.javabdd; import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -26,8 +23,8 @@ * you are _completely_ sure that all BDD objects that reference the old * factory have been freed.</p> * - * <p>If you really need multiple BDD factories, consider using the JavaFactory - * class for the additional BDD factories --- JavaFactory can have multiple + * <p>If you really need multiple BDD factories, consider using the JFactory + * class for the additional BDD factories --- JFactory can have multiple * factory instances active at a time.</p> * * @see net.sf.javabdd.BDDFactory @@ -35,14 +32,10 @@ * @author John Whaley * @version $Id$ */ -public class BuDDyFactory extends BDDFactory { +public class BuDDyFactory extends BDDFactoryIntImpl { public static BDDFactory init(int nodenum, int cachesize) { - BuDDyFactory f; - if (USE_FINALIZER) - f = new BuDDyFactoryWithFinalizer(); - else - f = new BuDDyFactory(); + BuDDyFactory f = new BuDDyFactory(); f.initialize(nodenum, cachesize); return f; } @@ -98,93 +91,128 @@ private BuDDyFactory() {} - private static final boolean USE_FINALIZER = false; + /** An invalid id, for use in invalidating BDDs. */ + static final int INVALID_BDD = -1; - private static class BuDDyFactoryWithFinalizer extends BuDDyFactory { - - /** - * @see java.lang.Object#finalize() - */ - protected void finalize() throws Throwable { - super.finalize(); - this.done(); - } - - } + // Redirection functions. - private static BuDDyBDD makeBDD(int id) { - BuDDyBDD b; - if (USE_FINALIZER) { - b = new BuDDyBDDWithFinalizer(id); - if (false) { // can check for specific id's here. - System.out.println("Created "+System.identityHashCode(b)+" id "+id); - new Exception().printStackTrace(System.out); - } - } else { - b = new BuDDyBDD(id); - } - return b; - } + protected void addref_impl(int v) { addRef(v); } + private static native void addRef(int b); + protected void delref_impl(int v) { delRef(v); } + private static native void delRef(int b); + protected int zero_impl() { return 0; } + protected int one_impl() { return 1; } + protected int invalid_bdd_impl() { return INVALID_BDD; } + protected int var_impl(int v) { return var0(v); } + private static native int var0(int b); + protected int level_impl(int v) { return var2Level0(var0(v)); } + protected int low_impl(int v) { return low0(v); } + private static native int low0(int b); + protected int high_impl(int v) { return high0(v); } + private static native int high0(int b); + protected int ithVar_impl(int var) { return ithVar0(var); } + private static native int ithVar0(int var); + protected int nithVar_impl(int var) { return nithVar0(var); } + private static native int nithVar0(int var); - private static BDDVarSet.DefaultImpl makeBDDVarSet(int id) { - return new BDDVarSet.DefaultImpl(makeBDD(id)); - } + protected int ite_impl(int v1, int v2, int v3) { return ite0(v1, v2, v3); } + private static native int ite0(int b, int c, int d); + protected int apply_impl(int v1, int v2, BDDOp opr) { return apply0(v1, v2, opr.id); } + private static native int apply0(int b, int c, int opr); + protected int not_impl(int v1) { return not0(v1); } + private static native int not0(int b); + protected int applyAll_impl(int v1, int v2, BDDOp opr, int v3) { return applyAll0(v1, v2, opr.id, v3); } + private static native int applyAll0(int b, int c, int opr, int d); + protected int applyEx_impl(int v1, int v2, BDDOp opr, int v3) { return applyEx0(v1, v2, opr.id, v3); } + private static native int applyEx0(int b, int c, int opr, int d); + protected int applyUni_impl(int v1, int v2, BDDOp opr, int v3) { return applyUni0(v1, v2, opr.id, v3); } + private static native int applyUni0(int b, int c, int opr, int d); + protected int compose_impl(int v1, int v2, int var) { return compose0(v1, v2, var); } + private static native int compose0(int b, int c, int var); + protected int constrain_impl(int v1, int v2) { return constrain0(v1, v2); } + private static native int constrain0(int b, int c); + protected int restrict_impl(int v1, int v2) { return restrict0(v1, v2); } + private static native int restrict0(int b, int var); + protected int simplify_impl(int v1, int v2) { return simplify0(v1, v2); } + private static native int simplify0(int b, int d); + protected int support_impl(int v) { return support0(v); } + private static native int support0(int b); + protected int exist_impl(int v1, int v2) { return exist0(v1, v2); } + private static native int exist0(int b, int var); + protected int forAll_impl(int v1, int v2) { return forAll0(v1, v2); } + private static native int forAll0(int b, int var); + protected int unique_impl(int v1, int v2) { return unique0(v1, v2); } + private static native int unique0(int b, int var); + protected int fullSatOne_impl(int v) { return fullSatOne0(v); } + private static native int fullSatOne0(int b); - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#zero() - */ - public BDD zero() { return makeBDD(0); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#one() - */ - public BDD one() { return makeBDD(1); } + protected int replace_impl(int v, BDDPairing p) { return replace0(v, unwrap(p)); } + private static native int replace0(int b, long p); + protected int veccompose_impl(int v, BDDPairing p) { return veccompose0(v, unwrap(p)); } + private static native int veccompose0(int b, long p); - /** - * Converts collection of BuDDyBDD's into an int array, for passing to - * native code. - * - * @param c collection of BuDDyBDD's - * @return int array of indices - */ - private static int[] toBuDDyArray(Collection c) { - int[] a = new int[c.size()]; - int k = 0; - for (Iterator i = c.iterator(); k < a.length; ++k) { - BuDDyBDD b = (BuDDyBDD) i.next(); - a[k] = b._id; - } - return a; - } + protected int nodeCount_impl(int v) { return nodeCount0(v); } + private static native int nodeCount0(int b); + protected double pathCount_impl(int v) { return pathCount0(v); } + private static native double pathCount0(int b); + protected double satCount_impl(int v) { return satCount0(v); } + private static native double satCount0(int b); + protected int satOne_impl(int v) { return satOne0(v); } + private static native int satOne0(int b); + protected int satOne_impl2(int v1, int v2, boolean pol) { return satOne1(v1, v2, pol?1:0); } + private static native int satOne1(int b, int c, int d); + protected int nodeCount_impl2(int[] v) { return nodeCount1(v); } + private static native int nodeCount1(int[] a); + protected int[] varProfile_impl(int v) { return varProfile0(v); } + private static native int[] varProfile0(int b); + protected void printTable_impl(int v) { printTable0(v); } + private static native void printTable0(int b); - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#buildCube(int, java.util.List) - */ - public BDD buildCube(int value, List var) { - int[] a = toBuDDyArray(var); - int id = buildCube0(value, a); - return makeBDD(id); - } - private static native int buildCube0(int value, int[] var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#buildCube(int, int[]) - */ - public BDD buildCube(int value, int[] var) { - int id = buildCube1(value, var); - return makeBDD(id); - } - private static native int buildCube1(int value, int[] var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#makeSet(int[]) - */ - public BDDVarSet makeSet(int[] v) { - int id = makeSet0(v); - return makeBDDVarSet(id); - } - private static native int makeSet0(int[] var); + // More redirection functions. + public void addVarBlock(int first, int last, boolean fixed) { addVarBlock1(first, last, fixed); } + private static native void addVarBlock1(int first, int last, boolean fixed); + public void varBlockAll() { varBlockAll0(); } + private static native void varBlockAll0(); + public void clearVarBlocks() { clearVarBlocks0(); } + private static native void clearVarBlocks0(); + public void printOrder() { printOrder0(); } + private static native void printOrder0(); + public int getNodeTableSize() { return getAllocNum0(); } + private static native int getAllocNum0(); + public int getNodeNum() { return getNodeNum0(); } + private static native int getNodeNum0(); + public int getCacheSize() { return getCacheSize0(); } + private static native int getCacheSize0(); + public int reorderGain() { return reorderGain0(); } + private static native int reorderGain0(); + public void printStat() { printStat0(); } + private static native void printStat0(); + public void printAll() { printAll0(); } + private static native void printAll0(); + public void setVarOrder(int[] neworder) { setVarOrder0(neworder); } + private static native void setVarOrder0(int[] neworder); + public int level2Var(int level) { return level2Var0(level); } + private static native int level2Var0(int level); + public int var2Level(int var) { return var2Level0(var); } + private static native int var2Level0(int var); + public int getReorderTimes() { return getReorderTimes0(); } + private static native int getReorderTimes0(); + public void disableReorder() { disableReorder0(); } + private static native void disableReorder0(); + public void enableReorder() { enableReorder0(); } + private static native void enableReorder0(); + public int reorderVerbose(int v) { return reorderVerbose0(v); } + private static native int reorderVerbose0(int v); + public void reorder(ReorderMethod m) { reorder0(m.id); } + private static native void reorder0(int method); + public void autoReorder(ReorderMethod method) { autoReorder0(method.id); } + private static native void autoReorder0(int method); + public void autoReorder(ReorderMethod method, int max) { autoReorder1(method.id, max); } + private static native void autoReorder1(int method, int max); + public void swapVar(int v1, int v2) { swapVar0(v1, v2); } + private static native void swapVar0(int v1, int v2); + /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#initialize(int, int) */ @@ -208,27 +236,13 @@ * @see net.sf.javabdd.BDDFactory#done() */ public void done() { - if (USE_FINALIZER) { - System.gc(); - System.runFinalization(); - } + super.done(); INSTANCE = null; done0(); } private static native void done0(); /* (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) */ public void setError(int code) { @@ -317,78 +331,19 @@ private static native int setVarNum0(int num); /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#duplicateVar(int) - */ - public int duplicateVar(int var) { - return duplicateVar0(var); - } - private static native int duplicateVar0(int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#extVarNum(int) - */ - public int extVarNum(int num) { - return extVarNum0(num); - } - private static native int extVarNum0(int num); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#ithVar(int) - */ - public BDD ithVar(int var) { - int id = ithVar0(var); - return makeBDD(id); - } - private static native int ithVar0(int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#nithVar(int) - */ - public BDD nithVar(int var) { - int id = nithVar0(var); - return makeBDD(id); - } - private static native int nithVar0(int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#swapVar(int, int) - */ - public void swapVar(int v1, int v2) { - swapVar0(v1, v2); - } - private static native void swapVar0(int v1, int v2); - - /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#makePair() */ public BDDPairing makePair() { long ptr = makePair0(); if (USE_FINALIZER) { - return new BuDDyBDDPairingWithFinalizer(ptr); + return new BuDDyPairingWithFinalizer(ptr); } else { - return new BuDDyBDDPairing(ptr); + return new BuDDyPairing(ptr); } } private static native long makePair0(); /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printAll() - */ - public void printAll() { - printAll0(); - } - private static native void printAll0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printTable(net.sf.javabdd.BDD) - */ - public void printTable(BDD b) { - BuDDyBDD bb = (BuDDyBDD) b; - printTable0(bb._id); - } - private static native void printTable0(int b); - - /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#load(java.lang.String) */ public BDD load(String filename) { @@ -401,52 +356,11 @@ * @see net.sf.javabdd.BDDFactory#save(java.lang.String, net.sf.javabdd.BDD) */ public void save(String filename, BDD b) { - BuDDyBDD bb = (BuDDyBDD) b; - save0(filename, bb._id); + save0(filename, unwrap(b)); } private static native void save0(String filename, int b); /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#level2Var(int) - */ - public int level2Var(int level) { - return level2Var0(level); - } - private static native int level2Var0(int level); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#var2Level(int) - */ - public int var2Level(int var) { - return var2Level0(var); - } - private static native int var2Level0(int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorder(net.sf.javabdd.BDDFactory.ReorderMethod) - */ - public void reorder(BDDFactory.ReorderMethod method) { - reorder0(method.id); - } - private static native void reorder0(int method); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod) - */ - public void autoReorder(BDDFactory.ReorderMethod method) { - autoReorder0(method.id); - } - private static native void autoReorder0(int method); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod, int) - */ - public void autoReorder(BDDFactory.ReorderMethod method, int max) { - autoReorder1(method.id, max); - } - private static native void autoReorder1(int method, int max); - - /* (non-Javadoc) * @see net.sf.javabdd.BDDFactory#getReorderMethod() */ public BDDFactory.ReorderMethod getReorderMethod() { @@ -465,595 +379,18 @@ } private static native int getReorderMethod0(); - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getReorderTimes() - */ - public int getReorderTimes() { - return getReorderTimes0(); + static long unwrap(BDDPairing p) { + return ((BuDDyPairing)p)._ptr; } - private static native int getReorderTimes0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#disableReorder() - */ - public void disableReorder() { - disableReorder0(); - } - private static native void disableReorder0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#enableReorder() - */ - public void enableReorder() { - enableReorder0(); - } - private static native void enableReorder0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorderVerbose(int) - */ - public int reorderVerbose(int v) { - return reorderVerbose0(v); - } - private static native int reorderVerbose0(int v); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setVarOrder(int[]) - */ - public void setVarOrder(int[] neworder) { - setVarOrder0(neworder); - } - private static native void setVarOrder0(int[] neworder); /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#addVarBlock(net.sf.javabdd.BDD, boolean) - */ - public void addVarBlock(BDD var, boolean fixed) { - BuDDyBDD bb = (BuDDyBDD) var; - addVarBlock0(bb._id, fixed); - } - private static native void addVarBlock0(int var, boolean fixed); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#addVarBlock(int, int, boolean) - */ - public void addVarBlock(int first, int last, boolean fixed) { - addVarBlock1(first, last, fixed); - } - private static native void addVarBlock1(int first, int last, boolean fixed); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#varBlockAll() - */ - public void varBlockAll() { - varBlockAll0(); - } - private static native void varBlockAll0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#clearVarBlocks() - */ - public void clearVarBlocks() { - clearVarBlocks0(); - } - private static native void clearVarBlocks0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printOrder() - */ - public void printOrder() { - printOrder0(); - } - private static native void printOrder0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#nodeCount(java.util.Collection) - */ - public int nodeCount(Collection r) { - int[] a = toBuDDyArray(r); - return nodeCount0(a); - } - private static native int nodeCount0(int[] a); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getNodeTableSize() - */ - public int getNodeTableSize() { - return getAllocNum0(); - } - private static native int getAllocNum0(); - - /* (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() - */ - public int getNodeNum() { - return getNodeNum0(); - } - private static native int getNodeNum0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorderGain() - */ - public int reorderGain() { - return reorderGain0(); - } - private static native int reorderGain0(); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printStat() - */ - public void printStat() { - printStat0(); - } - private static native void printStat0(); - - /* (non-Javadoc) - * An implementation of a BDD class, used by the BuDDy interface. - */ - private static class BuDDyBDD extends BDD { - - /** The value used by the BDD library. */ - protected int _id; - - /** An invalid id, for use in invalidating BDDs. */ - static final int INVALID_BDD = -1; - - protected BuDDyBDD(int id) { - _id = id; - addRef(_id); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#getFactory() - */ - public BDDFactory getFactory() { - return INSTANCE; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#isZero() - */ - public boolean isZero() { - return _id == 0; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#isOne() - */ - public boolean isOne() { - return _id == 1; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#var() - */ - public int var() { - return var0(_id); - } - private static native int var0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#high() - */ - public BDD high() { - int b = high0(_id); - return makeBDD(b); - } - private static native int high0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#low() - */ - public BDD low() { - int b = low0(_id); - return makeBDD(b); - } - private static native int low0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#id() - */ - public BDD id() { - return makeBDD(_id); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#not() - */ - public BDD not() { - int b = not0(_id); - return makeBDD(b); - } - private static native int not0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#ite(net.sf.javabdd.BDD, net.sf.javabdd.BDD) - */ - public BDD ite(BDD thenBDD, BDD elseBDD) { - BuDDyBDD c = (BuDDyBDD) thenBDD; - BuDDyBDD d = (BuDDyBDD) elseBDD; - int b = ite0(_id, c._id, d._id); - return makeBDD(b); - } - private static native int ite0(int b, int c, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#relprod(net.sf.javabdd.BDD, net.sf.javabdd.BDDVarSet) - */ - public BDD relprod(BDD that, BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) that; - BuDDyBDD d = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = relprod0(_id, c._id, d._id); - return makeBDD(b); - } - private static native int relprod0(int b, int c, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#compose(net.sf.javabdd.BDD, int) - */ - public BDD compose(BDD that, int var) { - BuDDyBDD c = (BuDDyBDD) that; - int b = compose0(_id, c._id, var); - return makeBDD(b); - } - private static native int compose0(int b, int c, int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#constrain(net.sf.javabdd.BDD) - */ - public BDD constrain(BDD that) { - BuDDyBDD c = (BuDDyBDD) that; - int b = constrain0(_id, c._id); - return makeBDD(b); - } - private static native int constrain0(int b, int c); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#exist(net.sf.javabdd.BDDVarSet) - */ - public BDD exist(BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = exist0(_id, c._id); - return makeBDD(b); - } - private static native int exist0(int b, int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#forAll(net.sf.javabdd.BDDVarSet) - */ - public BDD forAll(BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = forAll0(_id, c._id); - return makeBDD(b); - } - private static native int forAll0(int b, int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#unique(net.sf.javabdd.BDDVarSet) - */ - public BDD unique(BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = unique0(_id, c._id); - return makeBDD(b); - } - private static native int unique0(int b, int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#restrict(net.sf.javabdd.BDD) - */ - public BDD restrict(BDD var) { - BuDDyBDD c = (BuDDyBDD) var; - int b = restrict0(_id, c._id); - return makeBDD(b); - } - private static native int restrict0(int b, int var); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#restrictWith(net.sf.javabdd.BDD) - */ - public BDD restrictWith(BDD var) { - BuDDyBDD c = (BuDDyBDD) var; - int b = restrict0(_id, c._id); - addRef(b); - delRef(_id); - if (this != c) { - delRef(c._id); - c._id = INVALID_BDD; - } - _id = b; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet) - */ - public BDD simplify(BDDVarSet d) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) d).b; - int b = simplify0(_id, c._id); - return makeBDD(b); - } - private static native int simplify0(int b, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#support() - */ - public BDDVarSet support() { - int b = support0(_id); - return makeBDDVarSet(b); - } - private static native int support0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#apply(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp) - */ - public BDD apply(BDD that, BDDFactory.BDDOp opr) { - BuDDyBDD c = (BuDDyBDD) that; - int b = apply0(_id, c._id, opr.id); - return makeBDD(b); - } - private static native int apply0(int b, int c, int opr); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyWith(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp) - */ - public BDD applyWith(BDD that, BDDFactory.BDDOp opr) { - BuDDyBDD c = (BuDDyBDD) that; - int b = apply0(_id, c._id, opr.id); - addRef(b); - delRef(_id); - if (this != c) { - delRef(c._id); - c._id = INVALID_BDD; - } - _id = b; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyAll(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyAll(BDD that, BDDFactory.BDDOp opr, BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) that; - BuDDyBDD d = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = applyAll0(_id, c._id, opr.id, d._id); - return makeBDD(b); - } - private static native int applyAll0(int b, int c, int opr, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyEx(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyEx(BDD that, BDDFactory.BDDOp opr, BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) that; - BuDDyBDD d = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = applyEx0(_id, c._id, opr.id, d._id); - return makeBDD(b); - } - private static native int applyEx0(int b, int c, int opr, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyUni(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyUni(BDD that, BDDFactory.BDDOp opr, BDDVarSet var) { - BuDDyBDD c = (BuDDyBDD) that; - BuDDyBDD d = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = applyUni0(_id, c._id, opr.id, d._id); - return makeBDD(b); - } - private static native int applyUni0(int b, int c, int opr, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satOne() - */ - public BDD satOne() { - int b = satOne0(_id); - return makeBDD(b); - } - private static native int satOne0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#fullSatOne() - */ - public BDD fullSatOne() { - int b = fullSatOne0(_id); - return makeBDD(b); - } - private static native int fullSatOne0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satOne(net.sf.javabdd.BDDVarSet, boolean) - */ - public BDD satOne(BDDVarSet var, boolean pol) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) var).b; - int b = satOne1(_id, c._id, pol?1:0); - return makeBDD(b); - } - private static native int satOne1(int b, int c, int d); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#printSet() - */ - public void printSet() { - printSet0(_id); - } - private static native void printSet0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#printDot() - */ - public void printDot() { - printDot0(_id); - } - private static native void printDot0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#nodeCount() - */ - public int nodeCount() { - return nodeCount0(_id); - } - private static native int nodeCount0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#pathCount() - */ - public double pathCount() { - return pathCount0(_id); - } - private static native double pathCount0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satCount() - */ - public double satCount() { - return satCount0(_id); - } - private static native double satCount0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satCount(net.sf.javabdd.BDDVarSet) - */ - public double satCount(BDDVarSet varset) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) varset).b; - return satCount1(_id, c._id); - } - private static native double satCount1(int b, int c); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#logSatCount() - */ - public double logSatCount() { - return logSatCount0(_id); - } - private static native double logSatCount0(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#logSatCount(net.sf.javabdd.BDDVarSet) - */ - public double logSatCount(BDDVarSet varset) { - BuDDyBDD c = (BuDDyBDD) ((BDDVarSet.DefaultImpl) varset).b; - return logSatCount1(_id, c._id); - } - private static native double logSatCount1(int b, int c); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#varProfile() - */ - public int[] varProfile() { - return varProfile0(_id); - } - private static native int[] varProfile0(int b); - - private static native void addRef(int b); - - private static native void delRef(int b); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#free() - */ - public void free() { - if (INSTANCE != null) { - delRef(_id); - } - _id = INVALID_BDD; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#veccompose(net.sf.javabdd.BDDPairing) - */ - public BDD veccompose(BDDPairing pair) { - BuDDyBDDPairing p = (BuDDyBDDPairing) pair; - int b = veccompose0(_id, p._ptr); - return makeBDD(b); - } - private static native int veccompose0(int b, long p); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#replace(net.sf.javabdd.BDDPairing) - */ - public BDD replace(BDDPairing pair) { - BuDDyBDDPairing p = (BuDDyBDDPairing) pair; - int b = replace0(_id, p._ptr); - return makeBDD(b); - } - private static native int replace0(int b, long p); - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#replaceWith(net.sf.javabdd.BDDPairing) - */ - public BDD replaceWith(BDDPairing pair) { - BuDDyBDDPairing p = (BuDDyBDDPairing) pair; - int b = replace0(_id, p._ptr); - addRef(b); - delRef(_id); - _id = b; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#equals(net.sf.javabdd.BDD) - */ - public boolean equals(BDD that) { - return this._id == ((BuDDyBDD) that)._id; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#hashCode() - */ - public int hashCode() { - return this._id; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#toVarSet() - */ - public BDDVarSet toVarSet() { - return makeBDDVarSet(this._id); - } - - } - - private static class BuDDyBDDWithFinalizer extends BuDDyBDD { - - protected BuDDyBDDWithFinalizer(int id) { - super(id); - } - - /* Finalizer runs in different thread, and BuDDy is not thread-safe. - * Also, the existence of any finalize() method hurts performance - * considerably. - */ - /* (non-Javadoc) - * @see java.lang.Object#finalize() - */ - protected void finalize() throws Throwable { - super.finalize(); - if (_id >= 0) { - System.out.println("BDD not freed! "+System.identityHashCode(this)+" _id "+_id+" nodes: "+nodeCount()); - } - //this.free(); - } - static { - //System.runFinalizersOnExit(true); - } - } - - /* (non-Javadoc) * An implementation of a BDDPairing, used by the BuDDy interface. */ - private static class BuDDyBDDPairing extends BDDPairing { + private static class BuDDyPairing extends BDDPairing { private long _ptr; - private BuDDyBDDPairing(long ptr) { + private BuDDyPairing(long ptr) { this._ptr = ptr; } @@ -1077,8 +414,7 @@ * @see net.sf.javabdd.BDDPairing#set(int, net.sf.javabdd.BDD) */ public void set(int oldvar, BDD newvar) { - BuDDyBDD c = (BuDDyBDD) newvar; - set2(_ptr, oldvar, c._id); + set2(_ptr, oldvar, unwrap(newvar)); } private static native void set2(long p, int oldvar, int newbdd); @@ -1086,8 +422,7 @@ * @see net.sf.javabdd.BDDPairing#set(int[], net.sf.javabdd.BDD[]) */ public void set(int[] oldvar, BDD[] newvar) { - int[] a = toBuDDyArray(Arrays.asList(newvar)); - set3(_ptr, oldvar, a); + set3(_ptr, oldvar, unwrap(Arrays.asList(newvar))); } private static native void set3(long p, int[] oldvar, int[] newbdds); @@ -1110,9 +445,9 @@ } - private static class BuDDyBDDPairingWithFinalizer extends BuDDyBDDPairing { + private static class BuDDyPairingWithFinalizer extends BuDDyPairing { - private BuDDyBDDPairingWithFinalizer(long ptr) { + private BuDDyPairingWithFinalizer(long ptr) { super(ptr); } Modified: trunk/JavaBDD/net/sf/javabdd/JDDFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-21 16:55:23 UTC (rev 463) @@ -208,7 +208,7 @@ return 0; } public boolean isInitialized() { return true; } - public void done() { bdd.cleanup(); bdd = null; } + public void done() { super.done(); bdd.cleanup(); bdd = null; } public void setError(int code) { // todo: implement this } Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-21 16:55:23 UTC (rev 463) @@ -188,7 +188,7 @@ public int setCacheSize(int v) { return bdd_setcachesize(v); } public boolean isZDD() { return ZDD; } public boolean isInitialized() { return bddrunning; } - public void done() { bdd_done(); } + public void done() { super.done(); bdd_done(); } public void setError(int code) { bdderrorcond = code; } public void clearError() { bdderrorcond = 0; } public int setMaxNodeNum(int size) { return bdd_setmaxnodenum(size); } @@ -3075,6 +3075,9 @@ gbc_handler(true, gcstats); } + // Handle nodes that were marked as free by finalizer. + handleDeferredFree(); + for (r = 0; r < bddrefstacktop; r++) bdd_mark(bddrefstack[r]); Modified: trunk/JavaBDD/net/sf/javabdd/MicroFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/MicroFactory.java 2006-07-21 14:32:13 UTC (rev 462) +++ trunk/JavaBDD/net/sf/javabdd/MicroFactory.java 2006-07-21 16:55:23 UTC (rev 463) @@ -188,7 +188,7 @@ public int setNodeTableSize(int size) { return bdd_setallocnum(size); } public int setCacheSize(int v) { return bdd_setcachesize(v); } public boolean isInitialized() { return bddrunning; } - public void done() { bdd_done(); } + public void done() { super.done(); bdd_done(); } public void setError(int code) { bdderrorcond = code; } public void clearError() { bdderrorcond = 0; } public int setMaxNodeNum(int size) { return bdd_setmaxnodenum(size); } @@ -3217,6 +3217,9 @@ gcstats.num = gbcollectnum; gbc_handler(true, gcstats); + // Handle nodes that were marked as free by finalizer. + handleDeferredFree(); + for (r = 0; r < bddrefstacktop; r++) bdd_mark(bddrefstack[r]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <joe...@us...> - 2006-07-21 14:32:20
|
Revision: 462 Author: joewhaley Date: 2006-07-21 07:32:13 -0700 (Fri, 21 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=462&view=rev Log Message: ----------- Changed MicroFactory, JDDFactory to use new BDDFactoryIntImpl shared superclass. More bug fixes in the test cases. Now the test cases won't fail if a BDD library doesn't support a (nonessential) operation and throws UnsupportedOperationException. Modified Paths: -------------- trunk/JavaBDD_tests/bdd/BDDTestCase.java trunk/JavaBDD_tests/bdd/BasicTests.java trunk/JavaBDD_tests/bdd/CallbackTests.java trunk/JavaBDD_tests/bdd/IteratorTests.java trunk/JavaBDD_tests/highlevel/NQueensTest.java trunk/JavaBDD_tests/regression/R1.java trunk/JavaBDD_tests/regression/R2.java trunk/JavaBDD_tests/regression/R3.java Modified: trunk/JavaBDD_tests/bdd/BDDTestCase.java =================================================================== --- trunk/JavaBDD_tests/bdd/BDDTestCase.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/bdd/BDDTestCase.java 2006-07-21 14:32:13 UTC (rev 462) @@ -23,9 +23,9 @@ "net.sf.javabdd.JFactory", "net.sf.javabdd.BuDDyFactory", "net.sf.javabdd.MicroFactory", - "net.sf.javabdd.CUDDFactory", + //"net.sf.javabdd.CUDDFactory", //"net.sf.javabdd.CALFactory", - //"net.sf.javabdd.JDDFactory", + "net.sf.javabdd.JDDFactory", }; protected static Collection factories; Modified: trunk/JavaBDD_tests/bdd/BasicTests.java =================================================================== --- trunk/JavaBDD_tests/bdd/BasicTests.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/bdd/BasicTests.java 2006-07-21 14:32:13 UTC (rev 462) @@ -55,7 +55,9 @@ while (hasNext()) { BDDFactory bdd = nextFactory(); if (bdd.varNum() < 5) bdd.setVarNum(5); - bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + try { + bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + } catch (UnsupportedOperationException _) { } BDD a = bdd.ithVar(1); BDD b = bdd.ithVar(2); BDD c = bdd.ithVar(3); @@ -66,11 +68,11 @@ Assert.assertEquals(3, c.var()); try { d.var(); - Assert.fail(); + Assert.fail(bdd.getVersion()); } catch (BDDException x) { } try { e.var(); - Assert.fail(); + Assert.fail(bdd.getVersion()); } catch (BDDException x) { } BDD f = a.and(b); Assert.assertEquals(1, f.var()); @@ -84,7 +86,12 @@ while (hasNext()) { BDDFactory bdd = nextFactory(); if (bdd.varNum() < 5) bdd.setVarNum(5); - bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + try { + bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + } catch (UnsupportedOperationException _) { + System.err.println("Warning: "+bdd.getVersion()+" does not support setVarOrder()"); + continue; + } BDD a = bdd.ithVar(0); BDD b = bdd.ithVar(1); BDD c = bdd.ithVar(2); @@ -116,7 +123,9 @@ while (hasNext()) { BDDFactory bdd = nextFactory(); if (bdd.varNum() < 5) bdd.setVarNum(5); - bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + try { + bdd.setVarOrder(new int[] { 0, 1, 2, 3, 4 }); + } catch (UnsupportedOperationException _) { } BDD a, b, c; a = bdd.ithVar(0); a.andWith(bdd.ithVar(1)); @@ -124,6 +133,16 @@ Assert.assertEquals(0, a.var()); b = a.low(); Assert.assertEquals(true, b.isZero()); + try { + b.low(); + Assert.fail(); + } catch (BDDException _) { + } + try { + b.high(); + Assert.fail(); + } catch (BDDException _) { + } b.free(); b = a.high(); Assert.assertEquals(1, b.var()); @@ -132,6 +151,16 @@ Assert.assertEquals(2, c.var()); b = c.low(); Assert.assertEquals(true, b.isOne()); + try { + b.low(); + Assert.fail(); + } catch (BDDException _) { + } + try { + b.high(); + Assert.fail(); + } catch (BDDException _) { + } a.free(); b.free(); c.free(); } } @@ -318,7 +347,9 @@ while (hasNext()) { BDDFactory bdd = nextFactory(); // TODO: more tests - testApply(bdd, BDDFactory.less, false, true, false, false); + try { + testApply(bdd, BDDFactory.less, false, true, false, false); + } catch (UnsupportedOperationException _) { } } } @@ -328,7 +359,9 @@ while (hasNext()) { BDDFactory bdd = nextFactory(); // TODO: more tests - testApply(bdd, BDDFactory.invimp, true, false, true, true); + try { + testApply(bdd, BDDFactory.invimp, true, false, true, true); + } catch (UnsupportedOperationException _) { } } } @@ -362,12 +395,18 @@ testApplyWith(bdd, BDDFactory.or, false, true, true, true); testApplyWith(bdd, BDDFactory.xor, false, true, true, false); testApplyWith(bdd, BDDFactory.imp, true, true, false, true); - testApplyWith(bdd, BDDFactory.biimp, true, false, false, true); testApplyWith(bdd, BDDFactory.diff, false, false, true, false); - testApplyWith(bdd, BDDFactory.less, false, true, false, false); - testApplyWith(bdd, BDDFactory.invimp, true, false, true, true); testApplyWith(bdd, BDDFactory.nand, true, true, true, false); testApplyWith(bdd, BDDFactory.nor, true, false, false, false); + try { + testApplyWith(bdd, BDDFactory.biimp, true, false, false, true); + } catch (UnsupportedOperationException _) { } + try { + testApplyWith(bdd, BDDFactory.less, false, true, false, false); + } catch (UnsupportedOperationException _) { } + try { + testApplyWith(bdd, BDDFactory.invimp, true, false, true, true); + } catch (UnsupportedOperationException _) { } } } Modified: trunk/JavaBDD_tests/bdd/CallbackTests.java =================================================================== --- trunk/JavaBDD_tests/bdd/CallbackTests.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/bdd/CallbackTests.java 2006-07-21 14:32:13 UTC (rev 462) @@ -45,7 +45,12 @@ Assert.assertTrue(hasNext()); while (hasNext()) { BDDFactory bdd = nextFactory(); - bdd.registerGCCallback(this, m); + try { + bdd.registerGCCallback(this, m); + } catch (UnsupportedOperationException _) { + System.err.println("Warning: "+bdd.getVersion()+" does not support callbacks"); + continue; + } gc_called = 0; final int numBits = 20; final int max = (1 << numBits) - 1; @@ -89,7 +94,12 @@ Assert.assertTrue(hasNext()); while (hasNext()) { BDDFactory bdd = nextFactory(); - bdd.registerReorderCallback(this, m); + try { + bdd.registerReorderCallback(this, m); + } catch (UnsupportedOperationException _) { + System.err.println("Warning: "+bdd.getVersion()+" does not support callbacks"); + continue; + } reorder_called = false; if (bdd.varNum() < 5) bdd.setVarNum(5); //bdd.varBlockAll(); @@ -127,7 +137,12 @@ Assert.assertTrue(hasNext()); while (hasNext()) { BDDFactory bdd = nextFactory(); - bdd.registerResizeCallback(this, m); + try { + bdd.registerResizeCallback(this, m); + } catch (UnsupportedOperationException _) { + System.err.println("Warning: "+bdd.getVersion()+" does not support callbacks"); + continue; + } resize_called = false; int newSize = bdd.getNodeTableSize() * 2; bdd.setNodeTableSize(newSize); Modified: trunk/JavaBDD_tests/bdd/IteratorTests.java =================================================================== --- trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/bdd/IteratorTests.java 2006-07-21 14:32:13 UTC (rev 462) @@ -37,7 +37,7 @@ BDDVarSet var = d.set(); Iterator i = b.iterator(var); b.free(); - Assert.assertEquals(i.hasNext(), false); + Assert.assertEquals(bdd.getVersion(), i.hasNext(), false); try { i.next(); Assert.fail(); @@ -53,18 +53,18 @@ while (i1.hasNext()) { BDD b1 = (BDD) i1.next(); double sc = b1.satCount(var); - Assert.assertEquals(1., sc, 0.0000001); + Assert.assertEquals(bdd.getVersion(), 1., sc, 0.0000001); s1.add(b1); } while (i2.hasNext()) { BDD b2 = (BDD) i2.next(); double sc = b2.satCount(var); - Assert.assertEquals(1., sc, 0.0000001); + Assert.assertEquals(bdd.getVersion(), 1., sc, 0.0000001); s2.add(b2); } var.free(); - Assert.assertEquals(s1.size(), domainSize); - Assert.assertEquals(s2.size(), domainSize); + Assert.assertEquals(bdd.getVersion(), s1.size(), domainSize); + Assert.assertEquals(bdd.getVersion(), s2.size(), domainSize); if (!s1.equals(s2)) { Set s1_minus_s2 = new HashSet(s1); s1_minus_s2.removeAll(s2); @@ -118,13 +118,13 @@ while (i1.hasNext()) { BDD b1 = (BDD) i1.next(); double sc = b1.satCount(var); - Assert.assertEquals(1., sc, 0.0000001); + Assert.assertEquals(bdd.getVersion(), 1., sc, 0.0000001); s1.add(b1); } while (i2.hasNext()) { BDD b2 = (BDD) i2.next(); double sc = b2.satCount(var); - Assert.assertEquals(1., sc, 0.0000001); + Assert.assertEquals(bdd.getVersion(), 1., sc, 0.0000001); s2.add(b2); } var.free(); @@ -133,7 +133,7 @@ s1_minus_s2.removeAll(s2); Set s2_minus_s1 = new HashSet(s2); s2_minus_s1.removeAll(s1); - Assert.fail("iterator() contains these extras: "+s1_minus_s2+"\n"+ + Assert.fail(bdd.getVersion()+": iterator() contains these extras: "+s1_minus_s2+"\n"+ "iterator2() contains these extras: "+s2_minus_s1); } for (Iterator k = s1.iterator(); k.hasNext(); ) { Modified: trunk/JavaBDD_tests/highlevel/NQueensTest.java =================================================================== --- trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/highlevel/NQueensTest.java 2006-07-21 14:32:13 UTC (rev 462) @@ -34,7 +34,7 @@ for (int i = 1; i <= CHECK; ++i) { NQueens.N = i; double n = NQueens.runTest(); - Assert.assertEquals(n, ANSWERS[i-1], 0.1); + Assert.assertEquals(NQueens.B.getVersion(), n, ANSWERS[i-1], 0.1); NQueens.freeAll(); } } Modified: trunk/JavaBDD_tests/regression/R1.java =================================================================== --- trunk/JavaBDD_tests/regression/R1.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/regression/R1.java 2006-07-21 14:32:13 UTC (rev 462) @@ -31,7 +31,7 @@ double s1 = x.satCount(set); if (bdd.varNum() < 20) bdd.setVarNum(20); double s2 = x.satCount(set); - Assert.assertEquals(bdd.toString(), s1, s2, 0.00001); + Assert.assertEquals(bdd.getVersion(), s1, s2, 0.00001); x.free(); set.free(); } } Modified: trunk/JavaBDD_tests/regression/R2.java =================================================================== --- trunk/JavaBDD_tests/regression/R2.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/regression/R2.java 2006-07-21 14:32:13 UTC (rev 462) @@ -26,12 +26,12 @@ BDDFactory bdd = nextFactory(); BDD zero = bdd.zero(); BDD one = bdd.one(); - Assert.assertTrue(bdd.toString(), zero.isZero()); - Assert.assertTrue(bdd.toString(), one.isOne()); + Assert.assertTrue(bdd.getVersion(), zero.isZero()); + Assert.assertTrue(bdd.getVersion(), one.isOne()); BDDVarSet s0 = zero.support(); BDDVarSet s1 = one.support(); - Assert.assertTrue(bdd.toString(), s0.isEmpty()); - Assert.assertTrue(bdd.toString(), s1.isEmpty()); + Assert.assertTrue(bdd.getVersion(), s0.isEmpty()); + Assert.assertTrue(bdd.getVersion(), s1.isEmpty()); zero.free(); one.free(); s0.free(); s1.free(); } Modified: trunk/JavaBDD_tests/regression/R3.java =================================================================== --- trunk/JavaBDD_tests/regression/R3.java 2006-07-21 14:32:02 UTC (rev 461) +++ trunk/JavaBDD_tests/regression/R3.java 2006-07-21 14:32:13 UTC (rev 462) @@ -35,28 +35,33 @@ one = bdd.one(); or = x0.or(x1); - z0 = or.unique(xs0); + try { + z0 = or.unique(xs0); + } catch (UnsupportedOperationException _) { + System.err.println("Warning: "+bdd.getVersion()+" does not support unique()"); + continue; + } t = x1.not(); - Assert.assertTrue(bdd.getVersion()+": "+z0.toString(), z0.equals(t)); + Assert.assertTrue(bdd.getVersion(), z0.equals(t)); t.free(); z1 = or.unique(xs1); t = x0.not(); - Assert.assertTrue(bdd.getVersion()+": "+z1.toString(), z1.equals(t)); + Assert.assertTrue(bdd.getVersion(), z1.equals(t)); t.free(); t = one.unique(xs0); - Assert.assertTrue(bdd.getVersion()+": "+t.toString(), t.isZero()); + Assert.assertTrue(bdd.getVersion(), t.isZero()); t.free(); y0 = x0.applyUni(x1, BDDFactory.or, xs0); t = x1.not(); - Assert.assertTrue(bdd.getVersion()+": "+y0.toString(), y0.equals(t)); + Assert.assertTrue(bdd.getVersion(), y0.equals(t)); t.free(); y1 = x0.applyUni(x1, BDDFactory.or, xs1); t = x0.not(); - //Assert.assertTrue(bdd.getVersion()+": "+y1.toString(), y1.equals(t)); + //Assert.assertTrue(bdd.getVersion(), y1.equals(t)); t.free(); x0.free(); x1.free(); y0.free(); y1.free(); z0.free(); z1.free(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <joe...@us...> - 2006-07-21 14:32:09
|
Revision: 461 Author: joewhaley Date: 2006-07-21 07:32:02 -0700 (Fri, 21 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=461&view=rev Log Message: ----------- Changed MicroFactory, JDDFactory to use new BDDFactoryIntImpl shared superclass. More bug fixes in the test cases. Now the test cases won't fail if a BDD library doesn't support a (nonessential) operation and throws UnsupportedOperationException. Modified Paths: -------------- trunk/JavaBDD/net/sf/javabdd/BDD.java trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java trunk/JavaBDD/net/sf/javabdd/JDDFactory.java trunk/JavaBDD/net/sf/javabdd/JFactory.java trunk/JavaBDD/net/sf/javabdd/MicroFactory.java Modified: trunk/JavaBDD/net/sf/javabdd/BDD.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-07-17 16:03:04 UTC (rev 460) +++ trunk/JavaBDD/net/sf/javabdd/BDD.java 2006-07-21 14:32:02 UTC (rev 461) @@ -588,7 +588,8 @@ allsatProfile[useLevel?LEVEL_r:f.level2Var(LEVEL_r)] = lo_empty ? (byte)1 : (byte)0; BDD rn = lo_empty ? r.high() : r.low(); - for (int v = rn.level() - 1; v > LEVEL_r; --v) { + int v = rn.isOne()||rn.isZero() ? f.varNum() - 1 : rn.level() - 1; + for ( ; v > LEVEL_r; --v) { allsatProfile[useLevel?v:f.level2Var(v)] = -1; } if (!lo_empty) { Modified: trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-17 16:03:04 UTC (rev 460) +++ trunk/JavaBDD/net/sf/javabdd/BDDFactoryIntImpl.java 2006-07-21 14:32:02 UTC (rev 461) @@ -16,49 +16,49 @@ static final boolean USE_FINALIZER = false; - protected abstract void addref_impl(int v); - protected abstract void delref_impl(int v); - protected abstract int zero_impl(); - protected abstract int one_impl(); - protected abstract int invalid_bdd_impl(); - protected abstract int var_impl(int v); - protected abstract int level_impl(int v); - protected abstract int low_impl(int v); - protected abstract int high_impl(int v); - protected abstract int ithVar_impl(int var); - protected abstract int nithVar_impl(int var); + protected abstract void addref_impl(/*bdd*/int v); + protected abstract void delref_impl(/*bdd*/int v); + protected abstract /*bdd*/int zero_impl(); + protected abstract /*bdd*/int one_impl(); + protected abstract /*bdd*/int invalid_bdd_impl(); + protected abstract int var_impl(/*bdd*/int v); + protected abstract int level_impl(/*bdd*/int v); + protected abstract /*bdd*/int low_impl(/*bdd*/int v); + protected abstract /*bdd*/int high_impl(/*bdd*/int v); + protected abstract /*bdd*/int ithVar_impl(int var); + protected abstract /*bdd*/int nithVar_impl(int var); - protected abstract int ite_impl(int v1, int v2, int v3); - protected abstract int apply_impl(int v1, int v2, BDDOp opr); - protected abstract int not_impl(int v1); - protected abstract int applyAll_impl(int v1, int v2, BDDOp opr, int v3); - protected abstract int applyEx_impl(int v1, int v2, BDDOp opr, int v3); - protected abstract int applyUni_impl(int v1, int v2, BDDOp opr, int v3); - protected abstract int compose_impl(int v1, int v2, int var); - protected abstract int constrain_impl(int v1, int v2); - protected abstract int restrict_impl(int v1, int v2); - protected abstract int simplify_impl(int v1, int v2); - protected abstract int support_impl(int v); - protected abstract int exist_impl(int v1, int v2); - protected abstract int forAll_impl(int v1, int v2); - protected abstract int unique_impl(int v1, int v2); - protected abstract int fullSatOne_impl(int v); + protected abstract /*bdd*/int ite_impl(/*bdd*/int v1, /*bdd*/int v2, /*bdd*/int v3); + protected abstract /*bdd*/int apply_impl(/*bdd*/int v1, /*bdd*/int v2, BDDOp opr); + protected abstract /*bdd*/int not_impl(/*bdd*/int v1); + protected abstract /*bdd*/int applyAll_impl(/*bdd*/int v1, /*bdd*/int v2, BDDOp opr, /*bdd*/int v3); + protected abstract /*bdd*/int applyEx_impl(/*bdd*/int v1, /*bdd*/int v2, BDDOp opr, /*bdd*/int v3); + protected abstract /*bdd*/int applyUni_impl(/*bdd*/int v1, /*bdd*/int v2, BDDOp opr, /*bdd*/int v3); + protected abstract /*bdd*/int compose_impl(/*bdd*/int v1, /*bdd*/int v2, int var); + protected abstract /*bdd*/int constrain_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int restrict_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int simplify_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int support_impl(/*bdd*/int v); + protected abstract /*bdd*/int exist_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int forAll_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int unique_impl(/*bdd*/int v1, /*bdd*/int v2); + protected abstract /*bdd*/int fullSatOne_impl(/*bdd*/int v); - protected abstract int replace_impl(int v, BDDPairing p); - protected abstract int veccompose_impl(int v, BDDPairing p); + protected abstract /*bdd*/int replace_impl(/*bdd*/int v, BDDPairing p); + protected abstract /*bdd*/int veccompose_impl(/*bdd*/int v, BDDPairing p); - protected abstract int nodeCount_impl(int v); - protected abstract double pathCount_impl(int v); - protected abstract double satCount_impl(int v); - protected abstract int satOne_impl(int v); - protected abstract int satOne_impl2(int v1, int v2, boolean pol); - protected abstract int nodeCount_impl2(int[] v); - protected abstract int[] varProfile_impl(int v); - protected abstract void printTable_impl(int v); + protected abstract int nodeCount_impl(/*bdd*/int v); + protected abstract double pathCount_impl(/*bdd*/int v); + protected abstract double satCount_impl(/*bdd*/int v); + protected abstract /*bdd*/int satOne_impl(/*bdd*/int v); + protected abstract /*bdd*/int satOne_impl2(/*bdd*/int v1, /*bdd*/int v2, boolean pol); + protected abstract int nodeCount_impl2(/*bdd*/int[] v); + protected abstract int[] varProfile_impl(/*bdd*/int v); + protected abstract void printTable_impl(/*bdd*/int v); public class IntBDD extends BDD { - protected int v; - protected IntBDD(int v) { + protected /*bdd*/int v; + protected IntBDD(/*bdd*/int v) { this.v = v; addref_impl(v); } @@ -75,8 +75,8 @@ return makeBDD(applyUni_impl(v, unwrap(that), opr, unwrap(var))); } public BDD applyWith(BDD that, BDDOp opr) { - int v2 = unwrap(that); - int v3 = apply_impl(v, v2, opr); + /*bdd*/int v2 = unwrap(that); + /*bdd*/int v3 = apply_impl(v, v2, opr); addref_impl(v3); delref_impl(v); if (this != that) @@ -146,7 +146,7 @@ return makeBDD(replace_impl(v, pair)); } public BDD replaceWith(BDDPairing pair) { - int v3 = replace_impl(v, pair); + /*bdd*/int v3 = replace_impl(v, pair); addref_impl(v3); delref_impl(v); v = v3; @@ -156,8 +156,8 @@ return makeBDD(restrict_impl(v, unwrap(var))); } public BDD restrictWith(BDD that) { - int v2 = unwrap(that); - int v3 = restrict_impl(v, v2); + /*bdd*/int v2 = unwrap(that); + /*bdd*/int v3 = restrict_impl(v, v2); addref_impl(v3); delref_impl(v); if (this != that) @@ -198,7 +198,7 @@ } public class IntBDDWithFinalizer extends IntBDD { - protected IntBDDWithFinalizer(int v) { + protected IntBDDWithFinalizer(/*bdd*/int v) { super(v); } @@ -214,19 +214,19 @@ } - protected IntBDD makeBDD(int v) { + protected IntBDD makeBDD(/*bdd*/int v) { if (USE_FINALIZER) return new IntBDDWithFinalizer(v); else return new IntBDD(v); } - protected static final int unwrap(BDD b) { + protected static final /*bdd*/int unwrap(BDD b) { return ((IntBDD) b).v; } - protected static final int[] unwrap(Collection/*<BDD>*/ c) { - int[] result = new int[c.size()]; + protected static final /*bdd*/int[] unwrap(Collection/*<BDD>*/ c) { + /*bdd*/int[] result = new /*bdd*/int[c.size()]; int k = -1; for (Iterator i = c.iterator(); i.hasNext(); ) { result[++k] = ((IntBDD) i.next()).v; @@ -235,8 +235,8 @@ } public class IntBDDVarSet extends BDDVarSet { - int v; - private IntBDDVarSet(int v) { + /*bdd*/int v; + private IntBDDVarSet(/*bdd*/int v) { this.v = v; addref_impl(v); } @@ -260,8 +260,8 @@ return makeBDDVarSet(apply_impl(v, unwrap(b), or)); } public BDDVarSet intersectWith(BDDVarSet b) { - int v2 = unwrap(b); - int v3 = apply_impl(v, v2, or); + /*bdd*/int v2 = unwrap(b); + /*bdd*/int v3 = apply_impl(v, v2, or); addref_impl(v3); delref_impl(v); if (this != b) @@ -274,7 +274,7 @@ } public int size() { int result = 0; - for (int p = v; p != one_impl(); p = high_impl(p)) { + for (/*bdd*/int p = v; p != one_impl(); p = high_impl(p)) { if (p == zero_impl()) throw new BDDException("varset contains zero"); ++result; @@ -284,7 +284,7 @@ public int[] toArray() { int[] result = new int[size()]; int k = -1; - for (int p = v; p != one_impl(); p = high_impl(p)) { + for (/*bdd*/int p = v; p != one_impl(); p = high_impl(p)) { result[++k] = var_impl(p); } return result; @@ -304,14 +304,14 @@ return makeBDDVarSet(apply_impl(v, unwrap(b), and)); } public BDDVarSet union(int var) { - int v2 = ithVar_impl(var); - int v3 = apply_impl(v, v2, and); + /*bdd*/int v2 = ithVar_impl(var); + /*bdd*/int v3 = apply_impl(v, v2, and); delref_impl(v2); return makeBDDVarSet(v3); } public BDDVarSet unionWith(BDDVarSet b) { - int v2 = unwrap(b); - int v3 = apply_impl(v, v2, and); + /*bdd*/int v2 = unwrap(b); + /*bdd*/int v3 = apply_impl(v, v2, and); addref_impl(v3); delref_impl(v); if (this != b) @@ -320,8 +320,8 @@ return this; } public BDDVarSet unionWith(int var) { - int v2 = ithVar_impl(var); - int v3 = apply_impl(v, v2, and); + /*bdd*/int v2 = ithVar_impl(var); + /*bdd*/int v3 = apply_impl(v, v2, and); addref_impl(v3); delref_impl(v); delref_impl(v2); @@ -348,14 +348,14 @@ } - protected IntBDDVarSet makeBDDVarSet(int v) { + protected IntBDDVarSet makeBDDVarSet(/*bdd*/int v) { if (USE_FINALIZER) return new IntBDDVarSetWithFinalizer(v); else return new IntBDDVarSet(v); } - protected static final int unwrap(BDDVarSet b) { + protected static final /*bdd*/int unwrap(BDDVarSet b) { return ((IntBDDVarSet) b).v; } @@ -371,11 +371,11 @@ } - public BDD ithVar(int var) { + public BDD ithVar(/*bdd*/int var) { return makeBDD(ithVar_impl(var)); } - public BDD nithVar(int var) { + public BDD nithVar(/*bdd*/int var) { return makeBDD(nithVar_impl(var)); } @@ -399,12 +399,12 @@ return makeBDD(zero_impl()); } - protected int[] to_free = new int[8]; - protected int to_free_length = 0; + protected /*bdd*/int[] to_free = new /*bdd*/int[8]; + protected /*bdd*/int to_free_length = 0; public void deferredFree(int v) { synchronized(to_free) { if (to_free_length == to_free.length) { - int[] t = new int[to_free.length * 2]; + /*bdd*/int[] t = new /*bdd*/int[to_free.length * 2]; System.arraycopy(to_free, 0, t, 0, to_free.length); to_free = t; } Modified: trunk/JavaBDD/net/sf/javabdd/JDDFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-17 16:03:04 UTC (rev 460) +++ trunk/JavaBDD/net/sf/javabdd/JDDFactory.java 2006-07-21 14:32:02 UTC (rev 461) @@ -3,632 +3,257 @@ // Licensed under the terms of the GNU LGPL; see COPYING for details. package net.sf.javabdd; -import java.util.Collection; -import java.math.BigInteger; +import java.lang.reflect.Method; - /** * JDDFactory * * @author John Whaley * @version $Id$ */ -public class JDDFactory extends BDDFactory { +public class JDDFactory extends BDDFactoryIntImpl { - private final jdd.bdd.BDD bdd; - private int[] vars; // indexed by EXTERNAL - private int[] level2var; // internal -> external - private int[] var2level; // external -> internal + public static final String REVISION = "$Revision$"; - private JDDFactory(int nodenum, int cachesize) { - bdd = new jdd.bdd.BDD(nodenum, cachesize); - vars = new int[256]; - jdd.util.Options.verbose = true; + public String getVersion() { + return "JDDFactory "+REVISION.substring(11, REVISION.length()-2); } - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#init(int, int) - */ - public static BDDFactory init(int nodenum, int cachesize) { - BDDFactory f = new JDDFactory(nodenum, cachesize); - return f; + static final int INVALID_BDD = -1; + + // Redirection functions. + + protected void addref_impl(int v) { bdd.ref(v); } + protected void delref_impl(int v) { bdd.deref(v); } + protected int zero_impl() { return bdd.getZero(); } + protected int one_impl() { return bdd.getOne(); } + protected int invalid_bdd_impl() { return INVALID_BDD; } + protected int var_impl(int index) { + int v = level_impl(index); + return level2var != null ? level2var[v] : v; } - - /** - * Wrapper for the BDD index number used internally in the representation. - */ - private class bdd extends BDD { - int _index; - - static final int INVALID_BDD = -1; - - bdd(int index) { - this._index = index; - bdd.ref(_index); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#getFactory() - */ - public BDDFactory getFactory() { - return JDDFactory.this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#isZero() - */ - public boolean isZero() { - return _index == bdd.getZero(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#isOne() - */ - public boolean isOne() { - return _index == bdd.getOne(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#var() - */ - public int var() { - int v = bdd.getVar(_index); - return level2var != null ? level2var[v] : v; - } - - public int level() { - int v = bdd.getVar(_index); - return v; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#high() - */ - public BDD high() { - return new bdd(bdd.getHigh(_index)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#low() - */ - public BDD low() { - return new bdd(bdd.getLow(_index)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#id() - */ - public BDD id() { - return new bdd(_index); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#not() - */ - public BDD not() { - return new bdd(bdd.not(_index)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#ite(net.sf.javabdd.BDD, net.sf.javabdd.BDD) - */ - public BDD ite(BDD thenBDD, BDD elseBDD) { - int x = _index; - int y = ((bdd) thenBDD)._index; - int z = ((bdd) elseBDD)._index; - return new bdd(bdd.ite(x, y, z)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#relprod(net.sf.javabdd.BDD, net.sf.javabdd.BDDVarSet) - */ - public BDD relprod(BDD that, BDDVarSet var) { - int x = _index; - int y = ((bdd) that)._index; - int z = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - return new bdd(bdd.relProd(x, y, z)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#compose(net.sf.javabdd.BDD, int) - */ - public BDD compose(BDD g, int var) { - int x = _index; - int y = ((bdd) g)._index; - return null; // todo. - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#veccompose(net.sf.javabdd.BDDPairing) - */ - public BDD veccompose(BDDPairing pair) { - int x = _index; - return null; // todo. - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#constrain(net.sf.javabdd.BDD) - */ - public BDD constrain(BDD that) { - int x = _index; - int y = ((bdd) that)._index; - return null; // todo. - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#exist(net.sf.javabdd.BDDVarSet) - */ - public BDD exist(BDDVarSet var) { - int x = _index; - int y = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - return new bdd(bdd.exists(x, y)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#forAll(net.sf.javabdd.BDDVarSet) - */ - public BDD forAll(BDDVarSet var) { - int x = _index; - int y = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - return new bdd(bdd.forall(x, y)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#unique(net.sf.javabdd.BDDVarSet) - */ - public BDD unique(BDDVarSet var) { - int x = _index; - int y = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - return null; // todo. - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#restrict(net.sf.javabdd.BDD) - */ - public BDD restrict(BDD var) { - int x = _index; - int y = ((bdd) var)._index; - return new bdd(bdd.restrict(x, y)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#restrictWith(net.sf.javabdd.BDD) - */ - public BDD restrictWith(BDD that) { - int x = _index; - int y = ((bdd) that)._index; - int a = bdd.restrict(x, y); - //System.out.println("restrictWith("+System.identityHashCode(this)+") "+x+" -> "+a); - bdd.deref(x); - if (this != that) - that.free(); - bdd.deref(a); - this._index = a; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#simplify(net.sf.javabdd.BDDVarSet) - */ - public BDD simplify(BDDVarSet d) { - int x = _index; - int y = ((bdd) ((BDDVarSet.DefaultImpl) d).b)._index; - return new bdd(bdd.simplify(x, y)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#support() - */ - public BDDVarSet support() { - int x = _index; - return new BDDVarSet.DefaultImpl(new bdd(bdd.support(x))); - } - - private int apply0(int x, int y, int z) { - int r; - switch (z) { - case 0: r = bdd.and(x, y); break; - case 1: r = bdd.xor(x, y); break; - case 2: r = bdd.or(x, y); break; - case 3: r = bdd.nand(x, y); break; - case 4: r = bdd.nor(x, y); break; - case 5: r = bdd.imp(x, y); break; - case 6: r = bdd.biimp(x, y); break; - case 7: r = bdd.and(x, bdd.not(y)); break; // diff - default: - throw new BDDException(); // TODO. - } - return r; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#apply(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp) - */ - public BDD apply(BDD that, BDDOp opr) { - int x = _index; - int y = ((bdd) that)._index; - int z = opr.id; - return new bdd(apply0(x, y, z)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyWith(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp) - */ - public BDD applyWith(BDD that, BDDOp opr) { - int x = _index; - int y = ((bdd) that)._index; - int z = opr.id; - int a = apply0(x, y, z); - bdd.deref(x); - if (this != that) - that.free(); - bdd.ref(a); - this._index = a; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyAll(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyAll(BDD that, BDDOp opr, BDDVarSet var) { - int x = _index; - int y = ((bdd) that)._index; - int z = opr.id; - int a = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - // todo: combine. - int r = apply0(x, y, z); - bdd.ref(r); - int r2 = bdd.forall(r, a); - bdd.deref(r); - return new bdd(r2); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyEx(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyEx(BDD that, BDDOp opr, BDDVarSet var) { - int x = _index; - int y = ((bdd) that)._index; - int z = opr.id; - int a = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - // todo: combine. - int r = apply0(x, y, z); - bdd.ref(r); - int r2 = bdd.exists(r, a); - bdd.deref(r); - return new bdd(r2); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#applyUni(net.sf.javabdd.BDD, net.sf.javabdd.BDDFactory.BDDOp, net.sf.javabdd.BDDVarSet) - */ - public BDD applyUni(BDD that, BDDOp opr, BDDVarSet var) { - int x = _index; - int y = ((bdd) that)._index; - int z = opr.id; - int a = ((bdd) ((BDDVarSet.DefaultImpl) var).b)._index; - throw new BDDException(); // todo. - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satOne() - */ - public BDD satOne() { - int x = _index; - return new bdd(bdd.oneSat(x)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#replace(net.sf.javabdd.BDDPairing) - */ - public BDD replace(BDDPairing pair) { - int x = _index; - return new bdd(bdd.replace(x, ((bddPairing) pair).pairing)); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#replaceWith(net.sf.javabdd.BDDPairing) - */ - public BDD replaceWith(BDDPairing pair) { - int x = _index; - int y = bdd.replace(x, ((bddPairing) pair).pairing); - //System.out.println("replaceWith("+System.identityHashCode(this)+") "+x+" -> "+y); - bdd.deref(x); - bdd.ref(y); - _index = y; - return this; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#nodeCount() - */ - public int nodeCount() { - return bdd.nodeCount(_index); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satCount() - */ - public double satCount() { - return bdd.satCount(_index); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#equals(net.sf.javabdd.BDD) - */ - public boolean equals(BDD that) { - return this._index == ((bdd) that)._index; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#hashCode() - */ - public int hashCode() { - return _index; - } - - static final boolean USE_FINALIZER = false; - - /** - * @see java.lang.Object#finalize() - */ - /* - protected void finalize() throws Throwable { - super.finalize(); - if (USE_FINALIZER) { - if (false && _index >= 0) { - System.out.println("BDD not freed! "+System.identityHashCode(this)); - } - this.free(); - } - } - */ - - /** - * @see net.sf.javabdd.BDD#free() - */ - public void free() { - bdd.deref(_index); - _index = INVALID_BDD; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#fullSatOne() - */ - public BDD fullSatOne() { + protected int level_impl(int index) { + // NOTE: jdd seems to returns the total number of variables when + // calling getVar() on a terminal. + int v = bdd.getVar(index); + if (index == bdd.getOne() || index == bdd.getZero()) throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#satOne(net.sf.javabdd.BDDVarSet, boolean) - */ - public BDD satOne(BDDVarSet var, boolean pol) { - // TODO Implement this. - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#pathCount() - */ - public double pathCount() { + if (v == -1) throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#varProfile() - */ - public int[] varProfile() { + return v; + } + protected int low_impl(int v) { + if (v == bdd.getOne() || v == bdd.getZero()) throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDD#toVarSet() - */ - public BDDVarSet toVarSet() { - return new BDDVarSet.DefaultImpl(new bdd(_index)); - } - + return bdd.getLow(v); } - - private class bddPairing extends BDDPairing { - - private int[] from; - private int[] to; - private jdd.bdd.Permutation pairing; - - private bddPairing() { - reset(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDPairing#set(int, int) - */ - public void set(int oldvar, int newvar) { - for (int i = 0; i < from.length; ++i) { - if (from[i] == vars[oldvar]) { - to[i] = vars[newvar]; - pairing = bdd.createPermutation(from, to); - return; - } - } - int[] oldfrom = from; - from = new int[from.length + 1]; - System.arraycopy(oldfrom, 0, from, 0, oldfrom.length); - from[oldfrom.length] = vars[oldvar]; - int[] oldto = to; - to = new int[to.length + 1]; - System.arraycopy(oldto, 0, to, 0, oldto.length); - to[oldto.length] = vars[newvar]; - pairing = bdd.createPermutation(from, to); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDPairing#set(int, net.sf.javabdd.BDD) - */ - public void set(int oldvar, BDD newvar) { + protected int high_impl(int v) { + if (v == bdd.getOne() || v == bdd.getZero()) throw new BDDException(); + return bdd.getHigh(v); + } + protected int ithVar_impl(int var) { + if (var >= bdd.numberOfVariables()) + throw new BDDException(); + return vars[var]; + } + protected int nithVar_impl(int var) { + if (var >= bdd.numberOfVariables()) + throw new BDDException(); + return bdd.not(vars[var]); + } + protected int ite_impl(int v1, int v2, int v3) { return bdd.ite(v1, v2, v3); } + protected int apply_impl(int x, int y, BDDOp opr) { + int r; + switch (opr.id) { + case 0: r = bdd.and(x, y); break; + case 1: r = bdd.xor(x, y); break; + case 2: r = bdd.or(x, y); break; + case 3: r = bdd.nand(x, y); break; + case 4: r = bdd.nor(x, y); break; + case 5: r = bdd.imp(x, y); break; + case 6: r = bdd.biimp(x, y); break; + case 7: r = bdd.and(x, bdd.not(y)); break; // diff + default: + throw new UnsupportedOperationException(); // TODO. } - - public void set(int[] oldvar, int[] newvar) { - int[] oldfrom = from; - from = new int[from.length + oldvar.length]; - System.arraycopy(oldfrom, 0, from, 0, oldfrom.length); - for (int i = 0; i < oldvar.length; ++i) { - from[i + oldfrom.length] = vars[oldvar[i]]; - } - int[] oldto = to; - to = new int[to.length + newvar.length]; - System.arraycopy(oldto, 0, to, 0, oldto.length); - for (int i = 0; i < newvar.length; ++i) { - to[i + oldto.length] = vars[newvar[i]]; - } - //debug(); - pairing = bdd.createPermutation(from, to); + return r; + } + protected int not_impl(int v1) { return bdd.not(v1); } + protected int applyAll_impl(int v1, int v2, BDDOp opr, int v3) { + // todo: combine. + int r = apply_impl(v1, v2, opr); + bdd.ref(r); + int r2 = bdd.forall(r, v3); + bdd.deref(r); + return r2; + } + protected int applyEx_impl(int v1, int v2, BDDOp opr, int v3) { + if (opr == and) + return bdd.relProd(v1, v2, v3); + // todo: combine. + int r = apply_impl(v1, v2, opr); + bdd.ref(r); + int r2 = bdd.exists(r, v3); + bdd.deref(r); + return r2; + } + protected int applyUni_impl(int v1, int v2, BDDOp opr, int v3) { + throw new UnsupportedOperationException(); // todo. + } + protected int compose_impl(int v1, int v2, int var) { + throw new UnsupportedOperationException(); // todo. + } + protected int constrain_impl(int v1, int v2) { + throw new UnsupportedOperationException(); // todo. + } + protected int restrict_impl(int v1, int v2) { return bdd.restrict(v1, v2); } + protected int simplify_impl(int v1, int v2) { return bdd.simplify(v1, v2); } + protected int support_impl(int v) { return bdd.support(v); } + protected int exist_impl(int v1, int v2) { return bdd.exists(v1, v2); } + protected int forAll_impl(int v1, int v2) { return bdd.forall(v1, v2); } + protected int unique_impl(int v1, int v2) { + throw new UnsupportedOperationException(); // todo. + } + protected int fullSatOne_impl(int v) { + if (v == bdd.getZero()) + return v; + int[] res = bdd.oneSat(v, null); + int result = bdd.getOne(); + for (int i = res.length - 1; i >= 0; --i) { + int u; + if (res[i] == 1) + u = bdd.mk(i, 0, result); + else + u = bdd.mk(i, result, 0); + bdd.ref(u); bdd.deref(result); + result = u; } - - void debug() { - for (int i = 0; i < from.length; ++i) { - System.out.println(bdd.getVar(from[i])+" -> "+bdd.getVar(to[i])); + bdd.deref(result); + return result; + } + + protected int replace_impl(int v, BDDPairing p) { return bdd.replace(v, ((bddPairing) p).pairing); } + protected int veccompose_impl(int v, BDDPairing p) { + throw new UnsupportedOperationException(); // todo. + } + + protected int nodeCount_impl(int v) { return bdd.nodeCount(v); } + protected double pathCount_impl(int v) { + throw new UnsupportedOperationException(); // todo. + } + protected double satCount_impl(int v) { return bdd.satCount(v); } + protected int satOne_impl(int v) { return bdd.oneSat(v); } + protected int satOne_impl2(int v1, int v2, boolean pol) { + if (v1 == bdd.getZero()) + return v1; + int[] res = bdd.oneSat(v1, null); + int result = bdd.getOne(); + for (int i = res.length - 1; i >= 0; --i) { + while (bdd.getVar(v2) < i) + v2 = bdd.getHigh(v2); + boolean p; + if (res[i] == 1) p = true; + else if (res[i] == 0) p = false; + else { + if (bdd.getVar(v2) != i) + continue; + p = pol; } + int u = bdd.mk(i, p?0:result, p?result:0); + bdd.ref(u); bdd.deref(result); + result = u; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDPairing#reset() - */ - public void reset() { - from = to = new int[] { }; - pairing = null; - } - + bdd.deref(result); + return result; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#zero() - */ - public BDD zero() { - return new bdd(bdd.getZero()); + protected int nodeCount_impl2(int[] v) { + throw new UnsupportedOperationException(); // todo. } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#one() - */ - public BDD one() { - return new bdd(bdd.getOne()); + protected int[] varProfile_impl(int v) { + throw new UnsupportedOperationException(); // todo. } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#initialize(int, int) - */ - protected void initialize(int nodenum, int cachesize) { - throw new BDDException(); + protected void printTable_impl(int v) { + throw new UnsupportedOperationException(); // todo. } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#isInitialized() - */ - public boolean isInitialized() { - // TODO Auto-generated method stub - return true; + + // More redirection functions. + + protected void initialize(int initnodesize, int cs) { + bdd = new jdd.bdd.BDD(initnodesize, cs); + vars = new int[256]; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#done() - */ - public void done() { - bdd.cleanup(); + public void addVarBlock(int first, int last, boolean fixed) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setError(int) - */ + public void varBlockAll() { + throw new UnsupportedOperationException(); + } + public void clearVarBlocks() { + throw new UnsupportedOperationException(); + } + public void printOrder() { + throw new UnsupportedOperationException(); + } + public int getNodeTableSize() { + // todo. + return bdd.countRootNodes(); + } + public int setNodeTableSize(int x) { + // TODO. + return getNodeTableSize(); + } + public int setCacheSize(int x) { + // TODO. + return 0; + } + public boolean isInitialized() { return true; } + public void done() { bdd.cleanup(); bdd = null; } public void setError(int code) { - // TODO Implement this. + // todo: implement this } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#clearError() - */ public void clearError() { - // TODO Implement this. + // todo: implement this } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setMaxNodeNum(int) - */ public int setMaxNodeNum(int size) { - // TODO Auto-generated method stub - //throw new BDDException(); + // todo: implement this return 0; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setMinFreeNodes(double) - */ public double setMinFreeNodes(double x) { int old = jdd.util.Configuration.minFreeNodesProcent; jdd.util.Configuration.minFreeNodesProcent = (int)(x * 100); return (double) old / 100.; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setIncreaseFactor(double) - */ - public double setIncreaseFactor(double x) { - // TODO. - return 0.; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setMaxIncrease(int) - */ public int setMaxIncrease(int x) { int old = jdd.util.Configuration.maxNodeIncrease; jdd.util.Configuration.maxNodeIncrease = x; return old; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setNodeTableSize(int) - */ - public int setNodeTableSize(int x) { - // TODO. - return getNodeTableSize(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setCacheSize(int) - */ - public int setCacheSize(int x) { - // TODO. + public double setIncreaseFactor(double x) { + // todo: implement this return 0; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getCacheSize() - */ + public int getNodeNum() { + // todo. + return bdd.countRootNodes(); + } public int getCacheSize() { // TODO Implement this. + return 0; + } + public int reorderGain() { throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setCacheRatio(int) - */ + public void printStat() { + bdd.showStats(); + } public double setCacheRatio(double x) { - // TODO Auto-generated method stub + // TODO Implement this. return 0; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#varNum() - */ public int varNum() { return bdd.numberOfVariables(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setVarNum(int) - */ public int setVarNum(int num) { if (num > Integer.MAX_VALUE / 2) throw new BDDException(); @@ -664,128 +289,13 @@ } return old; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#duplicateVar(int) - */ - public int duplicateVar(int var) { - // TODO Implement this. + public void printAll() { throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#ithVar(int) - */ - public BDD ithVar(int var) { - if (var >= bdd.numberOfVariables()) - throw new BDDException(); - //int v = var2level != null ? var2level[var] : var; - int v = var; - return new bdd(vars[v]); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#nithVar(int) - */ - public BDD nithVar(int var) { - if (var >= bdd.numberOfVariables()) - throw new BDDException(); - //int v = var2level != null ? var2level[var] : var; - int v = var; - return new bdd(bdd.not(vars[v])); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printAll() - */ - public void printAll() { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printTable(net.sf.javabdd.BDD) - */ - public void printTable(BDD b) { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#level2Var(int) - */ - public int level2Var(int level) { - return level2var != null ? level2var[level] : level; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#var2Level(int) - */ - public int var2Level(int var) { - return var2level != null ? var2level[var] : var; - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorder(net.sf.javabdd.BDDFactory.ReorderMethod) - */ - public void reorder(ReorderMethod m) { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod) - */ - public void autoReorder(ReorderMethod method) { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#autoReorder(net.sf.javabdd.BDDFactory.ReorderMethod, int) - */ - public void autoReorder(ReorderMethod method, int max) { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getReorderMethod() - */ - public ReorderMethod getReorderMethod() { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getReorderTimes() - */ - public int getReorderTimes() { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#disableReorder() - */ - public void disableReorder() { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#enableReorder() - */ - public void enableReorder() { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorderVerbose(int) - */ - public int reorderVerbose(int v) { - throw new BDDException(); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#setVarOrder(int[]) - */ public void setVarOrder(int[] neworder) { - // todo: setting var order corrupts all existing BDD's! + // todo: setting var order corrupts all existing BDDs! if (var2level != null) - throw new BDDException(); + throw new UnsupportedOperationException(); if (bdd.numberOfVariables() != neworder.length) throw new BDDException(); @@ -809,139 +319,149 @@ //System.out.println("Set for domain "+d+": "+d.var.toStringWithDomains()); } } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#addVarBlock(net.sf.javabdd.BDD, boolean) - */ - public void addVarBlock(BDD var, boolean fixed) { - throw new BDDException(); + public int level2Var(int level) { return level2var != null ? level2var[level] : level; } + public int var2Level(int var) { return var2level != null ? var2level[var] : var; } + public ReorderMethod getReorderMethod() { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#addVarBlock(int, int, boolean) - */ - public void addVarBlock(int first, int last, boolean fixed) { - throw new BDDException(); + public int getReorderTimes() { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#varBlockAll() - */ - public void varBlockAll() { - throw new BDDException(); + public void disableReorder() { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#clearVarBlocks() - */ - public void clearVarBlocks() { - throw new BDDException(); + public void enableReorder() { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printOrder() - */ - public void printOrder() { - throw new BDDException(); + public int reorderVerbose(int v) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#nodeCount(java.util.Collection) - */ - public int nodeCount(Collection r) { - throw new BDDException(); + public void reorder(ReorderMethod m) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getNodeTableSize() - */ - public int getNodeTableSize() { - // todo. - return bdd.countRootNodes(); + public void autoReorder(ReorderMethod method) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getNodeNum() - */ - public int getNodeNum() { - // todo. - return bdd.countRootNodes(); + public void autoReorder(ReorderMethod method, int max) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#reorderGain() - */ - public int reorderGain() { - throw new BDDException(); + public void swapVar(int v1, int v2) { + throw new UnsupportedOperationException(); } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#printStat() - */ - public void printStat() { - bdd.showStats(); + + private jdd.bdd.BDD bdd; + private int[] vars; // indexed by EXTERNAL + private int[] level2var; // internal -> external + private int[] var2level; // external -> internal + + static { + jdd.util.Options.verbose = true; } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#makePair() - */ - public BDDPairing makePair() { - return new bddPairing(); + + private JDDFactory(int nodenum, int cachesize) { + initialize(nodenum, cachesize); } - + /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#swapVar(int, int) + * @see net.sf.javabdd.BDDFactory#init(int, int) */ - public void swapVar(int v1, int v2) { - throw new BDDException(); + public static BDDFactory init(int nodenum, int cachesize) { + BDDFactory f = new JDDFactory(nodenum, cachesize); + return f; } - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#createDomain(int, BigInteger) - */ - protected BDDDomain createDomain(int a, BigInteger b) { - return new bddDomain(a, b); - } - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#createBitVector(int) - */ - protected BDDBitVector createBitVector(int a) { - return new bddBitVector(a); - } - - private class bddDomain extends BDDDomain { - - private bddDomain(int a, BigInteger b) { - super(a, b); + private class bddPairing extends BDDPairing { + + private int[] from; + private int[] to; + private jdd.bdd.Permutation pairing; + + private bddPairing() { + reset(); } - + /* (non-Javadoc) - * @see net.sf.javabdd.BDDBitVector#getFactory() + * @see net.sf.javabdd.BDDPairing#set(int, int) */ - public BDDFactory getFactory() { return JDDFactory.this; } - - } - - private class bddBitVector extends BDDBitVector { - - private bddBitVector(int a) { - super(a); + public void set(int oldvar, int newvar) { + for (int i = 0; i < from.length; ++i) { + if (from[i] == vars[oldvar]) { + to[i] = vars[newvar]; + pairing = bdd.createPermutation(from, to); + return; + } + } + int[] oldfrom = from; + from = new int[from.length + 1]; + System.arraycopy(oldfrom, 0, from, 0, oldfrom.length); + from[oldfrom.length] = vars[oldvar]; + int[] oldto = to; + to = new int[to.length + 1]; + System.arraycopy(oldto, 0, to, 0, oldto.length); + to[oldto.length] = vars[newvar]; + pairing = bdd.createPermutation(from, to); } - + /* (non-Javadoc) - * @see net.sf.javabdd.BDDBitVector#getFactory() + * @see net.sf.javabdd.BDDPairing#set(int, net.sf.javabdd.BDD) */ - public BDDFactory getFactory() { return JDDFactory.this; } - + public void set(int oldvar, BDD newvar) { + throw new UnsupportedOperationException(); + } + + public void set(int[] oldvar, int[] newvar) { + int[] oldfrom = from; + from = new int[from.length + oldvar.length]; + System.arraycopy(oldfrom, 0, from, 0, oldfrom.length); + for (int i = 0; i < oldvar.length; ++i) { + from[i + oldfrom.length] = vars[oldvar[i]]; + } + int[] oldto = to; + to = new int[to.length + newvar.length]; + System.arraycopy(oldto, 0, to, 0, oldto.length); + for (int i = 0; i < newvar.length; ++i) { + to[i + oldto.length] = vars[newvar[i]]; + } + //debug(); + pairing = bdd.createPermutation(from, to); + } + + void debug() { + for (int i = 0; i < from.length; ++i) { + System.out.println(bdd.getVar(from[i])+" -> "+bdd.getVar(to[i])); + } + } + + /* (non-Javadoc) + * @see net.sf.javabdd.BDDPairing#reset() + */ + public void reset() { + from = to = new int[] { }; + pairing = null; + } + } - public static final String REVISION = "$Revision$"; - - /* (non-Javadoc) - * @see net.sf.javabdd.BDDFactory#getVersion() - */ - public String getVersion() { - return "JDD "+REVISION.substring(11, REVISION.length()-2); + public BDDPairing makePair() { + return new bddPairing(); } + + public void registerGCCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } + public void unregisterGCCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } + public void registerReorderCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } + public void unregisterReorderCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } + public void registerResizeCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } + public void unregisterResizeCallback(Object o, Method m) { + throw new UnsupportedOperationException(); + } } Modified: trunk/JavaBDD/net/sf/javabdd/JFactory.java =================================================================== --- trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-17 16:03:04 UTC (rev 460) +++ trunk/JavaBDD/net/sf/javabdd/JFactory.java 2006-07-21 14:32:02 UTC (rev 461) @@ -28,8 +28,16 @@ */ public class JFactory extends BDDFactoryIntImpl { - static final boolean VERIFY_ASSERTIONS = false; + /**** Options ****/ + + /** + * Flush the operation cache on every garbage collection. If this is false, + * we only clean the collected entries on every GC, rather than emptying the + * whole cache. For most problems, you should keep this set to true. + */ public static boolean FLUSH_CACHE_ON_GC = true; + + static final boolean VERIFY_ASSERTIONS = false; static final boolean CACHESTATS = false; static final boolean SWAPCOUNT = false; @@ -47,11 +55,20 @@ public static BDDFactory init(int nodenum, int cachesize) { BDDFactory f = new JFactory(); f.initialize(nodenum, cachesize); + if (CACHESTATS) addShutdownHook(f); return f; } - public boolean ZDD = false; + static void addShutdownHook(final BDDFactory f) { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + System.out.println(f.getCacheStats().toString()); + } + }); + } + boolean ZDD = false; + /** * Implementation of BDDPairing used by JFactory. */ @@ -122,7 +139,7 @@ protected void addref_impl(int v) { bdd_addref(v); } protected void delref_impl(int v) { bdd_delref(v); } protected int zero_impl() { return BDDZERO; } - protected int one_impl() {return BDDONE; } + protected int one_impl() { return BDDONE; } protected int invalid_bdd_impl() { return INVALID_BDD; } protected int var_impl(int v) { return bdd_var(v); } protected int level_impl(int v) { return LEVEL(v); } @@ -917,25 +934,20 @@ int bdd_not(int r) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(r, bddfalse); if (applycache == null) applycache = BddCacheI_init(cachesize); again : for (;;) { try { INITREF(); - - if (firstReorder == 0) - bdd_disable_reorder(); + if (numReorder == 0) bdd_disable_reorder(); res = ZDD ? znot_rec(r) : not_rec(r); - if (firstReorder == 0) - bdd_enable_reorder(); + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - if (firstReorder-- == 1) - continue again; - res = bddfalse; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } @@ -948,10 +960,8 @@ BddCacheDataI entry; int res; - if (ISZERO(r)) - return bddtrue; - if (ISONE(r)) - return bddfalse; + if (ISCONST(r)) + return 1 - r; entry = BddCache_lookupI(applycache, NOTHASH(r)); @@ -1007,7 +1017,7 @@ int bdd_ite(int f, int g, int h) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(f, bddfalse); CHECKa(g, bddfalse); @@ -1020,18 +1030,13 @@ try { INITREF(); - if (firstReorder == 0) - bdd_disable_reorder(); + if (numReorder == 0) bdd_disable_reorder(); res = ZDD ? zite_rec(f, g, h) : ite_rec(f, g, h); - if (firstReorder == 0) - bdd_enable_reorder(); + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - - if (firstReorder-- == 1) - continue again; - res = BDDZERO; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } @@ -1201,7 +1206,7 @@ int bdd_replace(int r, bddPair pair) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(r, bddfalse); @@ -1214,18 +1219,13 @@ replacelast = pair.last; replaceid = (pair.id << 2) | CACHEID_REPLACE; - if (firstReorder == 0) - bdd_disable_reorder(); + if (numReorder == 0) bdd_disable_reorder(); res = replace_rec(r); - if (firstReorder == 0) - bdd_enable_reorder(); + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - - if (firstReorder-- == 1) - continue again; - res = BDDZERO; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } @@ -1298,7 +1298,7 @@ int bdd_apply(int l, int r, int op) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(l, bddfalse); CHECKa(r, bddfalse); @@ -1315,29 +1315,22 @@ INITREF(); applyop = op; - if (firstReorder == 0) - bdd_disable_reorder(); + if (numReorder == 0) bdd_disable_reorder(); switch (op) { case bddop_and: res = ZDD ? zand_rec(l, r) : and_rec(l, r); break; case bddop_or: res = ZDD ? zor_rec(l, r) : or_rec(l, r); break; case bddop_diff: res = ZDD ? zdiff_rec(l, r) : apply_rec(l, r); break; default: res = apply_rec(l, r); break; } - if (firstReorder == 0) - bdd_enable_reorder(); + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - - if (firstReorder-- == 1) - continue again; - res = BDDZERO; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } - //validate(res); - checkresize(); return res; } @@ -1705,7 +1698,7 @@ int bdd_appex(int l, int r, int opr, int var) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(l, bddfalse); CHECKa(r, bddfalse); @@ -1734,18 +1727,16 @@ appexid = (var << 5) | (appexop << 1); /* FIXME: range! */ quantid = (appexid << 3) | CACHEID_APPEX; - if (firstReorder == 0) + if (numReorder == 0) bdd_disable_reorder(); res = opr == bddop_and ? relprod_rec(l, r) : appquant_rec(l, r); - if (firstReorder == 0) + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - if (firstReorder-- == 1) - continue again; - res = BDDZERO; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } @@ -2073,7 +2064,7 @@ int bdd_constrain(int f, int c) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(f, bddfalse); CHECKa(c, bddfalse); @@ -2085,18 +2076,16 @@ INITREF(); miscid = CACHEID_CONSTRAIN; - if (firstReorder == 0) + if (numReorder == 0) bdd_disable_reorder(); res = constrain_rec(f, c); - if (firstReorder == 0) + if (numReorder == 0) bdd_enable_reorder(); } catch (ReorderException x) { bdd_checkreorder(); - if (firstReorder-- == 1) - continue again; - res = BDDZERO; - /* avoid warning about res being uninitialized */ + numReorder--; + continue again; } break; } @@ -2166,7 +2155,7 @@ int bdd_compose(int f, int g, int var) { int res; - firstReorder = 1; + int numReorder = 1; CHECKa(f, bddfalse); CHECKa(g, bddfalse); @@ -2184,18 +2173,16 @@ composelevel = bddvar2level[var]; replaceid = (composelevel << 2) | CACHEID_COMPOSE; - if (firstReorder == 0) + if (numReorder == 0) bdd_disable_reorder(); res = compose_rec(f, g); - if (fir... [truncated message content] |
|
From: <joe...@us...> - 2006-07-17 16:03:09
|
Revision: 460 Author: joewhaley Date: 2006-07-17 09:03:04 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/javabdd/?rev=460&view=rev Log Message: ----------- Update maven project files to JavaBDD 2.0. Modified Paths: -------------- trunk/JavaBDD/project.xml Modified: trunk/JavaBDD/project.xml =================================================================== --- trunk/JavaBDD/project.xml 2006-07-17 15:54:24 UTC (rev 459) +++ trunk/JavaBDD/project.xml 2006-07-17 16:03:04 UTC (rev 460) @@ -5,7 +5,7 @@ <name>JavaBDD</name> <groupId>javabdd</groupId> <id>javabdd</id> - <currentVersion>1.0b2</currentVersion> + <currentVersion>2.0</currentVersion> <logo>/images/logo2_mid.jpg</logo> <organization> <name>John Whaley</name> @@ -80,6 +80,11 @@ <name>1.0b2</name> <tag>v1_0b2</tag> </version> + <version> + <id>2.0</id> + <name>2.0</name> + <tag>v2_0</tag> + </version> </versions> <mailingLists> <mailingList> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |