Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  transform a collection into a stepwiseFunction

    Posted 10/12/15 04:24 AM

    Originally posted by: DavidGravot


    Hi

    Suppose I have a collection of "workload" items, e.g triplets (start,end, value) with each attribute integer , but these items may overlap

    I wanted to compute the "sum" of these items, e.g define a curve that will give me at any time point the sum of all values that overlap this point

    The easiest way I found so far is using the tiny following CP model. It uses a cumulFunction.

    I'm wondering if 

    1. is it easy to build in OPL a stepwise function out of this workload collection
    2. do we have iterator of a stepwise function in OPL
     using CP;
    
    execute SETTINGS{     settings.forceUsage=true;}
     
     tuple Workload{ int start; int end; int value;}
     
     {Workload} workload = ...;
     int startmin = min(w in workload) w.start;
     int endMax = max(w in workload) w.end;
     
     cumulFunction f = sum(<s,e,v> in workload) pulse(s,e,v);
     
     subject to{
            f>=0; 
     }
     
     {Workload} result;
     
     execute REBUILD_WORKLOAD{
     writeln(); 
     writeln("Rebuilding workload from ", startmin, " to ", endMax); 
     
      for(var i=0;i<Opl.numberOfSegments(f);i++){
            var s = Opl.segmentStart(f,i);
            var e =   Opl.segmentEnd(f,i);
            var v = Opl.segmentValue(f,i);
      
            if (s<endMax && startmin<e){
                    writeln(s," to ", e," : ", v);
                    result.add(s,e,v);
            }    
      }
     }
    

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: transform a collection into a stepwiseFunction

    Posted 10/12/15 03:52 PM

    Hi,

    a direct way to do the same in OPL:

    sorted {int} breakpoints={w.start| w in workload }
     union {w.end | w in workload };
     
     int values[b in breakpoints diff {last(breakpoints)}]=
     sum(w in workload:w.start<=b && w.end>=next(breakpoints,b)) w.value;
     
     execute
     {
      for(var b in breakpoints) if (b!=Opl.last(breakpoints))
      writeln(b," to ",Opl.next(breakpoints,b)," : ",values[b])
     }

    and then in order to build the stepwise

    int valuesforstepwise[b in breakpoints]=
     (b==first(breakpoints)?0:values[prev(breakpoints,b)]);
     
     
     stepFunction st=
     stepwise(b in breakpoints)
     {valuesforstepwise[b]->b;0};

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: transform a collection into a stepwiseFunction

    Posted 10/13/15 04:54 AM

    Originally posted by: DavidGravot


    Thanks a lot

    And how could I iterate on this step function ? 

    My initial idea was actually to rebuild a new Workload collection with the step function


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: transform a collection into a stepwiseFunction

    Posted 10/14/15 01:54 AM

    Hi,

    once you have a step function you can evaluate it in many points as you can see in the documentation.

    stepFunction f=stepwise {0->3; 2};

    assert f(-1)==0;

    You may also writeln this step. I am not sure you can iterate.

    But with

    sorted {int} breakpoints={w.start| w in workload }
     union {w.end | w in workload };
     
     int values[b in breakpoints diff {last(breakpoints)}]=
     sum(w in workload:w.start<=b && w.end>=next(breakpoints,b)) w.value;

    you have everything you need to build a new workload. (To get a nice workload yoyu may remove following doublons in the array values.

    Regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: transform a collection into a stepwiseFunction

    Posted 10/14/15 03:25 AM

    Originally posted by: DavidGravot


    Either from the array values or from the stepwise function, I find it not straightforward at all to build a collection with as many items as the step function steps...


    #DecisionOptimization
    #OPLusingCPOptimizer