Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Naming Subconstraints

    Posted 09/15/16 05:02 PM

    Originally posted by: mathygirl


    Is there a way to name subconstraints in OPL?

    By subconstraint, I mean a "forall" iteration nested inside an outer "forall".

    In particular, the code below throws an error, though it demonstrates what I'm trying to do with "namedConstraint":

    tuple Tsets {

        {string} members;
    }

    {Tsets} mySet = {<{"s1", "s2"}>, <{"s3", "s4", "s5", "s6"}>, <{"s7", "s8", "s9"}>};

    minimize myObjective;

    subject to {
        forall(s in mySet) {
            forall(m in s.members) namedConstraint[m] {
                doSomething;
            }
        }
    }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Naming Subconstraints

    Posted 09/16/16 03:11 AM

    Hi,

    naming constraint works at the top of the tree and the leaf, not in the middle.

    So what you could do if you want to have some info or relaxation in the middle is use logical constraint.

    Let me give you an example:

    dvar int x[1..2] in 1..10;
    dvar int y[1..2] in 1..10;

    dvar boolean bool[1..2][0..2];

    subject to
    {

    forall(i in 1..2) x[i]==1;


    ct12:forall(i in 1..2)
      cti:forall(j in 0..2)
      {
         ct1:x[i]<=i+j;
         ct2:y[i]<=i+1+j;  
      }
     
    forall(i in 1..2) forall(j in 0..2)
      bool[i][j]== ((x[i]<=i+j) &&  (y[i]<=i+1+j));
     
    forall(i in 1..2,j in 0..2) ctbi:bool[i][j]==1;
     
     
    }

    execute
    {
    writeln(ct2[1][1].slack);
    writeln(cti[1].slack);
    writeln(ct12.slack);
    }

    the label cti is useless but ctbi can help you deal with relaxation

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer