Optimal Energy Management within a Microgrid : A Comparative Study

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.


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 Energies 2018, 11, 2167 2 of 22 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.

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.

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 t z j and angle θ t z j within the limits given by Equation (1): 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 t z RP j denotes the power exchanged through the jth PCC.The decision variables associated with the PCC are V t z j , θ t z j , P t z RP j ∈ y RD (∀t z ∈ T, ∀j ∈ PCC) where y RD are the distribution grid variables.

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).

Feeders
Each feeder is modeled as a line of transmission, as is illustrated in Figure 1, where Ii and Ei are the phasors of the injected electricity and voltage, respectively, on the node i (i = k, m) of the microgrid.R, L, and Bc 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).
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 tT  z [21] where j = k, m, being j  i.The variables V n t z and n t z (n = i, j) represent the magnitude and the angle of the nodal voltage phasor Ei: The decision variables associated to these feeders correspond to the nodal voltages in its ,θ m t z ∈ y RD (∀t z ∈T).

Transformer
The primary winding is considered an ideal transformer with relation to complex tap Tv:1 and Ti:1 in series with the impedance Zp (refers to Figure 2) where Tv = Ti* = Tvtv, and the symbol * denotes a complex conjugate.The secondary winding is also represented as an ideal transformer with relation to complex tap Uv:1 and Ui:1 in series with the impedance Zs where Uv = Ui* = Uvuv.The relationship between voltage Vp and electricity Ip of the primary winding and the voltage Vs and electricity Is of the secondary one is given by Equation ( 8) [21].
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 t z n and θ t z n (n = i, j) represent the magnitude and the angle of the nodal voltage phasor E i : The decision variables associated to these feeders correspond to the nodal voltages in its terminals

Transformer
The primary winding is considered an ideal transformer with relation to complex tap T 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].

Feeders
Each feeder is modeled as a line of transmission, as is illustrated in Figure 1, where Ii and Ei are the phasors of the injected electricity and voltage, respectively, on the node i (i = k, m) of the microgrid.R, L, and Bc 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).
= / + ( ) ; = − / + ( ) 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 tT  z [21] where j = k, m, being j  i.The variables V n t z and n t z (n = i, j) represent the magnitude and the angle of the nodal voltage phasor Ei: The decision variables associated to these feeders correspond to the nodal voltages in its ,θ m t z ∈ y RD (∀t z ∈T).

Transformer
The primary winding is considered an ideal transformer with relation to complex tap Tv:1 and Ti:1 in series with the impedance Zp (refers to Figure 2) where Tv = Ti* = Tvtv, and the symbol * denotes a complex conjugate.The secondary winding is also represented as an ideal transformer with relation to complex tap Uv:1 and Ui:1 in series with the impedance Zs where Uv = Ui* = Uvuv.The relationship between voltage Vp and electricity Ip of the primary winding and the voltage Vs and electricity Is of the secondary one is given by Equation (8) [21]. where 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

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 t z Bc j ≤ 0 and the other the discharge power P t z Bd j ≥ 0; the sum of both powers represents the net power P t z Bn j provided or consumed by the battery in their connection node.

P t z
Bn j = P t z Bc j + P t z Bd j ; 0 ≤ P t z Bd j ; P t z Bc j ≤ 0; ∀t z ∈ T In addition, the voltage phasor in the connection node is represented by its magnitude V t z j and its angle θ t z j .Thus, the decision variables of the jth battery are P t z Bd j , P t z Bc j ∈ y B (∀t z ∈ T) where y B are the battery variables, while V t z j , θ t z j ∈ y RD (∀t z ∈ T).Moreover, the State of Charge (SOC) of the jth battery in the time t z (SOC t z B j ) can be approximated by means of Equation (10).In Equation ( 10), SOC t 0 B j 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 ε cj and ε dj , respectively.Lastly, ∆t is a fixed time step length.
Energies 2018, 10, x FOR PEER REVIEW 6 of 22 where 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

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 j t z ≤ 0 and the other the discharge power P Bd j t z ≥ 0; the sum of both powers represents the net power P Bn j t z provided or consumed by the battery in their connection node.
In addition, the voltage phasor in the connection node is represented by its magnitude V j t z and its angle θ j t z .Thus, the decision variables of the jth battery are P Bd j t z ,P Bc j t z ∈ y B (∀t z ∈T) where y B are are the battery variables, while [V j t z , ] ∈ y RD (∀t z ∈T).Moreover, the State of Charge (SOC) of the jth battery in the time tz (SOC B j t z ) can be approximated by means of Equation (10).In Equation ( 10), SOC B j t 0 represents the SOC at a given initial time t0, whereas Enom is the energy capacity of the battery, whose efficiencies for charge and discharge operations are given by εcj and εdj, respectively.Lastly, ∆t is a fixed time step length.Energies 2018, 11, 2167 Bd j (10) 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.

