Skip to main content

Java Callback setSolution for CB_MIPSOL

Ongoing

Comments

7 comments

  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Tobias,

    Unfortunately, it is not possible to set a solution during the MIPSOL callback. You would need to store the information and add the new solution during the next MIPNODE callback.

    Cheers,
    Matthias

    0
  • Tobias Klein
    Gurobi-versary
    First Question
    First Comment

    Hi Matthias,

    that is unfortunate. But thank you for the quick answer!

    Best regards,

    Tobias Klein

    0
  • yi qi
    Gurobi-versary
    First Comment

    Hi Tobias,

        I am also using the SetSolution in GUROBI. As pointed by Matthias, there is no way to SetSolution during the MIPSOL callback, so i store the information and add the new solution during the next MIPNODE callback.

        But i don't know what will happen after seting SetSolution.  After we do like this:

        if (where == GRB.Callback.MIPNODE)

        {

                 SetSolution(Vars, values);

        }

        What else we have to do, then the GUROBI knows this is a better solution. Will GUROBI reoptimizes automaticly? 

        I try to find source code example on the SetSolution, but i can't find.

    Best regards,

    Hao YiSheng

    0
  • Tobias Achterberg
    Gurobi Staff Gurobi Staff

    With the "SetSolution()" call you are modifying the user solution that is stored in the callback object. So, you can, for example, call SetSolution() for each variable individually to specify all values, or you can overwrite previously specified values by new values with a second call. When you exit the callback function, Gurobi will then take the user specified solution and check whether it is feasible and whether it improves the current incumbent solution. If both is the case, this solution will become the new incumbent. If you specify values for only some of the variables, Gurobi will try to find values for the remaining ones by solving a sub-MIP.

    If you want to immediately see if your solution is accepted and what the solution objective value is, then you can call UseSolution() hafter having specified your solution via SetSolution(). This function will return the objective value of the solution if it was feasible and if it improved the incumbent. Otherwise, it will return GRB.INFINITY (1e+100).

    Regards,

    Tobias

     

    0
  • Charitha Heendeniya
    Gurobi-versary
    Collaborator
    Investigator

    Dear Tobias Achterberg

    If you specify values for only some of the variables, Gurobi will try to find values for the remaining ones by solving a sub-MIP.

    For example, say I have a problem with two variables, x and y. Then I write in the callback;

    if where == GRB.Callback.MIPSOL:
    val = model.cbGetSolution(model._x)
      val_new = []
    var_new = []

      # if the 2nd index of the x variable is "pupil", set a new heuristic value.
      for k, v in val.items():
    if k[-1] == 'pupil':
    val_new.append(val[k] / 3)
             var_new.append(model._x[k])

    model.cbSetSolution(var_new, val_new)

    I want to know whether Gurobi will try to re-optimize (by solving the subMIP) both the unspecified x and y variables. Thank you. 

    0
  • David Torres Sanchez
    Gurobi Staff Gurobi Staff

    Hi Charitha,

    Yes, this fits into Tobias' description. You are setting the value for a single variable.
    This is also mentioned in the model.cbSetSolution page.

    Cheers, 
    David

    0
  • Antonio Coppola
    Gurobi-versary
    First Comment

    Dear all,

    when useSolution() tries to produce an heuristic solution, does it check if it is feasible also w.r.t branching constraints added during the branch-and-cut algorithm?

    I am asking because I am sure to have a feasible solution which improves over the incumbent, which gets surely accepted by useSolution (i.e., that does not return INFINITY) only as long as I am in the root node, while during the branching it may or may not be accepted.
    If this is the case, how can I know which are the branching constraints added in the MIPNODE in which I'm feeding the solution? With this information I can modify accordingly my heuristic solution and use it.

    Thanks!

    0

Please sign in to leave a comment.