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

Can I print values of integer variable during optimization?

回答済み

コメント

2件のコメント

  • Jaromił Najman
    • Gurobi Staff

    You can use callbacks.

    In particular, you can use the MIPSOL callback to get the latest found incumbent via the cbGetSolution method.

    Let's assume that you are interested in the value of a particular variable \(x_{\text{important}}\).

    def mycallback(model, where):
        if where == GRB.Callback.MIPSOL:
          print(model.cbGetSolution(model._importantvars))

    # [...]

    model = gp.Model()

    x_important = model.addVar(...)

    # [...]

    model._importantvars = [x_important] # you can also add more variables of interest to the list
    model.optimize(mycallback)

    Best regards, 
    Jaromił

    0
  • Rahul Mitra
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you! This was really helpful! 

    Rahul

    0

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