メインコンテンツへスキップ

Single Constraint with Sum of Binary Variable

回答済み

コメント

3件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Eli Towle
    • 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
  • Pete Furseth
    • Gurobi-versary
    • First Comment
    • First Question

    Eli - That did the trick. Thank you.

    0

投稿コメントは受け付けていません。