A Mixed Binary Linear Programming Model for Optimal Energy Management of Smart Buildings

: E ﬃ cient alternatives in energy production and consumption are constantly being investigated and conducted by increasingly strict policies. Buildings have a signiﬁcant inﬂuence on electricity consumption, and their management may contribute to the sustainability of the electricity sector. Additionally, with growing incentives in the distributed generation (DG) and electric vehicle (EV) industries, it is believed that smart buildings (SBs) can play a key role in sustainability goals. In this work, an energy management system is developed to reduce the power demands of a residential building, considering the ﬂexibility of the contracted power of each apartment. In order to balance the demand and supply, the electrical power provided by the external grid is supplemented by microgrids such as battery energy storage systems (BESS), EVs, and photovoltaic (PV) generation panels. Here, a mixed binary linear programming formulation (MBLP) is proposed to optimize the scheduling of the EVs charge and discharge processes and also those of BESS, in which the binary decision variables represent the charging and discharging of EVs / BESS in each period. In order to show the e ﬃ ciency of the model, a case study involving three scenarios and an economic analysis are considered. The results point to a 65% reduction in peak load consumption supplied by an external power grid and a 28.4% reduction in electricity consumption costs.


Introduction
Due to it great potential to be exploited, there has been a significant increase in investments in distributed generation (DG) ventures worldwide. This is noticeable in the increase in programs that are aimed at popularizing the implementation of renewable energy sources (RES) in addition to investments in research and development (R&D) and publications of works in this field [1]. For example, in 1994, the Japanese government subsidized 50% of the investment for installation of photovoltaic generators on about 70,000 roofs [2]. In Europe, the German government in 1999 launched the 100,000 Roofs Solar Program aimed at installing photovoltaic generators on 100,000 roofs with 10-year financing at a 0% interest rate [3]. According to [4], in 2017, China had the largest power capacity of wind turbines in the world with 164 GW installed. The United States and Germany had 89 GW and 56.1 GW of wind turbines installed, respectively.
In consequence of the popularization of sustainable policies and the advancement in the DG field, Smart Grid (SG) is strengthened with the implementation of new approaches and techniques, enabling better control of the operation, generation, and consumption of electricity [1]. Thus, by exploiting the evolution of information technology we can to replace manual generation and consumption measurement methods with computerized systems, allowing for the collection of recorded energy values in real-time, creating a historical database of information to allow, in a remote way, for system operation and monitoring of failures and electrical energy quality [1].
The directives from the European Union (EU) point to nearly zero energy buildings (nZEBs) for new building construction. nZEBs should guarantee the power generation to meet the building's electricity consumption in each time period. Therefore, the EU is strongly incented to develop RES and adequate strategies for nZEB operation [1].
Electric vehicles (EVs) have great potential to dominate the automotive sector in a few years, and, therefore, this market is greatly expanding. In this way, policies are aimed at implementing recharging points in residential buildings to reduce environmental and noise pollution, besides the consumption of fossil fuels. As EVs reach significant numbers in the automotive market, power distributors need to adapt to a new type of load that can be a significant impact on the power network [1].
New approaches are exploring the advantages of using electrical energy stored in EVs to inject power into the power grid at appropriate times, which is called vehicle-to-grid (V2G).
Therefore, charging and discharging preferences must comply with certain standards and protocols. The available energy that is injected into the grid should be defined taking into consideration users' needs. Charging and discharging periods must occur at different times, which can open opportunities for conciliation strategies, such as charging batteries during periods of low consumption and discharging them during periods of high consumption [5].
This paper aimed to model an optimization problem, considering energy resources in a residential building, such as photovoltaic (PV), EVs, and battery energy storage systems (BESS), and also considering the contracted power flexibility of each apartment to reduce the building power demand. During the mathematical formulation of the problem, it was assumed that the generated power data of the photovoltaic system, the building consumption load profile, and the trips of the EVs are known from forecasting methods. The energy resources scheduling problem was formulated as a mixed binary linear programming (MBLP) formulation problem, where the decision variables represent the charging and discharging processes, in each period, of EVs and the BESS. Therefore, these variables must be binary, and MBLP algorithms are used to obtain optimal solutions. The obtained results show that the management of all energy resources could be profitable for smart buildings, contributing to smoothing the electricity consumption peaks and optimizing the charging/discharging of EVs with interesting financial results. This paper contains five sections: In Section 2, a brief literature review related to smart buildings (SBs) optimization is presented. In Section 3, the methodology used in this work is presented along with the mathematical formulation. Section 4 presents the results obtained to validate the developed method, considering three different scenarios and an economic analysis. A comparison and discussion of the obtained results are made. Finally, the last section provides the concluding remarks.

