Open Access
This article is

- freely available
- re-usable

*Energies*
**2018**,
*11*(8),
2167;
doi:10.3390/en11082167

Article

Optimal Energy Management within a Microgrid: A Comparative Study

^{1}

Electrical Engineering Department, Campus Irapuato-Salamanca, University of Guanajuato, Guanajuato 36885, Mexico

^{2}

Department of Informatics, University of Almería, Agrifood Campus of International Excellence (ceiA3) CIESOL Joint Centre University of Almería-CIEMAT, 04120 Almería, Spain

^{*}

Author to whom correspondence should be addressed.

Received: 21 June 2018 / Accepted: 16 August 2018 / Published: 19 August 2018

## Abstract

**:**

In this work, we focus on optimal energy management within the context of the tertiary control of a microgrid operating in grid-connected mode. Specifically, the optimal energy management problem is solved in a unified way by using the optimal power flow (OPF) and day-ahead concepts. The elements considered in the microgrid are a photovoltaic panel, a wind turbine, electric vehicles, a storage system, and a point of common coupling with the main grid. The aim of this paper consists of optimizing the economic energy dispatch within the microgrid considering known predictions of electricity demand, solar radiation, and wind speed for a given period of time. The OPF is solved using three different algorithms provided by the optimization toolbox of MATLAB

^{®}(R2015a, MathWorks^{®}, Natick, MA, USA): the interior point method (IP), a hybrid genetic algorithm with interior point (GA-IP), and a hybrid direct search with interior point (patternsearch-IP). The efficiency and effectiveness of the algorithms to optimize the energy dispatch within the microgrid are verified and analyzed through a case study, where real climatological data of solar irradiance, wind speed in Almería city, photovoltaic system data, and room load from a bioclimatic building were considered.Keywords:

microgrid; optimal power flow; distributed power system; energy management## 1. Introduction

Nowadays, continuous technological advances have caused a remarkable reduction in prices of electricity generation systems powered by renewable energy resources. This fact and the high level of efficiency achieved in small generating plants, availability of technology for generation from renewable resources, and the release of the electricity market have promoted the integration of Distributed Generation (DG) at the distribution level. Distributed generation sources provide energy directly to the distribution network or supplied directly to a set of consumers [1]. Technological innovation, enabling policies, and the drive to address climate change have placed renewables at the centre of the global energy transformation [2]. Accordingly, renewable energy systems have taken a core position for electric power distributed generation. Due to its fast technological development, the commonly installed distributed generators are photovoltaic and wind turbine systems. The integration of these renewable DG systems refreshes the electric distribution networks and provides new opportunities and benefits. Its integration, however, brings new challenges for the protection, control, and operation of these electric networks [3]. For example, traditional electric distribution networks were designed, controlled, and operated as passive systems, whereas the integration of DG transforms them into active power networks where the energy flow is now bidirectional. One of the main challenges for the integration of renewable DG systems is the intermittent power generation, i.e., their power production depends on weather conditions. The intermittency of these sources produces a power generation that requires a robust control system to fit the profile of the load demand. Moreover, it makes the balance of the network and planning reserves more complex [4].

The microgrid concept was introduced precisely as a solution for the reliable integration of DG systems [5]. The U.S. Department of Energy (DOE) defines a microgrid as “a group of interconnected loads and distributed energy resources within clearly defined electrical boundaries that acts as a single controllable entity with respect to the grid. A microgrid can connect and disconnect from the grid to enable it to operate in both grid-connected or island mode [6].” Currently, many other organizations and research groups define microgrids with very similar definitions, including the concept of a system having Points of Common Coupling (PCC), of multiple controllable loads and distributed generation, energy storage, of islanding from the grid, and, recently included, the concept of a power system cell [3]. A microgrid must accomplish certain special needs, such as improving local security, reducing loss connection, supporting local tensions, correcting the voltage drop, or providing uninterruptible power supplies, etc. In addition, the microgrid must have the ability to respond in seconds to the system requirements and final consumers [7,8,9].

According to the aforementioned definition, a microgrid has two operation modes: grid-connected mode, where the microgrid is connected to the main network to a low or medium voltage level through one or more PCC, and island mode, where the microgrid works without connection with the main grid [10]. The operational requirements for each mode of operation as well as the specifications and stability control are different [11]. However, in either mode of operation, controlling the microgrid is performed by a hierarchical control of three levels: primary control, secondary control, and tertiary control systems [5]. This work focuses on the control task of tertiary control for microgrids operating in grid-connected mode.

The tertiary control is the lowest control level in the hierarchical structure of the microgrid control system. The control task of the tertiary control considers the economical concerns in the optimal operation of the microgrid, and manages the power flow between the microgrid and the main grid in grid-connected mode [12]. In order to achieve this control task, the formulation and solution of an optimal power flow (OPF) model is required. In grid-connected mode the power deficit can be supplied by the main grid, and excess power generated in the microgrid can be traded with the main grid and can provide ancillary services [5]. Accordingly, the OPF model in this work considers minimizing the cost of the total energy imported through the PCC for the time span of interest. For this purpose, the energy resources and the power flow within the microgrid are optimized. In this way, the energy management within the microgrid in grid-connected mode is optimized within the context of the tertiary control.

The problem is formulated according to the framework provided by the day-ahead dispatch problem. With the day-ahead dispatch scheme, it is possible to perform the optimum management of energy distribution systems to improve the use of renewable energy [13]; moreover, this concept is more related with the active energy management. In this approach, optimization of active power flow in this work is approached as a day-ahead dispatch problem in which appropriate predictions of demand and electricity generation to solve the economic power dispatch within the microgrid are considered.

The energy management within a microgrid is a research topic widely dealt with in literature in the last years. In [14] the proposed algorithm is able to adjust microgrid generation to demand on-line in grid-connected-mode. To this end, the algorithm optimizes both fuel consumption and emissions cost functions through a heuristic approach. The optimal power dispatch is virtually formulated as a lossless power dispatch problem. In this way, the algorithm computational burden and execution time (around 1 ms) are very low, which may allow its implementation on low-cost programmable controllers to perform the optimal power dispatch. It is noted that power losses and network voltages issues are not accounted for in this approach. Several simulation tests are presented to show the goodness of the proposed controller. On the other hand, in [15] an economic distributed Model-based Predictive Control (MPC) is proposed to manage the energy in several microgrids in a stochastic way. Through the probabilistic forecasts of renewable power generation and microgrid load, the proposed scheme effectively handles the uncertainties in both supply and demand. The proposed scheme was evaluated on ten interconnected microgrids. The results indicated that it successfully reduces the systemwide operating cost, achieves the supply–demand balance in each microgrid, and brings the energy exchange between the distribution network operator and main grid to a predefined trajectory. The originality of this work lies in the coordination of multi-microgrids and the distribution network through a hierarchical, distributed, economic, and stochastic MPC.

Other work which is focused on several microgrids is presented in [16], where optimization-based scheduling strategies for the coordination of microgrids are commented upon. The main novelty of this work is the simultaneous management of energy production and energy demand within a reactive scheduling approach to deal with the presence of uncertainty associated to production and consumption. A Mixed-Integer Linear Programming (MILP) formulation is presented and used within a rolling horizon scheme that periodically updates input data information. Although the use of rolling horizon strategies for scheduling problems in uncertain scenarios is well known, its application in microgrid scheduling constitutes a challenge in this area. The proposed strategy is tested with a microgrid basic structure formed by photovoltaic panels, wind turbines, and energy storage units. Results can be used as the basis for solving further problems with higher complexity. On the other hand, in [17] the problem of energy management in microgrids is formulated for real-time operation. The online energy management is modelled as a stochastic optimal power flow problem and an energy management strategy (EMS) based on Lyapunov optimization is proposed. Then, the proposed EMS is applied to a real microgrid system. The simulation tests done show that the performance of the proposed EMS is close to an optimal offline algorithm. In a similar way, an algorithm for EMS based on multilayer ant colony optimization (EMS-MACO) is presented in [18]. Its main aim is to find energy scheduling in a microgrid through the optimal operation of its microsources. By this way, the electricity production cost can be reduced. The performance of the proposed algorithm is compared with modified conventional EMS (MCEMS) and particle swarm optimization (PSO) based on EMS. Analysis of obtained results demonstrates that the system performance is improved and the energy cost reduced. Specifically, the MACO algorithm, due to needing less iterations to converge, can provide a better response than the PSO and, moreover, the application of MACO reaches the lowest energy cost, reducing it by about 5% and 20% when compared with PSO and MCEMS, respectively. A decentralized microgrid energy management system is proposed in [19]; the controllers are located in each household and built on open code optimizers, and low-cost hardware was developed. In order to minimize the chances of a failure, a solution redundant in the aspects of communication and hot standby control devices was developed. The optimization problem is solved through linear programming (linprog). The microgrid is basically formed by a load, two solar panels, two wind turbines, and an energy storage unit. Microgrid power lines can be made as AC or DC. Besides that, the microgrid can be connected to the power grid and can interact with it. The obtained results show that the proposed solution can be useful for small settlements and farms instead of industrial installations. Finally, the interested reader can find a survey which presents the latest advances in adaptive and intelligent methods to control microgrids in [20]. The motivation of applying intelligent techniques is to enhance the control system performance in the microgrid. Thus, in that work, several control and intelligent techniques, such as Proportional–Integral–Derivative (PID) controller, MPC, PSO, and so on, used to manage the energy in a microgrid are discussed and classified.

