Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Is there a reason 'IloModel::add' succeeds to add constraints to a model, but 'IloCplex::addLazyConstraints' fails with 'IloCplex::InvalidCutException'?

  • 1.  Is there a reason 'IloModel::add' succeeds to add constraints to a model, but 'IloCplex::addLazyConstraints' fails with 'IloCplex::InvalidCutException'?

    Posted Sat May 18, 2019 04:13 PM

    Originally posted by: snOm3ad


    Hello,

    I have a huge number of constraints that need to be added to a model in the form of lazy constraints, now as far as I know there are two ways to do this. Using the 'IloCplex::addLazyConstraints' method or create your own callback class either by hand or by means of the macros offered. My problem is that when I try to use the former method, I get an IloException thrown saying that the cut is invalid. Now according to the documentation this can happen whenever a cut is malformed, which can be one or more of the following cases:

    • A cut that uses variables that have not been extracted to the model is malformed.
    • A cut defined by an expression that is not linear is malformed.
    • A cut is also considered malformed when it has already been extracted for the invoking IloCplex object and is thus already a part of the model.

    However, none of these seem to fit my case, what's more confusing is that when solving a small instance I can add these constraints directly to the model using 'IloModel::add' method with no problems whatsoever. Is there something I am missing? For context, here is a sample of the code I am using.

     

            int const V = G.get_vertices();
            IloRangeArray linking(env, V * V * V * V, -IloInfinity, 0);
            linking.setNames("linking_avail_link");

            for (int i = 0; i < V; ++i) {
                for (int j = 0; j < V; ++j) {
                    for (int k = 0; k < V; ++k) {
                        for (int m = 0; m < V; ++m) {
                            if (i != j and k != m) {
                                // construct the cut expression
                                IloExpr cut { env };   
                                cut += w[i][j][k][m];
                                cut -= y[k][m];

                                int const idx = utl::compute_index(i, j, k, m);
                                linking[idx].setExpr(cut);
                                cut.end();
                            }
                        }
                    }
                }
            }

            //cplex.addLazyConstraints(linking); // Fails with IloCplex::InvalidCutException

            model.add(linking); // succeeds!

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Is there a reason 'IloModel::add' succeeds to add constraints to a model, but 'IloCplex::addLazyConstraints' fails with 'IloCplex::InvalidCutException'?

    Posted Mon May 20, 2019 09:37 AM

    Originally posted by: snOm3ad


    Okay I managed to solve the problem. The issue is that you need to extract the 'IloModel' instance before adding any lazy constraints! The wording of case one seems a bit confusing, cause I interpreted as the variables must be added to the model first, which is true but you must also extract the model using an instance of 'IloCplex'. Hopefully this helps.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Is there a reason 'IloModel::add' succeeds to add constraints to a model, but 'IloCplex::addLazyConstraints' fails with 'IloCplex::InvalidCutException'?

    Posted Tue May 28, 2019 04:32 AM

    Thanks a lot for reporting the issue and the fix. I have filed a defect to get the documentation improved.


    #CPLEXOptimizers
    #DecisionOptimization