-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
122b827
commit fd9846f
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|