Skip to content

Commit

Permalink
make tests for solution hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceBleukx committed Jul 27, 2023
1 parent 122b827 commit fd9846f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_solvers_solhint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest

import cpmpy as cp
from cpmpy.exceptions import NotSupportedError


class TestSolutionHinting(unittest.TestCase):


def test_hints(self):

a,b = cp.boolvar(shape=2)
model = cp.Model(a ^ b)

for n, solver_class in cp.SolverLookup.base_solvers():
slv = solver_class(model)
try:
args = {"cp_model_presolve": False} if n == "ortools" else {} # hints are not taken into account in presolve

slv.solution_hint([a,b], [True, False])
self.assertTrue(slv.solve(**args))
self.assertEqual(a.value(), True)
self.assertEqual(b.value(), False)

slv.solution_hint([a,b], [False, True]) # check hints are correctly overwritten
self.assertTrue(slv.solve(**args))
self.assertEqual(a.value(), False)
self.assertEqual(b.value(), True)

slv.solution_hint([a,b], [True,True])
self.assertTrue(slv.solve(**args)) # should also work with an UNSAT hint

except NotSupportedError:
continue


0 comments on commit fd9846f

Please sign in to comment.