How to write if condition in python gurobi 9.5?
回答済みits my first time using gurobi. I am trying to implement the following code via if statement however i keep getting errors .
m.addConstrs(p2g[t]==0 for t in range(A) if pv_generation[t]<=load[t] pfor t in range(A) )
m.addConstrs(p2g[t]==p2g[t] for t in range(A) if pv_generation[t]>load[t] for t in range(A))
I tried indicator constraint and got this error (unsupported operand type(s) for -=: 'NoneType' and 'float') . I guess the indicator constraint doesn't work with multi-constraint (m.addConstrs), but only works with (m.addConstr)
Please can you provide me with and examples of using if statement in gurobi 9.5
-
\(\texttt{if}\)-statements cannot be directly implemented into Gurobi when using optimization variables. Thus, one has to model an \(\texttt{if}\)-condition with the help of binary variables and additional constraints. I think that the KB article How do I model conditional statements in Gurobi? is what you are looking for.
Best regards,
Jaromił0
サインインしてコメントを残してください。
コメント
1件のコメント