本文整理汇总了Python中solver.Solver.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.compile方法的具体用法?Python Solver.compile怎么用?Python Solver.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solver.Solver
的用法示例。
在下文中一共展示了Solver.compile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_equalities_give_pseudo_boolean_constraints
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import compile [as 别名]
def test_equalities_give_pseudo_boolean_constraints(ls, m):
solver = Solver()
variables = [variable(i) for i in range(len(ls))]
objective = sum(l * v for l, v in zip(ls, variables))
constraint = solver.compile(objective == m)
pseudo_boolean = solver.builder.pseudo_boolean_constraint(
[(l, solver.compile(v)) for l, v in zip(ls, variables)], m, m)
assert constraint == pseudo_boolean
示例2: test_intervals_give_pseudo_boolean_constraints
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import compile [as 别名]
def test_intervals_give_pseudo_boolean_constraints(ls, m, n):
assume(m <= n)
solver = Solver()
variables = [variable(i) for i in range(len(ls))]
objective = sum(l * v for l, v in zip(ls, variables))
constraint = solver.compile((objective >= m) & (objective <= n))
pseudo_boolean = solver.builder.pseudo_boolean_constraint(
[(l, solver.compile(v)) for l, v in zip(ls, variables)], m, n)
assert constraint == pseudo_boolean
示例3: test_upper_bound_gives_pseudo_boolean_constraint
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import compile [as 别名]
def test_upper_bound_gives_pseudo_boolean_constraint(ls, m):
solver = Solver()
variables = [variable(i) for i in range(len(ls))]
objective = sum(l * v for l, v in zip(ls, variables))
constraint = solver.compile(objective <= m)
pseudo_boolean = solver.builder.pseudo_boolean_constraint(
[(l, solver.compile(v)) for l, v in zip(ls, variables)],
-sum(map(abs, ls)), m)
assert constraint == pseudo_boolean
示例4: test_can_multiply_associatively
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import compile [as 别名]
def test_can_multiply_associatively():
solver = Solver()
x = variable('x')
assert solver.compile((x * 2) * 3 == x * 6) is True