Python - Creating simple Algebraic Decision Diagram (ADD) with py-mdd or dd packages

I would like to create and ouput a graphical representation with Python 3 of an Algebraic Decision Diagram (ADD) [Bahar et al.].

Here an example of an ADD to output:

ADD example with two nodes and three sinks

The inputs a and b are Boolean values. A plain edge corresponds to set the variable to True, and a dotted edge to False. The outputs are integers.

The function in the example could be expressed as:

def my_function(a, b):
    if a == False and b == False:
       return 2
    if a == False and b == True:
       return 1
    if a == True and b == False:
       return 1
    if a == True and b == True:
       return 0

Or as a list of dictionnaries:

my_add = [{'a': False, 'b': False, 'output': 2},
          {'a': False, 'b': True, 'output': 1},
          {'a': True, 'b': False, 'output': 1},
          {'a': True, 'b': True, 'output': 0},]

How can I generate the graphical representation of this function as an ADD?

Which package is better suited for that: dd or py-mdd?

Many thanks!

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum