Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def test_can_multiply_associatively():
    solver = Solver()
    x = variable('x')
    assert solver.compile((x * 2) * 3 == x * 6) is True