Issues With Error code 10003 (Python)
回答済みHi,
I'm trying to model the following constraint for a given file:
\[\sum_{i=1}^{n}(0.69q_i x_i + 0.3x_i p_i)x_i \ge 0\]
However I keep getting the Error Code 10003: Invalid argument to QuadExpr multiplication. Any input on how to workaround the issue would be helpful!
-
正式なコメント
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?. -
Hi Johnny,
The code depends on which terms are optimization variables.
If \(q_i,p_i\) are constant parameters, then you can model your constraint as
\[\sum_{i=1}^{n}((0.69q_i + 0.3p_i) x_i^2) \geq 0\]
or in Python code
import gurobipy as gp
from gurobipy import GRB
m = gp.Model("test")
I = [0,1,2]
q = [10,20,30]
p = [40,50,60]
x = m.addVars(I, vtype=GRB.BINARY, name="x")
m.addConstr(gp.quicksum( (0.69*q[i] + 0.3*p[i]) * x[i]*x[i] for i in I) >= 0, name="qc0")If terms \(q_i,p_i\) are optimization variables, then you cannot model this constraint directly, because Gurobi currently does not allow to introduce multivariate polynomial terms (other than bilinear terms), in this case \(q_i x_i^2\) and \(p_i x_i^2\). You would have to introduce auxiliary variables for, e.g., \(x_i^2\) and use these for the constraint construction.
\[\begin{align}
y_i &= x_i^2 \quad \forall i \in I\\
\sum_{i=1}^{n}((0.69q_i y_i + 0.3p_i y_i)) &\geq 0
\end{align}\]or in Python code
import gurobipy as gp
from gurobipy import GRB
m = gp.Model("test")
I = [0,1,2]
x = m.addVars(I, vtype=GRB.BINARY, name="x")
y = m.addVars(I, vtype=GRB.BINARY, name="y")
p = m.addVars(I, vtype=GRB.BINARY, name="p")
q = m.addVars(I, vtype=GRB.BINARY, name="q")
for i in I:
m.addConstr(y[i] == x[i]*x[i])
m.addConstr(gp.quicksum( (0.69*q[i]*y[i] + 0.3*p[i]*y[i]) for i in I) >= 0, name="qc0")To further comment on the Error Code you see, please post a code snippet reproducing the issue.
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント