1

Dears, I need your help on that CP-SAT implementation. Here a simplified version of what I'm doing: assume that I have 3 boolean decision variables: x1, x2, x3 and boolean coefficents a1 a2 a3

model.Add(num == a1*x1+a2*x2+a3*x3)
model.Add(denom == x1+x2+x3)
model.Add(denom > 0)
model.AddDivisionEquality(division, num, denom)
model.Minimize(division)

When I solve it I receive MODEL_INVALID The divisor cannot span across zero in constraint: int_div { target { vars: 1004 coeffs: 1 } exprs { vars: 1002 coeffs: 1 } exprs { vars: 1003 coeffs: 1 } }

Seems the denominator is getting zero value temporary during the search. Is there a way to avoid this? Thanks!

  • Change your model. – Laurent Perron Aug 25 '22 at 11:17
  • I found the problem in the boundaries se in the NewIntVar definition, if I set from 1 to 100 instead that from -100 to 100 then It works....seems that the pre validation is checking that the variable can potentially assume 0 value and gives the model_Invalid status. Is there a way to set variable boundaries from -100 to 100 except 0? – stefano guerrieri Aug 25 '22 at 12:32
  • It will be rejected. The model validation checks the domain does not span across 0. – Laurent Perron Aug 25 '22 at 12:47
  • 1
    Potential division by zero is not the problem here, but rather that the constraints to enforce the equality are not set up to handle cases where the numbers may be both positive or negative. If you really need this, you can set up your model with two variables, one for the positive case, one for the negative case, and a boolean to decide which is applicable and enforce the relevant constraints. – Christopher Hamkins Aug 25 '22 at 14:15

0 Answers0