本文整理匯總了Python中dd.bdd.BDD.quantify方法的典型用法代碼示例。如果您正苦於以下問題:Python BDD.quantify方法的具體用法?Python BDD.quantify怎麽用?Python BDD.quantify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dd.bdd.BDD
的用法示例。
在下文中一共展示了BDD.quantify方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_quantify
# 需要導入模塊: from dd.bdd import BDD [as 別名]
# 或者: from dd.bdd.BDD import quantify [as 別名]
def test_quantify():
ordering = {'x': 0, 'y': 1, 'z': 2}
g = BDD(ordering)
# x & y
e = g.add_expr('x && ! y')
x = g.add_expr('x')
not_y = g.add_expr('! y')
assert g.quantify(e, {'x'}) == not_y
assert g.quantify(e, {'x'}, forall=True) == -1
assert g.quantify(e, {'y'}) == x
assert g.quantify(e, {'x'}, forall=True) == -1
# x | y | z
e = g.add_expr('x || y || z')
xy = g.add_expr('x || y')
yz = g.add_expr('y || z')
zx = g.add_expr('z || x')
assert g.quantify(e, {'x'})
assert g.quantify(e, {'y'})
assert g.quantify(e, {'z'})
assert g.quantify(e, {'z'}, forall=True) == xy
assert g.quantify(e, {'x'}, forall=True) == yz
assert g.quantify(e, {'y'}, forall=True) == zx
# complement edges
u = -x
v = g.quantify(u, {'y'}, forall=True)
assert v == -x, g.to_expr(v)
# multiple values: test recursion
e = g.add_expr('x & y & z')
x = g.add_expr('x')
r = g.quantify(e, {'y', 'z'})
assert r == x, r
示例2: test_preimage
# 需要導入模塊: from dd.bdd import BDD [as 別名]
# 或者: from dd.bdd.BDD import quantify [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')