Originally posted by: SystemAdmin
>
> Since now it is not supported to add user's cutcallback on the platform of matlab, thus I switched to C++. I use ILOG cplex 12.4. The example iloadmipex5.cpp showed us an exmaple to add user's cuts. However, my aim is a bit different. My cut is based on the solution of the relaxation of each node. For example, if the solution of the relaxation at node i is x0. Then we will add n cuts: x0(i)*x(i)<=5.
Since you mentioned user cut callbacks, I will assume that your generated cuts are user cuts, meaning that they do not cut off any integer-feasible solutions.
>Now my questions are as following:
> 1. How can I get the solution of the relaxation at each node?
IloCplex::UserCutCallback::getValues
> 2. After I get the solution, how can I generate and add the cuts dynamically?
Generating the cuts is a matter of coding your algorithm (within the UserCutCallback instance). Once you have created the cuts, call IloCplex::UserCutCallback::add once for each cut. Each time you call add, CPLEX will update the node solution and then immediately call the user cut callback again. So you might want to generate all the cuts at once, the first time the callback is called at the node, and store the cuts in a collection. Each time the callback is entered, if the collection is not empty, skip the parts where you get the solution and compute cuts, and instead just pop one cut from the collection and add it.
> 3. I hope the cuts I generated at node i will be added to original problem as a constraint, rather than delete is at node i+1, in the manual, it is said it should be deleted. If I want to reserve the cuts, can I? And How?
I'm not sure what you are asking here. If you use add() (rather than addLocal()) and omit the optional second argument to add(), the cuts will be global and CPLEX will not drop them during the solution process.
If you want to store the cuts (so that you can print them, or add them to the model after the solution process has ended), just store each one in global memory. After solve() returns, you can add all the stored cuts to the model if you wish.
> 4. In order to check whether I add the right cut at each node, can I get the problem formulation for the relaxation problem at each node, like cplex.exportModel('cplex.lp').
You cannot export the model during the solution process, and if you export it after solve() returns, you will only export the original model (not the added cuts). As I mentioned in the previous point, though, you can either print the cuts or store them and add them to the model after solve() returns (then export the modified model).
I believe (not positive) that you can access node LPs using the C API, but not the C++ API.
Paul
Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
#CPLEXOptimizers#DecisionOptimization