Condition within a condition in constraint
ユーザーの入力を待っています。How could I model my constraints in general and implement in Python Gurobi with the following conditions:
when \(q=0 \rightarrow y=0\) and when \(q=1\),
\[\begin{equation}
y = \begin{cases}
d & \mathrm{if }\; d\leq b\\
b & \mathrm{otherwise.}
\end{cases}
\end{equation}\]
where \(q\) is a binary variable, \(y\) is a continuous variable and \(b\), \(d\) are constants.
-
正式なコメント
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 why not try our AI Gurobot?. -
If \(b,d\) are constants, you could determine whether \(d\leq b\) a priori and then implement your condition as
d = 5
b = 4
a = min(b,d)
q = m.addVar(vtype=GRB.BINARY,name="q")
y = m.addVar(vtype=GRB.CONTINUOUS,name="y")
m.addConstr(y == q * a)Best regards,
Jaromił0 -
Hi Jaromil,
these $b$ and $d$ aren't known a priori and are in the form of a list.
0 -
Hi Syed,
In this case, could you elaborate more on the nature of the \(b\) and \(d\) terms? If they are both constant parameters, then both values should be available when the model is constructed. Otherwise they depend on the values of some other optimization variables making \(b\) and \(d\) optimization variables as well. How does the fact that \(b,d\) are lists take effect here? Do you actually want to introduce multiple constraints of the above form or do you want to check whether all values in \(d\) are \(\leq\) than \(b\)?
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
4件のコメント