Skip to main content

model parameter update on sequential model optimization

Answered

Comments

6 comments

  • Mario Ruthmair
    • Gurobi Staff

    Hi Iason,

    If I understood you correctly, in each iteration of your Benders algorithm, you need to adapt some coefficients in the model of your Benders subproblem.
    How did you change the coefficients? Could you paste the corresponding code snippet?
    Model.update() should take over the changes. Also, if you write the LP file after the changes, they should be reflected there.

    Best regards,
    Mario

    0
  • Iason Liagkas
    • Gurobi-versary
    • Detective
    • Thought Leader

    Hello Mario, what worked for me is to make a function that forms my LP model, and each time I want to update a parameter I call the function so the problem is formed again. My function includes the line SPmodel = gp.Model('SP'). I found out you can add constraints by using Model.update() but you cannot change the parameters this way. 

    Kind regards
    Iason

    0
  • Mario Ruthmair
    • Gurobi Staff

    Your function should not include "SPmodel = gp.Model('SP')" since this creates a new model in every function call instead of modifying an existing one. You should create the model once and then hand over SPmodel to your function.

    Then, with SPmodel.chgCoeff(), you can modify coefficients of variables in the constraints. For this, you need variable and constraint object references that you can either get with getVars() and getConstrs(), or by storing the return values of addVars() and addConstrs().

    0
  • Iason Liagkas
    • Gurobi-versary
    • Detective
    • Thought Leader

    Mario will the execution of the code be slower with my method? Do you have any handy example of how to use SPmodel.chgCoeff()

    Kind regards
    Iason

    0
  • Mario Ruthmair
    • Gurobi Staff

    If you create the model from scratch in each Benders iteration, it could lead to some runtime overhead, but it mainly depends on the size of the subproblem model. You could measure the time from SPmodel = g.Model('SP') to SPmodel.optimize() (without optimize()), and see whether the building time summed up over all iterations is significant.

    Unfortunately, I have not found a nice example for chgCoeff() in our example library, but you can find a few related posts in this community, e.g., this one.

    0
  • Iason Liagkas
    • Gurobi-versary
    • Detective
    • Thought Leader

    Thanks Mario, this example works. 

    Kind regards
    Iason

    0

Please sign in to leave a comment.