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

Having 2 implemented Callback methods

回答済み

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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.
  • David Torres Sanchez
    • Gurobi Staff

    I think this can be achieved using a single callback (only one can be passed to Gurobi). In the callback example, using the MIP callback, you can check if the GAP is large enough and terminate early. This can be tweaked for more complex checks, for instance by passing your data to use in the callback.
    You can read more in the Callbacks section.

    If you can provide more details, it will be easier to help.

    Best,
    David

    0
  • MG
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you David,

    I have written an algorithm which uses the callback method to insert two types of lazy constraints. I  want to spilt this in two different callbacks. The first callback shoud add new constraints as much as possible. This happens in many iterations. After that I intend to run the second callback to add different types of constraints to my model but before doing that, I want that all the possible first type of constraints are added to my model.

    Did I explain it better ?

     

    0
  • David Torres Sanchez
    • Gurobi Staff

    I see! Yes, I think that should be possible. You can have two separate functions for this (outside or inside a single callback function up to you) that add the constraints as required.
    You'll need to pass all the data you need for this through the model private attributes (as described in the link in my previous comment), and the callback function will have to orchestrate everything.

    def myfunc(model):
    # you can use model._data here
      pass

    def mycallback(model, where):
      def myotherfunc():
           # you can use model._data here
          pass

    # model creation
    model.optimize(mycallback)

     

    0

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