How do I model multiple conditional statements in gurobi?
ユーザーの入力を待っています。I 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
-
正式なコメント
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. -
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 4Hope this helps.
Best regards,
Jonasz0
投稿コメントは受け付けていません。
コメント
2件のコメント