Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to use getSlack in cplex?

    Posted 10/25/17 01:05 PM

    Originally posted by: yuhan0814


    Hi, I am wondering how to check slack value of a constraint. My code is 

    ---------------------------

    IloConstraintArray3  OptCut(env);

    OptCut[nIte][m].add(IloRange(env,0,z-1/nOpt*Z1,IloInfinity));

    Model_master.add(OptCut[nIte][m][OptCut[nIte][m].getSize()-1]);

    Z1.end();

    ...

    cplex_master.solve();

    GAP=cplex_master.getSlack(OptCut[nIte][m][OptCut[nIte][m].getSize()-1]);

    ...

    ---------------------------------

    but it returns "ERROR:Cannot create an IloForAllRange instance with this constraint Program ended with exit code: 0."

    How to get slack value of a particular constraint?

     

    Thanks in advance. 

    Han


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to use getSlack in cplex?

    Posted 10/25/17 02:07 PM

    Your code looks correct at first glance. Are you sure the exception is thrown from the getSlack() line? What is Z1?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to use getSlack in cplex?

    Posted 10/25/17 09:54 PM

    Originally posted by: yuhan0814


    Yes, I am.

    Z1 is IloExpr. z is variable.

    If I changed IloConstraintArray to IloRangeArray, it works.... 

    Is the error because of "IloConstraintArray"? 


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to use getSlack in cplex?

    Posted 10/27/17 05:08 AM

    The problem is indeed that you are passing an IloConstraint instance to getSlack().

    There are two overloads of getSlack():

    getSlack (const IloRange con, IloInt soln = IncumbentId) const
    getSlack (const IloForAllRange con, IloInt soln = IncumbentId) const

    As you can see, none of them takes an IloConstraint argument. So when you pass an IloConstraint the compiler has to either fail or create an appropriate argument from your IloConstraint instance. There is no constructor that creates an IloRange from an IloConstraint. But there is a constructor that creates an IloForAllRange from an IloConstraint. So the compiler ends up using that (in order to call the second overload) but that constructor fails.

    As you noted, you can avoid this by passing the constraint as IloRange instead of IloConstraint.


    #CPLEXOptimizers
    #DecisionOptimization