Example: peak power fee
Consider the peak power fee pipeline from the calculation reference. To optimise consumption against this tariff, declare quarter-hourly energy offtake as the decision variable. Each function emits its optimisation form: Aggregate to hourly energy (: the four quarter-hours in hour ): Divide by 1 hour to get hourly power: Select the 3 highest hours per month (: the hours in month ). Introduce a binary and threshold : Aggregate(mean) over selected hours. Average the 3 selected values: Multiply by 50 SEK/kW to get the monthly cost: The optimiser minimises against , subject to whatever consumption constraints the customer’s assets impose.Alternative linear implementation
The select-3-highest formulation above introduces a binary per hour per month, which turns the problem into a Mixed Integer Linear Programming model (MILP). The solver must reason discretely about which 3 hours are selected. If only the cost matters, which is typically the case, the same exact monthly top- peak cost can be obtained from a purely linear formulation, with no binaries. For this we introduce positive excess variables above our monthly threshold: The monthly peak power is then simply calculated as: (monthly peak = threshold + average excess of the 3 highest hourly power values above the threshold)Functions
Add
Add
(where ranges over operand labels.)
Subtract
Subtract
Multiply
Multiply
When at least one operand is fixed (a constant or known data, ):If both operands are decision variables, the relation is bilinear — most
solvers cannot handle this directly. In tariffs this is essentially never
the case: multiplies are quantity × rate, where the rate is a known
Level
or constant data.Divide
Divide
When the denominator is fixed (a constant or known data, ):If the denominator is a decision variable, the relation is bilinear — most
solvers cannot handle this directly. In tariffs the denominator is almost
always a known quantity (e.g. dividing energy by 1 hour to convert to power,
or dividing by a fixed time-window length).
Aggregate
Aggregate
The form depends on
aggregation_function. ( denotes the set of
fine-resolution timesteps in group .)Sum:Mean:Max:When minimising a cost where has a positive coefficient,
this inequality alone is sufficient — the solver pushes
down to . The non-convex case — when cost pressure
doesn’t push toward —
introduces binary variables and indicator or big-M constraints.Min:Mirror of max: the inequality suffices when the cost coefficient is
negative (e.g. a credit being maximised); the non-convex case is handled
the same way.Resample
Resample
Broadcasting only: each fine-resolution slot takes the value of the
coarse-resolution input for its group.where is the coarse-resolution group containing .
Select
Select
The form depends on the condition.Time-based conditions (
month, day_of_week, time_of_day,
exclude_holidays, and their logical combinations): matching timesteps
are known a priori from timestamps — the output references the input for
matching timesteps, non-matching timesteps are absent.highest / lowest: discrete selection per group. Introduces a
binary variable per element and a continuous
threshold per group:For highest:lowest mirrors with the inequalities flipped. The implications are
modelled with indicator or big-M constraints.Mask
Mask
Conditional substitution: matching timesteps are known a priori from
timestamps — the output references the replacement where the condition
matches, the input otherwise.
Clip
Clip
The form depends on which bounds are configured.
minimum only (where is the configured minimum):When minimising a cost where has a positive coefficient,
these inequalities alone are sufficient — the solver pushes
down to . The non-convex
case introduces a binary variable per timestep and indicator or big-M
constraints.maximum only (where is the configured maximum):Mirror of minimum only: the inequalities suffice when the cost
coefficient is negative; the non-convex case is handled the same way.Both minimum and maximum: introduces two binary variables per
timestep (one per bound) and indicator or big-M constraints.Lookup
Lookup
Stepwise tier selection with tiers, boundaries
(ascending), and level values . Introduces a
binary variable per timestep per tier,
i.e. only 1 tier active at a time:The output is the active tier’s level: