-
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.
* implement solution hinting in exact * update error * make tests for solution hinting * update test
- Loading branch information
1 parent
014bd13
commit 3511d6d
Showing
3 changed files
with
59 additions
and
2 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
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
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,38 @@ | ||
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(): | ||
if not solver_class.supported(): | ||
continue | ||
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 | ||
|
||
|