Literature Review
In the last two decades, several policies have been implemented in order to reduce the ecological footprint and increase the sustainability of the electrical sector. There is a growing investment in the deployment of electricity generation based on DG resources, mainly in the residential building context, which is verified by an increasing number of research papers related to SBs [1].
It is known that combustion vehicles represent 18% of the world's carbon dioxide (CO 2 ) emissions. The EU committed itself to reducing emissions by up to 25% by the present year of 2020. As a result, the spotlight on EVs on the world stage is increasing, which gives rise to works related to this technology. Thus, many studies took advantage of the large penetration of DGs ventures to reduce electricity costs, peak load demand, and CO 2 emissions and to optimize the scheduling of charging and discharging of EVs and BESS [1,6].
With the objective to mitigate the problems caused by uncertainties in the generation of renewable sources, the work presented in [7,8] proposed a day-ahead optimization problem for managing energy resources, considering forecast errors, dispatching of EVs, and energy markets. The problem was simulated through mixed integer linear programming (MILP) formulation due to the large presence of continuous, discrete, and binary variables to minimize operating costs and maximize profits. The problem constraints involved active power balance, distributed generation, energy supply in each period, rate and efficiency of EVs' charging and discharging processes, and capacity and requisition of the EVs' trips.
A consumer-dependent system for smart buildings was proposed in [9] in order to manage energy and find a balance between cost and CO 2 emissions. In this way, a model was proposed that involves the manager of the building in the decisions of the renewable energy use acceptability, even though the energy from non-renewable sources is cheaper. The formulation of the problem was done by linear programming (LP) with the goal of minimizing the energy cost by assigning weights to each type of source. Weights corresponding to the renewable energy, non-renewable energy, Energy from diesel Generator, energy stored from renewable grid, energy stored from non-renewable grid and Energy Discharged from Storage unit are used, properly achieved by an implemented algorithm, to support decisions related to: energy amount that it is required to buy from providers and the energy amount that it is required to withdraw from the storage unit to meet consumers' demand. Balance constraints related to the energy system, renewable and non-renewable sources limits, minimum and maximum limits of BESS energy storage capacity, and the limit of energy supplied by a diesel generator were proposed.
The work developed by [10] presented an approach to find out the optimal scheduling for charging and discharging of EVs in a SB context. Artificial neural networks (ANN) were used in order to predict the power load demand of the building and the PV energy generation, where the problem was formulated by LP. Total energy costs were minimized, taking into consideration an objective function formulation, while its constraints covered the limits for the EVs batteries' state of charge (SOC) and charging and discharging limit rates, while also considering that the EV must have a fully charged battery at the end of the period and the system cannot inject power into the power network.
Works involving the operation of SBs, considering local generation and the use of EVs as an energy resource are presented in [11,12]. In [11], the charging and discharging process of plug-in hybrid electric vehicles (PHEVs) was optimized to reduce the building's power demand and its electricity costs. The objective function was formulated to minimize the costs of the energy supplied by the grid, while its constraints presented the updates and limits for the PHEV battery SOC and the system energy balance, while ensuring that the system should not sell and buy energy from the power grid at the same time. In [12], an MILP model was presented to minimize the total daily cost with electric energy consumption, and the stochastic model was also considered to forecast PV generation and building load demand.
The effect of a PHEV fleet on a building demand profile in Belgium was analyzed in [13]. In this work, the energy demand and electricity costs were minimized by the implementation of a MILP formulation. This work presented a similar objective function to that presented in [11], where its restrictions used binary variables to ensure that the PHEV was not charging and discharging at the same time, while the available energy in the batteries respected the EV's minimum and maximum limits and guaranteed the system energy balance.
The work presented by the authors of [14] used a MILP model to optimize the EVs charging/discharging processes as well as an energy storage system. The method defines an ideal charging time for a day, considering the arrival and departure periods of the EVs and their initial SOC. In [15], optimal scheduling for a BESS on a microgrid (MG) application was proposed. For this, a MILP model was developed to minimize the operating cost of the MG, and the problem was solved through the CPLEX tool, a solver for integer programming problems. The constraints of the problem involved the system energy balance, electrical energy, and power limits for the EVs and the BESS. In addition, binary variables were used to ensure that resources could not be charged and discharged at the same time.
The authors of [16] presented mathematical models for application in several types of loads and operated them in real time. The peak load demand was minimized, taking into consideration the problem constraints, such as the system energy balance and the limitation for power and electrical energy in each load. An integrated model for the charging process of EVs using PV generation, as a primary source, was proposed in [17]. In the proposed MILP formulation, a dynamic price scheme was considered as well as V2G and restrictions of the networks' capacity. The objective function intended to minimize the total costs with electricity from the grid to charge the EVs.
The optimization of the EVs charging process was achieved considering solar PV generation in [18,19]. Reference [18] had the following main objectives: to minimize EVs charging cost, reduce demand on the power grid, and increase energy consumption from PV generation. The work considered a forecasting model for PV generation and formulated the optimization problem through MILP. In [19], it was possible to find a collaborative assessment of dynamic prices and demand response (DR) strategies based on the peak power limit with the possibility of bidirectional energy use for EVs and BESS. The paper proposed a model based on MILP formulation, considering a home energy management (HEM) system. The HEM system considered small-scale renewable energy generation, V2G, BESS, and DR strategies.
The work presented in [20] developed a model to optimize EV charging by considering a V2G strategy, charging and discharging efficiency, and battery degradation. In this way, it was possible to analyze the viability of V2G and define limits for the model profitability. A linear objective function was proposed in the problem model that minimizes the energy cost, and it was solved by integer linear programming.
The work presented in this paper follows the path and ambitions of some of the other current studies. However, it is important to highlight some aspects that are the main motivators of this work and distinguish it from other studies:

