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

How do I model if elif else conditional statements in Gurobi?

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Hi Lenard,

    Note that your \(\texttt{if-else}\)-clause states that

    if delta_k == 1 or y_old == 1 then y = 1 else y = 0. I omitted the indices for better readability.

    Since all of your variables are binary, you could use Gurobi's or constraint to model your \(\texttt{if-else}\)-clause. 

    model.addConstr(y == or_(delta_k, y_old))

    Again, I omitted the indices for readability.

    Best regards, 
    Jaromił

    0
  • Lenard Ruede
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Jaromil,

    thank you very much!

    Best regards,

    Lenard

    0

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