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
-
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
Please sign in to leave a comment.
Comments
2 comments