•
The proposed mathematical formulation was implemented using mixed binary linear programming; • It is considered that all customers and common property installations do not have a fixed contracted power. In Portugal, currently, this approach it is not permitted by law. However, this work points to a future direction and business plan that can be followed within the scope of electricity consumption optimization in the context of buildings.
In this way, the building is considered as a single electrical customer, having only one power contract (and not a power contract for each end-consumer), requiring the existence of an entity responsible for the management of all energy resources and that establishes the technical and commercial relationship with the external electricity supplier. This entity can be an aggregator that can also act as an electricity supplier.

Methodology
The proposed methodology that it is intended to apply to the management of energy resources in the context of buildings, namely PV generation, battery energy storage system (BESS), electrical vehicles usage, external electricity supply, and knowledge about both residents and common property load diagram consumption, is depicted in Figure 1. The main idea is to take advantage of solar PV generation, promoting the use of BESS in order to schedule EVs charging/discharging processes, aiming to smooth the building load diagram. In this approach, the building is considered as a single electricity customer enabling each apartment to have flexibility in the contracted power value. The limit of the residents' electricity consumption is imposed by the electrical infrastructure. Demand response (DR) programs may be used by the management entity (aggregator) in order to minimize the building's contracted power value. In order to reduce the power demanded of a residential building, the scheduling of the charging and discharging processes of EVs and a BESS are considered. The decision variables of the problem are binary. Therefore, the problem is formulated by a MBLP. In the following subsection, the objective function and constraints of the proposed mathematical formulation are presented, and the most important notation and parameters are shown in Table 1.

Index of time periods Index of EVs
Parameters The length of interval in each period Active power extracted from the grid in period (kW) Penalty factor based on the available PV versus the consumption in period Active power related to the smart building load expected in period (kW) Active power related to the photovoltaic generation foreseen in period (kW) _ Active power related to the charging process of the EV (kW) _ Active power related to the discharging process of the EV (kW) Binary parameter based on the forecasted EVs' trips, which represents the connection of the EV in period _ Active power related to the charging process of the BESS (kW) _ Active power related to the discharging process of BESS (kW) Maximum SOC that EV can assume in period Minimum SOC that EV can assume in period _ Minimum SOC that EV can assume at the end of the period Maximum SOC that BESS can assume in period Minimum SOC that BESS can assume in period Maximum power that the grid can feed to the building (kW)

Variables
Binary variable that represents the EV charging process in period Binary variable that represents the EV discharging process in period Binary variable that represents the BESS charging process in period In order to reduce the power demanded of a residential building, the scheduling of the charging and discharging processes of EVs and a BESS are considered. The decision variables of the problem are binary. Therefore, the problem is formulated by a MBLP. In the following subsection, the objective function and constraints of the proposed mathematical formulation are presented, and the most important notation and parameters are shown in Table 1. Table 1. Nomenclature of the mathematical formulation.

Indices i
Index of time periods j Index of EVs

Parameters τ
The length of interval in each period i P i g Active power extracted from the grid in period i (kW) c i Penalty factor based on the available PV versus the consumption in period i P i sb Active power related to the smart building load expected in period i (kW) P i pv Active power related to the photovoltaic generation foreseen in period i (kW) P ch_evj Active power related to the charging process of the EV j (kW) P dis_evj Active power related to the discharging process of the EV j (kW) σ i j Binary parameter based on the forecasted EVs' trips, which represents the connection of the EV j in period i P ch_B Active power related to the charging process of the BESS (kW) P dis_B Active power related to the discharging process of BESS (

