In Java, I have set of expressions like cond1 AND (cond2 OR cond3) AND ( cond 4 OR cond5). I would like to convert it into tree and then evaluate the final boolean answer. I tried searching a lot around java BDD but not able to get any. Any suggestion with sample code ?
-
I think this BDD is Behaviour Driven Development. good luck with your question - I don't have a clue :) – nick Jan 19 '11 at 20:54
-
Do you want to evaluate an expression and get the results matching the expression? That's more like @Jochen's answer then anything to do with binary decision diagrams. – Andrew Dalke Jan 22 '11 at 18:30
3 Answers
A 5-second Google search returned some reasonable-looking results:
Is this not what you're looking for?
He means Binary Decision Diagrams.
I've been tinkering with JavaBDD and JBDD/JDD. Both are based on BuDDY (a C library) -- JBDD actually uses the C DLLs for a marginal performance boost.
It looks to me like JavaBDD is more fully-featured (ex. it supports composing BDDs, which is what I need). But there is also no tutorial for it, and while the class docs aren't terrible, frankly I can't figure out how to use it for the most basic of boolean operations (like the problem you pose).
JBDD/JDD requires you to use manual garbage collection, and does weird things like store BDD objects in Java integers -- clearly carry-overs from C. But it has a set of tutorials.

- 463
- 6
- 13
-
Update: This weekend I wrote a simple (and doubtless inefficient) BDD library, source code available [here](https://github.com/SigmaX/LightBDD). I haven't had time to make it presentable (i.e. write a nice readme and/or tutorial), and it's only been moderately tested, but it could be useful to you. – SigmaX Dec 12 '11 at 18:52
If you want to run your own parser, check out JavaCC. Here is a nice tutorial to get you started. A bit older, but still valid:

- 4,093
- 24
- 26