Java Callback setSolution for CB_MIPSOL
OngoingHi,
during my Callback, I want to set a better solution for some of my variables. During CB_MIPNODE, i can do this with the setSolution()  method.
But setSolution can only be called during CB_MIPNODE, and not CB_MIPSOL. Is there any way to achieve the same when the callbackcode is CB_MIPSOL?
Hint: I am currently solving variations of the TSP with Drones and separate the Drones from the Trucks. I solve the TruckPart in a simple TSP and want to use the solution of the TSP as a heuristicvalue in the original problem.
Best regards,
Tobias Klein

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,
Matthias0 
Hi Matthias,
that is unfortunate. But thank you for the quick answer!
Best regards,
Tobias Klein
0 
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 
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 subMIP.
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 
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 subMIP.
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 reoptimize (by solving the subMIP) both the unspecified x and y variables. Thank you.
0 
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,
David0 
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 branchandcut 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.
Comments
7 comments