当前位置: 首页>>代码示例>>Python>>正文


Python BDD.apply方法代码示例

本文整理汇总了Python中dd.bdd.BDD.apply方法的典型用法代码示例。如果您正苦于以下问题:Python BDD.apply方法的具体用法?Python BDD.apply怎么用?Python BDD.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dd.bdd.BDD的用法示例。


在下文中一共展示了BDD.apply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_quantifier_syntax

# 需要导入模块: from dd.bdd import BDD [as 别名]
# 或者: from dd.bdd.BDD import apply [as 别名]
def test_quantifier_syntax():
    b = BDD()
    [b.add_var(var) for var in ['x', 'y']]
    # constants
    u = b.add_expr('\E x: True')
    assert u == b.true, u
    u = b.add_expr('\E x, y: True')
    assert u == b.true, u
    u = b.add_expr('\E x: False')
    assert u == b.false, u
    u = b.add_expr('\A x: True')
    assert u == b.true, u
    u = b.add_expr('\A x: False')
    assert u == b.false, u
    u = b.add_expr('\A x, y: False')
    assert u == b.false, u
    # variables
    u = b.add_expr('\E x: x')
    assert u == b.true, u
    u = b.add_expr('\A x: x')
    assert u == b.false, u
    u = b.add_expr('\E x, y: x')
    assert u == b.true, u
    u = b.add_expr('\E x, y: y')
    assert u == b.true, u
    u = b.add_expr('\A x: y')
    assert u == b.var('y'), u
    u = b.add_expr('\A x: ! y')
    u_ = b.apply('not', b.var('y'))
    assert u == u_, (u, u_)
开发者ID:roon63,项目名称:dd,代码行数:32,代码来源:bdd_test.py

示例2: test_preimage

# 需要导入模块: from dd.bdd import BDD [as 别名]
# 或者: from dd.bdd.BDD import apply [as 别名]
def test_preimage():
    # exists: x, y
    # forall: z
    ordering = {'x': 0, 'xp': 1,
                'y': 2, 'yp': 3,
                'z': 4, 'zp': 5}
    rename = {0: 1, 2: 3, 4: 5}
    g = BDD(ordering)
    f = g.add_expr('!x')
    t = g.add_expr('x <-> !xp')
    qvars = {1, 3}
    p = preimage(t, f, rename, qvars, g)
    x = g.add_expr('x')
    assert x == p, (x, p)
    # a cycle
    # (x & y) -> (!x & y) ->
    # (!x & !y) -> (x & !y) -> wrap around
    t = g.add_expr(
        '((x & y) -> (!xp & yp)) && '
        '((!x & y) -> (!xp & !yp)) && '
        '((!x & !y) -> (xp & !yp)) && '
        '((x & !y) -> (xp & yp))')
    f = g.add_expr('x && y')
    p = preimage(t, f, rename, qvars, g)
    assert p == g.add_expr('x & !y')
    f = g.add_expr('x && !y')
    p = preimage(t, f, rename, qvars, g)
    assert p == g.add_expr('!x & !y')
    # backward reachable set
    f = g.add_expr('x & y')
    oldf = None
    while oldf != f:
        p = preimage(t, f, rename, qvars, g)
        oldf = f
        f = g.apply('or', p, oldf)
    assert f == 1
    # go around once
    f = g.add_expr('x & y')
    start = f
    for i in range(4):
        f = preimage(t, f, rename, qvars, g)
    end = f
    assert start == end
    # forall z exists x, y
    t = g.add_expr(
        '('
        '    ((x & y) -> (zp & xp & !yp)) | '
        '    ((x & y) -> (!zp & !xp & yp))'
        ') & '
        '(!(x & y) -> False)')
    f = g.add_expr('x && !y')
    ep = preimage(t, f, rename, qvars, g)
    p = g.quantify(ep, {'zp'}, forall=True)
    assert p == -1
    f = g.add_expr('(x & !y) | (!x & y)')
    ep = preimage(t, f, rename, qvars, g)
    p = g.quantify(ep, {'zp'}, forall=True)
    assert p == g.add_expr('x & y')
开发者ID:lummax,项目名称:dd,代码行数:60,代码来源:bdd_test.py


注:本文中的dd.bdd.BDD.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。