How can I get the value of sub-optimal solutions in solpool by var name?
AnsweredI can get the value of optimal solution by m.getVarByName(), I wonder how can I do this to other solutions in the solution pool?
only found .Xn to get all the value, without var name information.
0
-
Official comment
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. -
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,
Ronald0 -
Thank you, Ronald. Problem solved.
0
Post is closed for comments.
Comments
3 comments