two side condition with binary
回答済みHi!
I have a binary x_in_grid, which is to decide if my variable X is in the range [0,5]
X is a continuous variable.
So, my constraints is : if 0<=X<=5, then x_in_grid==1
here is something I'm trying to do, but it doesn't work
model.addConstr(X >=0- M * (1 - x_in_grid))
model.addConstr(X <= 5+ M * x_in_grid)
0
-
Hi Haung,
Assuming X can only take non-negative values, you can model the condition "if 0<=X<=5, then x_in_grid==1" with the following constraints:
X <= 5 + M*(1-x_in_grid)
X >= 6*(1-x_in_grid)If X <= 5, x_in_grid will have to take value 1, as otherwise, the second constraint above will cause an infeasibility.
Best regards,
Simran0
サインインしてコメントを残してください。
コメント
1件のコメント