Creating conditional binary variables
AnsweredHey all
I'm pretty new to mathematical programming, and currently doing so through Python. I have a variable, lets call it X, that I need to be 1 if Y is greater than 0, else 0.
I'm struggling to find a way to linearize this constraint in a simple way as to not increase my solve time too much. Any suggestions are appreciated!
-
Hi Summer,
You could try \(Y \leq M \cdot X\), where \(M\) is a number that is at least as large as the upperbound of \(Y\). Ideally you keep \(M\) as tight as possible to avoid running into numerical issues.If you also want to force \(X=0\) when \(Y=0\) then you would need a second constraint. But in many cases this is either irrelevant, or the objective function automatically enforces this relationship (e.g. when there's a cost associated to \(X\).
Kind regards,
Ronald0 -
In addition to Ronald's reply, you can also refer to the Knowledge Base article How do I model conditional statements in Gurobi? which describes how to use indicator constraints.
0
Please sign in to leave a comment.
Comments
2 comments