Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

array of sets

  • 1.  array of sets

    Posted 05/10/16 04:54 AM

    Originally posted by: SaschaTS


     

    Hi everyone, 

    I am trying to assign values to an array of sets. I am a beginner and have a little trouble. 

    GIVEN:

    range J=1..maxJ; // days per planning period e.g. 28

    range W = 0..maxW-1;// number of weeks per planning period e.g. 4

    {int} DaysOfWeek[W];

     

    how can I assign values to DaysOfWeek using execute block.

    execute createDaysOfWeek {
        } 

    Result should be[ {1, 2,3,4,5,6,7},{8,9,10,11,12,13,14},{15,16,17,18,19,20,21},{22,23,24,25,26,27,28}]             
     

    I hope, that my explanation is understandable.

    Thanks a lot for your help.

    Kind regards,

    Sascha


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: array of sets

    Posted 05/10/16 02:55 PM

    Hi

    int maxJ=28;
     int maxW=4;
     
     range J=1..maxJ; // days per planning period e.g. 28

    range W = 0..maxW-1;// number of weeks per planning period e.g. 4

    {int} DaysOfWeek[w in W]={j | j in J: (j-1) div 7==w};

    execute
    {
    writeln(DaysOfWeek);
    }

    gives

    [{1 2 3 4 5 6 7} {8 9 10 11 12 13 14} {15 16 17 18 19 20 21} {22 23 24 25 26
             27 28}]

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: array of sets

    Posted 05/11/16 05:20 AM

    Originally posted by: SaschaTS


    Hey,

    thank you for your answer.

    But it is still not the needed approach. I should write this values using execution block with for-loops.

    smth. like (but it does not work this way)

    execute createDaysOfWeek {

    for(var u = 1; u <= maxJ; u++){
        for(r in W) {    
        
    DaysOfWeek[r]=u;

        } 
        
    }    
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: array of sets

    Posted 05/11/16 06:07 AM

    Hi,

    then you could write

    int maxJ=28;
         int maxW=4;
         
         range J=1..maxJ; // days per planning period e.g. 28

        range W = 0..maxW-1;// number of weeks per planning period e.g. 4

        {int} DaysOfWeek[w in W]={j | j in J: (j-1) div 7==w};
        {int} DaysOfWeek2[w in W];

        execute
        {
        writeln(DaysOfWeek);
        for(var i in J) DaysOfWeek2[Opl.floor((i-1) / 7)].add(i);
        writeln(DaysOfWeek2);
        }

    I wonder why you prefer to use scripting to OPL. We recommend the opposite.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer