Conditional stament in Gurobi
AnsweredConsider a binary variable \(x_s(t)\), and a continuous variable \(z_s(t) = t - t_s\), where \(t_s\) is a known constant. We define a conditional variable \(sr_s(t) = x_s(t)\) if \(0 \leq z_s(t) < ht_s\), otherwise \(sr_s(t) = 0\). How could I implement this using Gurobi indicators? Should I define two indicator variables? One for the lower bound and one for the upper bound?
-
Please check the article How do I model conditional statements in Gurobi? which formulates a constraint very similar to the one you are interested in.
Best regards,
Maliheh
0 -
Thanks for the comment. I have seen the article you mention. The problem is that in my own case, the variable $z_s(t)$ is upper and lower bounded. I am not quite sure if that means that i need two variables $b_1$, and $b_2$, one for each bound respectively, and then a new variable $\hat_{b} = b_1 \cdot b_2$. Is there a simpler way?
Thank you in advance,
Nick
0 -
- If the continuous variable \(z_s(t)\) is defined with lower bound 0, you do not need any additional binary variable.
- If the variable \(z_s(t)\) can take negative values as well, you then need two binary variables:
\[\mbox{if}~ z_s(t) < 0 \rightarrow b_0=0, ~\mbox{and if}~ z_s(t) \geq 0 \rightarrow b_0=1\]
\[\mbox{if}~ z_s(t) < ht_s \rightarrow b_1=1, ~\mbox{and if}~ z_s(t) \geq ht_s \rightarrow b_1=0\]
You then need to define the binary variable \(b_2\) to equal 1 if both \(b_0\) and \(b_1\) are equal to 1. You can rely on the API for the simple general constraint And(). Finally you can model
\[\mbox{if}~ b_2=1 \rightarrow sr_s(t)=x_s(t), ~\mbox{and if}~ b_2= 0 \rightarrow sr_s(t)=0\]
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
3 comments