Skip to content

Commit

Permalink
translate int to bool for bool variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimosts committed Sep 21, 2023
1 parent 2911932 commit 98d29f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cpmpy/solvers/choco.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def solve(self, time_limit=None, **kwargs):
if has_sol:
# fill in variable values
for cpm_var in self.user_vars:
cpm_var._value = sol.get_int_val(self.solver_var(cpm_var))
value = sol.get_int_val(self.solver_var(cpm_var))
if isinstance(cpm_var, _BoolVarImpl):
cpm_var._value = bool(value)
else:
cpm_var._value = value

# translate objective
if self.has_objective():
Expand Down Expand Up @@ -194,7 +198,11 @@ def solveAll(self, display=None, time_limit=None, solution_limit=None, **kwargs)
for sol in sols:
# map the solution to user vars
for cpm_var in self.user_vars:
cpm_var._value = sol.get_int_val(self.solver_var(cpm_var))
value = sol.get_int_val(self.solver_var(cpm_var))
if isinstance(cpm_var, _BoolVarImpl):
cpm_var._value = bool(value)
else:
cpm_var._value = value
# print the desired display
if isinstance(display, Expression):
print(display.value())
Expand Down
3 changes: 2 additions & 1 deletion tests/test_solveAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_solveall_no_obj(self):
else:
count = solver.solveAll(solution_limit=1000, display=add_sol)
self.assertEqual(3, count)

self.assertSetEqual(sols,
{"[True, True]", "[True, False]", "[False, True]"})

def test_solveall_with_obj(self):

Expand Down

0 comments on commit 98d29f4

Please sign in to comment.