メインコンテンツへスキップ

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

回答済み

コメント

2件のコメント

  • 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

サインインしてコメントを残してください。