Skip to main content

How do I model multiple conditional statements in gurobi?

Awaiting user input

Comments

1 comment

  • Jonasz Staszek
    Community Moderator 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

Please sign in to leave a comment.