メインコンテンツへスキップ

Conditional stament in Gurobi

回答済み

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Maliheh Aramon
    • Gurobi Staff

    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
  • Nick Fryganiotis
    • Gurobi-versary
    • Conversationalist
    • Curious

    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
  • Maliheh Aramon
    • Gurobi Staff
    • 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

投稿コメントは受け付けていません。