Demand Response Optimization Using Particle Swarm Algorithm Considering Optimum Battery Energy Storage Schedule in a Residential House

Demand response as a distributed resource has proved its significant potential for power systems. It is capable of providing flexibility that, in some cases, can be an advantage to suppress the unpredictability of distributed generation. The ability for participating in demand response programs for small or medium facilities has been limited; with the new policy regulations this limitation might be overstated. The prosumers are a new entity that is considered both as producers and consumers of electricity, which can provide excess production to the grid. Moreover, the decision-making in facilities with different generation resources, energy storage systems, and demand flexibility becomes more complex according to the number of considered variables. This paper proposes a demand response optimization methodology for application in a generic residential house. In this model, the users are able to perform actions of demand response in their facilities without any contracts with demand response service providers. The model considers the facilities that have the required devices to carry out the demand response actions. The photovoltaic generation, the available storage capacity, and the flexibility of the loads are used as the resources to find the optimal scheduling of minimal operating costs. The presented results are obtained using a particle swarm optimization and compared with a deterministic resolution in order to prove the performance of the model. The results show that the use of demand response can reduce the operational daily cost.


Introduction
The future of power systems has been guided of a new structure where consumers (end-users) are considered as a central entity.This vision is presented in the Strategic Energy Technology (SET) plan of the European Union [1].The transformation of end-users' roles allows these entities to have an active contribution in electric power systems.The prosumer is a new concept that has its origin in the proliferation of Distributed Generation (DG) in end-user facilities.The Prosumer definition is presented in Reference [2], where prosumers are considered agents that can either consume or produce energy.The integration of renewable energy sources (RESs) and energy storage systems results in the increase the complexity of energy management.In Reference [3], some methods to optimize renewable energy systems management are revised.
Regarding demand response (DR) programs, the potential for participation in facilities is significantly increased by the distributed energy resources and especially the energy storage systems.With the participation in DR programs, the roles of the consumers change from a passive entity to an active entity that manages both local consumption and generation resources [4].DR constitutes a modification of load profile in response to monetary or price signals, and thus provides flexibility and aims to help power systems during peak hours of demand or contingencies cases [5].As the DR programs are able to reschedule part of the load, the use of these programs is a way to increase the flexibility of the grid management, avoiding the need to invest in more capacity [6].
Categorizing DR programs, it can be divided into two main categories: incentive-based DR programs and price-based DR programs.The incentive-based DR programs are referred to as the first category for DR programs, where the consumers can offer an incentive to change their consumption patterns.Direct load control programs, load curtailment programs, demand bidding programs, and emergency demand reduction programs are examples of incentive-based DR programs.The "price-based DR programs" are the second category of DR programs, where the consumers are charged with different rates at different consumptions times.Therefore, the retail electricity tariff is affected by the cost of electricity supply.The price-based DR programs types are a time of use pricing, critical peak pricing, real-time pricing, and inclining block rate [7].Advanced infrastructure metering is needed to implement DR programs at the residential, commercial, or industrial level.Such infrastructure (i.e., smart meters) is able to measure and store energy utilization at different times and also obtain the current usage information remotely.
The European Union has shown significant interest in the concept of smart metering.According to [8], it is expected by 2020 to invest ~45 million euros for 200 million smart electricity meters and 45 million smart meters of natural gas.This facilitates the application of DR programs in most electrical facilities.
Regarding the formulation of DR optimization problems, linear programming (LP) or nonlinear programming (NLP) can be used.Frequently the DR problems are able to use binary decision variables for determining the status (ON or OFF) of various consumers or appliances; in these situations, mixed-integer linear programming (MILP) or mixed-integer nonlinear programming (MINLP) may be used.In Reference [9], the authors use MILP to optimize DR and generate scheduling in a residential community grid using renewable energies, batteries, and electric vehicles.In this optimization, a minimization problem of purchased energy costs of the residential community has been solved.In Reference [10] a cost minimization in smart building microgrid considering DR optimization and day-ahead operation is implemented using MILP.This case study is composed of two different smart buildings with 30 and 90 houses.During the optimization process, the optimal schedule of house appliances is found.Another MILP approach is applied in Reference [11], showing how strategies like DR can achieve suitability in any region considering the presence of high penetration of renewable-based generation.
An example of NLP applied for DR optimization is presented in Reference [12], where the unit commitment problem for a microgrid is solved.The optimization problem finds the amount of load reduction and paid incentives for each time interval.Another example of MINLP has been presented in Reference [13], which considers the minimization of purchase gas and electricity from the grid by including the consumption of different loads at different periods.The optimal day-ahead scheduling of resources in energy hubs is determined.
The DR application in end consumers has been over time applied through an aggregator.It works as a service provider, and the DR services must be paid to this provider.In Reference [14], an aggregation of thermostatically controlled loads for performing DR is presented.In this case, the air conditioning consumption is considered as the load.The aggregation services are not restricted to the application of DR programs, in Reference [15] an aggregation of generalized energy storage can be found.The aggregator storage is used to participate in the energy and regulation market.DR programs targeting independent users, without the need of contracts or service providers, are also possible [16,17].These applications are considered independent because the user is not connected to any aggregator.Usually, when the application is independent the user has a device installed in its house to control the loads.In Reference [16], the controller is a PV inverter, while in Reference [17], a home energy management system is used.The controllable loads can be divided into passive (i.e., air Energies 2019, 12, 1645 3 of 18 conditioning, fridges, washing machine) and active (i.e., DG, ESS, vehicle-to-grid, PV) loads [18].In References [16,19] the DR is applied on discrete loads, which only have two states: on or off.
With focus on artificial intelligence (AI), its application in power systems has increased in the past years.The metaheuristics are a very popular part of AI for solving optimization problems.These techniques have acceptable performance in order to solve engineering problems by finding a near-optimal solution with a limited computation burden.Metaheuristics can be applied in problems with a large number of decision variables and easily adapted to a problem that has several constraints [20].A PSO variant is used in Reference [17] for finding the optimal operation of price-driven demand response with a load shifting dispatch strategy for photovoltaic, storage battery, and power grid systems.The optimization algorithm is implemented on Home Energy Manage System.In Reference [21], the PSO algorithm is also used.The DR is optimized considering the variation of electricity price imposed by DSO to provoke a consumption reduction.In the microgrid environment [22], a PSO is used for solve the DR optimization problem.In this case a dynamic pricing model is considered for increase the profit of costumers.In Reference [23] a PSO algorithm is proposed to optimize the performance of a smart microgrid in a short term to minimize operating costs and emissions.Other algorithms like genetic algorithm [24], simulated annealing [25], and differential evolution [26] are frequently used algorithms to solve DR optimization problems.
The present paper proposes DR optimization considering the optimal battery schedule in a residential house with Photovoltaic (PV) generation.A PSO approach is implemented to solve the optimization problem (MILP), and the results are compared with a deterministic resolution (CPLEX solver).The consumer (residential house) is provided with independent management that approaches the several resources capabilities and contributions for the minimization of energy bought from the grid.The main contributions of this paper are as follows.
(1) To perform DR without any contract with the DR service provider-this presented methodology allows the user to perform DR actions without any connection with DR services provider.The consumer is provided with independent management that approaches the several resources capabilities and contributions for the minimization of bought energy from the grid.(2) The implementation of PSO which is a very simple metaheuristic to implement, open access, multiplatform (Windows, MacOS, Linux, etc.), executable from an Arduino/Raspberry and also is the cheapest implementation option.Referring to the presented solution in [16], which uses a CPLEX solver for MATLAB/TOMLAB platform, the implementation of the PSO is a much affordable solution, once that MATLAB and TOMLAB are non-open access.PSO can be implemented in an open access environment and can be executed in free simple platforms, such as Python.(3) The proposed methodology represents an optimization problem that can considerably improve the consumer's energy savings-the combined use of resources (PV production, storage capacity, and loads flexibility) allows for a significant reduction in daily operation costs.The optimal solution obtained by PSO has a daily cost of 3.28 €, while an operation without PV production, storage capacity and loads flexibility has a cost of 16.83 € per day, which is five times higher than PSO result for best scenario.If one considers a base scenario that was obtained by using a simple management mechanism considering the PV production and storage capacity, the daily cost is 9.33 €, which is three times higher than PSO result for the best scenario.The assessment of PSO can be verified in the comparison of the base scenario and the optimized base scenario with the PSO.The daily costs with PSO decreases 1.38 €.
The paper is structured into seven sections: In Section 1 an introduction about DR and how to solve DR problems is presented.Section 2 presents the proposed methodology; in Section 3 the problem formulation is presented.Section 4 presents the algorithm (PSO) and its adaptation to the problem formulation.In Section 5, the case study is presented as well as all input variables and PSO parameters.Section 6 presents the results, and the conclusions are presented in Section 7.

