CPMpy/cpmpy

Negative Boolvars in objective not supported for linear solvers

Opened this issue · 0 comments

Boolean variables do not get converted to positive ones in the objective for linear solver such as gurobi or Exact.

import cpmpy as cp

a,b,c = cp.boolvar(shape=3)
m = cp.Model(cp.any([a,b,c]))
m.minimize(3*a + 4 * ~b + 3 * ~c)
m.solve(solver="gurobi") # error
m.solve(solver="exact") # error

To fix this, there are two options:

  1. Either we create a new variable "obj_var" and add the constraint obj_var == obj_func to the model and minimize the objective variable. This way the negative Boolean variables are removed by only_positive_bv when going through the transformation chain
  2. Or we create a new transformation "only_positive_bv_obj" which converts the negative Boolean variables in the objective to 1-bv directly

Not sure what is prefered