def test_graphpartitioning_quso_solve(): e, sol = solve_quso_bruteforce(problem.to_quso()) solution = problem.convert_solution(sol) assert solution in solutions assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert allclose(e, 1) e, sol = solve_quso_bruteforce(problem_weighted.to_quso()) solution = problem_weighted.convert_solution(sol) assert solution in solutions_weighted assert problem_weighted.is_solution_valid(solution) assert problem_weighted.is_solution_valid(sol) assert allclose(e, 1)
def test_qubo_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, obj)
def test_jobsequencing_quso_solve(): e, sol = solve_quso_bruteforce(L) solution = problem.convert_solution(sol) assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert solution in solutions assert allclose(e, obj_val)
def test_setcover_quso_solve(): e, sol = solve_quso_bruteforce(problem.to_quso()) solution = problem.convert_solution(sol) assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert solution == {0, 2} assert allclose(e, len(solution))
def test_numberpartitioning_quso_solve(): e, sol = solve_quso_bruteforce(problem_withsoln.to_quso()) solution = problem_withsoln.convert_solution(sol) assert solution in solutions_withsoln assert problem_withsoln.is_solution_valid(solution) assert problem_withsoln.is_solution_valid(sol) assert allclose(e, 0) e, sol = solve_quso_bruteforce(problem_withoutsoln.to_quso()) solution = problem_withoutsoln.convert_solution(sol) assert solution in solutions_withoutsoln assert not problem_withoutsoln.is_solution_valid(solution) assert not problem_withoutsoln.is_solution_valid(sol) assert e != 0
def test_bilp_quso_solve(): e, sol = solve_quso_bruteforce(problem.to_quso()) conv_solution = problem.convert_solution(sol) assert allclose(conv_solution, solution) assert problem.is_solution_valid(conv_solution) assert problem.is_solution_valid(sol) assert allclose(e, 2)
def test_AlternatingSectorsChain_quso_solve(): e, sol = solve_quso_bruteforce(problem.to_quso(True)) solution = problem.convert_solution(sol, True) assert solution == (-1, ) * 12 or solution == (1, ) * 12 assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert allclose(e, -66) # not pbc e, sol = solve_quso_bruteforce(problem.to_quso(False)) solution = problem.convert_solution(sol, True) assert solution == (-1, ) * 12 or solution == (1, ) * 12 assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert allclose(e, -65)
def test_vertexcover_quso_solve(): e, sol = solve_quso_bruteforce(problem.to_quso()) solution = problem.convert_solution(sol) assert solution == problem.convert_solution( [sol[i] for i in range(problem.num_binary_variables)] ) assert solution == {"a", "c"} assert problem.is_solution_valid(solution) assert problem.is_solution_valid(sol) assert allclose(e, 2)
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 )
def runtests(self): assert self.problem.solve_bruteforce() == self.solution e, sol = solve_qubo_bruteforce(self.problem.to_qubo()) assert self.is_valid(e, sol, False) e, sol = solve_quso_bruteforce(self.problem.to_quso()) assert self.is_valid(e, sol, True) for deg in (None, ) + tuple(range(2, self.problem.degree + 1)): e, sol = solve_puso_bruteforce(self.problem.to_puso(deg)) assert self.is_valid(e, sol, True) e, sol = solve_pubo_bruteforce(self.problem.to_pubo(deg)) assert self.is_valid(e, sol, False) assert (self.problem.value(self.solution) == puso_value( self.solution, self.problem) == e)