Skip to content

Commit

Permalink
cleanup and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceBleukx committed Sep 21, 2023
1 parent 1c5ef0e commit 5543d5f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cpmpy/solvers/exact.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,8 @@ def solution_hint(self, cpm_vars, vals):
"""

cpm_vars = flatlist(cpm_vars)

vals = flatlist(vals)

assert (len(cpm_vars) == len(vals)), "Variables and values must have the same size for hinting"
try:
pkg_resources.require("exact>=1.1.5")
self.xct_solver.setSolutionHints(self.solver_vars(cpm_vars), vals)
Expand Down
3 changes: 0 additions & 3 deletions cpmpy/solvers/ortools.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,8 @@ def solution_hint(self, cpm_vars, vals):
self.ort_model.ClearHints() # because add just appends

cpm_vars = flatlist(cpm_vars)

vals = flatlist(vals)

assert (len(cpm_vars) == len(vals)), "Variables and values must have the same size for hinting"

for (cpm_var, val) in zip(cpm_vars, vals):
self.ort_model.AddHint(self.solver_var(cpm_var), val)

Expand Down
2 changes: 1 addition & 1 deletion cpmpy/solvers/pysat.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def solution_hint(self, cpm_vars, vals):
"""

cpm_vars = flatlist(cpm_vars)

vals = flatlist(vals)
assert (len(cpm_vars) == len(vals)), "Variables and values must have the same size for hinting"

literals = []
for (cpm_var, val) in zip(cpm_vars, vals):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_solvers_solhint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def test_hints(self):
slv.solution_hint([a,b], [True,True])
self.assertTrue(slv.solve(**args)) # should also work with an UNSAT hint

slv.solution_hint([a,[b]], [[[False]], True]) # check nested lists
self.assertTrue(slv.solve(**args))

except NotSupportedError:
continue

Expand Down

0 comments on commit 5543d5f

Please sign in to comment.