本文整理汇总了Python中sympy.logic.algorithms.dpll.dpll_satisfiable函数的典型用法代码示例。如果您正苦于以下问题:Python dpll_satisfiable函数的具体用法?Python dpll_satisfiable怎么用?Python dpll_satisfiable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dpll_satisfiable函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: satisfiable
def satisfiable(expr, algorithm="dpll2"):
"""
Check satisfiability of a propositional sentence.
Returns a model when it succeeds
Examples:
>>> from sympy.abc import A, B
>>> from sympy.logic.inference import satisfiable
>>> satisfiable(A & ~B)
{A: True, B: False}
>>> satisfiable(A & ~A)
False
"""
expr = to_cnf(expr)
if algorithm == "dpll":
from sympy.logic.algorithms.dpll import dpll_satisfiable
return dpll_satisfiable(expr)
elif algorithm == "dpll2":
from sympy.logic.algorithms.dpll2 import dpll_satisfiable
return dpll_satisfiable(expr)
raise NotImplementedError
开发者ID:hector1618,项目名称:sympy,代码行数:25,代码来源:inference.py
示例2: satisfiable
def satisfiable(expr, algorithm="dpll2", all_models=False):
"""
Check satisfiability of a propositional sentence.
Returns a model when it succeeds.
Returns {true: true} for trivially true expressions.
On setting all_models to True, if given expr is satisfiable then
returns a generator of models. However, if expr is unsatisfiable
then returns a generator containing the single element False.
Examples
========
>>> from sympy.abc import A, B
>>> from sympy.logic.inference import satisfiable
>>> satisfiable(A & ~B)
{A: True, B: False}
>>> satisfiable(A & ~A)
False
>>> satisfiable(True)
{True: True}
>>> next(satisfiable(A & ~A, all_models=True))
False
>>> models = satisfiable((A >> B) & B, all_models=True)
>>> next(models)
{A: False, B: True}
>>> next(models)
{A: True, B: True}
>>> def use_models(models):
... for model in models:
... if model:
... # Do something with the model.
... print(model)
... else:
... # Given expr is unsatisfiable.
... print("UNSAT")
>>> use_models(satisfiable(A >> ~A, all_models=True))
{A: False}
>>> use_models(satisfiable(A ^ A, all_models=True))
UNSAT
"""
expr = to_cnf(expr)
if algorithm == "dpll":
from sympy.logic.algorithms.dpll import dpll_satisfiable
return dpll_satisfiable(expr)
elif algorithm == "dpll2":
from sympy.logic.algorithms.dpll2 import dpll_satisfiable
return dpll_satisfiable(expr, all_models)
raise NotImplementedError
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:52,代码来源:inference.py
示例3: test_dpll_satisfiable
def test_dpll_satisfiable():
A, B, C = symbols('A,B,C')
assert dpll_satisfiable( A & ~A ) == False
assert dpll_satisfiable( A & ~B ) == {A: True, B: False}
assert dpll_satisfiable( A | B ) in ({A: True}, {B: True}, {A: True, B: True})
assert dpll_satisfiable( (~A | B) & (~B | A) ) in ({A: True, B: True}, {A: False, B:False})
assert dpll_satisfiable( (A | B) & (~B | C) ) in ({A: True, B: False}, {A: True, C:True})
assert dpll_satisfiable( A & B & C ) == {A: True, B: True, C: True}
assert dpll_satisfiable( (A | B) & (A >> B) ) == {B: True}
assert dpll_satisfiable( Equivalent(A, B) & A ) == {A: True, B: True}
assert dpll_satisfiable( Equivalent(A, B) & ~A ) == {A: False, B: False}
开发者ID:ALGHeArT,项目名称:sympy,代码行数:11,代码来源:test_inference.py
示例4: satisfiable
def satisfiable(expr, algorithm="dpll"):
"""Check satisfiability of a propositional sentence.
Returns a model when it succeeds
Examples
>>> from sympy import symbols
>>> A, B = symbols('AB')
>>> satisfiable(A & ~B)
{A: True, B: False}
>>> satisfiable(A & ~A)
False
"""
expr = to_cnf(expr)
if algorithm == "dpll":
from sympy.logic.algorithms.dpll import dpll_satisfiable
return dpll_satisfiable(expr)
raise NotImplementedError
开发者ID:ryanGT,项目名称:sympy,代码行数:17,代码来源:inference.py
示例5: main
def main():
with open(sys.argv[1]) as cnf_file:
cnf = load(cnf_file.read())
result = dpll_satisfiable(cnf)
print(result)
return 0
开发者ID:fokinpv,项目名称:SymbSAT,代码行数:6,代码来源:sympysat.py
示例6: test_f1
def test_f1():
assert bool(dpll_satisfiable(load(f1)))
开发者ID:ryanGT,项目名称:sympy,代码行数:2,代码来源:test_dimacs.py
示例7: test_f4
def test_f4():
# re-enable this when dpll is efficient
skip('Takes too much time')
assert not bool(dpll_satisfiable(load(f4)))
开发者ID:ryanGT,项目名称:sympy,代码行数:4,代码来源:test_dimacs.py
示例8: test_f3
def test_f3():
assert bool(dpll_satisfiable(load(f3)))
开发者ID:ryanGT,项目名称:sympy,代码行数:2,代码来源:test_dimacs.py
示例9: test_f2
def test_f2():
assert bool(dpll_satisfiable(load(f2)))
开发者ID:ryanGT,项目名称:sympy,代码行数:2,代码来源:test_dimacs.py
示例10: test_f4
def test_f4():
assert not bool(dpll_satisfiable(load(f4)))
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:2,代码来源:test_dimacs.py
示例11: test_f5
def test_f5():
assert bool(dpll_satisfiable(load(f5)))
开发者ID:AdrianPotter,项目名称:sympy,代码行数:2,代码来源:test_dimacs.py
注:本文中的sympy.logic.algorithms.dpll.dpll_satisfiable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论