Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Get Decision Variables from IloConstraint Instance

    Posted 04/29/13 05:14 AM

    Originally posted by: Ketov


    Hello,

    I am solving a Mixed Integer Linear Program with Cplex 12.2 C++ API and would like to get all decision variables (Ids or names) in the space of one certain IloConstraint instance.

    My first idea was to convert the IloConstraint to a string and work further with that, but probably there is an easier way.

     

    Thank you,

    Ketov


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Get Decision Variables from IloConstraint Instance

    Posted 04/29/13 07:27 AM

    Are your constraints instances of IloRange or are they more complicated things? If they are not instances of IloRange then you have no choice but to parse the stringified version of the constraint :-( If they are instances of IloRange then you can cast them to IloRange and use IloRange's functions to iterate over the constraint:

    IloConstraint c = ...;
    IloRangeI *impl = dynamic_cast<IloRangeI *>(c.getImpl());
    if ( !impl )
       // Not an IloRange instance, throw an exception, etc.
    else {
       IloRange r(impl);
       IloExpr e(r.getExpr());
       for (IloExpr::LinearIterator it = e.getLinearIterator(); it.ok(); ++it) {
          ...
       }
    }

    A word of caution here: some C++ compilers require extra compiler flags so that dynamic_cast<> works correctly.

    Also note that in more recent releases (12.4 and newer, I think) the API of IloRange has been improved so that you can now call IloRange::getLinearIterator() directly without taking the detour via the IloExpr instance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Get Decision Variables from IloConstraint Instance

    Posted 04/30/13 09:38 AM

    Originally posted by: Ketov


    That's a good solution for the IloRange constraints. Unfortunately there are also other constraints in my case, so it looks like there is no way around parsing.


    #CPLEXOptimizers
    #DecisionOptimization