Constraints in Gurobi
回答済みI have the following information:
My question is whether the following code represent the attached constraint:
state_OPM_term = gp.LinExpr()
state_OPM_term = gp.quicksum((b1["O+", "1", m, t] - (0.1 * gp.quicksum(b2["O+", "1", m, demand, t] for demand in D))* weights["O+", "1", m]) for m in M)
-
正式なコメント
This post is more than two 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 Shahrzad,
attached constraint
It looks like we are missing this.
- Riley
0 -
0 -
Hi Shahrzad,
This looks correct, however this line creates an empty linear expression:
state_OPM_term = gp.LinExpr()
The next line is overwriting it, not adding to it, so the first line is unnecessary.
Just a note on the terminology, the above is not a constraint until there is a relation introduced: "<=", ">=", "==", at the moment it is just a linear expression.
- Riley
0 -
Thank you so much Riley for your comment. As I'm using:
state_OPM_term = gp.quicksum((b1["O+", "1", m, t] - (0.1 * gp.quicksum(b2["O+", "1", m, demand, t] for demand in D))* weights["O+", "1", m]) for m in M)
as a linear expression in my objective function, would it be correct to have the following:
state_OPM_term = gp.quicksum((b1["O+", "1", m, t] - (0.1 * gp.quicksum(b2["O+", "1", m, demand, t] for demand in D))* weights["O+", "1", m]) for m in M)
obj = state_OPM_term + (the rest linear expressions)0 -
That should work without any problems. If you did something like this and found there was an error you should verify that state_OPM_term is a LinExpr (or some other type of expression like QuadExpr) by inspecting the value of type(state_OPM_term).
- Riley
0
投稿コメントは受け付けていません。

コメント
6件のコメント