Proposed Methodology
With the goal to reduce the electricity bill of the end consumers is introduced the presented methodology.This methodology aims to minimize the operation costs considering the batteries and flexibility provided by the DR actions.The costs minimization considered the grid, the PV systems, energy storage batteries, and consumption flexibility through load scheduling.The end consumer is connected to the grid, and has a tariff contract that allows selling energy in the grid in exchange for monetary payment.This methodology is able to be expanded to other consumers with different conditions and with different numbers of resources.Figure 1 presents the context scheme of the idea proposed.This scheme is typical for a household prosumer.The scheme of Figure 1 has a unit generation (PV), energy storage system (ESS) (battery), one inverter module, the controllable and noncontrollable loads, and a smart meter.

Proposed Methodology
With the goal to reduce the electricity bill of the end consumers is introduced the presented methodology.This methodology aims to minimize the operation costs considering the batteries and flexibility provided by the DR actions.The costs minimization considered the grid, the PV systems, energy storage batteries, and consumption flexibility through load scheduling.The end consumer is connected to the grid, and has a tariff contract that allows selling energy in the grid in exchange for monetary payment.This methodology is able to be expanded to other consumers with different conditions and with different numbers of resources.Figure 1 presents the context scheme of the idea proposed.This scheme is typical for a household prosumer.The scheme of Figure 1 has a unit generation (PV), energy storage system (ESS) (battery), one inverter module, the controllable and noncontrollable loads, and a smart meter.For household, the use of PV generation is considered free (the generation unit is household property).In this paper, the PV generation is considered priority above all others, meaning that when it is available it will always be used either by load's necessities, battery charge, or injection in the grid.The connection with the grid is considered bidirectional.The PV rated power is usually limited by a contract between retailer and household.This limitation occurs because it can be a source of problems for the physical grid.In this way, it is difficult to reach a situation in which, as limit case if no injection to the grid is allowed, the PV is higher than the load plus the energy that can be used to charge the battery.However, if it happens, the inverter will disconnect the PV in order to avoid overvoltage.In Figure 1 one can see power flows and information flows.The information flows are connected to the inverter and controllable loads.In this case, the inverter is enabled with a control and management system that allows controlling loads, adding DR actions in household installation.
In general, the consumer can take advantage of the use of PV generation, ESS, and DR actions to minimize the cost of consumption from the grid.The consumer can look for the periods where electricity is cheaper to satisfy the consumption and charge the ESS, and the periods where the electricity price is most expensive to sell the excess electricity from the facility.Thus, it can be considered as a management system for the consumer to improve his energy bill.
Figure 2 is a representative illustration of the load's control using relays.The controller, in this case, is a component of the inverter.Each controllable load must have one relay associated with it, which allows for its control.So, when the controller sends the signal to the relay, the load is connected or disconnected from the electrical circuit.In this case, this control is considered a DR cut (direct load control).The scheme in Figure 2 considers only one relay for simplification; however, the proposed methodology is able to consider several relays, one for each load in the facility.For household, the use of PV generation is considered free (the generation unit is household property).In this paper, the PV generation is considered priority above all others, meaning that when it is available it will always be used either by load's necessities, battery charge, or injection in the grid.The connection with the grid is considered bidirectional.The PV rated power is usually limited by a contract between retailer and household.This limitation occurs because it can be a source of problems for the physical grid.In this way, it is difficult to reach a situation in which, as limit case if no injection to the grid is allowed, the PV is higher than the load plus the energy that can be used to charge the battery.However, if it happens, the inverter will disconnect the PV in order to avoid overvoltage.In Figure 1 one can see power flows and information flows.The information flows are connected to the inverter and controllable loads.In this case, the inverter is enabled with a control and management system that allows controlling loads, adding DR actions in household installation.
In general, the consumer can take advantage of the use of PV generation, ESS, and DR actions to minimize the cost of consumption from the grid.The consumer can look for the periods where electricity is cheaper to satisfy the consumption and charge the ESS, and the periods where the electricity price is most expensive to sell the excess electricity from the facility.Thus, it can be considered as a management system for the consumer to improve his energy bill.
Figure 2 is a representative illustration of the load's control using relays.The controller, in this case, is a component of the inverter.Each controllable load must have one relay associated with it, which allows for its control.So, when the controller sends the signal to the relay, the load is connected or disconnected from the electrical circuit.In this case, this control is considered a DR cut (direct load control).The scheme in Figure 2 considers only one relay for simplification; however, the proposed methodology is able to consider several relays, one for each load in the facility.

