问题
Is there a software package (preferable an application, not library) that creates Reduced Ordered Binary Decision Diagrams (ROBDDs) from a given truth table (in some text format)?
回答1:
You can also try this: http://formal.cs.utah.edu:8080/pbl/BDD.php
It is the best tool for BDDs I used so far.
回答2:
With any BDD library you can do what you want. Of course, you must write a piece of code by yourself.
If you are looking for a lightweight tool, I often use an applet like this to have a quick look at the BDD of a function:
http://tams-www.informatik.uni-hamburg.de/applets/java-bdd/
回答3:
BDDs are a memory constrained data structure because of the heavy reliance on detecting duplicate sub-truthtables. Most BDD packages you'll find aren't exactly a good fit for large, general truth tables, instead optimized for very sparse or highly repetitive expressions.
With the standard BDD packages, you work with expressions operating on variables. So you'd have to iterate over your truth table, constructing something like a product-of-sums expression for 1s in the table. Along the way, most libraries will dynamically reorder the variables to fit memory constraints, causing another huge slowdown. After around 24 variables, even with very sparse truth tables, these libraries will start to thrash on modern systems.
If you're only looking for the final BDD nodes given a truth table with its variable ordering already implicitly defined, you can skip a lot of the complexity with external libraries and horrible runtimes, just using some Unix text processing tools.
A good resource on BDDs, Knuth's TAOCP v4.1b, shows the equivalence of BDD nodes and their "beads," sub-truthtables that are non-square strings. I'm going to address a simpler version, ZDDs which have similar structures called "zeads": positive part sub-truthtables that are not completely zero. To generalize back to BDDs, replace sed+grep in the pipeline with a program filtering square strings instead of keeping positive part non-zero strings.
To print all the zeads of a truthtable (given as a one-line file of ascii '1's and '0's, newline at end), run the following command after setting the number of variables and filename:
MAX=8; FILENAME="8_vars_truthtable.txt"; for (( ITER=0; ITER<=${MAX}; ITER++ )) ; do INTERVAL=$((2 ** ${ITER})); fold -w ${INTERVAL} ${FILENAME} | sed -n '1~2!p' | grep -v "^0*$" | sort -u ; done
This has many benefits over BDD packages:
- Simple with essentially no extraneous dependencies.
- External sorting means no thrashing unlike in-memory hash tables.
- Easily parallelizeable & scalable if you understand line buffering and disk caching when forking in the for loop.
- If writing to intermediate files sorting will parallelize too.
I use it regularly for truthtables up to 32 variables large, which are impossible to realistically come up with using BDD libraries. It doesn't tax the memory system at all, barely using a few MBs. But if you have a ton of RAM available, a decent OS like Linux will gladly use it all for caching disk to make it even faster.
回答4:
I also searched for something like that but could not find a javascript implementation.
I now created my own module which is capable of creating, minimizing and sort-optimising a bdd from a truth-table.
https://github.com/pubkey/binary-decision-diagram
来源:https://stackoverflow.com/questions/15610219/create-reduced-ordered-binary-decision-diagram-robdd-from-truth-table