Wind Turbine
For the aim of the stationary analysis, the wind turbine can be considered a source of noncontrolled active power P t z A j , depending on its density δ w , wind speed S t z w , and the area A w covered by the blades of the wind turbine [23].
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 t z w ∀ t z ∈ T; density, δ w , and area, A w , given.Clearly, the magnitude V t z j and angle θ t z j of the voltage phasor of the connection node are considered decision variables, such that V t z j , θ t z j ∈ y RD (∀t z ∈ 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.

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 t z CD k panel terminals, where I ph , I 0 , V t z CD k , 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 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.

Wind Turbine
For the aim of the stationary analysis, the wind turbine can be considered a source of noncontrolled active power P A j t z , depending on its density w , wind speed S w t z , and the area A w covered by the blades of the wind turbine [23].
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 ∀ t z ∈ T; density, w , and area, A w , given.Clearly, the magnitude V j t z and angle j t z of the voltage phasor of the connection connection node are considered decision variables, such that [V j t z , ] ∈ y RD (∀t z ∈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.

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 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 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 t z CA k is the active power injected at the terminals of the primary transformer coupling module; V t z k and θ t z k are the magnitude and the angle, respectively, of the voltage phasor for such terminals; and V t z m and θ t z m represent the same but for the secondary terminals.Therefore, P t z CA k 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]: It is important to highlight that the decision variables introduced by the photovoltaic module are

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 t z li consumed in the node is then represented by Equation (19) where P t z li and Q t z li represent the power consumption active on that node at the instant t z .
The model of energy demand does not introduce decision variables to the optimization problem, but the magnitude V t z i and angle θ t z i of the connection node phasor voltage must be considered decision variables, such as In addition, it is assumed that a good forecast of the energy demand curves is available (S t z li ∀i, t z ∈ T).

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].
Energies 2018, 10, x FOR PEER REVIEW 9 of 22 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).
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, ( ), is the result of the sum of the energy storage at time t − 1, ( − 1), the energy consumed at time t, ( ), and the sum of the energy charged ∑ ( ( ) ) and the discharged energy ∑ ( ( ) ) at time t: where is the charge efficiency coefficient of EV, the discharge efficiency coefficient of EV, and and ∆ the differential of operational time.It is necessary to consider that the charged power is negative ( ) < 0 and the discharged power is positive ( ) > 0 , where the sum of these powers represents the total power injected or consumed by the battery of the EV on the grid point.
In addition, the voltage phasor in the connection node is represented by a magnitude V j t z and an angle j t z .Thus, the decision variables of the jth battery of the EV are

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 tz ( = 1, ..., end), such that T = [t1, ..., tend].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).
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 consumption (t), is the result of the sum of the energy storage at time t − 1, E storage (t − 1), the energy consumed at time t, E consumed (t), and the sum of the energy charged where ηc is the charge efficiency coefficient of EV, ηd the discharge efficiency coefficient of EV, and ∆t the differential of operational time.It is necessary to consider that the charged power is negative (P(t) charged < 0) and the discharged power is positive (P(t) 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.
In addition, the voltage phasor in the connection node is represented by a magnitude V t z j and an angle θ t z j .Thus, the decision variables of the jth battery of the EV are P t z chargedj ,

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 Subject to h t z y t z = 0; ∀t z ∈ T (23) y ≤ y t z ≤ y; ∀t z ∈ T (25) 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, y and y, of these variables are formulated through the inequality constraints; see Equation (25).

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 .

Objective Function
The intention is to minimize Equation (22), which is formulated explicitly taking into account Equation ( 2), as follows: 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 t z li ∀i, t z ∈ T.

Equality Constraints
The set of equality constraints h(y) in Equation ( 23) is expressed explicitly as follows: the constraints of active ∆P t z RD i and reactive power ∆Q t z RD i 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 ∑ ∀j∈i P t z A j 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 ∑ ∀j∈i|j∈N Al ,N T P t z iny j 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 (∀k / ∈ 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 (V, I) represents the term in the second member of Equation (17).Note that Equation ( 27) is formulated for (∀t z ∈ T).

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].

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 = V ∈ V t z j , θ ∈ θ t z j , P t z RP j ; ∀t z ∈ T and ∀j ∈ N bCA , whereas the decision variables batteries are y B = P t z Bd k , P t z Bc k ∀t z ∈ T and ∀k ∈ N B .Finally, the photovoltaic module decision variables are y MF = V t z CD i , I t z CD i ; ∀t z ∈ T and ∀i ∈ N MF .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 ∆P t z RD i and reactive ∆Q t z RD k 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.

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].

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].

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].

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.

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.

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, CO2 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 .

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, 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 .

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 Tables A1 and A2 given in Appendix A.
Energies 2018, 10, x FOR PEER REVIEW 14 of 22 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 Tables A1 and 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 ≤ ≤ 1.05 p.u.The SOC limits on the battery are 0.2 ≤ SOC ( ) ≤ 0.95 (%), whilst the initial condition of the battery charge is SOC ( ) = 0.9 (%).Moreover, all the cars in the PEV will be connected to the microgrid at hour 8 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( ) = 1).The SOC limits in the PEV for all the EV are 0.05 ≤ SOC ( ) ≤ 100 (%).
(  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, 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 ≤ V ≤ 1.05 p.u.The SOC limits on the battery are 0.2 ≤ SOC B (t z ) ≤ 0.95(%), whilst the initial condition of the battery charge is SOC B (t 0 ) = 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 (t end ) = 1).The SOC limits in the PEV for all the EV are 0.05 ≤ SOC PEV (t z ) ≤ 100(%).
Energies 2018, 10, x FOR PEER REVIEW 14 of 22 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 Tables A1 and 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 ≤ ≤ 1.05 p.u.The SOC limits on the battery are 0.2 ≤ SOC ( ) ≤ 0.95 (%), whilst the initial condition of the battery charge is SOC ( ) = 0.9 (%).Moreover, all the cars in the PEV will be connected to the microgrid at hour 8 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( ) = 1).The SOC limits in the PEV for all the EV are 0.05 ≤ SOC ( ) ≤ 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.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 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.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 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).
Energies 2018, 10, x FOR PEER REVIEW 17 of 22 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 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.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.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.

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.

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.

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.

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.

