Originally posted by: PhilippeLaborie
Hello,
The easiest way to smooth cumulative resource usage in CP Optimizer is to minimize the resource capacity. Let 'usage' denote the cumul function representing the resource usage over time, you can do :
cumulFunction usage = sum(...) ...;
int CapacityMax = ...;
dvar int peakUsage in 0..CapacityMax;
minimize peakUsage;
subject to {
usage <= peakUsage;
// ...
}
The strength of the CP model is that in the above model, you never need to explicit the time dimension and in particular you do not need to create decision variables for each time-point.
If you want a more fine grain control on how the resource is smoothed, you can get the maximal usage of the resource over a particular time window [t1,t2) by:
-
creating a fixed interval variable "hole" on the time window, then
-
having this fixed interval variable "hole" requiring the resource with a variable quantity
-
use the quantity of resource used by "hole" in the objective
The quantity of resource used by "hole" represents a quantity of resource that is not used by the actual activities on the resource.
dvar interval hole in t1..t2 size t2-t1; // Fixed interval variable
cumulFunction f = usage + pulse(hole, 0, CapacityMax);
dexpr int peakUsage12 = CapacityMax - heightAtStart(f, hole);
minimize peakUsage12;
subject to {
// ...
f <= CapacityMax;
}
That way, you can create one fixed interval variable per time-window and combine the local peak usages in the objective function to smooth the resource (for instance minimizing the sum of the squares of these local peak usages). This should work fine if you do not define too many time-windows.
Concerning tht syntax of the overlapLength expression, it takes as parameter either two interval variables or one interval variable and a time-window and returns the length of the overlap between the intervals.
dvar interval a ...;
dvar interval b ...;
int t1 = ...;
int t2 = ...;
dexpr int ov1 = overlapLength(a,b);
dexpr int ov2 = overlapLength(a, t1,t2);
Philippe
#DecisionOptimization#OPLusingCPOptimizer