Skip to main content

After using .feasRelax(), what should I do?

Answered

Comments

1 comment

  • Silke Horn
    Gurobi Staff Gurobi Staff

    When you call feasRelax, Gurobi modifies the model so that it computes the minimal violations necessary to make the model feasible. The new variables denote those violations, and the optimal objective value of the feasRelax model represents the total violation (sum of squares in your example). You can find more information about how to interpret the solution values in this article.

    Now, if you just want to know the value of your original objective in this solution (with the computed violations), you can save the objective to a variable (before calling feasRelax) and then call the getValue method after optimizing. E.g.:

    my_obj = m.getObjective()
    m.feasRelax(...)
    m.optimize()
    print(my_obj.getValue())

    However, it may also be interesting to look into the minrelax setting of the feasRelax function. If you set this to True, Gurobi will perform two steps:

    • First, it will compute the minimal violation. (The same as in your example code, but it will happen immediately after calling feasRelax.)
    • Gurobi will then restore your original objective. When you optimize, it will compute the optimal solution with respect to your original objective but only among those that minimize the cost of the violation.
    1

Please sign in to leave a comment.