Objective Function
In the case under analysis, the intent is to minimize the peak load power demand of a residential building. For this goal, the building load forecasted, local photovoltaic generation, and the connection of n EVs, which are able to charge and discharge, and also a BESS for energy storage are considered, in I periods of time, with one hour step range (τ = 1). In addition, the connection period of the EVs with the building is based on trip forecasts [7,8]. Therefore, the decision variables of the problem are binary and identified by α and β, which represent the charging and discharging EV j, respectively, and the BESS in each time period i. In this way, the objective function is presented by Equation (1). min : In order to guarantee the system power balance, the mathematical formulation of the electrical energy supplied by the power grid must be defined. As can be seen in Equation (2), this is composed of the expected building load consumption, which is considered the power required to supply the demand of each apartment, as well as the common services. It also considers the power generated by the photovoltaic panels and the EVs/BESS charging and discharging process.
A cost power availability for the EVs/BESS charging and discharging process, in period i, is considered in Equation (3). This parameter finds the most appropriate time to optimize the EVs/BESS charging and discharging process. Therefore, it is defined considering the power values related to the expected building loads and the generation of the PV panels.
It is worth mentioning that in this work, it is assumed that the consumption energy by SBs is higher than the PV production in each period.

Constraints
This subsection presents the constraints of the proposed MBLP problem. For the effectiveness of the model, it is necessary to ensure that the resources do not violate their physical limits and they are not charging and discharging at the same time. Also, there are restrictions related the minimum SOC of the batteries and the maximum value of the power to be consumed from the power grid.

Electric Vehicles Constraints
It is necessary to set the following restrictions to assure that the physical limitations of the storage capacity of the EVs batteries are not violated. The updated formulation of SOC for each EV i = 0, 1, . . . , I−1 is defined by the following constraint Note that SOC 0 j are the initial SOC values for each of the EVs when they connect with the building. Then, the following constraint is presented to guarantee the maximum value for the SOC that the battery of each EV can assume in each period i.
In addition, the minimum SOC values of the EVs have to be defined. Although they do not assume negative values. However, for the feasibility of the study, the minimum value for the SOC i j at i = 1, 2, . . . , I − 1 is set at 50% of their maximum capacity. Thus, Equations (6) and (7) represent the constraints for the minimum value of SOC i j at any period of time i, i = 1, 2, . . . , I − 1 and in the last To avoid the charging and discharging of EVs in the same period, the following constraint is formulated.
Finally, the following constraints are presented to ensure that the decision variables related to the EVs are binary.

BESS Constraints
Here, with a similar approach to that presented for the EVs in the last subsection, the required constraints for the SOC of BESS are defined. The following constraint presents the updated formulation for the SOC of BESS in each period of time i with i = 0, 2, . . . , I − 1.
As proposed for the EVs' constraints, the following constraint guarantees the maximum SOC value that the BESS can assume in each period i.
In addition, the following constraint assures that the SOC of the BESS system in each period "i" does not infringe on its minimum limit.
In the same way, as proposed for the EVs, it is necessary to ensure that the BESS cannot charge and discharge in the same period i, as formulated in (14).
Finally, the decision binary variables related to the BESS are shown by Equations (15) and (16).

Load Grid Constraints
In this subsection, the following constraint represents the maximum power from the external grid that can feed the building during each period i.
The presented model in this section was formulated as a MBLP problem. In order to solve this optimization problem, A Mathematical Programming Language (AMPL) software was used. In this way, the CPLEX solver was used to solve the MBLP, in which the branch and bound (B&B) algorithm was used.
The results obtained from this application are presented and discussed in the next section.

Results
In order to validate the proposed mathematical formulation, a case study for a residential building with 12 apartments and a common property was used. The case study refers to the analysis of the reduction in peak electricity consumption over a period of 6 hours. In addition, it was assumed that the actual data of PV, total building electrical energy consumption, trips, and initial values of SOC for the batteries of the EVs and BESS are known [7,8].

Case Study
Here, the following three scenarios are considered: 1.
In the first scenario, or base scenario, the EVs start their charging process as soon as they are plugged in to the building and the process is stopped as soon as their SOC reaches 65% of its total capacity. Note that, in this case, the discharge process does not occur and the BESS it is not considered.

2.
In the second scenario, the schedule of the charging and discharging process for each of the EVs is optimized. As the first scenario, the BESS is not considered.