At this point, it is important to emphasize the main problem of OPF dealt with in this work: optimal energy management as a part of the tertiary control in a microgrid. It is addressed according to the energy optimization approach for microgrids. The minimization of the cost of energy imported from the main network is the aspect considered to formulate the optimization objective; that is, it is considered an economic aspect. In addition, the determination of reference curves of power generated, stored, and exchanged with the main network throughout the day in advance, i.e., the optimum dispatch of energy, defines the scope of the present work. Thus, the problem has been formulated as a dispatch problem using the concept of day-ahead. The associated optimization model has been formulated as a unified model taking into account distributed generation sources and energy storage units, i.e., batteries. Moreover, different from traditional models, the proposed optimization model has taken into account constraints for the balance equations corresponding to the nodes of the microgrid. By this way, through the model optimization, not only is the best energy management for the microgrid obtained but, at the same time, the generation and voltage levels of all the elements which form the microgrid are fulfilled. Any of the works cited in the previous paragraph use a unified microgrid model which includes a wind turbine, photovoltaic modules, electric vehicle, and so on, and formulate it using the concept of day-ahead. Besides that, unlike the cited works in the previous paragraph, where only one optimization method to solve the energy management problem is used, in this work the optimum dispatch of energy is acquired through three different optimization methods for a unified model of OPF for microgrids. By this way, the optimization methods can be tested and compared in order to improve the computational cost associated with the optimum dispatch of energy. Specifically, the optimization methods are (i) interior point, (ii) hybrid genetic algorithm with interior point, and (iii) hybrid direct search with interior point; all of them provided by the optimization toolbox included in MATLAB

^{®}. In order to test the performance of each optimization method, real data from the Solar Energy Research Center (in Spanish: Centro de Investigación en Energía SOLar—CIESOL) bioclimatic building placed in Almería (south-east of Spain) have been used.The rest of the paper is organized as follows: In Section 2, each component of the microgrid is modelled and described. Then, in Section 3, a generic model of OPF for microgrid is described. Section 4 is devoted to the explicit model of OPC. Finally, the results are presented in Section 5, whereas in Section 6, conclusions are drawn and future work lines are exposed.

## 2. Model for Microgrid Components

The models for microgrid components presented in this section are considered to explicitly formulate the unified model of OPF for microgrid presented in Section 4.

#### 2.1. Points of Common Coupling

It is considered that the microgrid operates in grid-connected mode, such that it is connected to the main grid via N

_{pcc}(N_{pcc}≥ 1) Points of Common Coupling (PCC). It is assumed that each PCC is electrically robust and is an interface for the unlimited exchange of both active and reactive power between the microgrid and the main grid. In this context, the PCC are modeled as generational sources that operate at voltage levels magnitude ${V}_{j}^{{t}_{z}}$ and angle ${\theta}_{j}^{{t}_{z}}$ within the limits given by Equation (1):
$${\underset{\_}{V}}_{j}\le {V}_{j}^{{t}_{z}}\le {\overline{V}}_{j};{\underset{\_}{\theta}}_{j}\le {\theta}_{j}^{{t}_{z}}\le {\overline{\theta}}_{j};\forall {t}_{z}\in T;\forall j\in \mathrm{PCC}$$

For time t

_{z}, the cost of active total power exchanged through the PCC is modeled by Equation (2), where a_{j}, b_{j}, and c_{j}are weight constant coefficients for the jth PCC. The variable ${P}_{RP\text{}j}^{{t}_{z}}$ denotes the power exchanged through the jth PCC. The decision variables associated with the PCC are $\left[{V}_{j}^{{t}_{z}},{\theta}_{j}^{{t}_{z}},{P}_{RP\text{}j}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T,\text{}\forall j\in \mathrm{PCC}$) where ${y}_{RD}$ are the distribution grid variables.
$${f}^{{t}_{z}}\left({y}^{{t}_{z}}\right)={\displaystyle \sum}_{j=1}^{{N}_{\mathrm{pcc}}}{a}_{j}+{b}_{j}\left({P}_{RP\text{}j}^{{t}_{z}}\right)+{c}_{j}{\left({P}_{RP\text{}j}^{{t}_{z}}\right)}^{2};\forall {t}_{z}\in T$$

#### 2.2. Feeders

Each feeder is modeled as a line of transmission, as is illustrated in Figure 1, where I

_{i}and E_{i}are the phasors of the injected electricity and voltage, respectively, on the node i (i = k, m) of the microgrid. R, L, and B_{c}represent the parameters of resistance series, inductance series, and shunt susceptance, respectively, of the feeder. The relationship electricity–voltage of the equivalent circuit is given by Equation (5) [21]. Admittance matrix elements are evaluated in Equations (4) and (5).
$$\left[\begin{array}{c}{I}_{k}^{{t}_{z}}\\ {I}_{m}^{{t}_{z}}\end{array}\right]=\left[\begin{array}{cc}{Y}_{kk}& {Y}_{km}\\ {Y}_{mk}& {Y}_{mm}\end{array}\right]\left[\begin{array}{c}{E}_{k}^{{t}_{z}}\\ {E}_{m}^{{t}_{z}}\end{array}\right];\forall {t}_{z}\in T$$

$${Y}_{kk}={Y}_{mm}=\left({y}_{km}+j\xb70.5\xb7Bc\right)={G}_{kk}+j{B}_{kk};{Y}_{km}={Y}_{mk}=-{y}_{km}={G}_{km}+j{B}_{km}$$

$${G}_{km}=R/{R}^{2}+{\left(\omega L\right)}^{2};{B}_{km}=-\omega L/{R}^{2}+{\left(\omega L\right)}^{2}$$

Starting from Figure 1 and Equation (3) it is possible to obtain expressions that model the injection of active and reactive power—Equations (6) and (7), respectively—on the node i (i = k, m) at each moment t

_{T}∈ z [21] where j = k, m, being j ≠ i. The variables ${V}_{n}^{{t}_{z}}$ and ${\theta}_{n}^{{t}_{z}}$ (n = i, j) represent the magnitude and the angle of the nodal voltage phasor E_{i}:
$${P}_{iny\text{}i}^{{t}_{z}}={\left({V}_{i}^{{t}_{z}}\right)}^{2}{G}_{ii}+{V}_{i}^{{t}_{z}}{V}_{j}^{{t}_{z}}\left[{G}_{ij}\mathrm{cos}\left({\theta}_{i}^{{t}_{z}}-{\theta}_{j}^{{t}_{z}}\right)+{B}_{ij}\mathrm{sin}\left({\theta}_{i}^{{t}_{z}}-{\theta}_{j}^{{t}_{z}}\right)\right]$$

$${Q}_{iny\text{}i}^{inj\text{}{t}_{z}}=-{\left({V}_{i}^{{t}_{z}}\right)}^{2}{B}_{ii}+{V}_{i}^{{t}_{z}}{V}_{j}^{{t}_{z}}\left[{G}_{ij}\mathrm{sin}\left({\theta}_{i}^{{t}_{z}}-{\theta}_{j}^{{t}_{z}}\right)-{B}_{ij}\mathrm{cos}\left({\theta}_{i}^{{t}_{z}}-{\theta}_{j}^{{t}_{z}}\right)\right]$$

The decision variables associated to these feeders correspond to the nodal voltages in its terminals $\left[{V}_{k}^{{t}_{z}}{,V}_{m}^{{t}_{z}}{,\theta}_{k}^{{t}_{z}}{,\theta}_{m}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$).

#### 2.3. Transformer

The primary winding is considered an ideal transformer with relation to complex tap T
where

_{v}:1 and T_{i}:1 in series with the impedance Z_{p}(refers to Figure 2) where T_{v}= T_{i}* = T_{v}∠φ_{tv}, and the symbol * denotes a complex conjugate. The secondary winding is also represented as an ideal transformer with relation to complex tap U_{v}:1 and U_{i}:1 in series with the impedance Z_{s}where U_{v}= U_{i}* = U_{v}∠φ_{uv}. The relationship between voltage V_{p}and electricity I_{p}of the primary winding and the voltage V_{s}and electricity I_{s}of the secondary one is given by Equation (8) [21].
$$\left[\begin{array}{c}{I}_{P}^{{t}_{z}}\\ {I}_{s}^{{t}_{z}}\end{array}\right]=\left[\begin{array}{cc}{G}_{PP}& {G}_{PS}\\ {G}_{SP}& {G}_{SS}\end{array}\right]+j\left[\begin{array}{cc}{B}_{PP}& {B}_{PS}\\ {B}_{SP}& {B}_{SS}\end{array}\right]\left[\begin{array}{c}{V}_{P}^{{t}_{z}}\\ {V}_{s}^{{t}_{z}}\end{array}\right];\forall {t}_{z}\in T$$

