Skip to main content

About cbSetSolution() and cbUseSolution()

Answered

Comments

2 comments

  • Marika Karbstein
    • Gurobi Staff Gurobi Staff

    Hi Nicolás,

    I think there is some misunderstanding w.r.t. cbSetSolution() and cbUseSolution(): 

    Since I want to use this solution a soon as possible and not whenever Gurobi is available, when the callback is at MIPNODE and there is a stored MIP solution (this is a True/False condition that gets updated everytime I update/find a MIP soln) I call cbUseSolution(). 

    This is not necessary and does not work. If you find a new solution during the MIPSOL callback and set the variable values, Gurobi will try to compute a feasible solution from the specified values after the callback, see the documentation of Model.cbSetSolution()

    After the callback, if values have been specified for any variables, the Gurobi optimizer will try to compute a feasible solution from the specified values, possibly filling in values for variables whose values were left undefined. You can also optionally call cbUseSolution within your callback function to try to immediately compute a feasible solution from the specified values.

    The last sentence about optionally calling cbUseSolution is especially for the callback MIPNODE because solutions set during MIPNODE callback can immediately be processed. For MIP and MIPSOL the solution cannot be processed immediately but after the callback (and before a succeeding MIPNODE callback).

    This can also be seen in the log

    Saved Feasibilized Solution on MIPSOL of node 9.0
    Warning: Completing partial solution with 1500 unfixed non-continuous variables out of 1600
    Used feasibilized solution on node 9.0

    You set the solution values in the MIPNODE callback and then Gurobi tries to compute a feasible solution. The use-solution call in the MIPNODE callback does not do anything.

    Cheers,
    Marika

    0
  • Nicolas Zerega
    • Gurobi-versary
    • First Comment
    • First Question

    Dear Marika:

    I understand now! I thought that having the cbSetSolution() at MIPSOL and then calling cbUseSolution() at MIPNODE would use the stored solution.

    Thank you very much for the clarification!

    0

Please sign in to leave a comment.