Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

OPL Array of User-Defined Tuples

  • 1.  OPL Array of User-Defined Tuples

    Posted Fri February 28, 2020 08:07 PM

    Originally posted by: tjnelso


    I have a model with multiple time periods and I receive some data in the format of a tupleset with a time dimension. Thus, the original tupleset is the superset of the tupleset required for each time period. I also have an array of integers which represent the time periods. In preprocessing, I need to iterative over this data separately for each time period, and only the data associated with that time period is relevant during this iteration, so I can reduce preprocessing time significantly by splitting the original tupleset into its subsets which are associated with each time period, and then iterative each of these independently during preprocessing.

     

    In dat file:

    timeSet = {1 2};
    dataset = {
    \\<attribute1, attribute2, time period>
    <a,b,1>
    <a,c,1>
    <a,b,2>
    <a,d,2>
    };
    

    In mod file:

    {int} timeSet = ...;
    tuple data {string attribOne; string attribTwo; int time;};
    {data} dataset = ...;
    

    I don't know ahead of time how many time periods there will be, so if I can't split up the tupleset on the fly, then I would need to do something like this:

    execute{
        for(var t in timeSet) {
            for(var r in dataSet) {
                if(r.Time == t) {
                    //call a function that executes on r
                }
            }
        }
    }
    

    However, if I can split out dataSet into multiple tuples or arrays based on the value of the time field, then I could replace the above with something like the following:

    execute{
        for(var t in timeSet) {
            for(var r in dataSetsCollection[t]) {
                //call a function that executes on r
            }
        }
    }
    

    Since I would be working on dataSetsCollection[t] instead of dataSets there should be significantly less data to evaluate. Is it possible to create an item such as dataSetsCollection from the code above? I attempted to do so with a tuple:

    tuple TdataSetsCollection {data row;};
    {TdataSetsCollection} dataSetsCollection = {<ds> | ds in dataset : ds.Time = t};
    

    and with an array:

    tuple TdataSetsCollection {data row;};
    TdataSetsCollection DataSetsArr[t in TimeSet] = [t : ds | ds in dataset, t in TimeSet : ds.Time == t];
    

    Neither of the above worked so I'm not sure if this is possible. Please help if you can.

    Thanks.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL Array of User-Defined Tuples

    Posted Mon March 02, 2020 12:41 PM

    Hi,

    you could use slicing:

    .mod

    {int} timeSet = ...;
    tuple data {string attribOne; string attribTwo; int time;};
    {data} dataset = ...;

    {int} computedTimeSet={d.time | d in dataset};
    {data} dataSetPerTime[t in computedTimeSet]={d | d in dataset : d.time==t};

    execute
    {
      writeln(dataSetPerTime);
    }

     

    .dat

    timeSet = {1 2};
    dataset = {

    <a,b,1>
    <a,c,1>
    <a,b,2>
    <a,d,2>
    };

    gives

     

     [{<"a" "b" 1> <"a" "c" 1>} {<"a" "b" 2> <"a" "d" 2>}]

    regards

     

    https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL Array of User-Defined Tuples

    Posted Mon March 02, 2020 01:28 PM

    Originally posted by: tjnelso


    This worked perfectly. Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer