two side condition with binary
AnsweredHi!
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
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
2 comments