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

How to update the model after editing the coefficients.

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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?.
  • Greg Glockner
    • Gurobi Staff Gurobi Staff

    Unfortunately, what you want is not how the API works. Consider this small Python example:

    from gurobipy import *

    m = Model()
    c = [1, 2]
    x = m.addVars(2, name='x')
    m.addConstr(c[0]*x[0] + c[1]*x[1] <= 2)

    Once you call Model.addConstr(), it uses the values of c to create the constraint, without any reference to c. Any changes to c will not change the existing change.

    To change the constraint, you have 2 options:

    1. Remove the constraint and add the new one
    2. Call Model.chgCoeff() to modify the coefficient in the model

    Note that you would have this issue for any programming language, not just Python.

     

     

    0

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