Skip to main content

Leveraging Gurobi Callbacks to Incorporate Expensive Heuristics into Optimization

Answered

Comments

2 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Mohammad,

    I think it would be a good idea to closely read the API doc for cbSetSolution.

    When you use 

    model.cbSetSolution(z_var,new_z_val)

    You are telling the solver you have a new solution, and that z_var = new_z_val, but this is then only a partial solution consisting of 1 variable - and Gurobi must try and complete the solution, which involves solving your model with fixed z.  Unless this solve is trivial then Gurobi would almost certainly abandon trying to complete the solution and ignore your attempt.

    However, I think the larger issue here is that this approach does not do what you want it to.  I will explain it with a simpler example:  minimize x, x >= 0, x is integer

    Solver: "I have a solution of x = 0"
    Callback: "Ok, now I have calculated that x should equal 2, so I will give you a solution with x = 2"
    Solver: "I have accepted your solution.  But x=0 is better, so I will now ignore your solution".

    The problem you are trying to solve might be better approached with gurobi-machinelearning where you first train a ML model to approximate g(x) - either with your data provided by your heuristic, or the data that the heuristic was trying to approximate - then embed the trained model in the optimization model.  There would be no use of callbacks in this approach.

    - Riley

    1
  • Mohammad Rohani Nezhad
    First Comment
    First Question

    Hi Riley

    Thank you for your thorough explanation, and I appreciated how you simplified the answer :). It appears I may have overestimated the callback, so I'll explore alternative approaches, particularly the one you suggested.

    Regards

    -M

    1

Please sign in to leave a comment.