예제 #1
0
파일: bdd_test.py 프로젝트: maweki/dd
def test_rename():
    ordering = {'x': 0, 'xp': 1}
    g = BDD(ordering)
    x = g.add_expr('x')
    xp = g.add_expr('xp')
    dvars = {'x': 'xp'}
    xrenamed = _bdd.rename(x, g, dvars)
    assert xrenamed == xp, xrenamed
    ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5}
    g = BDD(ordering)
    u = g.add_expr('x && y && ! z')
    dvars = {'x': 'xp', 'y': 'yp', 'z': 'zp'}
    urenamed = _bdd.rename(u, g, dvars)
    up = g.add_expr('xp && yp && ! zp')
    assert urenamed == up, urenamed
    # assertion violations
    # non-neighbors
    dvars = {'x': 'yp'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(u, g, dvars)
    # u not in bdd
    dvars = {'x': 'xp'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(15, g, dvars)
    # y essential for u
    dvars = {'xp': 'y'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(u, g, dvars)
    # old and new vars intersect
    dvars = {'x': 'x'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(u, g, dvars)
예제 #2
0
파일: bdd_test.py 프로젝트: lummax/dd
def test_rename():
    ordering = {'x': 0, 'xp': 1}
    g = BDD(ordering)
    x = g.add_expr('x')
    xp = g.add_expr('xp')
    dvars = {'x': 'xp'}
    xrenamed = _bdd.rename(x, g, dvars)
    assert xrenamed == xp, xrenamed
    ordering = {'x': 0, 'xp': 1,
                'y': 2, 'yp': 3,
                'z': 4, 'zp': 5}
    g = BDD(ordering)
    u = g.add_expr('x && y && ! z')
    dvars = {'x': 'xp', 'y': 'yp', 'z': 'zp'}
    urenamed = _bdd.rename(u, g, dvars)
    up = g.add_expr('xp && yp && ! zp')
    assert urenamed == up, urenamed
    # assertion violations
    # non-neighbors
    dvars = {'x': 'yp'}
    r = _bdd.rename(u, g, dvars)
    r_ = g.add_expr('yp && y && ! z')
    assert r == r_, (r, r_)
    # u not in bdd
    dvars = {'x': 'xp'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(1000, g, dvars)
    # y essential for u
    dvars = {'xp': 'y'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(u, g, dvars)
    # old and new vars intersect
    dvars = {'x': 'x'}
    with nt.assert_raises(AssertionError):
        _bdd.rename(u, g, dvars)
예제 #3
0
def require_closure(z, aut):
    bdd = aut.bdd
    for p in aut.players:
        (action,) = aut.action[p]
        zp = _bdd.rename(z, bdd, aut.prime[p])
        stay = bdd.apply('and', z, zp)
        u = bdd.apply('and', action, stay)
        aut.action[p] = [u]
예제 #4
0
def image(source, aut):
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    pre = bdd.false
    for i, p in aut.turns.iteritems():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        (action,) = aut.action[p]
        qvars = aut.prime[p]
        u = symbolic.cofactor(source, ivar, i, bdd, aut.vars)
        u = bdd.apply('and', action, u)
        u = bdd.quantify(u, qvars, forall=False)
        u = _bdd.rename(u, bdd, aut.unprime[p])
        s = '{ivar} = {ip}'.format(ivar=ivar, ip=ip)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        pre = bdd.apply('or', pre, u)
    return pre
예제 #5
0
def image(source, aut):
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    pre = bdd.false
    for i, p in aut.turns.items():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        (action, ) = aut.action[p]
        qvars = aut.prime[p]
        u = symbolic.cofactor(source, ivar, i, bdd, aut.vars)
        u = bdd.apply('and', action, u)
        u = bdd.quantify(u, qvars, forall=False)
        u = _bdd.rename(u, bdd, aut.unprime[p])
        s = '{ivar} = {ip}'.format(ivar=ivar, ip=ip)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        pre = bdd.apply('or', pre, u)
    return pre
예제 #6
0
def ue_preimage(target, team, aut):
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    pre = bdd.false
    for i, p in aut.turns.iteritems():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars)
        u = _bdd.rename(u, bdd, aut.prime[p])
        (action,) = aut.action[p]
        if p not in team:
            u = bdd.apply('not', u)
        u = bdd.apply('and', action, u)
        u = bdd.quantify(u, aut.unprime[p], forall=False)
        if p not in team:
            u = bdd.apply('not', u)
        s = '{ivar} = {i}'.format(ivar=ivar, i=i)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        pre = bdd.apply('or', pre, u)
    return pre
예제 #7
0
def preimage(target, aut):
    """Predecessors with interleaving repr."""
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    # needed to force extra steps outside
    pre = bdd.false
    for i, p in aut.turns.iteritems():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars)
        (action,) = aut.action[p]
        u = _bdd.rename(u, bdd, aut.prime[p])
        u = bdd.apply('and', action, u)
        qvars = aut.unprime[p]
        u = bdd.quantify(u, qvars, forall=False)
        s = '{ivar} = {i}'.format(ivar=ivar, i=i)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        # TODO: revisit the index behavior
        pre = bdd.apply('or', pre, u)
    return pre
예제 #8
0
def ue_preimage(target, team, aut):
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    pre = bdd.false
    for i, p in aut.turns.items():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars)
        u = _bdd.rename(u, bdd, aut.prime[p])
        (action, ) = aut.action[p]
        if p not in team:
            u = bdd.apply('not', u)
        u = bdd.apply('and', action, u)
        u = bdd.quantify(u, aut.unprime[p], forall=False)
        if p not in team:
            u = bdd.apply('not', u)
        s = '{ivar} = {i}'.format(ivar=ivar, i=i)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        pre = bdd.apply('or', pre, u)
    return pre
예제 #9
0
def preimage(target, aut):
    """Predecessors with interleaving repr."""
    bdd = aut.bdd
    n = len(aut.players)
    ivar = '_i'
    # needed to force extra steps outside
    pre = bdd.false
    for i, p in aut.turns.items():
        assert i < n, (i, n)
        assert p in aut.players, (p, aut.players)
        ip = (i + 1) % n
        u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars)
        (action, ) = aut.action[p]
        u = _bdd.rename(u, bdd, aut.prime[p])
        u = bdd.apply('and', action, u)
        qvars = aut.unprime[p]
        u = bdd.quantify(u, qvars, forall=False)
        s = '{ivar} = {i}'.format(ivar=ivar, i=i)
        turn = aut.add_expr(s)
        u = bdd.apply('and', turn, u)
        # TODO: revisit the index behavior
        pre = bdd.apply('or', pre, u)
    return pre
예제 #10
0
파일: autoref.py 프로젝트: lummax/dd
def rename(u, bdd, dvars):
    r = _bdd.rename(u.node, u.bdd, dvars)
    return bdd._wrap(r)
예제 #11
0
def rename(u, bdd, dvars):
    r = _bdd.rename(u.node, u.bdd, dvars)
    return bdd._wrap(r)