Skip to main content

How to compute the objective and feasibility of a manually given solution?

Answered

Comments

1 comment

  • Jaromił Najman
    • Gurobi Staff

    One easy way is to fix every variable to its sol value. The following pseudo code should give you an idea

    sol = ... # given solution values
    for var in model.getVars():
    # fix variable to its sol value
    var.lb = sol[var]
    var.ub = sol[var]

    # optimize model
    model.optimize()

    if model.status == GRB.OPTIMAL:
    print(model.ObjVal) # print objective value
    print(model.MaxVio) # print maximum violation of the solution

    if model.status == GRB.INFEASIBLE:
    # if given sol values are infeasible generate an IIS file called iis.ilp
    # to easily check why it is infeasible
    model.computeIIS()
    model.write("iis.ilp")

    For additional information please refer to the Attributes documentation and How does Gurobi compute the IIS for infeasible models?

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.