Skip to main content

How to update value of parameter during model iteration?

Answered

Comments

4 comments

  • Maliheh Aramon
    • Gurobi Staff Gurobi Staff

    Hi Tanmoy, 

    Do you mean your model formulation is parametrized based on a given \(p\) value?

    Gurobi Callbacks provide some flexibility such that you can add new lazy constraints to the model by the method Model.cbLazy() from within a callback function when the search tree is at a MIP node or when a MIP solution is found. 

    However, it seems to me that you would like to modify your model formulation depending on whether specific feasible solutions found or not. If this is the case, you can still use Gurobi Callbacks, terminate the Gurobi Optimizer as soon as a feasible solution with the specific criteria is found, update the model by removing/adding new constraints/variables, and then call optimize again on the model object. You might want to look at the article How do I change parameters in a callback?. In this article, parameters refer to Gurobi parameters, but this is a good example of how to use Gurobi Callbacks to conditionally terminate the solver.

    Best regards,

    Maliheh

    1
  • Tanmoy Das
    • Gurobi-versary
    • Investigator
    • Collaborator

    Hi Meliheh,

    Thanks for your reply. 

    Yes, I am trying to modify formulation based on feasible solution found. I will try out your suggestion and keep progress posted here.

    0
  • Ali Salah
    • Gurobi-versary
    • First Comment

    Hi Tanmoy,

    Did you solve this issue please? Because I want to update a parameter set value in an i+1 stage to start from its beginning value if a decision value of a binary variable become 1 in an ith stage. please let me know if you found a way to do that.

    1
  • Tanmoy Das
    • Gurobi-versary
    • Investigator
    • Collaborator

    I solved the “updating parameter” issue by using “for loop”,
    Steps in the for loop:
    1. Run the model.
    2. Once optimal solution found, gather them, update parameter I needed.
    3. Recreate new model & use updated parameters.
    Note: whatever I need from previous model, I’d store them in a dataframe when I am inside that model.
    Feel free to ask more specifics or tell more details about your problem.

    0

Please sign in to leave a comment.