gurobipy.GurobiError: Invalid argument to QuadExpr multiplication
AnsweredHello,
I've been trying to formulate a basic optimization problem in python,
the warning code are as follows:
la = m.addVars(fullhour, vtype=GRB.CONTINUOUS, name="la", ub=1, lb=0)
ll = m.addVars(fullhour, vtype=GRB.CONTINUOUS, name="ll", ub=1, lb=0)
P = m.addVars(fullhour, vtype=GRB.CONTINUOUS, name="P")
L = m.addVars(fullhour, vtype=GRB.CONTINUOUS, name="L")
for t in range(14):
m.addConstr(ll[t] == la[t] * la[t])
expr == -1* ll[t] + 7 * la[t] + 0.6
m.addConstr(L[t] == P[t] * expr)
gurobi error: m.addConstr(L[t] == P1[t] * expr1)
File "src\gurobipy\quadexpr.pxi", line 555, in gurobipy.QuadExpr.__mul__
File "src\gurobipy\quadexpr.pxi", line 292, in gurobipy.QuadExpr._mul
gurobipy.GurobiError: Invalid argument to QuadExpr multiplication
How can I solve it? I don't understand if there are any prohibited multilinear terms in the code. Any suggestions will be much appreciated.
-
Hi Aria,
I would guess that the issue is about the \(\texttt{expr}\) object.
You don't assign a value to it but you check for equality, you use \(\texttt{==}\) instead of \(\texttt{=}\).
Then, the
m.addConstr(L[t] == P[t] * expr)
is outside of the \(\texttt{for}\)-loop.
Instead of using an intermediate \(\texttt{expr}\) object, you could directly model
m.addConstr(L[t] == P[t] * -1 * ll[t] + 7 * P[t] * la[t] + 0.6 * P[t])
On a side note: The error seems to not match the snippet, because there is a \(\texttt{expr1}\) in the error which is not present in your snippet.
Best regards,
Jaromił1 -
Hi Jaromił,
The error messages I was encountering with previous code have been resolved.
Thank you.
0
Please sign in to leave a comment.
Comments
2 comments