$${G}_{PP}=\frac{F1\left({U}_{v}^{2}+R1\right)+F2R2}{F{1}^{2}+F{2}^{2}},{B}_{PP}=\frac{F1R2-F2\left({U}_{v}^{2}+R1\right)}{F{1}^{2}+F{2}^{2}}$$

$${G}_{SS}=\frac{F1\left({T}_{v}^{2}+R3\right)+F2R4}{F{1}^{2}+F{2}^{2}},{B}_{SS}=\frac{F1R4-F2\left({T}_{v}^{2}+R3\right)}{F{1}^{2}+F{2}^{2}}$$

$${B}_{PS}=\frac{{T}_{v}{U}_{v}\left(F2\mathrm{cos}\left({\varphi}_{1}\right)+F1\mathrm{sin}({\varphi}_{1}\right)}{F{1}^{2}+F{2}^{2}},{G}_{SP}=\frac{-{T}_{v}{U}_{v}\left(F1\mathrm{cos}\left({\varphi}_{2}\right)+F2\mathrm{sin}({\varphi}_{2}\right)}{F{1}^{2}+F{2}^{2}}$$

$${B}_{SP}=\frac{{T}_{v}{U}_{v}\left(F2\mathrm{cos}\left({\varphi}_{2}\right)+F1\mathrm{sin}({\varphi}_{2}\right)}{F{1}^{2}+F{2}^{2}},F1={T}_{v}^{2}{R}_{S}+{U}_{v}^{2}{R}_{P}+{R}_{eq1},\phantom{\rule{0ex}{0ex}}F2={T}_{v}^{2}{X}_{S}+{U}_{v}^{2}{X}_{P}+{X}_{eq1}$$

$${R}_{eq1}=\left(\xi \right){G}_{0}-\left(\zeta \right){B}_{0},{X}_{eq1}=\left(\xi \right){B}_{0}-\left(\zeta \right){G}_{0},\xi ={R}_{P}{R}_{S}-{X}_{P}{X}_{S},\zeta ={R}_{P}{X}_{S}-{R}_{S}{X}_{P}$$

$$R1={R}_{S}{G}_{0}-{X}_{S}{B}_{0},R2={R}_{S}{B}_{0}-{X}_{S}{G}_{0},R3={R}_{P}{G}_{0}-{X}_{P}{B}_{0},R4={R}_{P}{B}_{0}-{X}_{P}{G}_{0}$$

$${\varphi}_{1}={\varphi}_{tv}-{\varphi}_{uv},{\varphi}_{2}={\varphi}_{uv}-{\varphi}_{tv}$$

As the feeders, the injections of active and reactive power in the nodes of connection i and j, where i = p, s; j = p, s; i ≠ j are represented by Equations (6) and (7), but considering the conductance and susceptance matrices of Equation (8), it is important to highlight that the decision variables associated to transformers correspond to the nodal voltages in its terminals $\left[{V}_{p}^{{t}_{z}}{,V}_{s}^{{t}_{z}},{\theta}_{p}^{{t}_{z}},{\theta}_{s}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$).

#### 2.4. Batteries

The batteries are elements that can operate in charge or discharge mode to provide or consume a net amount of active power in their connection node. Then, the jth battery is represented by two sources of active power, as shown in Figure 3 [22]. One of them represents the charge power ${P}_{Bc\text{}j}^{{t}_{z}}\le 0$ and the other the discharge power ${P}_{Bd\text{}j}^{{t}_{z}}\ge 0$; the sum of both powers represents the net power ${P}_{Bn\text{}j}^{{t}_{z}}$ provided or consumed by the battery in their connection node.

$${P}_{Bn\text{}j}^{{t}_{z}}={P}_{Bc\text{}j}^{{t}_{z}}+{P}_{Bd\text{}j}^{{t}_{z}};0\le {P}_{Bd\text{}j}^{{t}_{z}};{P}_{Bc\text{}j}^{{t}_{z}}\le 0;\forall {t}_{z}\in T$$

In addition, the voltage phasor in the connection node is represented by its magnitude ${V}_{j}^{{t}_{z}}$ and its angle ${\theta}_{j}^{{t}_{z}}$. Thus, the decision variables of the jth battery are $\left[{P}_{Bd\text{}j}^{{t}_{z}}{,P}_{Bc\text{}j}^{{t}_{z}}\right]\in {y}_{B}$ ($\forall {t}_{z}\in T$) where ${y}_{B}$ are the battery variables, while $\left[{V}_{j}^{{t}_{z}},{\theta}_{j}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$). Moreover, the State of Charge (SOC) of the jth battery in the time t

_{z}(${\mathrm{SOC}}_{B\text{}j}^{{t}_{z}}$) can be approximated by means of Equation (10). In Equation (10), ${\mathrm{SOC}}_{B\text{}j}^{{t}_{0}}$ represents the SOC at a given initial time t_{0}, whereas E_{nom}is the energy capacity of the battery, whose efficiencies for charge and discharge operations are given by ε_{c}_{j}and ε_{dj}, respectively. Lastly, ∆t is a fixed time step length.
$${\mathrm{SOC}}_{B\text{}j}^{{t}_{z}}={\mathrm{SOC}}_{B\text{}j}^{{t}_{0}}-\frac{{\epsilon}_{cj}\Delta t}{{E}_{Bnom\text{}j}}{\displaystyle \sum}_{t=1}^{{t}_{z}}{P}_{Bc\text{}j}^{t}-\frac{\Delta t}{{E}_{Bnom\text{}j}{\epsilon}_{dj}}{\displaystyle \sum}_{t=1}^{{t}_{z}}{P}_{Bd\text{}j}^{t}$$

It is assumed that the energy provided by the batteries has no cost since it is absorbed and provided in the same node of connection. However, since the optimization algorithm will manage the power, batteries will be charged in periods of low-cost energy and will be discharged in periods of high cost. This fact involves an economic benefit in the operation of the microgrid.

#### 2.5. Wind Turbine

For the aim of the stationary analysis, the wind turbine can be considered a source of noncontrolled active power ${P}_{A\text{}j}^{{t}_{z}}$, depending on its density ${\delta}_{w}$, wind speed ${S}_{w}^{{t}_{z}}$, and the area ${A}_{w}$ covered by the blades of the wind turbine [23].

$${P}_{Bn\text{}j}^{{t}_{z}}={\delta}_{w}{A}_{w}{\left({S}_{w}^{{t}_{z}}\right)}^{3}/2;\forall {t}_{z}\in T$$

Since it is considered that the power delivered by the wind turbine is not controllable, this element does not introduce decision variables. However, Equation (12) is required to assess the contribution of the power of the jth wind turbine for a wind speed curve, ${S}_{w}^{{t}_{z}}\text{}\forall \text{}{t}_{z}\in T$; density, ${\delta}_{w}$, and area, ${A}_{w}$, given. Clearly, the magnitude ${V}_{j}^{{t}_{z}}$ and angle ${\theta}_{j}^{{t}_{z}}$ of the voltage phasor of the connection node are considered decision variables, such that $\left[{V}_{j}^{{t}_{z}},{\theta}_{j}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$). Finally, it is assumed that the energy provided by the wind turbine has no cost. In addition, a good forecast for wind speed curves is considered to be available.

#### 2.6. Photovoltaic Modules

Figure 4 shows the schematic model of a photovoltaic module connected to the kth node through a DC/AC converter [24]. The implicit expression showed in Equation (12) models the behavior of the DC current in ${I}_{CD\text{}k}^{{t}_{z}}$ panel terminals, where I

_{ph}, I_{0}, ${V}_{CD\text{}k}^{{t}_{z}}$, R_{s}, n_{s}, and n_{p}represent the current of the photovoltaic panel, the current of saturation, the DC voltage in the module terminals, the resistance in series, and the number of cells in series and in parallel, respectively. The term R_{s}is evaluated from Equation (13), where V_{oc}, V_{mp}, I, and I_{mp}represent the open circuit voltage, the voltage of the point of maximum power, short circuit electricity, and maximum power point electricity, respectively. Terms I_{sc}and V_{oc}are evaluated through Equations (14) and (15), respectively, where I_{sc}_{,stc}, G, G_{stc}, k_{i}, T, T_{stc}, V_{oc,stc}, and k_{v}represent the short circuit electricity standard under conditions of test, irradiance under test, electricity temperature coefficient, temperature of the panel, standard temperature under test, standard low open circuit voltage conditions test, and voltage and temperature coefficient, respectively.
$${I}_{CD\text{}k}^{{t}_{z}}=\left[{I}_{ph}-{I}_{0}\left(\mathrm{exp}\left(\frac{\frac{{V}_{CD\text{}k}^{{t}_{z}}}{{n}_{s}}+\frac{{I}_{CD\text{}k}^{{t}_{z}}}{{n}_{p}}{R}_{S}}{{V}_{CD}^{{t}_{z}}}\right)-1\right)\right]{n}_{p};\forall {t}_{z}\in T$$

$${R}_{S}=\frac{\frac{{V}_{oc}-{V}_{mp}}{{n}_{s}}+{V}_{CD}^{{t}_{z}}\mathrm{ln}\left(\frac{{I}_{SC}-{I}_{mp}}{{I}_{SC}}\right)}{\frac{{I}_{mp}}{{n}_{p}}}$$

$${I}_{SC}\left(T,G\right)={I}_{SC,stc}-\frac{G}{{G}_{stc}}\left[1+\frac{{k}_{i}}{100}\left(T-{T}_{stc}\right)\right]$$

$${V}_{oc}\left(T\right)={V}_{oc,stc}\left[1+\frac{{k}_{v}}{100}\left(T-{T}_{stc}\right)\right]$$

In this work, the photovoltaic module parameters involved in Equations (12)–(15) were taken from the features of the polycrystalline module ATERSA A-222P [25]. Moreover, a good forecast of solar irradiance curves is considered to be available.

According to the model in Figure 4, the injected power in DC terminals (generated by module) can be expressed directly as

$${P}_{CD\text{}k}^{{t}_{z}}\left({V}_{CD\text{}k}^{{t}_{z}},{I}_{CD\text{}k}^{{t}_{z}}\right)={I}_{CD\text{}k}^{{t}_{z}}{V}_{CD\text{}k}^{{t}_{z}};\forall {t}_{z}\in T$$

Moreover, the balance of power between the AC and DC terminals of the inverter must also be fulfilled. If the losses of the converter are rejected, then
where ${P}_{CA\text{}k}^{{t}_{z}}$ is the active power injected at the terminals of the primary transformer coupling module; ${V}_{k}^{{t}_{z}}$ and ${\theta}_{k}^{{t}_{z}}$ are the magnitude and the angle, respectively, of the voltage phasor for such terminals; and ${V}_{m}^{{t}_{z}}$ and ${\theta}_{m}^{{t}_{z}}$ represent the same but for the secondary terminals. Therefore, ${P}_{CA\text{}k}^{{t}_{z}}$ in Equation (17) is formulated explicitly by means of Equation (7), but considering the matrix of conductances and susceptances of Equation (9). It is important to mention that, due to being considered a DC/AC converter multipulse with 48 pulses, the following relationship must also hold [26]:

$${P}_{CA\text{}k}^{{t}_{z}}\left({V}_{k}^{{t}_{z}},{V}_{m}^{{t}_{z}},{\theta}_{k}^{{t}_{z}},{\theta}_{m}^{{t}_{z}}\right)={P}_{CD\text{}k}^{{t}_{z}}\left({V}_{CD\text{}k}^{{t}_{z}},{I}_{CD\text{}k}^{{t}_{z}}\right);\forall {t}_{z}\in T$$

$${V}_{CD\text{}k}^{{t}_{z}}=\frac{\pi}{16}{V}_{k}^{{t}_{z}};\forall {t}_{z}\in T.$$

It is important to highlight that the decision variables introduced by the photovoltaic module are $\left[{V}_{CD\text{}k}^{{t}_{z}},{I}_{CD\text{}k}^{{t}_{z}}\right]\in {y}_{\mathrm{MF}}$ ($\forall {t}_{z}\in T$), whereas $\left[{V}_{k}^{{t}_{z}},{V}_{m}^{{t}_{z}},{\theta}_{k}^{{t}_{z}},{\theta}_{m}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$).

#### 2.7. Electrical Load

Energy consumption in load nodes of the microgrid is represented by a model of constant power for any interval of time T. The ith complex power ${S}_{li}^{{t}_{z}}$ consumed in the node is then represented by Equation (19) where ${P}_{li}^{{t}_{z}}$ and ${Q}_{li}^{{t}_{z}}$ represent the power consumption active on that node at the instant t

_{z}.
$${S}_{li}^{{t}_{z}}={P}_{li}^{{t}_{z}}+j{Q}_{li}^{{t}_{z}};\forall {t}_{z}\in T$$

The model of energy demand does not introduce decision variables to the optimization problem, but the magnitude ${V}_{i}^{{t}_{z}}$ and angle ${\theta}_{i}^{{t}_{z}}$ of the connection node phasor voltage must be considered decision variables, such as $\left[{V}_{i}^{{t}_{z}},{\theta}_{i}^{{t}_{z}}\right]\in {y}_{RD}$ ($\forall {t}_{z}\in T$). In addition, it is assumed that a good forecast of the energy demand curves is available (${S}_{li}^{{t}_{z}}\forall {i,t}_{z}\in T$).

#### 2.8. Electric Vehicle

Nowadays, tendencies exist to make energy consumption more efficient to satisfy transportation needs. In this case, it is necessary to consider that an Electric Vehicle (EV) will be connected into a microgrid to charge its battery efficiently. Also, the EV will work as a storage system responsible for energy management and optimization within the microgrid.

The structure of an EV is constituted mainly by an AC engine, a three-phase power rectifier (AC/DC), a storage system (battery), and a three-phase power inverter. This last component injects power from the storage system to the grid (Figure 5). The three-phase power inverter is considered as a Controlled Voltage Source (CVS), which has the ability to control the active and reactive power flow between the EV and the microgrid [27].

The real power and the reactive power injected are represented through the Equations (6) and (7), respectively. Supposing that power loss does not exist on the CVS, the power storage in the battery and the active power injected by the CVS are the same with an equality constraint, Equation (20).

$${P}_{vsc}={P}_{ev-s}$$

The State of Charge (SOC) of an EV in a determined time is described by the Equation (21) [28]. The energy consumption for an instant of time t, ${E}_{\mathrm{consumption}}\left(t\right)$, is the result of the sum of the energy storage at time t − 1, ${E}_{\mathrm{storage}}\left(t-1\right)$, the energy consumed at time t, ${E}_{\mathrm{consumed}}\left(t\right)$, and the sum of the energy charged $\sum}_{t=1}^{{t}_{z}}(P{\left(t\right)}_{\mathrm{charged}})$ and the discharged energy $\sum}_{t=1}^{{t}_{z}}(P{\left(t\right)}_{\mathrm{discharged}})$ at time t:
where $\eta c$ is the charge efficiency coefficient of EV, $\eta d$ the discharge efficiency coefficient of EV, and $\Delta t$ the differential of operational time. It is necessary to consider that the charged power is negative $(P{\left(t\right)}_{\mathrm{charged}}<0)$ and the discharged power is positive $(P{\left(t\right)}_{\mathrm{discharged}}>0)$, where the sum of these powers represents the total power injected or consumed by the battery of the EV on the grid point.

$$\begin{array}{l}\mathrm{SOC}\left(t\right)={E}_{\mathrm{consumption}}\left(t\right)\\ ={E}_{\mathrm{storage}}\left(t-1\right)+\Delta t\xb7\eta c\xb7{\displaystyle {\displaystyle \sum}_{t=1}^{{t}_{z}}}(P{\left(t\right)}_{\mathrm{charged}})\\ -{E}_{\mathrm{consumed}}\left(t\right)-\frac{1}{\eta d}\xb7\Delta t\xb7{\displaystyle {\displaystyle \sum}_{t=1}^{{t}_{z}}}(P{\left(t\right)}_{\mathrm{discharged}})\end{array}$$

In addition, the voltage phasor in the connection node is represented by a magnitude ${V}_{j}^{{t}_{z}}$ and an angle ${\theta}_{j}^{{t}_{z}}$. Thus, the decision variables of the jth battery of the EV are $\left[{P}_{\mathrm{charged}j}^{{t}_{z}},{P}_{\mathrm{discharged}j}^{{t}_{z}}\right]\in {y}_{B}$ ($\forall {t}_{z}\in T$) whereas $\left[{V}_{j}^{{t}_{z}},{\theta}_{j}^{{t}_{z}}\right]\in {y}_{VH}$ ($\forall {t}_{z}\in T$).

## 3. Generic Model of OPF for Microgrid

For electric demand curves, solar radiation, and predicted wind speed for an interval of time T, the general model of OPF is given by Equations (22)–(25). It should be noted that, in this model, it is considered that the period of time T is composed of a set of time stages t

_{z}(∀ = 1, ..., end), such that T = [t_{1}, ..., t_{end}].
$$\mathrm{Minimize}\text{}{F}_{T}={\displaystyle \sum}_{{t}_{z}=1}^{{t}_{\mathrm{end}}}{f}^{{t}_{z}}\left({y}^{{t}_{z}}\right)$$

$$\mathrm{Subject}\text{}\mathrm{to}\text{}{h}^{{t}_{z}}\left({y}^{{t}_{z}}\right)=0;\text{}\forall {t}_{z}\in T$$

$${g}^{{t}_{z}}\left({y}^{{t}_{z}}\right)\le 0;\text{}\forall {t}_{z}\in T$$

$$\underset{\_}{y}\le {y}^{{t}_{z}}\le \overline{y};\forall {t}_{z}\in T$$

Taking into account that t

_{z}represents the zth time stage, the description of the terms of the model, Equations (22)–(25), is as follows: F_{T}is the objective function to optimize along the interval T; h(y) is a set of equality constraints, which represents the balance equations of active and reactive power on all the nodes in the microgrid, as well as other operating conditions that must be fulfilled unconditionally; g(y) is a set of constraints of inequalities that represents the physical and operating limits of the elements that make up the microgrid; and y is the set of decision variables (to be optimized) composed of subsets y_{RD}, y_{MF}, and y_{B}such y = [y_{RD}, y_{MF}, y_{B}]. As has been pointed out in Section 2, y_{B}, y_{RD}, and y_{MF}represent the battery variables, distribution grid, and photovoltaic modules, respectively. The upper and lower limits, $\overline{y}$ and $\underset{\_}{y}$, of these variables are formulated through the inequality constraints; see Equation (25).## 4. Explicit Model of OPF for Microgrid

Models of the microgrid components described in Section 2 are considered in this section to formulate the explicit model of OPF for a grid-connected microgrid. For this purpose, one generic microgrid composed of a number of N

_{bAC}nodes in AC, N_{bCD}nodes in DC, N_{Al}feeders, N_{T}transformers, N_{B}battery, N_{A}wind turbines, N_{MF}photovoltaic modules, and N_{CE}electrical loads is considered. Note that the N_{pcc}points of common coupling are a subset of the N_{bAC}nodes in AC. In addition, the nodes in DC represent DC terminals of the photovoltaic modules, such that N_{bCD}= N_{MF}.#### 4.1. Objective Function

The intention is to minimize Equation (22), which is formulated explicitly taking into account Equation (2), as follows:

$${F}_{T}={\displaystyle \sum}_{{t}_{z=1}}^{{t}_{\mathrm{end}}}{\displaystyle \sum}_{j=1}^{{N}_{\mathrm{pcc}}}{a}_{j}+{b}_{j}\left({P}_{RP\text{}j}^{{t}_{z}}\right)+{c}_{j}{\left({P}_{RP\text{}j}^{{t}_{z}}\right)}^{2}.$$

Note that Equation (26) denotes that the objective is to minimize the total cost in $/h of the power imported through the PCC during the period of time T to supply the predicted demand curves ${S}_{li}^{{t}_{z}}\forall {i,t}_{z}\in T$.

#### 4.2. Equality Constraints

The set of equality constraints h(y) in Equation (23) is expressed explicitly as follows: the constraints of active $\Delta {P}_{RD\text{}i}^{{t}_{z}}$ and reactive power $\Delta {Q}_{RD\text{}i}^{{t}_{z}}$ balance corresponding to the nodes of the microgrid in AC are written in the first block of Equation (27) where the lower limit ∀j ∈ i means each element j is connected to the node i. For example, the term $\sum}_{\forall j\in i}{P}_{A\text{}j}^{{t}_{z}$ denotes the sum of the provided active powers (generated) for all wind turbines connected to the node i. It should be clarified that the term $\sum}_{\forall j\in i|j\in {N}_{\mathrm{Al}}{,N}_{T}}{P}_{iny\text{}j}^{{t}_{z}$ denotes the sum of the active powers injected to the node i through all terminal feeders and transformers connected to that node. Furthermore, the balance equations of reactive power are formulated only for the k nodes in AC that have not been connected to power sources ($\forall {k\notin N}_{GEN}$), that is, not formulated in PCC nodes or nodes where batteries, wind turbines, and photovoltaic modules are connected. From Equation (6), Equations (16) and (17) with the constraints that shape the behavior of the stationary state of each battery and its corresponding DC/AC inverter, as shown in the bottom block of Equation (27), are formulated where ${P}_{CD}\mathrm{(}V,I\mathrm{)}$ represents the term in the second member of Equation (17). Note that Equation (27) is formulated for ($\forall {t}_{z}\in T$).

$${h}^{{t}_{z}}\left({y}^{{t}_{z}}\right)=\left\{\begin{array}{c}\Delta {P}_{RD\text{}i}^{{t}_{z}}={P}_{RP\text{}i}^{{t}_{z}}+{\displaystyle {\displaystyle \sum}_{\forall j\in i}}{P}_{Bc\text{}j}^{{t}_{z}}+{\displaystyle {\displaystyle \sum}_{\forall j\in i}}{P}_{Bd\text{}j}^{{t}_{z}}+{\displaystyle {\displaystyle \sum}_{\forall j\in i}}{P}_{A\text{}j}^{{t}_{z}}+\\ {\displaystyle {\displaystyle \sum}_{\forall j\in i}}{P}_{CD\text{}j}^{{t}_{z}}-{\displaystyle {\displaystyle \sum}_{\forall j\in i}}{P}_{lj}^{{t}_{z}}-{\displaystyle {\displaystyle \sum}_{\forall j\in i|j\in {N}_{Al},{N}_{T}}}{P}_{inj\text{}j}^{{t}_{z}}\left(V,\theta \right)=0,\\ \Delta {Q}_{RD\text{}k}^{{t}_{z}}=-{\displaystyle {\displaystyle \sum}_{\forall j\in k}}{Q}_{lj}^{{t}_{z}}-{\displaystyle {\displaystyle \sum}_{\forall j\in k}}{Q}_{inj\text{}j}^{{t}_{z}}\left(V,\theta \right)=0\\ i=1,2,\dots ,{N}_{bAC};k=1,2,\dots ,{N}_{bAC}|\forall k\notin {N}_{GEN}\\ \Delta {I}_{CD\text{}k}^{{t}_{z}}={I}_{CD\text{}k}^{{t}_{z}}-{f}_{CD}\left({V}_{CD\text{}k}^{{t}_{z}},{I}_{CD\text{}k}^{{t}_{z}}\right)=0,\\ \Delta {P}_{CD\text{}k}^{{t}_{z}}={P}_{CA\text{}k}^{{t}_{z}}\left(V,\theta \right)-\Delta {P}_{CD\text{}k}^{{t}_{z}}\left({V}_{CD\text{}k}^{{t}_{z}},{I}_{CD\text{}k}^{{t}_{z}}\right)=0,\\ \Delta {V}_{CD\text{}k}^{{t}_{z}}={V}_{CD\text{}k}^{{t}_{z}}-\left(\frac{\pi}{16}\right){V}_{k}^{{t}_{z}}=0\\ k={N}_{bAC}+1,\dots ,{N}_{bAC}+{N}_{bCD}\end{array}\right\}\forall {t}_{z}\in T$$

#### 4.3. Inequality Constraints Functions

According to the element models introduced in Section 2, the only inequality constraints function g(y) in Equation (24) corresponds to the batteries, as follows. The batteries have finite capacity of charge and discharge. With this point in mind, the SOC is modulated over the period of time T through Equation (28) [22].

$${h}^{{t}_{z}}\left({y}^{{t}_{z}}\right)=\left\{{\mathrm{SOC}}_{B\text{}j}^{\mathrm{min}}\le {\mathrm{SOC}}_{B\text{}j}^{{t}_{z}}\le {\mathrm{SOC}}_{B\text{}j}^{\mathrm{max}}\right\}\forall j\in {N}_{B},\forall {t}_{z}\in T$$

#### 4.4. Equality Constraints Variables

It should be taken into account that the decision variables must acquire admissible values; otherwise, the solution provided by the OPF model could not make sense from a practical point of view. For this reason, the decision variables y are limited during the interval of time T by means of the constraints set in Equation (29):
where the set of decision variables associated to the distribution network is given by the magnitude and angle of the voltage phasor at each node, as well as the active powers exchanged with the main grid, such as ${y}_{RD}=\left[V\in {V}_{j}^{{t}_{z}},\theta \in {\theta}_{j}^{{t}_{z}},{P}_{RP\text{}j}^{{t}_{z}}\right]$; $\forall {t}_{z}\in T$ and $\forall j\in {N}_{bCA}$, whereas the decision variables batteries are ${y}_{B}=\left[{P}_{Bd\text{}k}^{{t}_{z}}{,P}_{Bc\text{}k}^{{t}_{z}}\right]\forall {t}_{z}\in T$ and $\forall k\in {N}_{B}$. Finally, the photovoltaic module decision variables are ${y}_{MF}=\left[{V}_{CD\text{}i}^{{t}_{z}}{,I}_{CD\text{}i}^{{t}_{z}}\right]$; $\forall {t}_{z}\in T$ and $\forall i\in {N}_{MF}$.

$$\left\{\begin{array}{c}{\underset{\_}{y}}_{RD}\le {y}_{RD}^{{t}_{z}}\le {\overline{y}}_{RD}\\ {\underset{\_}{y}}_{MF}\le {y}_{MF}^{{t}_{z}}\le {\overline{y}}_{MF}\\ {\underset{\_}{y}}_{B}\le {y}_{B}^{{t}_{z}}\le {\overline{y}}_{B}\end{array}\right\}\forall {t}_{z}\in T$$

In this work the IP, GA-IP, and patternsearch-IP methods provided by the MATLAB

^{®}optimization solvers are used to solve the microgrid OPF problem given by Equations (26)–(29). Since these methods can directly deal with the whole set of constraints as Equations (27)–(29) [29,30,31], the active $\Delta {P}_{RD\text{}i}^{{t}_{z}}$ and reactive $\Delta {Q}_{RD\text{}k}^{{t}_{z}}$ power balance constraints in Equation (27) do not need to be handled and solved by a power flow algorithm external to the optimization solvers. Externally solving these constraints imposes the need of an extra power flow algorithm, which in addition should be substantially upgraded to take into account the new variables and constraints introduced by the models of renewable distributed generation and storage systems. In this way, the use of the three methods provided by the MATLAB^{®}optimization solvers yields a simple approach for solving the optimization problem as Equations (26)–(29) in unified way.#### 4.5. Interior Point Method

The interior point method is applied in this work through the “fmincon” function, which belongs to the MATLAB

^{®}“Optimization Toolbox” (R2015, MathWorks^{®}, Natick, MA, USA) [29]. This method is a deterministic derivative-based tool that can be applied for local search in multivariable, smooth, continuous, differentiable, and nonlinear constrained optimization problems. The method transforms the constrained problem to an unconstrained optimization problem by using penalty barrier functions and slack variables. Based on an initial condition of the decision variables, the method performs an iterative process where the decision variables are actualized until the optimality conditions are satisfied. This deterministic method has been widely adopted to solve optimization problems in the context of OPF; hence, it is adopted in this work. The readers interested in a detailed description of the method are referred to [32].#### 4.6. Hybrid Algorithm Composed of Direct Search and Interior Point Methods

The patternsearch method is applied through the function “patternsearch” which belongs to the MATLAB

^{®}“Direct Search and Genetic Algorithm Toolbox” (R2015, MathWorks^{®}, Natick, MA, USA) [33]. Contrary to the aforementioned IP method, this method is a derivative-free metaheuristic tool for global search. The method can even deal with multivariable, nonsmooth, noncontinuous, nondifferentiable, and nonlinear constrained optimization problems. For this purpose, the nonlinear constrained optimization problems are formulated as an augmented Lagrangian function where Lagrangian multipliers, penalty parameters, and shift factors are used to combine the objective function and the nonlinear constraint. Then, the pattern search for unconstrained optimization problems is applied to minimize that augmented Lagrangian function for a sequence of Lagrangian multipliers and penalty parameters, until a stopping criterion is satisfied (typically the number of iterations) [31]. When the stopping criterion is met, the approximate solution can be provided as an initial condition to the IP method to speed up the convergence to the optimal solution [34], as was done in this work. The readers interested in a detailed description of the patternsearch method are referred to [35].#### 4.7. Hybrid Algorithm Composed of Genetic Algorithm and Interior Point Methods

This algorithm is applied through the “ga” function which belongs to the MATLAB

^{®}“Direct Search and Genetic Algorithm Toolbox” [33]. The method can deal with similar optimization problems to those described in Section 4.6. The techniques for handling nonlinear constraints and to perform the coupling with the IP method are also the ones described in that section [30]. The readers interested in a detailed description of the method are referred to [36,37].## 5. Results

Before discussing the numeric results related to the optimal energy management in microgrids through the optimal power flow (OPF) implemented in this work, it is necessary to describe the microgrid and the hardware used for the simulation of the OPF.

Firstly, the microgrid is called microgrid test (MT), and is composed of an integrated system of a photovoltaic panel (PV), a wind turbine (WT), a storage system (battery, BT), a main grid (MG), electric transformers (ET), a Park of EV (PEV), and a point of load within the system. The MT is selected as a case study to show the results of the optimal energy management obtained from the tools selected. Moreover, the generators in the microgrid use a real irradiance profile, wind speed profile of Almería city, and the electricity demand curve. All previous data were taken from Laboratory 6 of the CIESOL with different climatic variabilities.

Subsequently, an analysis of the computational performance of the interior point method (fmincon), hybrid genetic algorithm with interior point (GA-IP), and direct search hybrid with interior point (patternsearch-IP) is presented, which allows us to identify the most effective methods for solving the model presented in Equations (26)–(29). Finally, all the methods to solve the OPF are executed on a DELL computer, with 8 GB RAM and an Intel i5-4210U CPU@ 2.40 GHz processor (DELL, Mexico city, Mexico). The numerical results are reported in terms of per unit (PU) quantities.

#### 5.1. CIESOL Building

In this paper, several optimization methods are compared at a time to optimize the economic energy dispatch within a microgrid. Besides this, with the aim to evaluate the performance of each optimization method with different scenarios, real climatological data of solar radiation, wind speed, photovoltaic system data, and laboratory load saved during regular operation of the CIESOL building (http://www.ciesol.es) were considered. CIESOL is a solar energy research center placed inside the Campus of the University of Almería in the south-east of Spain; see Figure 6.

More specifically, this building is divided into two different floors with a total surface approximately equal to 1072 m

^{2}. In addition, it has been designed to be a Nearly-Zero Energy Building (NZEB), and, thus, it has several bioclimatic criteria such as the use of photovoltaic panels to produce electricity and a Heating, Ventilation, and Air Conditioning system based on solar cooling which is composed of a solar collector field, a hot water storage system, a boiler, and an absorption machine with its refrigeration tower.Furthermore, the CIESOL building works as a research center which deals with the study of the implemented bioclimatic strategies, the analysis of their influence over energy efficiency, and greenhouse-effect gasses reduction, and, also, the development of optimization techniques to increase the ratio of renewable energies use against conventional ones. For this reason, it uses a wide network of sensors and actuators whose measured data is stored in a database by means of measurement and acquisition software. More specifically, the building has a meteorological station composed of different types of sensors (e.g., temperature, relative humidity, direct and diffuse irradiance, CO

_{2}concentration, etc.) and the building rooms measure air temperature, plane radiant temperature, globe temperature, relative humidity sensors, and power meters in order to measure the energy consumption in each room. In order to use a load profile to compare the different optimization methods, one of the representative rooms of the CIESOL building has been selected as a reference, specifically, Laboratory 6. This room was chosen among the characteristic ones mainly due to its occupancy profile. In more detail, this room works as an office and it is placed in the upper floor of the CIESOL building. In addition, it is characterized by having north orientation, a volume of 76.8 m^{3}, and a window with a total surface of 2.15 × 2.09 m^{2}.#### 5.2. Microgrid Test

The microgrid test (MT) described previously is shown in Figure 7. The microgrid is connected to the main grid through the single PCC (Node 1). Furthermore, between the Nodes 3–6, 4–7, 5–8, and Nodes 9, 10, there are transformers connected. The elements that have the ability to provide active power are the main grid (PCC), WT, PV, PEV, and the battery. The parameters considered for modeling the components of this MT and the cost coefficients associated with imported energy through the PCC are presented in Table A1 and Table A2 given in Appendix A.

The PEV are composed of four EV, while the forecasting curve of load, the irradiation profile for two different clear days (summer and winter), and the speed of wind corresponding to the city of Almería, Spain, can be observed in Figure 8. All the power within the microgrid is working on per unit (p.u.), where the power base and voltage base were selected to be 10 kW and 100 V, respectively.

The voltage magnitude limits for all nodes in the microgrid are $0.95\le V\le 1.05$ p.u. The SOC limits on the battery are $0.2\le {\mathrm{SOC}}_{B}\left({t}_{z}\right)\le 0.95(\%)$, whilst the initial condition of the battery charge is ${\mathrm{SOC}}_{B}\left({t}_{0}\right)=0.9(\%)$. Moreover, all the cars in the PEV will be connected to the microgrid at hour 8 and disconnected at hour 18. All the cars have initial SOC as shown in Table 1. To compensate the owners of the EV for the use of the battery, at the end of hour 18, the SOC in the battery will be 100% (SOCPVH $\left({t}_{\mathrm{end}}\right)=1$). The SOC limits in the PEV for all the EV are $0.05\le {\mathrm{SOC}}_{\mathrm{PEV}}\left({t}_{z}\right)\le 100(\%)$.

The OPF was solved using the interior point method provided by the “fmincon” function developed by MATLAB

^{®}, the direct search method with interior point hybrid (GA-IP), and hybrid genetic algorithm with interior point (patternsearch-IP); their results are discussed below.Figure 9 shows the active power supplied by the battery, PEV, WT, and PV, and the imported power from the main grid. The powers of the PV and WT are for a clear summer day. This figure shows that between the stages 0 and 6 h or 20 and 24 h the power demand by the load is small (35 kW), and the generators (PV, WT) and batteries supply this power to satisfy the load demand. Nevertheless, between 8 and 10 h or 16 and 20 h, the power supplied by the generators and the batteries is not enough to supply the load demand, making it necessary to import power from the main grid to satisfy the load and avoid problems within the microgrid. In addition, the PV have the maximum power supplied between 9 and 17 h, agreeing with the forecasting profile of irradiance shown in Figure 8a; in the same way, the maximum power of WT corresponds to the maximum speed of wind predicted by the forecasting profile of wind speed shown in Figure 8b.

It is noteworthy that the PEV and the battery are working in charge mode when the power supplied by the PV and PW is high. This power storage in the PEV and battery is important to reduce the energy cost when peak load demand exists (8–10 h with PEV and 16–20 h with battery)—in other words, to reduce imported power from the main grid. Figure 10 shows the state of charge of the battery and the PEV, confirming the previous idea.

In Figure 11 it is possible to see the active power supplied by the elements within the microgrid (WT, PV, Battery, PEV, and Main grid) on a clear winter day. It is important to understand that the power supplied by the PV on a clear winter day is less than on a clear summer day. This reduction of power produces an increment in the imported power from the main grid and a gradual decrement in the power supplied by the WT, battery, and the PEV. Those increments and decrements in the power flow inside the microgrid are shown in Figure 12 through a comparison between the power generators on summer and winter days.

Figure 12 shows the active (P) and reactive (Q) power flow exchanged between the main grid and the microgrid through the PCC for the whole time period T of interest (24 h). Also, the active power provided by the electric vehicles, battery, and photovoltaic system is shown in that figure. It is observed that the amount of active and reactive power exchanged with the main grid through the PCC changes along the time period T. This is due to the optimal energy dispatch driven by the proposed approach, which handles the energy storage systems under the variation of the system load demand and the power generated by the renewable generation systems. This optimal energy management also involves low total active power losses and an acceptable voltage profile. For example, for the microgrid operating on a summer day, Figure 13 shows the low total active power losses obtained along the time period T. This fact is expected in this approach because loss reduction involves a decrement in the power imported from the main grid and, hence, in the total cost, which aids to minimize the fitness function. Also, the bus voltage profiles satisfy the specified operating limits (0.95 ≤ V ≤ 1.05) for the whole time period T, which is ensured in this approach because the bus voltage limits are explicitly considered in the proposed models (26)–(29).

The total energy costs of the imported power from the main grid without DG and with DG during winter and summer days are shown in Figure 14 When the microgrid is working without DG, high cost occurs when there is peak load demand. Nevertheless, the main aim of this paper is the optimization when the microgrid works with DG, and we observe in Figure 13 that the aim is being met in full. However, differences exist between the energy cost when the microgrid operates on clear summer and winter days (energy cost is higher when it is a winter day). This is because the irradiation is lower on a winter day, generating less power compared to a sunny summer day, making the import of power more expensive from the main grid when it is a winter day.

#### 5.3. Performance Comparison between Different Methods

This section presents the performance of the IP, GA-IP, and patternsearch-IP methods for solving the optimization problem given by the model in Equations (26)–(29). That performance is presented based on a comparison of the fitness value achieved at the optimal solution of Equations (26)–(29) and the CPU run time spent for three different microgrid setups. The microgrid under study is the one given in Section 5.2. The first and second setups consider the irradiance profiles for a summer day and a winter one and assume that all components of the microgrid illustrated in Figure 7 are online. The third setup considers the irradiance for a summer day, but assumes that the distributed generation (wind and PV) and storage (batteries and electric vehicles) systems of the microgrid are offline. The performance of the three suggested methods obtained for the three microgrid setups is as follows.

Figure 15 provides the value of the fitness Equation (26) achieved by the IP, GA-IP, and patternsearch-IP methods at the optimal solution of the optimization problem in Equations (26)–(29) for the three different microgrid setups. It is clearly observed that for each microgrid setup, the three methods have achieved practically the same value of the fitness function. These results suggest that they perform similarly in terms of effectiveness, i.e., they all obtain the same fitness function value when solving the optimization problem in Equations (26)–(29). On the contrary, their performance in terms of computing time is substantially different, as discussed below.

Figure 16 shows the CPU time spent by the IP, GA-IP, and patternsearch-IP methods for solving the optimization problem in Equations (26)–(29), for each one of the three different microgrid setups. As can be seen, GA-IP is the fastest algorithm for all the cases, followed by the patternsearch-IP algorithm. Please note that the GA-IP method is 57% (20%) faster than the IP method (patternsearch-IP method). Then, the results may suggest that hybrid algorithms are able to obtain solutions of the same quality as the ones provided by the IP method, but consuming less computing time.

However, it is important to point out that the CPU time spent by the hybrid algorithms may importantly depend on the optimization problem size. Then, bearing in mind the aforementioned, the size of the studied microgrid in this work, and the obtained results in this section, it must be concluded that the CPU time performance of hybrid methods shown here might be expected for small-scale microgrids.

## 6. Conclusions

This paper has shown a comparison among several optimization methods for the energy dispatch within a microgrid. Specifically, an OPF is solved by three different optimization methods—(i) interior point method, (ii) hybrid genetic algorithm with interior point (GA-IP), and (iii) direct search hybrid with interior point (patternsearch-IP)—all of them programed in the software MATLAB

^{®}as part of the tertiary control or energy management system within a microgrid. Solving the OPF by any of these three methods and the use of DG within the microgrid provides an optimal solution to the microgrid, minimizing energy imports from the main grid and using the energy from DG to supply the local load demand at any instant of time. With respect to the optimization problem solution, the three optimization methods get the same value on the fitness function but GA-IP can reach this value faster than the other two methods. Because the results are based on real data provided by CIESOL, the implementation of the optimization methods adopted in this work for the optimal energy management results is feasible for microgrids with similar features to those of the microgrid addressed here.## Author Contributions

Conceptualization, L.O.P.V. and J.D.A.H.; Formal analysis, L.O.P.V.; Funding acquisition, A.P.M. and M.P.G.; Investigation, L.O.P.V. and C.A.C.M.; Methodology, C.A.C.M.; Software, J.L.R.; Supervision, A.P.M., J.L.R., M.P.G. and J.D.A.H.; Writing—original draft, L.O.P.V.; Writing—review & editing, J.D.A.H.

## Funding

This research was funded by the National Council for Science and Technology (CONACYT), Mexico, through the grant with number 397633. and by grants from the Spanish Ministry of Science and Innovation (TIN2015-66680-C2-1-R, ENERPRO DPI2014-56364-C2-1-R and CHROMAE DPI2017-85007-R), Junta de Andalucía (P11-TIC7176 and P12-TIC301).

## Acknowledgments

This work has been possible thanks to the collaboration of CONACYT in conjunction with the University of Guanajuato Mexico and the CIESOL center of the University of Almeria Spain. Luis O. Polanco Vásquez, Cristian A. Carreño Meneses, Alejandro Pizano Martínez are fellows of Universidad de Guanajuato and CONACYT. Juana López Redondo and José Domingo Álvarez Hervás are fellows of the Spanish ‘Ramón y Cajal’ contract program, co-financed by the European Social Fund.

## Conflicts of Interest

The authors declare no conflict of interest.

## Appendix A

This appendix shows the parameters of the microgrid components. The Table A1 provides the general parameters of the microgrid. Table A2 provides the impedance of the microgrid fedeers.

Node | Lines | Battery | PEV | Loads | WT | PV | Node Slack Grid |
---|---|---|---|---|---|---|---|

10 | 8 | 1 | 4 | 1 | 1 | 1 | 1 |

Performance data of the microgrid components:

$${\mathrm{P}}_{\mathrm{Wind}}=38\text{}\mathrm{kW},-10\text{}\mathrm{kVA}{\mathrm{Q}}_{\mathrm{Wind}}15\text{}\mathrm{kVA}$$

$${\mathrm{P}}_{\mathrm{battery}}=12\text{}\mathrm{KW}$$

$${\mathrm{P}}_{\mathrm{Grid}}=40\text{}\mathrm{kW},-10\text{}\mathrm{kVA}{\mathrm{Q}}_{\mathrm{Grid}}15\text{}\mathrm{kVA}$$

$${\mathrm{P}}_{\mathrm{PV}}=9.2\text{}\mathrm{kW}$$

$${\mathrm{P}}_{\mathrm{PEV}}=39\text{}\mathrm{kW}$$

Cost coefficients of the objective function:

$$\mathrm{a}=0.014,\mathrm{b}=0.020,\mathrm{c}=0.0060$$

Voltage general bounds:

$$\mathrm{Min}=0.95\text{}\mathrm{p}.\mathrm{u}.,\mathrm{Max}=1.05\text{}\mathrm{p}.\mathrm{u}.$$

Node Sent | Node Receiving | R (p.u.) | X (p.u.) | B_{C} (p.u.) |
---|---|---|---|---|

3 | 2 | 0.00029 | 0.00086 | 0 |

4 | 3 | 0.00029 | 0.00086 | 0 |

5 | 4 | 0.00029 | 0.00086 | 0 |

1 | 2 | 0.00029 | 0.00086 | 0 |

6 | 3 | 0.00029 | 0.00086 | 0 |

5 | 8 | 0.00029 | 0.00086 | 0 |

5 | 9 | 0.00029 | 0.00086 | 0 |

9 | 10 | 0.00029 | 0.00086 | 0 |

## References

- Ackermann, T.; Andersson, G.; Söder, L. Distributed generation: A definition. Electr. Power Syst. Res.
**2001**, 57, 195–204. [Google Scholar] [CrossRef] - International Renewable Energy Agency. Renewable Power Generation Costs in 2017. Available online: http://www.irena.org/publications/2018/Jan/Renewable-power-generation-costs-in-2017 (accessed on 14 July 2018).
- Wang, J.; Costa, L.M.; Cisse, B.M. From distribution feeder to microgrid: An insight on opportunities and challenges. In Proceedings of the IEEE International Conference on Power System Technology (POWERCON 2016), Wollongong, Australia, 28 September–1 October 2016. [Google Scholar]
- Silva, M.; Morais, H.; Vale, Z. An integrated approach for distributed energy resource short-term scheduling in smart grids considering realistic power system simulation. Energy Conv. Manag.
**2012**, 64, 273–278. [Google Scholar] [CrossRef] - Olivares, D.E.; Mehrizi-Sani, A.; Etemadi, A.H.; Cañizares, C.A.; Iravani, R.; Kazerani, M.; Hajimiragha, A.H.; Gomis-Bellmunt, O.; Saeedifard, M.; Palma-Behnke, R.; et al. Trends in Microgrid Control. IEEE Trans. Smart Grid
**2014**, 5, 1905–1919. [Google Scholar] [CrossRef] - Smith, M.; Ton, D. Key Connections: The U.S. Department of Energy’s Microgrid Initiative. IEEE Power Energy Mag.
**2013**, 11, 22–27. [Google Scholar] [CrossRef] - Chowdhury, S.P.; Crossley, P.; Chowdhury, S. Microgrids and Active Distribution Networks; Institution of Engineering and Technology: London, UK, 2009. [Google Scholar]
- Majumder, R. Microgrid: Stability Analysis and Control: Modeling, Stability Analysis and Control of Microgrid for Improved Power Sharing and Power Flow Management; VDM Verlag: Saarbrücken, Germany, 2010. [Google Scholar]
- Momoh, J. Smart Grid: Fundamentals of Design and Analysis; Wiley-IEEE Press: Jersey, NJ, USA, 2012. [Google Scholar]
- Olivares, D.E.; Cañizares, C.A.; Kazerani, M. A Centralized energy management system for isolated microgrids. IEEE Trans. Smart Grid
**2014**, 5, 1864–1875. [Google Scholar] [CrossRef] - Ustun, T.S.; Ozanyoy, C.; Zayegh, A. Recent developments in microgrids and example cases around the world—A review. Renew. Sust. Energy Rev.
**2011**, 15, 4030–4041. [Google Scholar] [CrossRef] - Bidram, A.; Davoudi, A. Hierarchical structure of microgrids control system. IEEE Trans. Smart Grid
**2012**, 3, 1963–1976. [Google Scholar] [CrossRef] - Chen, C.; Wang, F.; Zhou, B.; Chan, K.; Cao, Y.; Tan, Y. An interval optimization based day-ahead scheduling scheme for renewable energy management in smart distribution systems. Energy Conv. Manag.
**2015**, 106, 584–586. [Google Scholar] [CrossRef] - Álvarez, E.; Campos, A.; Arboleya, P.; Gutiérrez, A. Microgrid management with a quick response optimization algorithm for active power dispatch. Int. J. Electr. Power Energy Syst.
**2012**, 43, 465–473. [Google Scholar] [CrossRef] - Kou, P.; Liang, D.; Gao, L. Distributed EMPC of multiple microgrids for coordinated stochastic energy management. Appl. Energy
**2017**, 185, 939–952. [Google Scholar] [CrossRef] - Silvente, J.; Kopanos, G.M.; Pistikopoulos, E.N.; Espuña, A. A rolling horizon optimization framework for the simultaneous energy supply and demand planning in microgrids. Appl. Energy
**2015**, 155, 485–501. [Google Scholar] [CrossRef] - Shi, W.; Li, N.; Chu, C.C.; Gadh, R. Real-Time Energy Management in Microgrids. IEEE Trans. Smart Grid
**2017**, 8, 228–238. [Google Scholar] [CrossRef] - Marzband, M.; Yousefnejad, E.; Sumper, A.; Domínguez-García, J. Real time experimental implementation of optimum energy management system in standalone microgrid by using multi-layer ant colony optimization. Int. J. Electr. Power Energy Syst.
**2016**, 75, 265–274. [Google Scholar] [CrossRef] - Kowalczyk, A.; Włodarczyk, A.; Tarnawski, J. Microgrid energy management system. In Proceedings of the 21st IEEE International Conference on Methods and Models in Automation and Robotics (MMAR 2016), Międzyzdroje, Poland, 29 August–1 September 2016. [Google Scholar]
- Mahmoud, M.; Alyazidi, N.; Abouheaf, M. Adaptive intelligent techniques for microgrid control systems: A survey. Int. J. Electr. Power Energy Syst.
**2017**, 90, 292–305. [Google Scholar] [CrossRef] - Acha, E.; Fuerte, C.R.; Ambriz, H.; Camacho, C. FACTS Modelling and Simulation in Power Network; John Wiley & Sons: Hoboken, NJ, USA, 2005. [Google Scholar]
- Gill, S.; Kockar, I.; Ault, G.W. Dynamic optimal power flow for active distribution networks. IEEE Trans. Power Syst.
**2014**, 29, 121–131. [Google Scholar] [CrossRef] - Wang, L.; Yeh, T.; Lee, W.; Zhe, C. Benefit evaluation of wind turbine generators in wind farms using capacity-factor analysis and economic-cost methods. IEEE Trans. Power Syst.
**2009**, 24, 692–704. [Google Scholar] [CrossRef] - Bellini, A.; Bifaretti, S.; Iacovone, V.; Cornaro, C. Simplified model of a photovoltaic module. In Proceedings of the International Conference Applied Electronics 2009 (AE 2009), Pilsen, Czech Republic, 9–10 September 2009. [Google Scholar]
- Modulo Fotovoltaico A-222P/A-232/A-238P. Available online: http://www.sfe-solar.com/wp-content/uploads/2011/06/Atersa_A222-238P.pdf (accessed on 20 June 2018).
- Zúñiga Haro, P. Analysis and Control of a Series Compensator. Ph.D. Thesis, CINVESTAV Gdl, Guadalajara, Mexico, May 2006. Available online: http://www.gdl.cinvestav.mx/jramirez/doctos/doctorado/Tesis_pavel2006.pdf (accessed on 20 June 2018). [Google Scholar]
- Jimenez, A.; García, N. Power flow modeling and analysis of voltage source converter-based plug-in electric vehicles. In Proceedings of the 2011 IEEE Power and Energy Society General Meeting, Detroit, MI, USA, 24–29 July 2011. [Google Scholar]
- Sousa, T.; Morais, H.; Vale, Z.; Faria, P.; Soares, J. Intelligent energy resource management considering vehicle-to-grid: A simulated annealing approach. IEEE Trans. Smart Grid
**2013**, 1, 535–542. [Google Scholar] - Optimization Toolbox. User’s Guide. Available online: http://www.mathworks.com/help/pdf_doc/optim/optim_tb.pdf (accessed on 20 June 2018).
- Augmented Lagrangian Genetic Algorithm. Available online: https://www.mathworks.com/help/gads/description-of-the-nonlinear-constraint-solver.html#bue48bb (accessed on 16 July 2018).
- Nonlinear Constraint Solver Algorithm. Available online: https://www.mathworks.com/help/gads/description-of-nonlinear-constraint-solver.html (accessed on 16 July 2018).
- Byrd, R.H.; Gilbert, J.C.; Nocedal, J. A Trust Region Method Based on Interior Point Techniques for Nonlinear Programming. Math. Program.
**2000**, 89, 149–185. [Google Scholar] [CrossRef] - Global Optimization Toolbox. User’s Guide. Available online: http://www.mathworks.com/help/pdf_doc/gads/gads_tb.pdf (accessed on 20 June 2018).
- Include a Hybrid Function. Available online: https://www.mathworks.com/help/gads/using-a-hybrid-function.html (accessed on 16 July 2018).
- Audet, C.; Dennis, J.E., Jr. Analysis of Generalized Pattern Searches. SIAM J. Optim.
**2002**, 13, 889–903. [Google Scholar] [CrossRef] - Xu, W.; Wang, Z.; Zhu, Q.; Geng, Z. A hybrid constraints scattered genetic algorithm with interior point method. In Proceedings of the 2011 International Conference on Mechatronic Science, Electric Engineering and Computer (MEC), Jilin, China, 19–22 August 2011. [Google Scholar]
- Yan, W.; Liu, F.; Chung, C.Y.; Wong, K.P. A hybrid genetic algorithm-interior point method for optimal reactive power flow. IEEE Trans. Power Syst.
**2006**, 21, 1163–1169. [Google Scholar] [CrossRef]

**Figure 8.**Forecasting curves for the microgrid test. (

**a**) Load forecast curve; (

**b**) wind speed profile for Almería, Spain; (

**c**) irradiation profile for clear days in summer (blue) and winter (red).

**Figure 12.**Comparison between power generation on summer and winter days. (

**a**) Active and reactive powers exchanged with the main grid.; (

**b**) Active power provided by the battery; (

**c**) Active power provided by the vehicle fleet; (

**d**) Active power provided by the photovoltaic panel.

**Figure 13.**Total active power losses and bus voltages for a summer day. (

**a**) Active power losses; (

**b**) Bus voltages.

**Figure 14.**Energy cost of power with and without Distributed Generation (DG) on a summer day and a winter day.

Vehicle Number | Initial SOC (%) |
---|---|

1 | 0.40 |

2 | 0.30 |

3 | 0.60 |

4 | 0.70 |

© 2018 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).