Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Set Intersection in OPL Script

    Posted Thu March 19, 2015 01:22 AM

    Originally posted by: mathygirl


    Is it possible to perform set intersection in OPL Script? Basically, what I have in my OPL script is set1 and set2 that are read in from a model. I'd like to perform the following operation:

    for(var s in set1 inter set2) {

        do something;

    }

    The above syntax doesn't work, and I'm wondering if something equivalent to this might work in OPL script.

    While trying to solve this, I've also stumbled on another question. Is it possible to get something equivalent to a HashMap or dictionary in OPL script?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Set Intersection in OPL Script

    Posted Thu March 19, 2015 05:21 AM

    Hi,

    three examples:

    {int} A={1,3};
    {int} B={1,2};
    {int} C=A inter B;

    execute
    {
    for(var i in C) writeln(i);
    for(var i in A) if (B.contains(i)) writeln(i);

    for(var i in Opl.operatorINTER(A,B))  writeln(i);
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Set Intersection in OPL Script

    Posted Thu March 19, 2015 10:53 AM

    Originally posted by: mathygirl


    Thank you, this is super helpful. Is this in the documentation?

    for(var i in C) writeln(i);
    for(var i in A) if (B.contains(i)) writeln(i);

    for(var i in Opl.operatorINTER(A,B)) writeln(i);


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Set Intersection of one- and two dimensional set

    Posted Tue May 19, 2015 11:15 AM

    Originally posted by: OPLnewbie


    Hey, 

    I've also got a problem with sets, in this case the difference, here with my example data:

    range D = 1..2;

    {int} T = {1,2};

    {int} ToD[D] = [{1},{1}];

       forall( d in D, t in ToD[d]){
              X[d][t]<= a[d];
         }
              
       forall( d in D, t in (T diff ToD[d])){
               X[d][t] == 0;
         }

    Unfortunately the difference of the set doesn't work, as it puts for all Xdt a value of 0. Can anybody help?

    Regards 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Set Intersection of one- and two dimensional set

    Posted Wed May 20, 2015 02:25 AM

    Hi,

    maybe you get that because you do not have any objective.

    If I slightly change your model into

    range D = 1..2;
      int a[i in D]=10*i;

    {int} T = {1,2};

    {int} ToD[D] = [{1},{1}];

    dvar int X[D][1..2];

    maximize sum(d in D,t in 1..2) X[d][t];
    subject to
    {
       forall( d in D, t in ToD[d]){
              X[d][t]<= a[d];
         }
              
       forall( d in D, t in (T diff ToD[d])){
               X[d][t] == 0;
         }
       }    
     

    then you get

    X = [[10 0]
                 [20 0]];

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Set Intersection of one- and two dimensional set

    Posted Fri May 22, 2015 01:11 PM

    Originally posted by: OPLnewbie


    Thank you very much for the quick answer. I did have an objective function, the constraints are part of a bigger model, but indeed there was the problem. At least I do know now for sure, that it was not the diffence of sets construction.

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer