Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How to extract and save CPLEX-generated cuts?

  • 1.  How to extract and save CPLEX-generated cuts?

    Posted 09/11/14 05:02 PM

    Originally posted by: maiklb2005


    I was wondering how to extract and save CPLEX-generated cuts such as Gomory cuts after the optimization is interrupted or complete (by default CPLEX outputs only cuts' names and their number, but not the cuts themselves).


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/12/14 02:58 AM

    Originally posted by: T_O


    This is a highly nontrivial task, but still possible.

    First of all: You have to use the C callable library.

    Here is a short summary of the procedure: Use a callback to inspect the root LP. Then you can obtain the rows, that have greater index than m. These are the cuts. Do this until CPLEX starts branching.

    Best regards,
    Thomas

    P.S.: Please do not ask the same question in several forums.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/22/14 04:58 PM

    Originally posted by: maiklb2005


    Thank you. I have found the appropriate library to do so: it is in the admipex1.c. What it does is it outputs the formulation along with the cuts into an .lp file, thus it extracts and saves the cuts.

    The difficulty with the resulting output .lp file is the following: sometimes original constraints are overwritten by stronger cuts. What is leads to, for example, is that a c1 constraint in the original formulation and a c1 constraint in the output .lp file are different. Also, alpha-numeric indicators that correspond to cuts are not necessarily of the formal c1, c2, ...etc. Rather, cuts have indicators that involve other letters, such as, "v," "m," "i" ... etc.

    To illustrate the issue, allow me to provide an example that I have been considering (for the sake of brevity, I will show only constraints): 

     c1: 35 x1 + 51 x2 + 67 x3 + 100 x4 <= 150

    then the constraints/cuts in the output .lp file are:

     c1: 35 x1 + 51 x2 + 67 x3 + 83 x4 <= 118
     c2: 3 x2 + 4 x4 - x5  = 0
     v0: x2 + x3 <= 1
     i1: x3 + 0.25 x5 <= 1

    The formulation with resulting constraints is no longer recognized as a MIP problem (CPLEX Error 3003: Not a mixed-integer problem.) Therefore, if one wants to make use of the resulting cuts, it is not directly achievable.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/22/14 05:07 PM

    Originally posted by: T_O


    At first sight, this looks ok. Could you post the whole lp-file?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/22/14 05:37 PM

    Originally posted by: maiklb2005


    Sure. I am posting two files: Original problem formulation, and the LP problem with cuts. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/22/14 05:49 PM

    Originally posted by: T_O


    CPLEX 12.6.0.1 can read both files without problems, I get no error 3003.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/23/14 02:25 AM

    I guess you exported the model returned by CPXgetcallbacknodelp()? That is only an LP, not a MIP (it is the LP relaxation at the current node), so applying any MIP-related function to it will give error 3003.


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/23/14 11:15 AM

    Originally posted by: maiklb2005


    That is exactly correct, and thank you for the clarification. Nevertheless, I was able to import the ProblemWithCuts.lp via C++ API by using cplex.importModel(model, ProblemWithCuts.lp).

    At this point, as an extension of the question, let me ask the question related to how the extracted cuts can be made use of within the original formulation.

    Typically, within C++ API, I add constraints by using model.add(lhs <= rhs), where lhs and rhs are appropriately defined left- and right-hand sides of a constraint. In term of the problem in Problem.lp, the constraint is defined as model.add(35 x1 + 51 x2 + 67 x3 + 100 x4 <= 150).  Now that we know the cuts (which presumably result in a tighter formulation), is there a way to add constraints/cuts c1, c2, v0 and i1 defined in ProblemWithCuts.lp instead of model.add(35 x1 + 51 x2 + 67 x3 + 100 x4 <= 150) assuming that the objective function is still added as model.add(IloMaximize(env, objective))? 

    Thank you.

    P.S. I know that the syntax for importModel is: importModel (IloModel& m, const char* filename, IloObjective& obj, IloNumVarArray vars, IloRangeArray rngs) const; However, the only part of the imported model I am interested in is rngs.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/23/14 12:38 PM

    Originally posted by: maiklb2005


    I figured it out.  We need to load the whole LP model by doing the following:

          IloObjective   obj;

          IloNumVarArray var(env);

          IloRangeArray  rng(env);

          cplex.importModel(model,"ProblemWithCuts.lp", obj, var, rng);

    Then, to avoid solving the multi-objective problem, we need to remove the objective function that was loaded from the LP file. 

          model.remove(obj);

    In the same way we can load the Problem.lp (Alternatively, the original problem formulation can be programmed in C++ API). It goes without saying that the original objective function is not removed.

    In this case, however, the optimization starts as if the cuts were not there. It can be verified easily by hand that the bound defined by cuts in ProblemWithCuts.lp is 162, but the optimization starts with the value of 262. Please see the screenshot of the optimization process and the file that resulted from merging Problem.lp and ProblemWithCuts.lp attached.


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/29/14 06:29 AM

    Originally posted by: prasenjit mandal


    Hi Mikhail,

    I have some queries.

    1) If you solve "ProblemWithCuts.lp", you will get a different solution (nothing but a feasible solution to the problem, where objective function value is 140 and solution is [1,0,1,0]). But, the original optimal objective function value is 149 (if you solve "Problem.lp", you will get the objective function value is 149 and solution is [1,1,0,0]). Why it is like that? What are the reasons behind it? Can you please explain! Obviously ultimately (usin brnach and cut) we will reach to 149.

     

    2) you mentioned that :

    Then, to avoid solving the multi-objective problem, we need to remove the objective function that was loaded from the LP file. 

          model.remove(obj);

    But, the objective function coefficients corresponding to both "Problem.lp" and "ProblemWithCuts.lp" are same. Then, why it is necessary to remove the objective by using command "model.remove(obj)".


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: How to extract and save CPLEX-generated cuts?

    Posted 09/29/14 05:15 PM

    Originally posted by: maiklb2005


    1) I am puzzled about it myself. 

    2) I did that because otherwise there was an error message. CPLEX recognizes both objective functions, but multi-objective optimization (quite understandably) is not supported. It does not matter if objective functions coincide. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: How to extract and save CPLEX-generated cuts?

    Posted 05/21/15 03:11 PM

    Originally posted by: ORstudent


    Hi,

    This topic seem really interesting. I am trying to save all the cuts provided by CPLEX in the way that I solve only for the some nodes and then I want to get all the cuts and the information for providing it to CPLEX for the same model with another random seed and see what happen. I know how to create the random seed but I need some help about getting the information (cuts) and re-using it by giving them to CPLEX. Can you help me????

    How can I do it? I have seach in the manual and in the forum and I need some help or some guide!

    Thanks!!!!

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: How to extract and save CPLEX-generated cuts?

    Posted 05/26/15 01:30 AM

    It has been discussed several times in this Forum how you can obtain cuts separated by CPLEX. You should be able to find that.

    Here is a short guide:

    1. This can only be using the callable library (C) API
    2. You have to use a control callback, for example a branch callback
    3. In the callback you have to query the nodelp and then extract the cuts from the nodelp

    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: How to extract and save CPLEX-generated cuts?

    Posted 05/26/15 05:34 AM

    Originally posted by: ORstudent


    Thanks for answering. In that case, if only I want the root node, I can use:

    CPXsetsolvecallbackfunc() and from there get the nodelp information for node 0. Stablishing CPLEX nodelim to 1.

    Is that right?

    Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: How to extract and save CPLEX-generated cuts?

    Posted 06/02/15 07:50 AM

    Yes, the solve callback would work here.


    #CPLEXOptimizers
    #DecisionOptimization