Skip to main content

Single Constraint with Sum of Binary Variable

Answered

Comments

2 comments

  • Eli Towle
    Gurobi Staff Gurobi Staff

    Model.addConstrs() is used to add multiple constraints to the model. To add one constraint to the model, use Model.addConstr().

    You are summing over all \(i\) in \(V\), so the \(\texttt{for}\) loop should be placed inside of the summation:

    x = m.addVars(V, V, vtype=GRB.BINARY, name='x')
    m.addConstr(gp.quicksum(x[i, i] for i in V) == p)
    0
  • Peter Furseth
    Gurobi-versary
    First Comment
    First Question

    Eli - That did the trick. Thank you.

    0

Please sign in to leave a comment.