Problem Formulation
The mathematical formulation is presented throughout this section.With the formulation presented it is intended to simulate the interaction of a consumer with the grid.The main goal is to minimize the operation costs, considering that the user has storage units and is also enabled to do DR in specific loads.The presented optimization model is considered a mixed-integer linear problem.Equation ( 1) presents the objective function.
Equation ( 1) is comprised of the sum of two different parcels: the energy bill present in Equation ( 2) and the DR curtailment present in Equation (3).The Energy Bill represents the cost of buying and selling energy, and the DR curtailment refers to cost weighting associated with kWh curtailment.
In Equation ( 2) the variable  represents the flow of energy between household and grid,  is an indicator variable for power flow into the grid and control the energy buy  = 1 and energy sell  = 0 ,  represents the cost of buying electricity and  represents the cost of selling electricity.The Energy bill in Equation ( 2), consider the costs of buying electricity  ×  ×  and the revenues of selling electricity 1 −  ×  ×  .
In each period () the user can make a single operation (buy or sell).
Also, in Equation ( 2) the term 1 −  ×  represents the power sent to the network.
The term ∆ is used for to adjust the consumption to the tariff price because normally the tariff is available in €/kWh and the optimization can be scheduled at different time intervals (e.g., 15 min). represents the daily contracted power cost.If the term  has a positive value during optimization it means that there is electricity consumption from the network.However, if it has a negative value it means that there is a sale of electricity to the network.Equation (3) presents the DR curtailment.
If the DR curtailment equation is implemented the cost of load is cut with the use of weights, and in fact does not have cost for the user.The variable  , represents the cut energy of load () in period (), the  , represents the decision binary variable to active the cut of load () in period

