Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

adding cuts in cplex 9 (using c++ concert technology)

  • 1.  adding cuts in cplex 9 (using c++ concert technology)

    Posted Thu April 02, 2009 05:03 AM

    Originally posted by: SystemAdmin


    [amirahr said:]

    Hi all

    I'm trying to add user cuts (named 'validprec') to my model. I've seen the example codes that deal with adding user cuts (iloadmipex4, iloadmipex5) and I emulated what was done in iloadmipex4 as it seemed less complicated. The difference was that I put everything in int main.  Here's what I've done so far:


    IloModel model(env);
    IloConstraintArray validprec(env);
    y = IloIntVarArray5(env, N);  //decision variable to be used in validprec
    for(i=0;i<N;i++)<br />{
    y[i] = IloIntVarArray4(env, R);
    for(r = 0 ; r < R ; r++)<br /> {
    y[i][r] = IloIntVarArray3(env, N);
    for( id = 0 ; id < N ; id++)<br /> {
    y[i][r][id] = IloIntVarArray2(env, R);
    for( rd = 0 ; rd < R ; rd++)<br /> {
    y[i][r][id][rd] = IloIntVarArray(env, J, 0, 1);
    }
    }
    }
    }



    for( i = 0 ; i < N-1 ; i++ )<br />{
    for( id = i+1 ; id < N ; id++ )<br /> {
    for( r = 0 ; r < R ; r++ )<br /> {
    for( rd = 0 ; rd < R ; rd++ )<br /> {
    for( j = 0 ; j < J ; j++ )<br /> {
    for( jd = 0 ; jd < J ; jd++ )<br /> {
    for( k=1 ; k < NoS&#91;i&#93; ; k++ )<br /> {
    for( kd = 1 ; kd < NoS&#91;id&#93; ; kd++ )<br /> {
    if( prec[jd][j] == 1 )
    {
    if( sigma[i][r][k] == j  &&  sigma[id][rd][kd-1] == j )
    {
    if( sigma[i][r][k-1] == jd  &&  sigma[id][rd][kd] == jd )
    {
    if( r%2 == 0  &&  rd%2 != 0 )
    {
    if( j > jd )
    {
    validprec.add
                                                                                                            (y[i][r][id][rd][j] - y[i][r][id][rd][jd] <= 0);<br /> }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }



    IloCplex cplex2(model);
    cplex2.addCuts(validprec);
    validprec.endElements();
    validprec.end();



    The code compiled all right but when I ran the .exe, I got this:
    Concert error: invalid cut

    Am I doing this wrong? Should there be an IloCplex::AddCuts() or an IloCplex::AddUserCuts() term in there somewhere? If yes, then what goes in the brackets? Or is there something wrong with my cuts?

    In the runs prior to making validprec a cut, it was a constraint. Building, compiling and running the model with it as a constraint yielded no error messages, it solved to optimality. So then why are they invalid as cuts?

    Thanks in advance.

    Amirah
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: adding cuts in cplex 9 (using c++ concert technology)

    Posted Fri April 03, 2009 02:45 AM

    Originally posted by: SystemAdmin


    [EdKlotz said:]

    The code compiled all right but when I ran the .exe, I got this:
    Concert error: invalid cut

    Am I doing this wrong? Should there be an IloCplex::AddCuts() or an IloCplex::AddUserCuts() term in there somewhere? If yes, then what goes in the brackets? Or is there something wrong with my cuts?

    In the runs prior to making validprec a cut, it was a constraint. Building, compiling and running the model with it as a constraint yielded no error messages, it solved to optimality. So then why are they invalid as cuts?

    First of all, as a general recommendation, any time you get unexpected behavior from a program
    that calls CPLEX, take advantage of all the diagnostic information CPLEX provides.  This means turning on the datacheck parameter (IloCplex::DataCheck in C++) regardless of the API you use.  Regarding C++, you can also enable assertion checking by removing the -DNDEBUG compiler option in the compile statement.

    Specific to the invalid cut error message, this means CPLEX through an IloCplex::InvalidCutException, which has the following description in the reference manual:

    >>>>>
    An instance of this exception is thrown by IloCplex when an an attempt is made to
    add a malformed cut. An example of a malformed cut is one that uses variables that have
    not been extracted or a cut that is defined with an expression that is not linear.
    >>>>>>

    Based on the code you sent, it does appear that the y variables in your cuts have not been
    added to the model.  Since user cuts are not part of the model itself, that probably explains
    the behavior you see.  So, try adding a call to 

    model.add(y);

    or adding a redundant constraint involving all of the y variables to the model. 
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: adding cuts in cplex 9 (using c++ concert technology)

    Posted Fri April 03, 2009 05:06 AM

    Originally posted by: SystemAdmin


    [amirahr said:]

    Thank you for replying.
    I added a redundant constraint as per your suggestion and now it works.
    As for IloCplex::InvalidCutException, It's not clear to me how to use that. I've tried using it as a catch:

    catch (IloCplex::InvalidCutException& ex)
    {
    cout << "Concert error: " << ex.getCut() << endl;<br />}

    Though I'm not sure this is the right way to go about it. Is it?

    Amirah
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: adding cuts in cplex 9 (using c++ concert technology)

    Posted Thu April 09, 2009 03:32 AM

    Originally posted by: SystemAdmin


    [EdKlotz said:]


    I added a redundant constraint as per your suggestion and now it works.
    As for IloCplex::InvalidCutException, It's not clear to me how to use that. I've tried using it as a catch:

    catch (IloCplex::InvalidCutException& ex)
    {
      cout << "Concert error: " << ex.getCut() << endl;<br />}

    Though I'm not sure this is the right way to go about it. Is it?



    Yes, that is the right way. 
    #CPLEXOptimizers
    #DecisionOptimization