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
-
is it easy to build in OPL a stepwise function out of this workload collection
-
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