3.
The last scenario is similar to the second one, but, in this case, a BESS with a storage capacity of 50 kWh is added to the model.
Finally, an economic analysis is performed for the considered scenarios, where a contracted power demand for the building is proposed, considering a penalty cost for each exceeded kWh and bonuses for users who choose to perform a DR, when it is necessary.
In order to validate the developed model in a manner close to real situations, the characteristics of the EVs and the BESS are considered based on market specifications. In this regard, the characteristics of the EVs come from the BMW i3 94 Ah vehicle found on the manufacturer's website [21], while the BESS data come from NARADA according to the model BESS-1000L [22]. Data for both are presented in Table 2.  Table 3 shows the values of some parameters regarding the initial SOC of each of the 12 EVs that were considered. For validation of the developed MBLP optimization model, first, the base scenario is considered in which the EVs continue with their charging process until they reach 65% of their maximum capacity. Figure 2 shows the power curves of the building resource, as well as the electricity consumption from the power grid (P g ) in the analyzed period, which is the base value used for comparison with the other scenarios, where P EV is the power from EVs, P SB the power from BESS, and P PV the power from solar PV generation.  A simple analysis indicates that the peak power consumed from the external power grid in this scenario reaches 49.99 kW and occurs at 19 h. Therefore, the implemented model aims to reduce this value (peak value) with a strategy of optimal scheduling for building resources.
It can be seen in Figure 3 that the ideal period for the EVs charging process occurs at the initial moments of the analyzed time horizon. However, the EVs' travel makes this difficult, because not all EVs are plugged into the building in the initial periods.

Scenario 2: Scheduling of the EVs Charging and Discharging Processes
For this scenario, it is assumed that each vehicle starts it's charging and discharging process in appropriate times that are considered by the model, to reduce the peak load demand from the grid during the analyzed period.
Analyzing Figure 4, it can be seen that in the periods when the load demanded from the building A simple analysis indicates that the peak power consumed from the external power grid in this scenario reaches 49.99 kW and occurs at 19 h. Therefore, the implemented model aims to reduce this value (peak value) with a strategy of optimal scheduling for building resources.
It can be seen in Figure 3 that the ideal period for the EVs charging process occurs at the initial moments of the analyzed time horizon. However, the EVs' travel makes this difficult, because not all EVs are plugged into the building in the initial periods.  A simple analysis indicates that the peak power consumed from the external power grid in this scenario reaches 49.99 kW and occurs at 19 h. Therefore, the implemented model aims to reduce this value (peak value) with a strategy of optimal scheduling for building resources.
It can be seen in Figure 3 that the ideal period for the EVs charging process occurs at the initial moments of the analyzed time horizon. However, the EVs' travel makes this difficult, because not all EVs are plugged into the building in the initial periods.

Scenario 2: Scheduling of the EVs Charging and Discharging Processes
For this scenario, it is assumed that each vehicle starts it's charging and discharging process in appropriate times that are considered by the model, to reduce the peak load demand from the grid during the analyzed period.
Analyzing Figure 4, it can be seen that in the periods when the load demanded from the building was low, that is at the initial moments, the model triggered the charge of the EVs. In the periods when

Scenario 2: Scheduling of the EVs Charging and Discharging Processes
For this scenario, it is assumed that each vehicle starts it's charging and discharging process in appropriate times that are considered by the model, to reduce the peak load demand from the grid during the analyzed period.
Analyzing Figure 4, it can be seen that in the periods when the load demanded from the building was low, that is at the initial moments, the model triggered the charge of the EVs. In the periods when the load demanded from the power grid was very high, the stored energy in EVs is discharged. It can be seen that the strategy adopted by the model reduced the peak load of the power grid to 23.35 kW, obtaining a 53% reduction when compared to the base scenario.
Energies 2020, 13, x FOR PEER REVIEW 10 of 16 the load demanded from the power grid was very high, the stored energy in EVs is discharged. It can be seen that the strategy adopted by the model reduced the peak load of the power grid to 23.35 kW, obtaining a 53% reduction when compared to the base scenario. In Figure 5 it is also possible to verify the impact of the model strategy. Note that some EVs had considerable variations during the period, but always respected the minimum limit (50% of the capacity) that is defined for the entire period under analysis. It is still possible to verify that all vehicles have an SOC with, at least, 65% of the capacity at the end of the period.

Scenario 3: Scheduling of the EVs and BESS Charging and Discharging Processes
Scenario 2 was intended to minimize the peak load demand identified in scenario 1, and it was able to manage the process of charging and discharging of each EV in the most appropriate way to comply with the objectives of the problem, without the presence of a BESS.
In scenario 3, a BESS with 80% initial SOC is added to the model. It can be seen in Figure 6 that In Figure 5 it is also possible to verify the impact of the model strategy. Note that some EVs had considerable variations during the period, but always respected the minimum limit (50% of the capacity) that is defined for the entire period under analysis. It is still possible to verify that all vehicles have an SOC with, at least, 65% of the capacity at the end of the period.
Energies 2020, 13, x FOR PEER REVIEW 10 of 16 the load demanded from the power grid was very high, the stored energy in EVs is discharged. It can be seen that the strategy adopted by the model reduced the peak load of the power grid to 23.35 kW, obtaining a 53% reduction when compared to the base scenario. In Figure 5 it is also possible to verify the impact of the model strategy. Note that some EVs had considerable variations during the period, but always respected the minimum limit (50% of the capacity) that is defined for the entire period under analysis. It is still possible to verify that all vehicles have an SOC with, at least, 65% of the capacity at the end of the period.

