Add Conditional Constraint
AnsweredHi,
I'm having constraints that should be activated once the solution of one variable is greater than a certain number.
For example: I have two variables x and y.
What I want to implement is:
if x>5: then f(x)>g(y). where f() and g() are certain expression of x and y.
if x<=5, then this constraint will not be activated.
How should I implement that?
Really appreciate!
-
Official comment
This post is more than three 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 why not try our AI Gurobot?. -
The reason I'm asking this is because every time I try to implement x>5 it reports:
'>' not supported between instances of 'Var' and 'float'
0 -
Hi,
Strict inequalities are not allowed in state-of-the-art optimization software due to compactness of the feasible set. The best thing you could model is an approximation of your statement which would be
if \(x\geq 5+\epsilon_1\) then \(f(x)\geq g(x) + \epsilon_2\)for some small positive \(\epsilon_1,\epsilon_2\).
You can achieve this by first modeling the relationship
if \(x\geq 5+\epsilon_1 \Leftrightarrow \delta=1\)
as described in this stackexchange post. This would be
\[\begin{align}
\epsilon_1&=10^{-6}\\
x &\geq 5+\epsilon_1 - 10\cdot(1-\delta)\\
x &\leq 5+\epsilon_1 + 10\cdot \delta\\
\delta &\in \{0,1\}
\end{align}\]
You can then use an indicator constraint to model the relationshipif \(\delta=1\) then \(g(y)+\epsilon_2-f(x) \leq 0\)
Best regards,
Jaromił0 -
Thanks a lot for your quick response Jaromił!
0
Post is closed for comments.
Comments
4 comments