Figure 2 .
Figure 2. T model for the transformers.

Figure 2 .
Figure 2. T model for the transformers.

Figure 2 .
Figure 2. T model for the transformers.

22 SOC
Figure4shows 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 t z CD k panel terminals, where I ph , I 0 , V t z CD k , 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.
Figure4shows 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 k t z panel terminals, where Iph, I0, V CD k t z , Rs, ns, and np 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 Rs is evaluated from Equation(13), where Voc, Vmp, I, and Imp represent the open circuit voltage, the voltage of the point of maximum power, short circuit electricity, and maximum power point electricity, respectively.Terms Isc and Voc are evaluated through Equations (14) and(15), respectively, where Isc,stc, G, Gstc, ki, T, Tstc, Voc,stc, and kv 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.
t) charged ) and the discharged energy t) discharged ) at time t:

Figure 8 .
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 8 .
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 8 .
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 9 .
Figure 9. Result of the power in generators for a clear summer day.

Figure 9 .
Figure 9. Result of the power in generators for a clear summer day.

Figure 10 .
Figure 10.SOC of battery and Park of EV (PEV) for a clear summer day.

Figure 11 .
Figure 11.Result of the power in generators for a clear winter day.

Figure 10 .
Figure 10.SOC of battery and Park of EV (PEV) for a clear summer day.

Energies 2018 , 22 Figure 10 .
Figure 10.SOC of battery and Park of EV (PEV) for a clear summer day.

Figure 11 .
Figure 11.Result of the power in generators for a clear winter day.

Figure 11 .
Figure 11.Result of the power in generators for a clear winter day.

Figure 12 .Figure 13 .
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 12 .
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 12 .Figure 13 .
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 .
Figure 13.Total active power losses and bus voltages for a summer day.(a) Active power losses; (b) Bus voltages.

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

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

Figure 15 .
Figure 15.Fitness function values for the proposed methods.

Figure 16 .
Figure 16.Run times for the proposed methods.

Figure 15 .
Figure 15.Fitness function values for the proposed methods.

Energies 2018 , 22 Figure 15 .
Figure 15.Fitness function values for the proposed methods.

Figure 16 .
Figure 16.Run times for the proposed methods.

Table 1 .
Initial State of Charge (SOC) of the electric vehicles.

Table 1 .
Initial State of Charge (SOC) of the electric vehicles.