Scenario 3: Scheduling of the EVs and BESS Charging and Discharging Processes
Scenario 2 was intended to minimize the peak load demand identified in scenario 1, and it was able to manage the process of charging and discharging of each EV in the most appropriate way to comply with the objectives of the problem, without the presence of a BESS.
In scenario 3, a BESS with 80% initial SOC is added to the model. It can be seen in Figure 6 that the model maintained the charging process of the EVs in the initial periods.

Scenario 3: Scheduling of the EVs and BESS Charging and Discharging Processes
Scenario 2 was intended to minimize the peak load demand identified in scenario 1, and it was able to manage the process of charging and discharging of each EV in the most appropriate way to comply with the objectives of the problem, without the presence of a BESS.
In scenario 3, a BESS with 80% initial SOC is added to the model. It can be seen in Figure 6 that the model maintained the charging process of the EVs in the initial periods.
Energies 2020, 13, x FOR PEER REVIEW 11 of 16 Figure 6. Specification of each type of source that feeds the building and the EVs charging process in scenario 3. Figure 6 still shows that the BESS plays a fundamental role in the reduction of the peak load consumed from the power grid. Note that, initially, it had a high initial SOC of 80%. It was possible to use the stored energy in the system to feed the building load and the EVs charging process, mainly in the time periods that it was needed to consume a significant electrical energy from the external grid. It is also possible to observe that the stored energy in the EVs in the initial periods was discharged (in yellow) in the final periods. This process contributes to significantly reduce the peak load consumption from the external power grid and proves the developed model aligns with the initial proposed objectives. Thus, it can be seen that the model was able to reduce the peak load consumed from the power grid to 17.68 kW, this being a reduction of 65% in comparison to scenario 1. Finally, in Figure 7, it is clearly confirmed that at the end of the period, all vehicles have an SOC of at least 65% of their maximum capacity. It can also be observed that the variations pointed out in Figure 6. Specification of each type of source that feeds the building and the EVs charging process in scenario 3. Figure 6 still shows that the BESS plays a fundamental role in the reduction of the peak load consumed from the power grid. Note that, initially, it had a high initial SOC of 80%. It was possible to use the stored energy in the system to feed the building load and the EVs charging process, mainly in the time periods that it was needed to consume a significant electrical energy from the external grid. It is also possible to observe that the stored energy in the EVs in the initial periods was discharged (in yellow) in the final periods. This process contributes to significantly reduce the peak load consumption from the external power grid and proves the developed model aligns with the initial proposed objectives. Thus, it can be seen that the model was able to reduce the peak load consumed from the power grid to 17.68 kW, this being a reduction of 65% in comparison to scenario 1.
Energies 2020, 13, x FOR PEER REVIEW 11 of 16 Figure 6. Specification of each type of source that feeds the building and the EVs charging process in scenario 3. Figure 6 still shows that the BESS plays a fundamental role in the reduction of the peak load consumed from the power grid. Note that, initially, it had a high initial SOC of 80%. It was possible to use the stored energy in the system to feed the building load and the EVs charging process, mainly in the time periods that it was needed to consume a significant electrical energy from the external grid. It is also possible to observe that the stored energy in the EVs in the initial periods was discharged (in yellow) in the final periods. This process contributes to significantly reduce the peak load consumption from the external power grid and proves the developed model aligns with the initial proposed objectives. Thus, it can be seen that the model was able to reduce the peak load consumed from the power grid to 17.68 kW, this being a reduction of 65% in comparison to scenario 1. Finally, in Figure 7, it is clearly confirmed that at the end of the period, all vehicles have an SOC of at least 65% of their maximum capacity. It can also be observed that the variations pointed out in scenario 2 were maintained, respecting the minimum and maximum limits that are defined for the SOC of the EVs. Finally, in Figure 7, it is clearly confirmed that at the end of the period, all vehicles have an SOC of at least 65% of their maximum capacity. It can also be observed that the variations pointed out in scenario 2 were maintained, respecting the minimum and maximum limits that are defined for the SOC of the EVs.
The curve of power consumption in each scenario is reported in Figure 8. When considering the possibility of managing the EVs and BESS charging and discharging processes, positive results were obtained, the model was able to charge enough power in the initial periods and discharge it at a time when it was needed during high building demand. With this, the reductions in the peak of the consumed power reached up to 65%. The curve of power consumption in each scenario is reported in Figure 8. When considering the possibility of managing the EVs and BESS charging and discharging processes, positive results were obtained, the model was able to charge enough power in the initial periods and discharge it at a time when it was needed during high building demand. With this, the reductions in the peak of the consumed power reached up to 65%.