Problem Formulation
The mathematical formulation is presented throughout this section.With the formulation presented it is intended to simulate the interaction of a consumer with the grid.The main goal is to minimize the operation costs, considering that the user has storage units and is also enabled to do DR in specific loads.The presented optimization model is considered a mixed-integer linear problem.Equation ( 1) presents the objective function.
Equation ( 1) is comprised of the sum of two different parcels: the energy bill present in Equation ( 2) and the DR curtailment present in Equation (3).The Energy Bill represents the cost of buying and selling energy, and the DR curtailment refers to cost weighting associated with kWh curtailment.
In Equation ( 2 .In each period (t) the user can make a single operation (buy or sell).
represents the power sent to the network.The term ∆t is used for to adjust the consumption to the tariff price because normally the tariff is available in €/kWh and the optimization can be scheduled at different time intervals (e.g., 15 min).DCP represents the daily contracted power cost.If the term P grid t has a positive value during optimization it means that there is electricity consumption from the network.However, if it has a negative value it means that there is a sale of electricity to the network.Equation (3) presents the DR curtailment.
If the DR curtailment equation is implemented the cost of load is cut with the use of weights, and in fact does not have cost for the user.The variable P cut l,t represents the cut energy of load (l) in period (t), the X cut l,t represents the decision binary variable to active the cut of load (l) in period (t), and W cut l,t represents the cut weight of load (l) in period (t).The term P cut l,t × X cut l,t × W cut l,t shows the interest of the user to perform cut in load (l) in period (t).
Equation ( 4) represents the balance between load and generation, P bat b,t represents the energy charged or discharged by baterry (b) in period (t).If the value of P bat b,t is less than 0 the battery is discharging, otherwise, if the value of P bat b,t is greater than 0, the battery is charging.
The Equation ( 5) shows the balance of battery systems.
Variable E stor b,t represents the state of the battery b in period t, in other words, it represents the amount of energy it has available.So, by Equation ( 5) the current battery state is obtained by adding the previous state E stor b,t−1 to the value of the variable P bat b,t .The power term P bat b,t in Equation ( 5) is multiplied by 1  ∆t to convert power into energy units.The system is governed by the following constraints (Equations ( 6)-( 10 P cut l,t = P cut max l,t ∀l ∈ {1, . . ., L}, ∀t ∈ {1, . . ., T} 0 ≤ E stor b,t ≤ E stor max b,t ∀b ∈ {1, . . ., B}, ∀t ∈ {1, . . ., T} − P dch max b,t ≤ P bat b,t ≤ P ch max b,t ∀b ∈ {1, . . ., B}, ∀t ∈ {1, . . ., T} X cut l,t = 1 0 ∀l ∈ {1, . . ., L}, ∀t ∈ {1, . . ., T}. In Equation ( 6), the variable P grid min t and P grid max t represent the limit values for variable P grid t .Equation (7) identifies that P cut l,t can only take the maximum value P cut max l,t . The P bat b,t variables can take a value between −P dch max b,t and P ch max b,t ; if the value of P bat b,t is less than zero it represents a discharge and if the value is greater than zero it represents a charge.The variable X cut l,t is a binary variable and represents a decision variable.When X cut l,t is equal to 1 the cut of load (l) at period (t) is active.

Particle Swarm Optimization
PSO was proposed by Kennedy and Eberhart in 1995, and it is a random search algorithm that simulates the foraging and flocking of birds in nature [27].When birds look randomly for food in a given area, each bird can be associated with a single solution and can be considered as a particle in the swarm.
For PSO implementations assume that it has j particles in the n-dimensional search space and each particle represent a solution in the search space.Equation (11) presents the position vector of particle j and in Equation ( 12) the velocity vector for particle j.
Energies 2019, 12, 1645 7 of 18 where, → x j i .represents the position vector of particle j for n. variables at iteration i.The → v j i represents the velocity vector of particle j for n variables.When the search process starts, both vectors are generated randomly between the respective limits of the n variables.
Equation ( 13 where, → v j i+1 is the velocity vector at iteration i + 1; w j i represents the inertia weight obtained through Equation ( 15); c1 j i and c2 j i are acceleration coefficients, which are obtained by Equations ( 16) and (17), respectively; and r1 j i and r2 j i are two uniformly distributed random numbers independently generated within [0,1] for the n-dimensional search space.P j best = x j pbest,1 , x j pbest,2 , . . ., x j pbest,n denotes the historical best position and G best = x gbest,1 , x gbest,2 , . . ., x gbest,n denotes the population historical best position.Equation ( 15) presents an inertia weight.
where, w max is the maximum value for inertia weight, w min is the minimum value for inertia weight, and i max represents the maximum value of iterations.The inertia weight present in Equation ( 15) is a linear decreasing method during the search process.The inertia weight reduction ensures strong global exploration properties in the initial phase and strong local exploitation properties in the advanced phase.The inertia weight is calculated at each iteration and is the same for the set of particles at each iteration [28].Equations ( 16) and ( 17) present the acceleration coefficients calculation: where, c max Energies 2019, 12, 1645 8 of 18 where, P bat 1.1 , . . ., P bat B,T is a group of continuous variables representing the electricity amount of charge or discharge in each battery (b) at period (t) and X cut 1.1 , . . ., X cut L,T are binary variables to enable the possibility of performed cut action in load (l) at period (t).Therefore, particle → x has dimensions of n = B × T + L × T. This encoding allows a direct evaluation in Equation (1).
The PSO implementation starts by defining the search space limits by setting the lower and upper bounds of each variable.In Equation ( 19), xlb j represents the lower limits for the solution of j particle and xub j in Equation (20) represent the upper limit for j particle.
Equation ( 21) presents the process of initialization where the initial solution was created.In this case, a random process into allowed bounds is executed.rand xlb j , xub j is a random number within the lower xlb j and the upper xub j bounds of j particle for n variables.
Equation ( 22) presents the boundary constrains method.The search process over the iterations will generate new solutions that may not be within the initially stipulated limits.To address this issue the boundary control strategies are used to repair infeasible individuals.In this paper is used a boundary control technique known as bounce-back [20].
In contrast to random reinitialization (the most used control technique), bounce-back uses the information on the progress towards the optimum region by reinitialized the variable value between the base variable value and the bound being violated.Making use of domain knowledge about the problem, the Equations ( 23) and ( 24) is proposed as a direct repair equation.The Equation ( 23) concerns the direct repair of E stor b,t .
Although boundary control is used it can only control the variables P bat and X cut , the variable E stor is a variable of control and balance, and when it is repaired other variables are necessarily changed.For the repair process E stor is needed to test two different conditions, E stor b,t < 0 represents a greater discharge than the allowed one, being that it fixes the variable to the minimum value.E stor b,t > E stor max b,t means that the battery has a charge greater than the allowed, the value of maximum energy in the battery is fixed in maximum that can accumulate.Equation ( 24) presents the direct repair for P bat variable.
P bat is repaired in Equation ( 22), but with the direct repair used in Equation ( 23) the variable P bat may not be correct, and it is necessary to perform direct repair on it.So, a battery power level test is performed, if E stor b,t < 0 the value for P bat b,t is equal to the difference between the battery power level in the previous period E stor b,t−1 and the current period E stor b,t .The same rule is applied when the battery power level is greater than the allowed maximum E stor b,t > E stor max b,t .
The particles should be evaluated according to a fitness function f f where, p f → x in Equation ( 26) represents the penalty value for a solution → x .Despite the application of bounce-back method Equation ( 22) and direct repair methods ( 23) and ( 24), the solution may still be infeasible.The penalty value is obtained checking the limits of variable P grid t for every period.In each period that the variable is out of limit is counted and multiplied by a penalty amount ρ, the sum of all individual (per period) penalties represents the total penalties per each solution.
Pseudocode of the PSO algorithm is presented in Algorithm 1.

INITIALIZE
Set control parameters w max ,w min ,c max 1 ,c min 1 ,c max 2 ,c min 2 , j max , and i max .Create an initial Pop (Equation ( 21)) and initial velocities.

IF Direct repair is used THEN
Apply direct repair to unfeasible individuals END IF Evaluate the fitness of Pop (Equation ( 25)).Create a P best vector for every particle.Create a G best vector of the swarm.FOR i = 1 to i max FOR j = 1 to j max Velocity update (Equation ( 13)) Position update (Equation ( 14)) Update w i , c1 i and c2 i (Equations ( 15)-( 17)) Verify boundary constraints for P bat (Equation ( 9))and X cut (Equation ( 10)) IF Boundary constraints are violated THEN Apply boundary control (Equation ( 22)) END IF Verify boundary constraints for E stor (Equation ( 8)) and P bat (Equation ( 9)) IF Boundary constraints are violated THEN Apply direct repair (Equations ( 23) and ( 24)) END IF x (Equation ( 25)).Verify boundary constraints for P grid (Equation ( 6 Basically, if in the evaluation process constraints violations are identified, the individual is randomly repaired using the initialization process from Equation (22).The pseudocode of Algorithm 1 is displayed step-by-step, starts with the definition of the parameters related to the PSO.The search begins with the creation of the initial population.After being evaluated, the best position of each particle and the best position of the population are defined.The main cycle starts, and at each iteration of the main cycle, another cycle is performed for each particle.For each particle a new velocity is generated, updated, verified, and evaluated.When all particles repeat the process, the value of the best personal position of each particle and the best overall position of the population is updated.

Case Study
This section presents the case study.The optimization problem was solved using PSO metaheuristic and compared to a solution obtained by a CPLEX solver in MATLAB™/TOMSYM™ environment to compare the results.
The proposed methodology addresses a Portuguese consumer and complies with actual Portuguese legislation, which allows small producers (consumers with local generation) to use the energy produced to satisfy the own load necessities and sell it to the grid.The consumer has a supply power contract of 10.35 KVA with the retailer, and it is characterized by three different periods: peak, intermediate, and off-peak [29].The prices applied to a consumer operation are present in Table 1.The input prices in Table 1 are real values of a Portuguese retailer (https://www.edp.pt/particulares/energia/tarifarios), which provides a realistic case study.The prosumer can inject his excess production into grid, but a limit is imposed by the retailer.The maximum value injected into grid is half of its contracted power, approximately 5.1 kW.The real prices and real condition inclusion in this problem contribute to more accurate in this study and prove the real value of the methodology application.The DR weights present in Table 1 are defined by the consumer taking into account the energy price variation within the day, adapted from [16].The use of DR is more appreciated when the energy is cheaper, so the weight of 0 is given in peak periods (highest price).With this weight distribution, the DR actions are expected to be executed during peak periods.Equation (3) gives the amount of DR actions contributing to the objective function.It does not represent costs for the consumer, but is rather a consumer's preference that influences the scheduling.In Table 2 are presented the problem input variables adapted from [16].
The system has two PV panels with different production, one has a maximum production of 7.5 kW and other has a maximum production of 2.5 kW.This PV panels and the battery storage unit are connected to the inverter.The battery can receive power from the PV production or the grid.In this case study, the inverter has two functionalities: the first is to convert the power from DC to AC and vice versa; the other functionality is to give the signal to manage certain loads.In this study, three different loads are considered: a dishwasher, an air conditioner, and a water heater.Figure 3 shows the disaggregated consumption and PV generation forecasts.In this case study, the forecast is performed for the next 24 h.In real-time operation, the forecast can be updated at every instant.Each time that user update the forecast can perform a new optimization.Regarding the influence of the forecasting results on optimization, in the case that the presented day-ahead forecasting strategies in References [30,31] are considered, the forecasting error, using Supporter Vector Machine algorithms to predict the values for the next 24 h, will be 9.11%.Figure 3 presents a typical load profile with a peak of 11.5 kW at ~11.45 h.The consumption per controllable load is present in Figure 3 with different colors.The total consumption includes the sum of all loads and the same situation for PV but is the sum of two PV units.The peak of production is forecasted between the 12.00 h and 13.30 h with 6 kW.In some periods, such as 10:30, the sum of the controllable loads corresponds to the total consumption.Table 3 presents the parameters for PSO; they were obtained from a previous study.Figure 3 presents a typical load profile with a peak of 11.5 kW at ~11.45 h.The consumption per controllable load is present in Figure 3 with different colors.The total consumption includes the sum of all loads and the same situation for PV but is the sum of two PV units.The peak of production is forecasted between the 12.00 h and 13.30 h with 6 kW.In some periods, such as 10:30, the sum of the controllable loads corresponds to the total consumption.Table 3 presents the parameters for PSO; they were obtained from a previous study.The member of evaluation is equal to j max × i max and presents the number of fitness function is evaluated during the search process.Considering that the PSO is an algorithm of a random nature, a group of 30 trials is performed.With a sample of 30 results, it is possible to extract a more robust conclusion from the application of the PSO to the problem in question.

Results
This section presents the results and analysis obtained from the implementation of the proposed methodology and respective case study.Table 4 presents the results for Equation (1) in both the CPLEX (deterministic) obtaining the optimal value, and PSO obtained an approximate resolution.Four different scenarios were created considering the resources combination: the scenario "PV + Bat + DR" combine the all available resources (PV production, the storage capacity and loads flexibility), scenario "PV + Bat" combines the PV production and storage capacity resources and "PV" scenario only considers the PV production resource.The nonoptimized value is used as a base case scenario and was obtained by using a simple management mechanism; the scenario "PV + Bat" considers PV production and storage capacity, and the "Without resources" scenario does not consider any resource.Analyzing the results of CPLEX for the set of scenarios can conclude that "PV + Bat + DR" presents the smallest fitness function.It can be said with resources combinations brings benefits for household management.The analysis of results is performed for the "PV + Bat + DR" scenario.The results present in Table 4 of PSO correspond to 30 trials.The minimum value that the PSO reached is 2.8% higher when compared with CPLEX value.Analyzing the standard deviation (std) value for the sample of PSO results is possible to conclude that it is relatively small and the values of the 30 trials should be relatively close to the mean value.The STD analysis is important because it is a measure that expresses the degree of dispersion of 30 trials solutions.Figure 4 presented the results related to the DR actions applied to the profile shown in Figure 3.
4 of PSO correspond to 30 trials.The minimum value that the PSO reached is 2.8% higher when compared with CPLEX value.Analyzing the standard deviation (std) value for the sample of PSO results is possible to conclude that it is relatively small and the values of the 30 trials should be relatively close to the mean value.The STD analysis is important because it is a measure that expresses the degree of dispersion of 30 trials solutions.Figure 4 presented the results related to the DR actions applied to the profile shown in Figure 3.In Figure 4, the positive values correspond to the consumption of appliances that had no changes with the application of the methodology.Negative values are energy that has been reduced due to cut of loads.With the loads cut, reduction of 63% in the total consumption of three loads (dish washer, air conditioner, and water heater) was obtained.The DR actions are performed during 10.00 h to 13.00 h and 19.00 to 21.00.Crossing this information with Table 1, one can see that these periods correspond to a peak hour, precisely when energy is more expensive.During peak hours the consumption with the present optimization methodology is 44.8 kW, without its application and not considering PV generation and energy storage systems, the consumption will be 115.4   In Figure 4, the positive values correspond to the consumption of appliances that had no changes with the application of the methodology.Negative values are energy that has been reduced due to cut of loads.With the loads cut, reduction of 63% in the total consumption of three loads (dish washer, air conditioner, and water heater) was obtained.The DR actions are performed during 10.00 h to 13.00 h and 19.00 to 21.00.Crossing this information with Table 1, one can see that these periods correspond to a peak hour, precisely when energy is more expensive.During peak hours the consumption with the present optimization methodology is 44.8 kW, without its application and not considering PV generation and energy storage systems, the consumption will be 115.4kW.This reduction represents 20% reduction of total daily consumption.In this way, it is concluded that the present methodology has an impact on the consumption of peak hours.In Figure 5 are presented the total load consumption (controllable and noncontrollable loads), the battery actions (charge and discharge), and the final load (load consumption plus battery charge).
Energies 2019, 12, x FOR PEER REVIEW 13 of 17 20% reduction of total daily consumption.In this way, it is concluded that the present methodology has an impact on the consumption of peak hours.In Figure 5 are presented the total load consumption (controllable and noncontrollable loads), the battery actions (charge and discharge), and the final load (load consumption plus battery charge).Figure 5 shows that due to this condition, the generation (see Figure 3) exceeds the consumption needs, and in this case, the energy surplus will either be used to charge the battery or sell to the grid.In this way, the user avoids buying energy from the grid to charge the battery and to meet consumption necessities.The battery discharge cycles are mostly represented between 11.00 and Figure 5 shows that due to this condition, the generation (see Figure 3) exceeds the consumption needs, and in this case, the energy surplus will either be used to charge the battery or sell to the grid.In this way, the user avoids buying energy from the grid to charge the battery and to meet consumption necessities.The battery discharge cycles are mostly represented between 11.00 and 21.00 periods that correspond to a peak and intermediate hour.Table 5 presents a summary of the results obtained by both methods applied.With the proposed methodology, the daily cost of operation for CPLEX is 3.18 (€) and 3.28 (€) for PSO, but if the PV system, battery and DR do not exist and the daily costs are 16.83 (€).When compared the results of Table 5 is possible to observe that daily cost for CPLEX is larger compared to PSO daily cost, but the value of revenues in CPLEX are also large than PSO values.With the case study present in Section 5, the value of Equation ( 1) is equal to Equation (2) in both of methods, which means that the value of Equation ( 3) is zero because Equation ( 1) is the sum of Equation ( 2) and (3).When Equation (3) has the value zero represents that the DR is performed on periods with weight equal to zero and do not have a contribution to Equation (1).Table 5 also presents the monthly costs, which are calculated considering that the profile present in Figure 3 is repeated for the 30 days of the month.The value obtained for PSO is 2.96 (€) higher.

Conclusions
The present work addresses a methodology for resource scheduling (PV battery, storage capacity, and load flexibility) in a residential house that has not any contract with a DR service provider.Usually, the DR services for residential consumers are available using a DR service provider.In contrast, in the presented methodology the user is independent of applying his preferences in decision-making.In this case, the PV inverter, installed to convert the PV production into DC to AC, can control the charge or discharge of the battery system and the interruption of the loads.The optimization results for P bat b,t and P cut l,t are the inputs for the PV inverter control to act on the battery system and controllable loads.
The optimization problem was solved using a stochastic method (PSO) and a deterministic method (CPLEX).The results obtained by PSO have a close approximation to the deterministic results.The simple implementation and open access possibility of programming PSO over different platforms are factors that potentiate its use in this type of problems.In fact, in the present work, it was possible to demonstrate the results of running a PSO-based algorithm on a connection with the inverter of the PV system for control of the connected loads and the charge or discharge of the battery storage system.
The numerical results presented demonstrate that it is possible to obtain advantages by using the optimal combination of available resources.Table 4 presents the fitness function value for different resources combination, showing that the scenario that combines the all available resources is the best.Although PSO can obtain near-optimal solutions, its solution using the best combination resource scenario is better than the normal operating solution.With the comparison between the base scenario and the same scenario with PSO optimization, it is possible to make the assessment of the PSO approach.The daily cost optimized by PSO for the base scenario is 14% lower compared with the obtained in the nonoptimized base scenario.
As the presented methodology was built for been applied in an independent agent, the agent facility (residential house) needs to be prepared with equipment to perform the actions that the presented method imposes.This condition may be a weakness of the methodology, as it will increase the initial investment in equipment.Assuming that the DR program is implemented efficiently, such investment can be recovered over time, as the user does not need to pay fees to any service provider to use the service.The use of PSO instead of CPLEX can make the initial investment more appealing, for reasons already discussed in the introduction.
For future work, an analysis incorporating more DR actions (e.g., reduction and shifting capabilities) in the presented methodology can be done.Also, robust optimization considering the forecast error in PV production and domestic consumption can also be made to analyze the impact of forecasts errors in the electricity bill.Velocity vector

Figure 1 .
Figure 1.Implementation scheme of the proposed work.

Figure 1 .
Figure 1.Implementation scheme of the proposed work.

Energies 2019 , 17 Figure 2 .
Figure 2. The control scheme for the demand response (DR) cut with one load.

Figure 2 .
Figure 2. The control scheme for the demand response (DR) cut with one load.
) represents the velocity update equation.This equation is composed of three different components: the w learning component.Equation (14) represents the position update.

1 and c min 1 are
the maximum and minimum values for the personal acceleration coefficient, respectively.c1 j i decreases over the iterations, which means that the acceleration component for the personal position at the beginning of the search is high allowing exploration.The parameters c min and maximum values for the global acceleration coefficient.c2 j i increases over the iterations, which means that the acceleration component for the global position at the end of the search is high allowing exploitation.The encoding of the solutions is crucial for the success of the algorithm.Equation(18) shows the encoded vector used for solving the problem present in Section 2. → x j i = P bat 1.1 , . . ., P bat B,T , X cut 1.1 , . . ., X cut L,T

Figure 4 .
Figure 4. DR result regarding initial profile.

Figure 4 .
Figure 4. DR result regarding initial profile.
Photovoltaic production xub jUpper bond for → x j

Table 1 .
Prices of the different periods and contracted power.
* is used for all periods.

Table 2 .
Problem input variables.The factor of 4 comes from the fact that there are four 15-min periods in an hour. *
Load consumptions, battery actions, and final load scheduling.

Table 5 .
Summary of results.