Skip to main content

How do I model multiple conditional statements in gurobi?

Awaiting user input

Comments

2 comments

  • Official comment
    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.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Yonghyun,

    this will depend on the Gurobi API you choose.

    I assume that A, B, C, D are Gurobi integer variables. Now, to retrieve their values, you must have successfully optimized first, as otherwise, the following code will throw an error.

    For Python, it could look as follows:

    # we assume that A, B, C and D are pre-defined Gurobi variablex
    if (A.X > B.X) and (C.X > D.X):
     # CASE 1
    elif (A.X > B.X) and (C.X < D.X):
     # CASE 2

    elif (A.X < B.X) and (C.X > D.X):
     # CASE 3
    else:
     # CASE 4

    Hope this helps. 

    Best regards,
    Jonasz

    0

Post is closed for comments.