Skip to content

Commit

Permalink
fix mistake in implied cons
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceBleukx committed Mar 25, 2024
1 parent 46c9049 commit 3784fc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions cpmpy/solvers/choco.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,17 @@ def _get_constraint(self, cpm_expr):
elif cpm_expr.name == '->':
cond, subexpr = cpm_expr.args
if isinstance(cond, _BoolVarImpl) and isinstance(subexpr, _BoolVarImpl): # bv -> bv
bv, chc_var = self.solver_vars([cond, subexpr])
chc_cond, chc_subexpr = self.solver_vars([cond, subexpr])
elif isinstance(cond, _BoolVarImpl): # bv -> expr
bv = self._get_constraint(subexpr).reify()
chc_var = self.solver_var(cond)
chc_cond = self.solver_var(cond)
chc_subexpr = self._get_constraint(subexpr).reify()
elif isinstance(subexpr, _BoolVarImpl): # expr -> bv
bv = self._get_constraint(cond).reify()
chc_var = self.solver_var(subexpr)
chc_cond = self._get_constraint(cond).reify()
chc_subexpr = self.solver_var(subexpr)
else:
raise ValueError(f"Unexpected implication {cpm_expr}")

return self.chc_model.or_([~bv, chc_var])
return self.chc_model.or_([self.chc_model.bool_not_view(chc_cond), chc_subexpr])

else:
raise NotImplementedError("Not a known supported Choco Operator '{}' {}".format(
Expand Down
5 changes: 3 additions & 2 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
# make sure that `SolverLookup.get(solver)` works
# also add exclusions to the 3 EXCLUDE_* below as needed
SOLVERNAMES = [name for name, solver in SolverLookup.base_solvers() if solver.supported()]
SOLVERNAMES.remove("minizinc")

# Exclude some global constraints for solvers
# Can be used when .value() method is not implemented/contains bugs
EXCLUDE_GLOBAL = {"ortools": {},
"gurobi": {},
"minizinc": {"circuit"},
"pysat": {"circuit", "element","min","max","count", "nvalue", "allequal","alldifferent","cumulative", "invese"},
"pysat": {"circuit", "element","min","max","count", "nvalue", "allequal","alldifferent","cumulative", "inverse"},
"pysdd": {"circuit", "element","min","max","count", "nvalue", "allequal","alldifferent","cumulative",'xor', "inverse"},
"exact": {},
"choco": {"inverse"} # bug 1099 on Choco github
"choco": {}
}

# Exclude certain operators for solvers.
Expand Down

0 comments on commit 3784fc6

Please sign in to comment.