Economic Analysis
By law, typically, each apartment has a contracted power value from a specific electricity supplier (in an electricity market environment). This study is based on real data and the considered building consists of 12 apartments and a common area in which 6 apartments have a contracted power of 6.9 kW, and the other 6 have a contracted power of 10.35 kW. The defined billing only takes into consideration the energy tariff in €/kWh. In this way, it is possible to verify how much the building would spend with the electrical energy consumption bill considering real used tariffs [23]. Thus, by considering the contract power by each apartment individually, the building would spend € 50.34 considering the electric energy spent in the analyzed period.

Comparison between Scenarios 1 and 2
In this part of the work, it is proposed that, instead of having individuals contract power for each apartment (and common property), the building manager hires a contracted power that covers the needs of apartments and common areas, managing the required demand for the EVs charging process. Thus, based on real load profiles, it is proposed to reach a contracted power for the entire building than can cover all power needs of 41.4 kW and a penalty of 3 €/kWh if this value is exceeded.
It is possible to verify that the exceeded power demand values are not significant, which allows for the consideration of a model of DR for the users that requires a reduction in their consumption as soon as the proposed contracted power value of the building is exceeded.
For this purpose, a subsidy (10% of the contracted demand tariff per each kWh reduction) is proposed for users to join the DR. In this way, demand response measures are advantageous for residents who do not want to pay a fine for exceeding the global building consumption value, and for those who adhere to this measure, they receive a bonus for electricity consumption reduction. As

Economic Analysis
By law, typically, each apartment has a contracted power value from a specific electricity supplier (in an electricity market environment). This study is based on real data and the considered building consists of 12 apartments and a common area in which 6 apartments have a contracted power of 6.9 kW, and the other 6 have a contracted power of 10.35 kW. The defined billing only takes into consideration the energy tariff in €/kWh. In this way, it is possible to verify how much the building would spend with the electrical energy consumption bill considering real used tariffs [23]. Thus, by considering the contract power by each apartment individually, the building would spend € 50.34 considering the electric energy spent in the analyzed period.

Comparison between Scenarios 1 and 2
In this part of the work, it is proposed that, instead of having individuals contract power for each apartment (and common property), the building manager hires a contracted power that covers the needs of apartments and common areas, managing the required demand for the EVs charging process. Thus, based on real load profiles, it is proposed to reach a contracted power for the entire building than can cover all power needs of 41.4 kW and a penalty of 3 €/kWh if this value is exceeded.
It is possible to verify that the exceeded power demand values are not significant, which allows for the consideration of a model of DR for the users that requires a reduction in their consumption as soon as the proposed contracted power value of the building is exceeded.
For this purpose, a subsidy (10% of the contracted demand tariff per each kWh reduction) is proposed for users to join the DR. In this way, demand response measures are advantageous for residents who do not want to pay a fine for exceeding the global building consumption value, and for those who adhere to this measure, they receive a bonus for electricity consumption reduction. As is shown in Table 4, for scenario 1, total building billing was € 46.85, corresponding to a reduction of 7% in the billing for the analyzed period. For scenario 2, there were four periods in which the grid power supply exceeded its proposed contracted limit, and these should present penalties. As a result, the billing for the period under analysis in scenario 2 was be € 42.38, corresponding a decrease of 10% in comparison with scenario 1. In this step, the same considerations made in the previous topic are assumed, that is, considering the possibility of using a penalty rate for each kWh exceeded and also the possibility of using DR programs. In Table 4, scenario 3, it is possible to verify that the electricity consumption exceeded the value of the proposed contracted energy twice: 16h and 17h. The strategy adopted by the model in scenario 3, applying the appropriate tariffs, provided a reduction of 28.4% in the costs related to electricity consumption, resulting in an invoice of € 36.05 for the analyzed period and, also, with a comparison with scenario 1, there was verified a 23% reduction.
When carrying out an economic analysis, the data from scenarios 1, 2, and 3 were submitted to a time-of-use (TOU) tariff structure, in accordance with the Portuguese legislation. Therefore, the possibility of the building contracting a single power to meet all its electricity demand was considered, assuming a penalty for overtaking and a bonus for users that adhere to DR calls. With this, it was possible to obtain a reduction up to 28% in the cost of electricity, as shown in Figure 9. In this step, the same considerations made in the previous topic are assumed, that is, considering the possibility of using a penalty rate for each kWh exceeded and also the possibility of using DR programs. In Table 4, scenario 3, it is possible to verify that the electricity consumption exceeded the value of the proposed contracted energy twice: 16h and 17h. The strategy adopted by the model in scenario 3, applying the appropriate tariffs, provided a reduction of 28.4% in the costs related to electricity consumption, resulting in an invoice of € 36.05 for the analyzed period and, also, with a comparison with scenario 1, there was verified a 23% reduction. When carrying out an economic analysis, the data from scenarios 1, 2, and 3 were submitted to a time-of-use (TOU) tariff structure, in accordance with the Portuguese legislation. Therefore, the possibility of the building contracting a single power to meet all its electricity demand was considered, assuming a penalty for overtaking and a bonus for users that adhere to DR calls. With this, it was possible to obtain a reduction up to 28% in the cost of electricity, as shown in Figure 9. When analyzing the obtained results, it can be seen that the management of energy resources in buildings is feasible and proves to be advantageous to its users. In this way, it is possible to conclude that the method developed in this work was effective, meeting the initially proposed objectives.

