How do I model multiple conditional statements in gurobi?
Awaiting user inputI want to use two if statements using binary variables, but I don't know how to use them.
Can two if statements are used in Gurobi? Examples are as follows.
A, B, C, and D are integer variables.
if (A > B) and (C>D) then,
CASE 1
else if (A > B) and (C<D) then,
CASE 2
else if (A < B) and (C>D) then,
CASE 3
else
CASE 4
0

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 predefined 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 4Hope this helps.
Best regards,
Jonasz0
Please sign in to leave a comment.
Comments
1 comment