I'm trying to modify the way Cplex does its branch & bound during optimization, using it's C++ API. What I actually want to do :
-Set parameters before calling the solve()
method. For example, using cplex.setParam(IloCplex::NodeSel, 0);
tells Cplex to do a DFS in the branch & bound tree.
-Once cplex has found the first incumbent (ie an integer solution to the problem), I would like to set this parameter to one (cplex.setParam(IloCplex::NodeSel, 1);
), which means Cplex should then do a best-bound search instead of a dfs in the tree.
I have tried to use the incumbent callback (which is executed whenever an integer solution is found) to set the parameter that way:
ILOINCUMBENTCALLBACK1(CustomIncumbentCallback, IloNumVarArray, vars){
cplex.setParam(IloCplex::NodeSel, 1);
...
}
and in main()
, before calling solve()
:
cplex.use(CustomIncumbentCallback(env));
However, it does not seem to work and the parameters keep their initial value, even when setParam
is called in a callback (I have made sure this callback is executed when an integer solution is found). Note that the cplex
variable is a global variable in my code.
My question is: Is it possible to modify the value of a parameter during the optimization (after solve()
is called, but before the end of it), and if so, how ?