# Energy management for an electric microgrid

We present here a microgrid problem introduced and solved by MILP techniques in , later studied in  with direct and Hamilton-Jacobi-Bellman methods. In the context of an isolated village in the Chilean mountains, we consider a microgrid comprised of a diesel generator, photo-voltaic panels and a battery energy storage system (BESS). The aim is to satisfy the energy demand (power load) from the villagers at all times, while minimizing the overall diesel consumption. One of the difficulties is that the diesel generator has a turn-on cost, thus we have to keep track of its on/off state over time. This problem falls in the class of switched systems and can be solved with a dynamic programming approach. We consider a fixed horizon T = 48 hours. For t ∈ [0, T], we denote by PS(t) the solar power from the photovoltaic panels, PD(t) the diesel generator power and PL(t) the electricity load.

Dynamics. The state of charge SOC(t) of the BESS evolves according to $Latex formula$

where Q_B is the maximum capacity of the battery, $Latex formula$ are the input and output power of the BESS, and $Latex formula$ are the efficiency ratios for the charge and discharge processes, assumed constant. We introduce the slack variable $Latex formula$ that represents the excess power $Latex formula$, which has to be shed, or the missing power in the microgrid $Latex formula$, which turns into unmet demand. The addition of this variable ensures the mathematical feasibility of the problem.

Cost function.We model the fuel consumption of the diesel generator by $Latex formula$

The fuel consumption curve is strictly concave and was extrapolated from the datasheet provided by the diesel generator manufacturer as in . Note that turning the diesel generator on adds a fixed instantaneous consumption of 2l. Total cost is the sum of the diesel cost and unserved energy cost $Latex formula$, with $Latex formula$ and the unit price for diesel $Latex formula$ (Chilean Pesos).

Constraints. For physical reasons, the system is subject to the following constraints at every time $Latex formula$ These include the bounds for the battery state of charge, diesel generator power output, and discharge charge limits for the BESS $Latex formula$

Moreover, the power equilibrium must hold at all times and can be used to eliminate some of the variables: $Latex formula$

External data. We choose two test cases of a 48h time frame in winter and summer. The power load $Latex formula$ and solar power $Latex formula$ are shown below. summer data winter data

The ‘PMP trick’.This problem can be solved directly by BocopHJB using a basic control discretization for $Latex formula$ and $Latex formula$. However, in this particular case, we are able to exploit the properties of the problem to improve the method. If $Latex formula$ is the optimal control, denote by $Latex formula$ the optimal state and $Latex formula$ the costate associated to the dynamics constraint $Latex formula$. Defining the Hamiltonian $Latex formula$ the Pontryagin’s Maximum Principle (PMP) says that for all $Latex formula$ we have $Latex formula$

Since the dynamics is continuous and piecewise affine, the Hamiltonian is the sum of a continuous, piecewise affine and of a continuous strictly concave functions, and therefore is continuous, piecewise strictly concave. Therefore it can attain its minimum only at one of the extreme points of the pieces. Taking into account the constraints, we have at most five possible optimal controls, as illustrated below. Moreover, the values of these controls can be computed explicitly, since they do not depend on $Latex formula$ (which is not true in general). Therefore, instead of the usual control discretization we only test these controls, gaining both in speed and precision.

So:
– if the Diesel is off (mode 0), we simply take $Latex formula$.
– if the Diesel is on (mode 1), we test the five cases:

• $Latex formula$ (minimum power)
• $Latex formula$ (maximum power)
• $Latex formula$ such that $Latex formula$ (battery unused)
• $Latex formula$ such that $Latex formula$ (maximal charge)
• $Latex formula$such that $Latex formula$ (maximal discharge) We present the results of the optimization for the two test cases. The Solar Power fills the demand, with any excess power used to charge the battery. The Diesel is always off when solar power is available, and is switched on once a day during the evening peak in demand. The Diesel output is often greater than power demand: it is also used to charge the battery. The battery fills the gaps between production and demand especially at night.

Other formulations. We can also solve the problem using a manual control discretization for $Latex formula$ Finally, given the small number of admissible controls, we can actually model each of them with modes and remove the control $Latex formula$ altogether. The solutions obtained by the different formulations are quite close. References
 R. Palma-Behnke, C. Benavides, F. Lanas, B. Severino, L. Reyes, J. Llanos, and D. Sez. A microgrid energy management system based on the rolling horizon strategy. IEEE Transactions on Smart Grid, 4(2):996–1006, 2013.
 Benjamin Heymann, J. Frédéric Bonnans, Pierre Martinon, Francisco J. Silva, Fernando Lanas, and Guillermo Jiménez-Estévez. Continuous optimal control approaches to microgrid energy management. Energy Systems, 2017. DOI