Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  dynamic cutcallback on the platform of cpp

    Posted 07/02/12 08:44 AM

    Originally posted by: SystemAdmin


    Hi,

    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. Now my questions are as following:
    1. How can I get the solution of the relaxation at each node?
    2. After I get the solution, how can I generate and add the cuts dynamically?
    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?
    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').

    Many thanks in advance and look forward for your reply.

    Best

    xjz
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: dynamic cutcallback on the platform of cpp

    Posted 07/04/12 05:54 PM

    Originally posted by: SystemAdmin


    > xjzheng wrote:
    > 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


  • 3.  Re: dynamic cutcallback on the platform of cpp

    Posted 07/04/12 10:33 PM

    Originally posted by: SystemAdmin


    Many Thanks, Paul. Based on your suggestion, I have switched to C API. However, I still have problem. In your reply, you mentioned I can generate all cuts at once. However, in my case, the cuts can not be generated until I know the optimal solution to the relaxation at each node. Thus, I can only add a cut at each node after I get the optimal solution to the relaxation at this node. Thus my question again: How to generate the cut dynamically? More sepcifically, if I get a relaxation solution x0 at node i, Then I will add cut
    x0(i)*x(i)<=5, i=1,...,n
    Here I suppose x is the variable in my algorithm of dimension n.

    Many thanks in advance.

    Best wishes

    xjz
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: dynamic cutcallback on the platform of cpp

    Posted 07/05/12 05:25 PM

    Originally posted by: SystemAdmin


    I'm afraid I do not understand what you are asking. I understand what you are trying to do, just not the question itself. You will attach a user cut callback to the solver instance. Inside that callback, you will use the appropriate CPLEX function to get the variable values (the specific function varies from API to API), you will use those values to compute your cut, and you will use the corresponding callback function (again dependent on the API) to add the cut to the problem.

    In your original question, it sounded as though you intended to generate n cuts at each node, which is why I said you would have to queue up the cuts -- you can create as many cuts as you want in one invocation of the callback, but you can only add one at a time. If you are only computing one cut per node, disregard that.

    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