Next Article in Journal
Generator Maintenance Scheduling Method Using Transformation of Mixed Integer Polynomial Programming in a Power System Incorporating Demand Response
Next Article in Special Issue
Distributed Energy Resources Management 2018
Previous Article in Journal
Mode Recognition and Fault Positioning of Permanent Magnet Demagnetization for PMSM
Previous Article in Special Issue
Virtual Organization Structure for Agent-Based Local Electricity Trading
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:

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

Polytechnic of Porto, Rua DR. Antonio Bernardino de Almeida, 431, 4200-072 Porto, Portugal
Author to whom correspondence should be addressed.
Energies 2019, 12(9), 1645;
Submission received: 4 March 2019 / Revised: 24 April 2019 / Accepted: 25 April 2019 / Published: 30 April 2019
(This article belongs to the Special Issue Distributed Energy Resources Management 2018)


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.

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

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

3. 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.
M i n i m i z e   f = E n e r g y   B i l l + D R   C u r t a i l m e n t
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 P t g r i d represents the flow of energy between household and grid, I t g r i d   i n is an indicator variable for power flow into the grid and control the energy buy ( I t g r i d   i n = 1 ) and energy sell ( I t g r i d   i n = 0 ) , C t g r i d   i n represents the cost of buying electricity and C t g r i d   o u t represents the cost of selling electricity. The Energy bill in Equation (2), consider the costs of buying electricity ( I t g r i d   i n × P t g r i d ) × C t g r i d   i n and the revenues of selling electricity ( ( 1 I t g r i d   i n ) × P t g r i d ) × C t g r i d   o u t . In each period ( t ) the user can make a single operation (buy or sell).
E n e r g y   B i l l = t = 1 T [ ( ( I t g r i d   i n × P t g r i d ) × C t g r i d   i n ( ( 1 I t g r i d   i n ) × P t g r i d ) × C t g r i d   o u t ) × 1 Δ t ] + D C P
I t g r i d   i n = { 1 ,    i f   P t g r i d > 0 0 ,    o t h e r w i s e              t { 1 , , T }
Also, in Equation (2) the term ( ( 1 I t g r i d   i n ) × P t g r i d ) 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). D C P represents the daily contracted power cost. If the term P t g r i d 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.
D R   C u r t a i l m e n t = t = 1 T ( l = 1 L P l , t c u t × X l , t c u t × W l , t c u t )
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 l , t c u t represents the cut energy of load ( l ) in period ( t ) , the X l , t c u t represents the decision binary variable to active the cut of load ( l ) in period ( t ) , and W l , t c u t represents the cut weight of load ( l ) in period ( t ) . The term ( P l , t c u t × X l , t c u t × W l , t c u 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 b , t b a t represents the energy charged or discharged by baterry ( b ) in period ( t ) . If the value of P b , t b a t is less than 0 the battery is discharging, otherwise, if the value of P b , t b a t is greater than 0, the battery is charging. The variable P p , t P V represents the photovoltaic production of unit p at period t , and P t l o a d corresponds to the value of load at period t .
P t g r i d = P t l o a d + b = 1 B P b , t b a t l = 1 L P l , t c u t × X l , t c u t p = 1 P P p , t P V ,    t { 1 , , T }
The Equation (5) shows the balance of battery systems.
E b , t s t o r = E b , t 1 s t o r + P b , t b a t × 1 Δ t ,    t { 2 , T } ,   b { 1 , , B }
Variable E b , t s t o r 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 b , t 1 s t o r to the value of the variable P b , t b a t .The power term P b , t b a 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 t g r i d   m i n P t g r i d P t g r i d   m a x    t { 1 , , T }
P l , t c u t = P l , t c u t   m a x    l { 1 , , L } ,   t { 1 , , T }
0 E b , t s t o r E b , t s t o r   m a x    b { 1 , , B } ,   t { 1 , , T }
P b , t d c h   m a x P b , t b a t P b , t c h   m a x    b { 1 , , B } ,   t { 1 , , T }
X l , t c u t = { 1 0    l { 1 , , L } ,   t { 1 , , T } .
In Equation (6), the variable P t g r i d   m i n and P t g r i d   m a x represent the limit values for variable P t g r i d . Equation (7) identifies that P l , t c u t can only take the maximum value P l , t c u t   m a x . The P b , t b a t variables can take a value between P b , t d c h   m a x and P b , t c h   m a x ; if the value of P b , t b a t is less than zero it represents a discharge and if the value is greater than zero it represents a charge. The variable X l , t c u t is a binary variable and represents a decision variable. When X l , t c u t is equal to 1 the cut of load ( l ) at period ( t ) is active.

4. 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.
x i j = ( x i , 1 j , x i , 2 j , , x i , n j )
v i j = ( v i , 1 j , v i , 2 j , , v i , n j )
where, x i j . represents the position vector of particle j for n . variables at iteration i . The v i j 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) represents the velocity update equation. This equation is composed of three different components: the w i j v i j component represents the previous positions in memory search, c 1 i j r 1 i j ( P b e s t j x i j ) corresponds to the cognitive learning component, and c 2 i j r 2 i j ( G b e s t x i j ) is a global learning component. Equation (14) represents the position update.
v i + 1 j = w i j × v i j + c 1 i j × r 1 i j × ( P b e s t j x i j ) + c 2 i j × r 2 i j × ( G b e s t x i j )
x i + 1 j = v i + 1 j + x i j
where, v i + 1 j is the velocity vector at iteration i + 1 ; w i j represents the inertia weight obtained through Equation (15); c 1 i j and c 2 i j are acceleration coefficients, which are obtained by Equations (16) and (17), respectively; and r 1 i j and r 2 i j are two uniformly distributed random numbers independently generated within [0,1] for the n-dimensional search space. P b e s t j = ( x p b e s t , 1 j , x p b e s t , 2 j , , x p b e s t , n j ) denotes the historical best position and G b e s t = ( x g b e s t , 1 ,   x g b e s t , 2 , ,   x g b e s t , n ) denotes the population historical best position. Equation (15) presents an inertia weight.
w i j = w m a x ( w m a x w m i n i m a x ) × i
where, w m a x is the maximum value for inertia weight, w m i n is the minimum value for inertia weight, and i m a x 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:
c 1 i j = c 1 m a x ( c 1 m a x c 1 m i n i m a x ) × i
c 2 i j = c 2 m i n + ( c 2 m a x c 2 m i n i m a x ) × i
where, c 1 m a x and c 1 m i n are the maximum and minimum values for the personal acceleration coefficient, respectively. c 1 i j 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 2 m i n and c 2 m a x represent the minimum and maximum values for the global acceleration coefficient. c 2 i j 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 i j = [ { P 1.1 b a t , ,   P B , T b a t } , { X 1.1 c u t , ,   X L , T c u t } ]
where, { P 1.1 b a t , ,   P B , T b a t } is a group of continuous variables representing the electricity amount of charge or discharge in each battery ( b ) at period ( t ) and { X 1.1 c u t , ,   X L , T c u 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), x l b j represents the lower limits for the solution of j particle and x u b j in Equation (20) represent the upper limit for j particle.
x l b j = [ { P 1.1 d c h   m a x , ,   P B , T d c h   m a x } , { X 1.1 c u t   m i n , ,   X L , T c u t   m i n } ]
x u b j = [ { P 1.1 c h   m a x , ,   P B , T c h   m a x } , { X 1.1 c u t   m a x , ,   X L , T c u t   m i n } ]
x 1 j = r a n d   [ x l b j , x u b j ]
Equation (21) presents the process of initialization where the initial solution was created. In this case, a random process into allowed bounds is executed. r a n d   [ x l b j , x u b j ] is a random number within the lower x l b j and the upper x u b 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].
x i j = { rand ( x l b j , x i j )     i f   x i j < x l b j rand ( x i j , x u b j )     i f   x i j > x u b j x i j                                o t h e r w i s e
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 b , t s t o r .
E b , t s t o r = { 0 P b , t c h   m a x E b , t s t o r i f                 E b , t s t o r < 0 i f   E b , t s t o r > E b , t s t o r   m a x o t h e r w i s e                          b { 1 , , B } ,   t { 1 , , T }
Although boundary control is used it can only control the variables P b a t and X c u t , the variable E s t o r is a variable of control and balance, and when it is repaired other variables are necessarily changed. For the repair process E s t o r is needed to test two different conditions, E b , t s t o r < 0 represents a greater discharge than the allowed one, being that it fixes the variable to the minimum value. E b , t s t o r > E b , t s t o r   m a x 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 b a t variable.
P b , t b a t = { E b , t s t o r E b , t 1 s t o r E b , t s t o r E b , t 1 s t o r P b , t b a t i f                 E b , t s t o r < 0 i f   E b , t s t o r > E b , t s t o r   m a x o t h e r w i s e        b { 1 , , B } ,   t { 2 , , T }
P b a t is repaired in Equation (22), but with the direct repair used in Equation (23) the variable P b a t may not be correct, and it is necessary to perform direct repair on it. So, a battery power level test is performed, if E b , t s t o r < 0 the value for P b , t b a t is equal to the difference between the battery power level in the previous period E b , t 1 s t o r and the current period E b , t s t o r . The same rule is applied when the battery power level is greater than the allowed maximum E b , t s t o r > E b , t s t o r   m a x .
The particles should be evaluated according to a fitness function f ( x ) , Equation (25), including objective function f ( x ) Equation (1) and constrains violation p f ( x ) .
f ( x ) = f ( x ) + p f ( x )
p f ( x ) = { t = 1 T t × ρ       i f   P t g r i d P t g r i d   m i n   P t g r i d P t g r i d   m a x 0                          o t h e r w i s e    t { 1 , , T }
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 t g r i d 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.
Algorithm 1. PSO pseudocode.
Set control parameters w m a x , w m i n , c 1 m a x , c 1 m i n , c 2 m a x , c 2 m i n , j m a x , and i m a x .
Create an initial Pop (Equation (21)) and initial velocities.
IF Direct repair is used THEN
  Apply direct repair to unfeasible individuals
Evaluate the fitness of Pop (Equation (25)).
Create a P b e s t vector for every particle.
Create a   G b e s t vector of the swarm.
FOR i = 1 to i m a x
  FOR j = 1 to j m a x
   Velocity update (Equation (13))
   Position update (Equation (14))
   Update w i , c 1 i and c 2 i (Equations (15)–(17))
   Verify boundary constraints for P b a t (Equation (9))and X c u t (Equation (10))
   IF Boundary constraints are violated THEN
     Apply boundary control (Equation (22))
   Verify boundary constraints for E s t o r (Equation (8)) and P b a t (Equation (9))
   IF Boundary constraints are violated THEN
     Apply direct repair (Equations (23) and (24))
   Evaluate fitness of x (Equation (25)).
   Verify boundary constraints for P g r i d (Equation (6))
   IF P g r i d is out of limits THEN
     Apply penalty function (Equation (26))
     Update fitness value (Equation (25))
   Update P b e s t vector for i particle.
  Update G b e s t vector of the swarm.
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.

5. 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 (, 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.
The member of evaluation is equal to j m a x × i m a x 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.

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

7. 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 b , t b a t and P l , t c u 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.

Author Contributions

Investigation, R.F.; Methodology, P.F. and Z.V.; Resources, Z.V.; Software, R.F. and J.S.; Writing—original draft, R.F.; Writing—review & editing, P.F. and Z.V.


The present work was done and funded in the scope of the following projects: SIMOCE Project (P2020-23575) and UID/EEA/00760/2019 funded by FEDER Funds through COMPETE program and by National Funds through FCT. Ricardo Faia is supported by national funds through Fundação para a Ciência e a Tecnologia (FCT) with PhD grant reference SFRH/BD/133086/2017.

Conflicts of Interest

The authors declare no conflicts of interest.


AIArtificial Intelligence
DRDemand Response
DGDistributed Generation
ESSEnergy Storage System
LPLinear Programming
MATLABMatrix Laboratory
MILPMixed-integer Linear Programming
MINLPMixed-integer Nonlinear Programming
NLPNonlinear Programing
PSOParticle Swarm Optimization
RESsRenewable Energy Sources
SETStrategic Energy Technology
b Battery unit
n Dimension
i Iteration
l Load unit
j Particle
t Period
p Photovoltaic unit
C t g r i d   i n Cost of buying electricity to the grid
C t g r i d   o u t Cost of selling electricity to the grid
W l , t c u t Cut weight of load
D C P Daily contracted power cost
x l b j Lower bond for x j
P t g r i d   m a x Maximum limit for P t g r i d
i m a x Maximum number of iterations
j m a x Maximum numbers of particles
P l , t c u t   m a x Maximum value for cut load
P b , t c h   m a x Maximum value for energy charge
P b , t d c h   m a x Maximum value for energy discharge
c 2 m a x Maximum value for global acceleration coefficient
w m a x Maximum value for inertia weight
c 1 m a x Maximum value for personal acceleration coefficient
E b , t s t o r   m a x Maximum value of accumulated energy in battery
P t g r i d   m i n Minimum limit for P t g r i d
c 2 m i n Minimum value for global acceleration coefficient
w m i n Minimum value for inertia weight
c 1 m i n Minimum value for personal acceleration coefficient
Δ t Multiplicative factor related with the time to calculate energy
B Number of batteries
L Number of controllable loads
T Number of Periods
ρ Penalty value
P p , t P V Photovoltaic production
x u b j Upper bond for x j
P t l o a d Value of load
I t g r i d   i n Binary variable for control the flow direction
P l , t c u t Cut power of load
X l , t c u t Decision binary variable to active the cut of loads
P b , t b a t Energy charged or discharged by battery
f ( x ) Fitness function
f ( x ) Fitness function with penalty
P t g r i d Flow of energy between household and grid
P b e s t j Historical best position
w i j Inertia weight
p f ( x ) Penalty function
c 1 i j and c 2 i j Personal and global acceleration coefficients
G b e s t Population historical best position
x i j Position vector
E b , t s t o r State of the battery
r 1 i j and r 2 i j Uniform distribution random numbers
v i j Velocity vector


  1. European Union. The Strategic Energy Technology (SET) Plan; European Union: Brussels, Belgium, 2017. [Google Scholar]
  2. Parag, Y.; Sovacool, B.K. Electricity market design for the prosumer era. Nat. Energy 2016, 1, 16032. [Google Scholar] [CrossRef] [Green Version]
  3. Bhandari, B.; Lee, K.-T.; Lee, G.-Y.; Cho, Y.-M.; Ahn, S.-H. Optimization of hybrid renewable energy power systems: A review. Int. J. Precis. Eng. Manuf. Technol. 2015, 2, 99–112. [Google Scholar] [CrossRef] [Green Version]
  4. Roldán-Blay, C.; Escrivá-Escrivá, G.; Roldán-Porta, C. Improving the benefits of demand response participation in facilities with distributed energy resources. Energy 2019, 169, 710–718. [Google Scholar] [CrossRef]
  5. Paterakis, N.G.; Erdinç, O.; Catalão, J.P.S. An overview of Demand Response: Key-elements and international experience. Renew. Sustain. Energy Rev. 2017, 69, 871–891. [Google Scholar] [CrossRef]
  6. Neves, D.; Silva, C.A. Optimal electricity dispatch on isolated mini-grids using a demand response strategy for thermal storage backup with genetic algorithms. Energy 2015, 82, 436–445. [Google Scholar] [CrossRef]
  7. Jordehi, A.R. Optimisation of demand response in electric power systems, a review. Renew. Sustain. Energy Rev. 2019, 103, 308–319. [Google Scholar] [CrossRef]
  8. European Commission. Benchmarking Smart Metering Deployment in the EU-27 with a Focus on Electricity; European Commission: Brussels, Belgium, 2014. [Google Scholar]
  9. Nan, S.; Zhou, M.; Li, G. Optimal residential community demand response scheduling in smart grid. Appl. Energy 2018, 210, 1280–1289. [Google Scholar] [CrossRef]
  10. Zhang, D.; Shah, N.; Papageorgiou, L.G. Efficient energy consumption and operation management in a smart building with microgrid. Energy Convers. Manag. 2013, 74, 209–222. [Google Scholar] [CrossRef]
  11. Pina, A.; Silva, C.; Ferrão, P. The impact of demand side management strategies in the penetration of renewable electricity. Energy 2012, 41, 128–137. [Google Scholar] [CrossRef]
  12. Nwulu, N.I.; Xia, X. Optimal dispatch for a microgrid incorporating renewables and demand response. Renew. Energy 2017, 101, 16–28. [Google Scholar] [CrossRef]
  13. Alipour, M.; Zare, K.; Abapour, M. MINLP Probabilistic Scheduling Model for Demand Response Programs Integrated Energy Hubs. IEEE Trans. Ind. Inform. 2018, 14, 79–88. [Google Scholar] [CrossRef]
  14. Zhou, X.; Shi, J.; Tang, Y.; Li, Y.; Li, S.; Gong, K. Aggregate Control Strategy for Thermostatically Controlled Loads with Demand Response. Energies 2019, 12, 683. [Google Scholar] [CrossRef]
  15. Yao, Y.; Zhang, P.; Chen, S. Aggregating Large-Scale Generalized Energy Storages to Participate in the Energy and Regulation Market. Energies 2019, 12, 1024. [Google Scholar] [CrossRef]
  16. Spínola, J.; Faria, P.; Vale, Z. Photovoltaic inverter scheduler with the support of storage unit to minimize electricity bill. Adv. Intell. Syst. Comput. 2017, 619, 63–71. [Google Scholar]
  17. Hussain, B.; Khan, A.; Javaid, N.; Hasan, Q.; Malik, S.A.; Ahmad, O.; Dar, A.; Kazmi, A. A Weighted-Sum PSO Algorithm for HEMS: A New Approach for the Design and Diversified Performance Analysis. Electronics 2019, 8, 180. [Google Scholar] [CrossRef]
  18. Shen, J.; Jiang, C.; Li, B. Controllable Load Management Approaches in Smart Grids. Energies 2015, 8, 11187–11202. [Google Scholar] [CrossRef] [Green Version]
  19. Kong, D.-Y.; Bao, Y.-Q.; Hong, Y.-Y.; Wang, B.-B.; Huang, H.-B.; Liu, L.; Jiang, H.-H. Distributed Control Strategy for Smart Home Appliances Considering the Discrete Response Characteristics of the On/Off Loads. Appl. Sci. 2019, 9, 457. [Google Scholar] [CrossRef]
  20. Jordehi, A.R. A review on constraint handling strategies in particle swarm optimisation. Neural Comput. Appl. 2015, 26, 1265–1275. [Google Scholar] [CrossRef]
  21. Faria, P.; Vale, Z.; Soares, J.; Ferreira, J. Demand Response Management in Power Systems Using Particle Swarm Optimization. IEEE Intell. Syst. 2013, 28, 43–51. [Google Scholar] [CrossRef] [Green Version]
  22. Shehzad Hassan, M.A.; Chen, M.; Lin, H.; Ahmed, M.H.; Khan, M.Z.; Chughtai, G.R. Optimization Modeling for Dynamic Price Based Demand Response in Microgrids. J. Clean. Prod. 2019, 222, 231–241. [Google Scholar] [CrossRef]
  23. Aghajani, G.R.; Shayanfar, H.A.; Shayeghi, H. Demand side management in a smart micro-grid in the presence of renewable generation and demand response. Energy 2017, 126, 622–637. [Google Scholar] [CrossRef]
  24. Hu, M.; Xiao, F. Price-responsive model-based optimal demand response control of inverter air conditioners using genetic algorithm. Appl. Energy 2018, 219, 151–164. [Google Scholar] [CrossRef]
  25. Qian, L.P.; Wu, Y.; Zhang, Y.J.A.; Huang, J. Demand response management via real-time electricity price control in smart grids. Smart Grid Netw. Data Manag. Bus. Model. 2017, 169–192. [Google Scholar]
  26. Lezama, F.; Sucar, L.E.; de Cote, E.M.; Soares, J.; Vale, Z. Differential evolution strategies for large-scale energy resource management in smart grids. In Proceedings of the Genetic and Evolutionary Computation Conference Companion on GECCO ’17, Berlin, Germany, 15–19 July 2017; ACM Press: New York, New York, USA, 2017; pp. 1279–1286. [Google Scholar]
  27. Eberhart, R.; Kennedy, J. A new optimizer using particle swarm theory. In Proceedings of the Sixth International Symposium on Micro Machine and Human Science (MHS’95), Nagoya, Japan, 4–6 October 1995; pp. 39–43. [Google Scholar]
  28. Faia, R.; Pinto, T.; Vale, Z.; Corchado, J.M. Strategic Particle Swarm Inertia Selection for the Electricity Markets Participation Portfolio Optimization Problem. Appl. Artif. Intell. 2018, 32, 1–23. [Google Scholar] [CrossRef]
  29. ERSE Tarifas e Precos Para a Energia Eletrica e Outros Servicos em 2019. Available online: ERSE 13-2018 (Tarifas e Preços EE 2019).pdf (accessed on 6 February 2019).
  30. Jozi, A.; Pinto, T.; Praca, I.; Vale, Z. Day-ahead forecasting approach for energy consumption of an office building using support vector machines. In Proceedings of the 2018 IEEE Symposium Series on Computational Intelligence (SSCI), Bangalore, India, 18–21 November 2018; pp. 1620–1625. [Google Scholar]
  31. Jozi, A.; Pinto, T.; Praça, I.; Vale, Z. Decision Support Application for Energy Consumption Forecasting. Appl. Sci. 2019, 9, 699. [Google Scholar] [CrossRef]
Figure 1. Implementation scheme of the proposed work.
Figure 1. Implementation scheme of the proposed work.
Energies 12 01645 g001
Figure 2. The control scheme for the demand response (DR) cut with one load.
Figure 2. The control scheme for the demand response (DR) cut with one load.
Energies 12 01645 g002
Figure 3. Disaggregated consumption by appliance and photovoltaic (PV) generation.
Figure 3. Disaggregated consumption by appliance and photovoltaic (PV) generation.
Energies 12 01645 g003
Figure 4. DR result regarding initial profile.
Figure 4. DR result regarding initial profile.
Energies 12 01645 g004
Figure 5. Load consumptions, battery actions, and final load scheduling.
Figure 5. Load consumptions, battery actions, and final load scheduling.
Energies 12 01645 g005
Table 1. Prices of the different periods and contracted power.
Table 1. Prices of the different periods and contracted power.
ParameterEnergy (€/kWh)Contracted Power (€/Day)
Buy from grid0.27380.15720.10380.5258
Periods10.30 h–13 h
19.30 h–21 h
08 h–10.30 h
13 h–19.30 h, 21 h–22 h
22 h–02 h
02 h–08 h
Sell to grid0.1659 *
DR weight00.20.4
* is used for all periods.
Table 2. Problem input variables.
Table 2. Problem input variables.
Maximum power injected to grid P t g r i d   m i n −5.1kW
Maximum power required from grid P t g r i d   m a x 1000kW
Maximum power accumulated in battery E b , t s t o r   m a x 12kW
Maximum energy of battery discharge P b , t d c h   m a x −6/4kWh
Maximum energy of battery charge P b , t c h   m a x 6/4kWh
Total Periods T 96
Total of controllable loads L 3
Total of batteries B 1
Total of PV units P 2
Adjust parameter Δ t 4 *
* The factor of 4 comes from the fact that there are four 15-min periods in an hour.
Table 3. Particle swarm optimization (PSO) parameters used.
Table 3. Particle swarm optimization (PSO) parameters used.
Population size j m a x 500
Maximum numbers of iterations i m a x 500
Maximum inertia weight w m a x 0.4
Minimum inertia weight w m i n 0.9
Maximum cognitive weight c 1 m a x 1.5
Minimum cognitive weight c 1 m i n 0.5
Maximum global weight c 2 m a x 1.5
Minimum global weight c 2 m i n 0.5
Number of evaluations250,000
Number of trials 30
Table 4. Results for Equation (2) (€/day).
Table 4. Results for Equation (2) (€/day).
Resources Combination ScenariosCPLEXPSO
Values optimizedPV + Bat + DR3.18743.27713.33810.0469
PV + Bat7.86527.94548.05950.1169
Nonoptimized valuesPV + Bat9.3298
Without resources16.8570
Table 5. Summary of results.
Table 5. Summary of results.
ScenarioMethodEquation (1)Equation (2)Equation (3)Daily Costs (€)Daily Revenues (€)Monthly Costs (€)
PV + Bat + DRCPLEX3.18743.187406.93803.750595.6233
PV + Bat + DRPSO *3.27713.277106.05652.779498.3140
PV + BatPSO *7.99227.992208.51360.5683239.7661
PV + BatNonoptimized9.32989.329809.32980279.8928
* represent the values of trial with the minimum fitness value.

Share and Cite

MDPI and ACS Style

Faia, R.; Faria, P.; Vale, Z.; Spinola, J. Demand Response Optimization Using Particle Swarm Algorithm Considering Optimum Battery Energy Storage Schedule in a Residential House. Energies 2019, 12, 1645.

AMA Style

Faia R, Faria P, Vale Z, Spinola J. Demand Response Optimization Using Particle Swarm Algorithm Considering Optimum Battery Energy Storage Schedule in a Residential House. Energies. 2019; 12(9):1645.

Chicago/Turabian Style

Faia, Ricardo, Pedro Faria, Zita Vale, and João Spinola. 2019. "Demand Response Optimization Using Particle Swarm Algorithm Considering Optimum Battery Energy Storage Schedule in a Residential House" Energies 12, no. 9: 1645.

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop