**1. Introduction**

A microgrid can be seen as a small energy network composed of loads, Distributed Generators (DG), and in some cases, Energy Storage Systems (ESS) to support supply demands [1]. Currently, conventional generation systems are shifting to lower capacity DG. In addition, the application of ESS is increasing and becoming very common. These technologies are significantly changing the energy landscape, spreading the concept of microgrids [2].

The increasing adoption of lithium-ion batteries for use in stationary banks or other applications such as electric vehicles has led to a reduction in the production costs of this technology [2]. Some studies showed that a price reduction of around 50% in lithium-ion batteries used in electric vehicles could occur over the next decade, keeping them at a lower cost than the price paid for stationary batteries' kWh [3]. Therefore, market interest in applications that benefit both the power grid and the environment is growing, which limits energy expenditure and reduces greenhouse gas emissions [4].

The automotive EV market has been increasing over the years, due to the decrease in the cost of its components and the concerns to reduce greenhouse gas emissions [4–9]. These concerns have forced industries and countries to implement plans to reduce the consumption of fossil fuels, such as the European target to have an EV share of 80% by 2050 [10]. However, this goal will add an extra demand of 150 GW in the European power system, resulting in demand peaks arising from EV charging stations [8,10,11]. Hence, although EVs with Photovoltaic renewable sources (PV) can be a suitable environmental and economic option assisting the reduction of fossil fuel dependence, when a large number of units is considered, higher demand peaks may erupt, causing stresses to the power system [4,5]. A typical issue of microgrids with EV charging and PV generation can be seen in Figure 1. The PV power depends on the solar irradiance while load and EV power are user dependent. The power grid results from the balance of EV, load, and PV generation.

**Figure 1.** Impact of electric vehicles' charging on the demand of a microgrid.

It is noted that there are periods in which the microgrid demand exceeds the contracted power due to EV charging. In another case, the PV surplus is not efficiently utilized. The results of this analysis point to the need for an Energy Management System (EMS) that properly coordinates EV units in the microgrid and takes into account the occurrence of peak demand. In addition, the EVM-EMS is expected to be able to store surplus energy in EV batteries in order to supply the system when needed (Vehicle to Grid (V2G)). Electric vehicles can act both as an alternative energy storage and as a generator to support the grid, improving efficiency and reliability [1,5,8,9]. Even more, other functions can be added to the EMS to allow ancillary services of frequency and voltage regulation in distribution grids [8]. Since for most of the parking time, the vehicles remain idle, the EVM-EMS enables more flexibility to the demand control [5,11].

If electric vehicles are properly considered in the management system, it may be possible to reduce demand peaks and integrate the elements of micro-grids. This will contribute to economic benefits, while using energy from renewable sources more efficiently and reliably. However, the coordination of intermittent power sources, dynamic loads, and unpredictability of EV, while maximizing efficiency and minimizing costs, implies a large number of obstacles that the EMS must overcome [1,2,9,11].

A significant number of techniques have been proposed for implementing microgrid managers in order to achieve multiple benefits, e.g., maximizing profit, minimizing operation costs, and reducing emissions. In [12], a multivariable strategy was proposed that intended to minimize operation costs while decreasing voltage deviation in the IEEE 33 bus system.

Most of the management systems apply optimization methods and generation and demand forecasting to improve the results of microgrid operation. In [13], irradiance and wind speed predictions were used for PV and wind renewable power sources and a heuristic based algorithm was built in the Python language. This strategy considers energy balance, charging limits, State Of Charge (SOC), and power generation. Another approach presented by [14] investigated microgrid management considering the energy price, taking into account the energy exchange with external agents. Model Predictive Control (MPC) was employed in the optimization algorithm, which considered the operating cost and the battery degradation in the cost function specification. In [6], the management established by the authors consisted of two parts: a modular topology that used an Autoregressive Integrated Moving Average (ARIMA) model for forecasting and Mixed-Integer Linear Programming (MILP) for optimization.

A two-step management strategy was presented in [7], which separated the load profile calculation from the PV forecast estimate. Moreover, a few works described heuristics optimization techniques. The authors in [15] formulated a game theory to minimize microgrid operation costs or maximize profit from generation units. Additional management methods handled hierarchical control to coordinate the active and reactive power dispatch [16]. The proposed microgrid manager was verified for IEEE 33 buses. Furthermore, stochastic optimization techniques were used for frequency regulation and power management [17], in which the authors followed a mixed strategy of a Bayesian estimator with a Kalman filter to achieve the energy price. Several other papers focused on real-time strategies for optimal power distribution. In [18], the authors applied the MPC method to dispatch power among charging stations. In comparison with the proposed article, a similar EMS strategy was given by [19], who proposed a new EMS approach that took the user preferences and prediction data into account, and the MILP method was chosen for the optimization using software MATLAB/GAMS to solve the computation.

This paper proposes a real-time optimized EMS with a multiple rule decision strategy for microgrids with electric vehicle charging stations. The microgrid is assumed to be comprised of dynamic user loads, PV units operating on the Maximum Power Point (MPP), and an EV parking lot with charging stations wherein all elements are connected to the external grid. The proposed scheme takes the PV generation forecast and the modes priority into account and applies dynamic programming for the optimization process, considering multiple factors in the cost functions. The proposed management system provides four EV charging modes to provide the user several options, as ultra/fast charging or energy/cost efficiency. The ECO and V2G modes apply dynamic programming to optimize the EV battery operation. The proposed approach takes into account the user preferences while aiming to alleviate the microgrid demand and make a profit for the facility owner. Moreover, the EMS system is implemented in a feasible architecture to verify the dynamic programming operation in real-time conditions.

The work is organized as follows: Section 2 presents the proposed microgrid structure, while Section 3 establishes the behavior model of EV and formulates the cost functions. Section 4 presents the algorithm of the management supervisor and shows the dynamic programming method that is utilized. The results of the management strategy are carried out in Section 5, while Section 6 concludes the work.

## **2. Microgrid Arrangement Description**

Microgrids with PV generation have been installed in a wide power range, from single string low power rooftops (∼1 kWp) up to multiple string power stations (∼5 MWp). Most PV powered microgrids include multiple user loads, such as lighting, electronics, motor-based loads, and demand controlled loads, e.g., air conditioners and water heating. Recently, with the growing EV power demand, charging stations have been also added to the microgrids.

This paper considers a microgrid composed of user loads and PV arrays connected to an AC power bus (AC MG). The proposed arrangement also incorporates a few EV charging stations throughout a dedicated bus (AC EV). Both power buses are connected to the grid through a power transformer, as shown in Figure 2. For simplicity, in this paper, only the active power will be considered for the optimization purposes, and therefore, the reactive power will not be taken into account. Likewise, the distribution impedance will not be considered; however, the efficiency of all converters will be taken

into account. EV users can select the charging mode on any station, so that the same station can be used for different charging modes. In Figure 2, each EV color represents a specific mode chosen by the user.

**Figure 2.** Physical diagram of the proposed microgrid.

Microgrid loads are usually classified into static or dynamic loads. In this paper, it will be considered a typical demand profile of a commercial establishment, and the PV generation profile will be used to represent the different weather conditions. In Figure 2, it is indicated that the EMS communicates with the converters by a communication path, and some EV information is acquired that will be used in the management.
