Skip to main content

unrelax a model

Answered

Comments

4 comments

  • Official comment
    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?.
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    When you relax a model in Python, a new model object is returned. So you should still have access to the original "unrelaxed" model. -G

    0
  • ghafour ahani
    Gurobi-versary
    First Comment
    First Question

    Correct. But, I am adding new variables to the relaxed model in an iterative process, and from time to time I need to switch back the model to integer form and solve the model.  Therefore, I need to switch back the relaxed model to the integer form, not the original one created at the begnining.

    Any help is appreciated.

     

    best,

    Ghafour

    0
  • Eli Towle
    Gurobi Staff Gurobi Staff

    The VType variable attribute gives the type of each variable. You can store the original types of all model variables in a new attribute, then switch all of the variables to continuous to build the relaxed model. Whenever you want to switch back to the integer form, revert all of the variable types to their original values using the new attribute.

    For example:

    # Store original variable types and relax model
    orig_vars = model.getVars()
    for v in orig_vars:
        v._VType = v.VType
        v.VType = GRB.CONTINUOUS

    # Do something with relaxed model here

    # Revert back to original variable types
    for v in orig_vars:
        v.VType = v._VType
    0

Post is closed for comments.