Skip to main content

Having 2 implemented Callback methods

Answered

Comments

3 comments

  • David Torres Sanchez
    Gurobi Staff 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 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

Please sign in to leave a comment.