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

Can I print values of integer variable during optimization?

回答済み

コメント

3件のコメント

  • 正式なコメント
    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.
  • 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

投稿コメントは受け付けていません。