I'm implementing in Java.
At the moment I'm trying to use BDDs (Binary Decision Diagramms) in order to store relations in a datastructure.
E.g. R={(3,2),(2,0)} and the corresponding BDD:
For this reason I was looking for libraries, which have BDD functionalities in order to help me.
I found two possibilities: JavaBDD and JDD.
But in both cases, I do not understand how I can encode a simple integer to a BDD, because how or when do I give the value of my integer? Or what does it mean, if the BDD is represented by an integer?
In both cases, there are methods like:
int variable = createBDD(); //(JBDD)
or
BDD bdd = new BDD(1000,1000);
int v1 = bdd.createVar(); // (JDD)
How can I simply create a BDD like my example?
Thank you very much!!
So I found a solution for this, but it is not very satisfying, as I cannot get the tuple back from the BDD without knowing, how many boolean variables I used for representing the integer in binary. So I have to define in the beginning for example: All my integers are smaller than 64, so they are represented by 6 binary variables. If I want to add a bigger integer than 64 afterwards I have a problem, but I don't want to use the maximum size of integers from the beginning, in order to save time, because I wanted to use BDDs in order to save running time, else there are a lot of easier things than BDDs for just representing tuples.
I use JDD as my BDD library, so in JDD BDDs are represented as integers.
So this is how I will get a BDD out of an integer tuple:
In the beginning you have to create the BDD-variables, the
maxVariableCount
is the maximum number of binary variables, which represent the integer (explained in the beginning of this answer):variablesDefinition
is just the number of integer variables I want to represent later in the BDD. So in the example of my question variablesDefinition would be 2, because each tuple has two intereger variables.The array
variables
is a two dimension array, which has all BDD variables inside. So for example if our tuple has 2 elements, the BDD variables which represent the first integer variable can be found invariables[0]
.Then we can create a bdd from a given integer tuple.
My first intention was to add these tuples to the BDD and afterwards being able to execute arithmetic functions in the integers in the BDD, but this is only possible after transforming the BDD back to tuples and executing the function and returning it to the BDD, which destroys all reasons why I wanted to use BDDs.