Skip to main content

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

Answered

Comments

2 comments

  • Jaromił Najman
    Gurobi Staff 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

Please sign in to leave a comment.