Skip to main content

How can I get the value of sub-optimal solutions in solpool by var name?

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Ronald van der Velden
    • Gurobi Staff

    Hi,

    When you call m.getVarByName(), the result is a Gurobi variable. You can then either get the optimal solution value using var.X or the value of any other solution in the pool using var.Xn (after setting SolutionNumber). The other way around, when you have a variable, then you can get its name using var.VarName.

    Here's a tiny example; see this page for a more extensive example.

    var = model.getVarByName('myvar')
    print(f'Optimal solution value: {var.X}')
    for i in range(model.SolCount):
    model.Params.SolutionNumber = i
    print(f'Value of {var.VarName} in solution #{i}: {var.Xn}')

    Kind regards,
    Ronald

    0
  • zichun ji
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you, Ronald. Problem solved.

    0

Post is closed for comments.