Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  OPL Script - Populate Array of Tuples

    Posted 01/15/16 11:34 AM

    Originally posted by: G.B.


    Hello, I have .mod where I declare an array of Tuples. After the Linear Program is solved, I want to populate this array with a script. I have tried several options, but I keep getting an error.

    What is the best way of populating an array of Tuples with an OPL script?

     

    My array of Tuple is:

    tuple TPlan {
      int start;
      int end;
    };
    TPlan plan [session][1..horizon.nbPeriods];

     

    My Variables:

    dvar boolean Start[session][Rangeperiods];
    dvar boolean End[session][Rangeperiods];

     

    My current script (giving an error):

    execute UPDATE_RESULTS {
      for(var s in session) {
        for (var p in Rangeperiods) {
         plan[s][p].add(Start[s][p], End[s][p]);
        }
      }
    }

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL Script - Populate Array of Tuples

    Posted 01/15/16 01:52 PM

    Hi

    range session =1..2;
    range Rangeperiods=1..2;

     tuple TPlan {
      int start;
      int end;
    };
    TPlan plan [session][1..2];

     


    execute UPDATE_RESULTS {
      for(var s in session) {
        for (var p in Rangeperiods) {
         plan[s][p].start=1;
         plan[s][p].end=2;
        }
      }
    }

    works

    add would work if plan was a set, but is is a tuple

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL Script - Populate Array of Tuples

    Posted 01/16/16 02:01 PM

    Originally posted by: G.B.


    Thank you Alex for your help. I tried your solution and it worked. I also tried changing the type to a set and using add, and it worked too.

    Do you know what is the "best" type to use in this case (tuple or set) - are there any pros or cons of using one of them?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL Script - Populate Array of Tuples

    Posted 01/18/16 03:34 AM

    Hi,

    in your case you seem to have 1 and only 1 plan for each session and each period so tuple are better here.

    If instead, you had had sometimes 1, sometimes 0 and sometimes 7 plans then sets would have been better

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer