Inverted Indicator Constraint In Gurobipy
Solution 1:
The implication
y+z ≤ 5 ⇒ x = 1
can be rewritten as:
x = 0 ⇒ y+z ≥ 6
This can be directly implemented as an indicator constraint.
This is based on propositional logic. This is called transposition:
A ⇒ B
⇔
not B ⇒ not A
So in theory we have
y+z ≤ 5 ⇒ x = 1
⇔
x = 0 ⇒ y+z > 5
If x and y are integers we can say x = 0 ⇒ y+z ≥ 6
If they are continuous variables you could do: x = 0 ⇒ y+z ≥ 5.0001
(in practice I would do: x = 0 ⇒ y+z ≥ 5
and keep things ambiguous at y+z = 5
).
This is kind of a standard trick when using indicator constraints. It seems not everyone is aware of or appreciates this.
Solution 2:
The indicator syntax is
binary expression >> linear constraint
So your constraint is invalid. You need a different model that forces x to 1 when y + z ≤ 5. Assuming y, z are non-negative integers, try 6x + y + z ≥ 6.
Solution 3:
I think the best way to go with this one is to use the big-M approach Let reconsider the problem you are trying to model
If y+z <= 5thenx== 1
It is equivalent to if y+z-5 <= 0 then x==1
From here we need a logic that will turn on and off the variable x depending on the condition on the y+z-5
y + z - 5 <= M(1-x)
will do the trick. Note that the x will need to be 1 for the relationship to hold if y+z-5 <= 0
which is what we want. Similarly, x will be turned off (set to 0) if y+z-5 >= 0
I hope this helps
Post a Comment for "Inverted Indicator Constraint In Gurobipy"