Function optimize_demand
and
add_battery_optimization
makes use of Quadratic programming
in order to obtain the optimal power load given certain conditions. The
Quadratic programming problem can be formulated according to multiple
objectives. Currently, flextools
package allows to optimize
a time-series power load considering two different goals:
- Minimize the power exchanged with the grid (net power)
- Minimize the energy cost
In this article, we’ll cover the optimization problem for the first objective, energy_cost minimization, for both the flexible demand (e.g. heatpumps, electric vehicles, etc.) and the battery.
Our energy cost optimization takes into account multiple profiles of energy prices with the objective to minimize the total cost, considering:
- Imported energy cost
- Exported energy income
- Income from balancing markets (turn up/down demand)
Demand optimization
To minimize the energy cost using the flexibility from a power demand profile, the objective function of the optimization problem has been raised in the following way:
The objective function and constraints of this optimization problem are represented below, where:
- : Number of time intervals within the optimization window
- : Local power generation time-series vector
- : Non-flexible load time-series vector
- : Flexible load time-series vector (if not optimized)
- : Optimal flexible load time-series vector
- : imported energy
- : exported energy
- : imported energy price
- : exported energy price
- : balancing price for turn-up power
- : balancing price for turn-down power
- : penalty on change for the flexible load
Moreover, this optimization problem has the following constraints:
- The energy consumed by the flexible load must remain the same than the expected behavior:
- Optimal flexible load must be lower than a certain maximum power :
- The imported energy must remain between 0 and the corresponding energy consumed with the maximum grid import capacity :
- The exported energy must remain between 0 and maximum grid export capacity :
- Energy balance behind-the-meter:
At the same time, we can optimize the flexible energy demand with two opposite approaches:
- Postpone the consumption to later time-slots (shift the energy forward)
- Consume now (store) the energy that will be consumed later (shift the energy backward)
We consider both approaches for different objectives or applications. The energy shift is always done within a maximum time horizon () to consider realistic scenarios. For example, the time horizon for the energy demand of a water boiler could have a time horizon of 6 hours, because it wouldn’t make sense to heat the water more than 6 hours before the final consumption. Each one of these approaches brings extra constraints to the optimization problem:
If the energy can only be shifted forward:
- The cumulative sum of the optimal load must be higher than the cumulative sum of the original flexible load except the last time slots, and lower than the total cumulative sum of the original flexible load (energy can only be shifted forwards):
- The maximum values for the optimal demand will depend on the time horizon :
If the energy can only be shifted backward:
- The cumulative sum of the optimal demand must be higher than the total cumulative sum of the original demand (energy can only be shifted backwards), and lower than the cumulative sum of the original demand except the following time slots:
- The maximum values for the optimal demand will depend on the time horizon :
Battery optimization
To minimize the energy cost using the flexibility from a battery, the objective function of the optimization problem has been raised in the following way:
Where:
- : Number of time intervals within the optimization window
- : Local power generation time-series vector
- : Power load time-series vector
- : Optimal battery power time-series vector. Positive charging, negative discharging.
- : imported energy
- : exported energy
- : imported energy price
- : exported energy price
- : balancing price for turn-up power
- : balancing price for turn-down power
- : penalty on change for the flexible load
Additionally, this optimization problem also counts with the following parameters used in the constraints below:
- : Battery capacity
- : Maximum charging power
- : Maximum discharging power
- : Minimum state of charge of the battery
- : Maximum state of charge of the battery
- : state of charge at the beginning/end of the optimization window
Optimization constraints:
- Battery power (positive = charging, negative = discharging) limits:
- State of charge limits:
- The balance of charged/discharge energy must be 0 at the end of the optimization window to have the same initial state of charge at the beginning of every optimization window:
- The imported energy must remain between 0 and the maximum grid import capacity :
- The exported energy must remain between 0 and the maximum grid export capacity :
- Energy balance behind-the-meter: