Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Lazy constraints?

    Posted Mon February 20, 2012 11:15 AM

    Originally posted by: stella1985


    Hello,

    I am using CPLEX 12.2 to solve a very large LP problem. I would like to solve this LP iteratively by progressively adding constraints that are violated by the solution to the relaxed LP (e.g. original LP with only half the constraints). Can this be done by using Lazyconstraints? If not, what would be the most efficient way to implement this?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Lazy constraints?

    Posted Mon February 20, 2012 11:30 AM

    Originally posted by: SystemAdmin


    Yes, this can be done using lazy constraints. Actually it is the purpose of lazy constraints.
    There are two ways to do it:
    1. Create all the constraints before you start the solve. Register some of them as hard constraints and some as lazy constraints. CPLEX will then look at the lazy constraints whenever it finds an integer feasible solution. If the solution satisfies all lazy constraints then it is accepted. If it violates a lazy constraint then this constraint is added to the set of hard constraints and the solution is rejected.
    2. Depending on the number of lazy constraints, generating all of them up front may not be a good idea. In that case you can implement a lazy constraint callback. This callback is invoked whenever CPLEX finds an integer feasible solution. The callback can then either accept the solution or produce a lazy constraint that is violated by the solution. This allows you to dynamically generate lazy constraints on an as-needed basis.
    We implemented some improvements concerning the handling of lazy constraints in version 12.3, so you may want to consider upgrading to that version. It is not required though, lazy constraints work in 12.2 as well.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Lazy constraints?

    Posted Mon February 20, 2012 11:54 AM

    Originally posted by: stella1985


    Dear Daniel,

    Thank you very much for your reply. Just to clarify a few points:
    1. At the moment, I am generating all lazy constraints at once, but I am having doubts as to whether I have implemented it correctly. Specifically, the solution times etc. do not seem to be affected at all when adding constraints as hard or as lazy. Also, the lp file created before calling solve() looks the same whether using lazy constraints or not. In short, is there a way to check whether lazy constraints is "working" e.g. by displaying a message when a lazy constraint becomes hard during solve?
    2. In what sense is it potentially not a good idea to generate all lazyconstraints at once? You mean because too many constraints might be added after just one iteration or for other reasons? Finally, is there an example of lazy constaint callback available?

    Thank you
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Lazy constraints?

    Posted Mon February 20, 2012 12:00 PM

    Originally posted by: SystemAdmin


    If the LP files look the same then something is wrong. If your model has lazy constraints then the LP file should have a section "Lazy constraints" in addition to sections "Subject To", "Bounds" etc.
    If CPLEX solves your model with lazy constraints and actually uses any of the lazy constraints then it should print a message like "10 user cuts used" at the end of the solve.
    Generating all constraints up front may not be a good idea because generating or checking all these constraints may consume a lot of time. It is just a performance issue, not a correctness issue.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Lazy constraints?

    Posted Mon February 20, 2012 12:08 PM

    Originally posted by: stella1985


    Thank you very much for your replies. It helps a lot!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Lazy constraints?

    Posted Mon February 20, 2012 12:38 PM

    Originally posted by: stella1985


    Dear Daniel,

    I now managed to add the lazyconstraints. But apparently, this is only for Mixed integer problems. I would need something similar for LPs (only continuous variables). Does it exist? If not, what Callback should I use in order to implement something similar?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Lazy constraints?

    Posted Mon February 20, 2012 12:54 PM

    Originally posted by: SystemAdmin


    You can easily trick CPLEX into thinking that it is solving a MIP: just add a dummy integer variable (that can even be fixed), for example (in C++)
    // Add a dummy integer variable so that we don't get
    // the "not a MIP" error.
    model.add(IloIntVar(env, 0.0, 0.0, "dummyvar"));
    

    You should then disable all cuts and heuristics since those are just a waste of time in your case.
    Does this work for you?
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Lazy constraints?

    Posted Mon February 20, 2012 02:35 PM

    Originally posted by: stella1985


    Dear Daniel,

    That did the job thank you!

    Two last questions:

    1. Is there a single command to disable all cuts and heuristics? So far, I have written
    cplex.setParam( IloCplex::HeurFreq, -1);
    cplex.setParam(IloCplex::RINSHeur,-1);
    cplex.setParam(IloCplex::MCFCuts,-1);
    cplex.setParam(IloCplex::CutsFactor,0);

    but maybe there are more settings?

    2. Is there any example available for a lazy constraint callback of the type described in your first answer or similar?
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Lazy constraints?

    Posted Tue February 21, 2012 02:21 AM

    Originally posted by: SystemAdmin


    To disable heuristics it should be sufficient to set HeurFreq to -1.
    To disable cuts it should be sufficient to set IloCplex::CutPass to -1.

    In CPLEX 12.3 we added a Benders decomposition example that heavily uses lazy constraints. In CPLEX 12.2 you have the admipex5 family of examples (admipex5.c, iloadmipex5.cpp, AdMIPEx5.java, ...) that use lazy constraints.
    #CPLEXOptimizers
    #DecisionOptimization