Skip to main content

Issues With Error code 10003 (Python)

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff

    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

Post is closed for comments.