Conclusions and Future Work
In this work, an optimization model based on MBLP was proposed to smooth the peak load of residential buildings with intensive EVs usage. In this approach, solar PV generation panels were considered, as well as a BESS and the possibility of charging and discharging from EVs/batteries.
Three scenarios were analyzed. The first scenario considers that the EVs start their charging process as soon as they are connected to the building and the process is stopped as soon as their SOC reaches 65% of its total capacity. A storage system is not considered. This scenario was used as a base scenario, and the occurrence of the peak load consumption was identified. Therefore, the developed model intended to reduce this identified value (peak value) with a strategy of optimal scheduling for building resources. When analyzing the obtained results, it can be seen that the management of energy resources in buildings is feasible and proves to be advantageous to its users. In this way, it is possible to conclude that the method developed in this work was effective, meeting the initially proposed objectives.

Conclusions and Future Work
In this work, an optimization model based on MBLP was proposed to smooth the peak load of residential buildings with intensive EVs usage. In this approach, solar PV generation panels were considered, as well as a BESS and the possibility of charging and discharging from EVs/batteries.
Three scenarios were analyzed. The first scenario considers that the EVs start their charging process as soon as they are connected to the building and the process is stopped as soon as their SOC reaches 65% of its total capacity. A storage system is not considered. This scenario was used as a base scenario, and the occurrence of the peak load consumption was identified. Therefore, the developed model intended to reduce this identified value (peak value) with a strategy of optimal scheduling for building resources.
In the second scenario, the charging and discharging processes of EVs were optimized. It was concluded that in the periods when the load demanded from the building was low, the model triggered the charging of the EVs. In the periods when the load demanded from the power grid was very high, the stored energy in EVs was discharged, reducing the building peak consumption from the power grid by 53%, in comparison to the base scenario.
Finally, the last scenario considered the optimization of the charging and discharging processes of EVs and BESS. It was verified that the BESS played an important role in supporting the supply of electricity to the building as well as in charging EVs. This process significantly contributed to reducing the consumption of the external power grid, thus smoothing the peak consumption load to 65%, compared to scenario 1.
In addition, an economic analysis was presented among the scenarios, considering a time-of-day tariff, as well as a final comparison of the obtained results.
The obtained results, like other research work in this area of study, aimed to reduce the consumption of electrical energy in buildings taking into account the production of solar photovoltaic energy and the scheduling of charging and discharging of EVs and BESS.
This work differs from others existing studies since it allows flexibility of the contracted power of each apartment. Thus, a certain consumer will be able to consume as much electrical energy as the technical conditions of the electrical installation (electrical cables) allow, provided that, in the total building, the power to be contracted is not exceeded. If this happens, the manager may use DR programs or impose a fine for each kWh exceeded.

Future Work
As discussed, some EVs were not able to perform the V2G process with the building, possibly due to the fact that the time horizon is relatively short (only 6h). Better results could be obtained for a greater time horizon, being able to increase the capacity of the model to more efficiently stagger the charging processes of the EVs.
In addition to the time horizon, future work could look at a two-level optimization. This is justified by the fact that the input data for the problem come from forecasting methods. These, however, are not 100% consistent with reality and may be discordant with real-time situations. Thus, a two-level optimization would consider the data from forecasting methods to generate a schedule for the next day, and thereby perform a second-level optimization, considering day-ahead scheduling as input information for the model, and data from real-time measurements. With this approach, it could be possible to increase significantly the robustness of the model. In order to optimize the overall building contracted power, aggregators can implement demand response programs (DR). In future work, DR programs will be considered, taking into account the exploration of the increase of the time study horizon.
Finally, the possibility of associating a degradation cost to the EVs' batteries should be considered. Currently, the price of batteries is still very high, which hinders the economic viability of models that consider the process of charging these vehicles. As discussed in other papers, works that considered the cost of EV battery degradation have concluded that it is not economically feasible to use the vehicles for this purpose. Developing new technologies that reduce the price of batteries increases the chance of including them as a resource to be managed and viable in the near future.

Conflicts of Interest:
The authors declare no conflict of interest.