Beispiel #1
0
def test_puso_quso_equal():

    random.seed(321)
    quso = {(i, j): random.random() for i in range(7) for j in range(7)}
    quso.update({(i, ): random.random() for i in range(7)})
    quso[()] = random.random()
    for sol in itertools.product((-1, 1), repeat=7):
        assert_allclose(puso_value(sol, quso), quso_value(sol, quso))
Beispiel #2
0
def test_qubo_quso_equal():

    random.seed(815)
    qubo = {(i, j): random.random() for i in range(7) for j in range(7)}
    qubo.update({(i, ): random.random() for i in range(7)})
    qubo[()] = random.random()
    for sol in itertools.product((0, 1), repeat=7):
        assert_allclose(qubo_value(sol, qubo),
                        quso_value(boolean_to_spin(sol), qubo_to_quso(qubo)))
Beispiel #3
0
def test_quso_quso_solve():

    e, sols = solve_quso_bruteforce(problem.to_quso())
    sol = problem.convert_solution(sols)
    assert problem.is_solution_valid(sol)
    assert problem.is_solution_valid(sols)
    assert sol == solution
    assert allclose(e, -10)

    assert (
        problem.value(sol) ==
        quso_value(sol, problem) ==
        e
    )