Beispiel #1
0
def test_copy_bdd_same_indices():
    # each va has same index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
        other.add_var(var)
    s = '(x & y) | !z'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, bdd, other)
    u2 = cudd.copy_bdd(u1, other, bdd)
    # involution
    assert u0 == u2, (u0, u2)
    # confirm
    w = other.add_expr(s)
    assert w == u1, (w, u1)
    # different nodes
    u3 = cudd.copy_bdd(other.true, other, bdd)
    assert u3 != u2, (u3, u2)
    # same bdd
    with assert_raises(AssertionError):
        cudd.copy_bdd(u0, bdd, bdd)
    del u0, u1, u2, u3, w
Beispiel #2
0
def test_copy_bdd_same_indices():
    # each va has same index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
        other.add_var(var)
    s = '(x & y) | !z'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, bdd, other)
    u2 = cudd.copy_bdd(u1, other, bdd)
    # involution
    assert u0 == u2, (u0, u2)
    # confirm
    w = other.add_expr(s)
    assert w == u1, (w, u1)
    # different nodes
    u3 = cudd.copy_bdd(other. True, other, bdd)
    assert u3 != u2, (u3, u2)
    # same bdd
    with assert_raises(AssertionError):
        cudd.copy_bdd(u0, bdd, bdd)
    del u0, u1, u2, u3, w
Beispiel #3
0
def test_copy_bdd_different_indices():
    # each var has different index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
    for var in reversed(dvars):
        other.add_var(var)
    u0 = bdd.add_expr('(x | !y) & !z')
    with assert_raises(AssertionError):
        cudd.copy_bdd(u0, bdd, other)
Beispiel #4
0
def test_copy_bdd_different_indices():
    # each var has different index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
    for var in reversed(dvars):
        other.add_var(var)
    u0 = bdd.add_expr('(x | !y) & !z')
    with assert_raises(AssertionError):
        cudd.copy_bdd(u0, bdd, other)
    del u0
Beispiel #5
0
def test_copy_bdd_same_indices():
    # each va has same index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
        other.add_var(var)
    s = '(x /\ y) \/ ~ z'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, other)
    u2 = cudd.copy_bdd(u1, bdd)
    # involution
    assert u0 == u2, (u0, u2)
    # confirm
    w = other.add_expr(s)
    assert w == u1, (w, u1)
    # different nodes
    u3 = cudd.copy_bdd(other.true, bdd)
    assert u3 != u2, (u3, u2)
Beispiel #6
0
def test_copy_bdd_same_indices():
    # each va has same index in each `BDD`
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z']
    for var in dvars:
        bdd.add_var(var)
        other.add_var(var)
    s = '(x /\ y) \/ ~ z'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, other)
    u2 = cudd.copy_bdd(u1, bdd)
    # involution
    assert u0 == u2, (u0, u2)
    # confirm
    w = other.add_expr(s)
    assert w == u1, (w, u1)
    # different nodes
    u3 = cudd.copy_bdd(other.true, bdd)
    assert u3 != u2, (u3, u2)
Beispiel #7
0
def test_copy_bdd_different_order():
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z', 'w']
    for index, var in enumerate(dvars):
        bdd.add_var(var, index=index)
        other.add_var(var, index=index)
    # reorder
    order = dict(w=0, x=1, y=2, z=3)
    cudd.reorder(other, order)
    # confirm resultant order
    for var in order:
        level_ = order[var]
        level = other.level_of_var(var)
        assert level == level_, (var, level, level_)
    # same indices
    for var in dvars:
        i = bdd._index_of_var[var]
        j = other._index_of_var[var]
        assert i == j, (i, j)
    # but different levels
    for var in dvars:
        i = bdd.level_of_var(var)
        j = other.level_of_var(var)
        assert i != j, (i, j)
    # copy
    s = '(x | !y) & w & (z | !w)'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, bdd, other)
    u2 = cudd.copy_bdd(u1, other, bdd)
    assert u0 == u2, (u0, u2)
    u3 = cudd.copy_bdd(other.false, other, bdd)
    assert u3 != u2, (u3, u2)
    # verify
    w = other.add_expr(s)
    assert w == u1, (w, u1)
    del u0, u1, u2, u3, w
Beispiel #8
0
def test_copy_bdd_different_order():
    bdd = cudd.BDD()
    other = cudd.BDD()
    assert bdd != other
    dvars = ['x', 'y', 'z', 'w']
    for index, var in enumerate(dvars):
        bdd.add_var(var, index=index)
        other.add_var(var, index=index)
    # reorder
    order = dict(w=0, x=1, y=2, z=3)
    other.reorder(order)
    # confirm resultant order
    for var in order:
        level_ = order[var]
        level = other.level_of_var(var)
        assert level == level_, (var, level, level_)
    # same indices
    for var in dvars:
        i = bdd._index_of_var[var]
        j = other._index_of_var[var]
        assert i == j, (i, j)
    # but different levels
    for var in dvars:
        i = bdd.level_of_var(var)
        j = other.level_of_var(var)
        assert i != j, (i, j)
    # copy
    s = '(x \/ ~ y) /\ w /\ (z \/ ~ w)'
    u0 = bdd.add_expr(s)
    u1 = cudd.copy_bdd(u0, other)
    u2 = cudd.copy_bdd(u1, bdd)
    assert u0 == u2, (u0, u2)
    u3 = cudd.copy_bdd(other.false, bdd)
    assert u3 != u2, (u3, u2)
    # verify
    w = other.add_expr(s)
    assert w == u1, (w, u1)