Skip to contents

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:

mint=1TIt·PItEt·PEtPTUt(OtLFt)PTDt(LFtOt)+λ(OtLFt)2 min \sum_{t=1}^{T} I_t·PI_t - E_t·PE_t - PTU_t(O_t-LF_t) - PTD_t(LF_t-O_t) + \lambda (O_t-LF_t)^{2}

The objective function and constraints of this optimization problem are represented below, where:

  • TT : Number of time intervals within the optimization window
  • GtG_t : Local power generation time-series vector
  • LStLS_t : Non-flexible load time-series vector
  • LFtLF_t : Flexible load time-series vector (if not optimized)
  • OtO_t : Optimal flexible load time-series vector
  • ItI_t : imported energy
  • EtE_t : exported energy
  • PItPI_t : imported energy price
  • PEtPE_t : exported energy price
  • PTUtPTU_t : balancing price for turn-up power
  • PTDtPTD_t : balancing price for turn-down power
  • λ\lambda : 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:

t=1TOtΔt=t=1TLFtΔt \sum_{t=1}^T O_t \Delta t = \sum_{t=1}^T LF_t \Delta t

  • Optimal flexible load must be lower than a certain maximum power LFmaxLF_{max}:

0OtLFmaxttT 0 \le O_t \le LFmax_t \quad t \in T

  • The imported energy must remain between 0 and the corresponding energy consumed with the maximum grid import capacity ICTIC_T:

0ItICtΔttT 0 \le I_t \le IC_t \Delta t \quad t \in T

  • The exported energy must remain between 0 and maximum grid export capacity ECtEC_t:

0EtECtΔttT 0 \le E_t \le EC_t \Delta t \quad t \in T

  • Energy balance behind-the-meter:

ItEt=Ot+LStGt I_t - E_t = O_t + LS_t - G_t

At the same time, we can optimize the flexible energy demand with two opposite approaches:

  1. Postpone the consumption to later time-slots (shift the energy forward)
  2. 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 (hh) 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 OO must be higher than the cumulative sum of the original flexible load LFLF except the last hh time slots, and lower than the total cumulative sum of the original flexible load LFLF (energy can only be shifted forwards):

t=1uhLFtt=1uOtt=1uLFtu=1T \sum_{t = 1}^{u-h} LF_t \le \sum_{t=1}^u O_t \le \sum_{t=1}^u LF_t \quad u = 1 \dots T

  • The maximum values for the optimal demand OtO_t will depend on the time horizon hh:

Out=uhuLFtu=1T O_u \le \sum_{t = u-h}^u LF_t \quad u = 1 \dots T

If the energy can only be shifted backward:

  • The cumulative sum of the optimal demand OO must be higher than the total cumulative sum of the original demand LFLF (energy can only be shifted backwards), and lower than the cumulative sum of the original demand LFLF except the following hh time slots:

t=1uLFtt=1uOtt=1u+hLFtu=1T \sum_{t=1}^u LF_t \le \sum_{t=1}^u O_t \le \sum_{t=1}^{u+h} LF_t \quad u = 1 \dots T

  • The maximum values for the optimal demand OtO_t will depend on the time horizon hh:

Out=uu+hLFtu=1T O_u \le \sum_{t = u}^{u+h} LF_t \quad u = 1 \dots T

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:

mint=1TIt·PItEt·PEtPTUt·BtPTDt·(Bt)+λt=1T1(Bt+1Bt)2 min \sum_{t=1}^{T} I_t·PI_t - E_t·PE_t - PTU_t·B_t - PTD_t·(-B_t) + \lambda \sum_{t=1}^{T-1}(B_{t+1} - B_t)^{2}

Where:

  • TT : Number of time intervals within the optimization window
  • GtG_t : Local power generation time-series vector
  • LtL_t : Power load time-series vector
  • BtB_t : Optimal battery power time-series vector. Positive charging, negative discharging.
  • ItI_t : imported energy
  • EtE_t : exported energy
  • PItPI_t : imported energy price
  • PEtPE_t : exported energy price
  • PTUtPTU_t : balancing price for turn-up power
  • PTDtPTD_t : balancing price for turn-down power
  • λ\lambda : penalty on change for the flexible load

Additionally, this optimization problem also counts with the following parameters used in the constraints below:

  • BcapB_{cap} : Battery capacity
  • BcB_c : Maximum charging power
  • BdB_d : Maximum discharging power
  • SOCminSOC_{min} : Minimum state of charge of the battery
  • SOCmaxSOC_{max} : Maximum state of charge of the battery
  • SOCiniSOC_{ini} : state of charge at the beginning/end of the optimization window

Optimization constraints:

  • Battery power (positive = charging, negative = discharging) limits:

BdBtBctT -B_d \le B_t \le B_c \quad t \in T

  • State of charge limits:

SOCminSOCini+t=1TBtΔtBcapSOCmaxtT SOC_{min} \le SOC_{ini} + \frac{\sum_{t=1}^T B_t \Delta t}{B_{cap}} \le SOC_{max} \quad t \in T

  • 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:

t=1TBtΔt=0 \sum_{t=1}^T B_t \Delta t = 0

  • The imported energy must remain between 0 and the maximum grid import capacity ICtIC_t:

0ItICtΔttT 0 \le I_t \le IC_t \Delta t \quad t \in T

  • The exported energy must remain between 0 and the maximum grid export capacity ECtEC_t:

0EtECtΔttT 0 \le E_t \le EC_t \Delta t \quad t \in T

  • Energy balance behind-the-meter:

ItEt=Bt+LtGt I_t - E_t = B_t + L_t - G_t