An Evaluation of a Metaheuristic Artificial Immune System for Household Energy Optimization

. Devices in a smart home should be connected in an optimal way; this helps save energy and money. Among numerous optimization models that can be found in the literature, we would like to highlight arti ﬁ cial immune systems, which use special bioinspired algorithms to solve optimization problems e ﬀ ectively. The aim of this work is to present the application of an arti ﬁ cial immune system in the context of di ﬀ erent energy optimization problems. Likewise, a case study is performed in which an arti ﬁ cial immune system is incorporated in order to solve an energy management problem in a domestic environment. A thorough analysis of the di ﬀ erent strategies is carried out to demonstrate the ability of an arti ﬁ cial immune system to ﬁ nd a successful optima which satis ﬁ es the problem constraints.


Introduction
A Home Energy Management System (HEMS) is a key element in a domestic environment that improves household economy through automated technologies.
In the recent years, different domestic buildings equipped with communication channels (smart houses) have actively participated in electrical networks [1] as building blocks in smart grids (SGs).Therefore, they play an important role in optimizing the scheduling of electric power [1,2].
There are a number of strategies that employ different techniques to optimize the scheduling of energy use in the home.Among many other strategies, statistical models are one example of them.We can see how they are leveraged in the work of [3], which models controllable loads using a Markovian approach.These loads depend on weather conditions.In [4], a demand-response program is automatically applied from classical methods to control the devices connected to the network under the uncertainty of the outside temperature and the price of electricity.In [5], three problems related to HEMS have been solved by applying an observable Markovian decision process.This work made it possible to reduce domestic energy costs in the electricity price market.
Classical approaches had some limitations [6]; thus, new paradigms have been applied to solve HEMS.One successfully developed paradigm is that which uses bioinspired algorithms to solve optimization problems.These algorithms try to mimic the behavior of some biological entities to find solutions which, applying classical computation, would be too costly or even implausible in terms of time and resources.Some widely used and noteworthy algorithms are artificial neural networks (ANN), genetic algorithms (GA), or swarm intelligence [7].Some bioinspired algorithms work in different contexts, and they render good results.One of these algorithms is the artificial immune system (AIS) which follows the principles of the vertebrae immune system to find solutions in an optimization problem.The AIS algorithm can be designed in a variety of ways.From the different variants, in this work, it is decided to use Opt-aiNet [8], which has been used successfully for the optimization of functions in different contexts [8].Opt-aiNet allows finding several solutions in parallel.By using operations such as mutation, cloning, and suppression, each solution corresponds to different optima (maxima or minima) points in the optimization function.
In the area of intelligent network optimization, several works that follow the bioinspired paradigm have been proposed.These include [9], who propose an energetic services modeling method based on the particle swarm optimization (PSO) algorithm.Soares et al. [10] propose a multiobjective genetic approach for scheduling domestic charge in an energy management system.Yuce et al. [11] present a neural network with a genetic algorithm (ANN-GA) to optimize energy management in the domestic sector.However, to the authors' knowledge, AIS has only been implicated in some preliminary achievements in power management, such as solving power supply problems, or electrical reconfigurations.For example, in [12], an AIS is used to control thermal units in residential buildings, and in [13], the authors optimize a wind energy-generating system also with an AIS.
In this paper, an in-depth review of the AIS concept and its application to different electrical problems is made.From the results of this review, a case study on a problem of home energy management optimization is described and solved using this algorithm.We aim to demonstrate that AIS can be successfully applied to electrical management problems in domestic settings.Part of our objective has been to adapt the Opt-aiNet algorithm to include complex constraints on the optimization problem and to work efficiently with a large number of variables.
This paper presents a simple electric context with different devices, namely, a photovoltaic panel (PV), a battery system, a space heater or heater, a water heater, and must-run services.All of them are connected in a smart home, within an electrical system.It is aimed at optimizing the scheduling for the next 24 hours so that the electrical benefit is maximized between the energy that is sold and the energy that is bought.
Two strategies are designed in our case study to represent two different electrical situations.In strategy 1, the HEMS manages the electric power with the electricity grid without considering any internal restriction.In other words, we do not consider any variable related to the maintenance of the domestic electric charge through the electrical energy produced by the PV system.Therefore, this strategy only seeks to optimize energy benefits.However, strategy 2 is aimed at supplying the electricity demand autonomously whenever possible.Therefore, the surplus generated by the PV is stored in the battery.HEMS will sell electricity to the grid when the battery is fully charged.Also, the battery is discharged when the electrical demand is greater than the power generated by the PV.If the battery cannot supply all the electrical charge, then the HEMS must buy electricity from the power grid.Based on these two strategies, three different experiments were developed.Firstly, a comparison of AIS with two different bioinspired algorithms is made, namely, the classical genetic algorithm (GA) and the particle swarm optimization (PSO).Secondly, both strategies are compared to analyze the influence of the battery in the home network.Finally, a deep analysis is carried out with different situations of the battery charge in the home network.The results obtained in all situations are expected to validate the AIS as an appropriate algorithm for the optimization of HEMS.
This document is structured as follows.Section 2 provides an overview of the design of AIS and a review about its involvement in electrical problems.Section 3 describes the technical details of the addressed electrical problem.Section 4 presents the configuration of AIS and its application to the electrical problem.In Section 5, the results obtained in the three case studies are outlined and discussed.Finally, Section 6 presents the conclusions of our research and future work.

Artificial Immune Systems
The organisms of many species have developed immune systems to protect them from external agents.Above all, vertebrate immune systems consist of different molecules, cells, and organs that are distributed throughout the body and are not controlled by any central entity.From an immunological point of view, any element present in the immune system is called an antigen.If this antigen belongs to the internal organism to protect the body, it is called self-antigen or antibody.Otherwise, the antigens from the external environment are called non-self-antigens and can provoke different diseases.Therefore, immune systems are aimed at distinguishing between self-antigens and non-selfantigens through a pattern recognition process, attacking only those that are harmful for the body [14].
Drawing on the concept of the immune system, [15] developed the CLONALG algorithm, a clonal selection procedure that allows mutating some antibodies according to their affinity to an external antigen; therefore, in order to perform pattern recognition, it generates copies of the antibodies according to their affinity with the antigen.The copies are mutated following a rate δ inversely proportional to their affinity with the antigen (1).
where β is a constant obtained empirically to normalize the effect of the fitness value f i of each cell.These new individuals are added to the general population and reevaluated to be reproduced and mutated again.
In order to give a new solution for the optimization of functions, [8] developed Opt-aiNet, an artificial immune system (AIS) based on the CLONALG behavior.The information is encoded as antigens which should be recognized by the antibodies of our immune system.Then, the fitness value of an antigen is defined as the affinity between the antigen and the antibody and can be compared with a distance 2 Complexity metric.Henceforth, small distances between an antigen and an antibody represent high affinity, whereas longer distances represent lower affinity.The Opt-aiNet algorithm follows the general description of an artificial immune system.Firstly, antibodies, which represent the different data to optimize, are randomly generated.Then, they are presented to the antigens, which encode the objective function, in order to calculate the affinity between them when the data are applied to the function.If one antibody obtains a good rating in the objective function, that means it has high affinity and therefore is selected.These chosen antibodies are reproduced and mutated based on their fitness value according to the CLONALG algorithm and the β parameter.In order to preserve diversity, antibodies whose affinity is lower than a given threshold t s are removed from the population.
Artificial immune systems, in particular Opt-aiNet, are able to find several optima of the objective function in parallel.This means that AIS can find a set of good candidates for the solution of optimization problems that are different from one another.Additionally, AIS can preserve those individuals that are good enough to be reproduced and mutated in consecutive iterations.

AIS Applications in Energy Contexts
. The concept of a next-generation power system such as smart grid, efficient energy management, and better power system planning cannot be achieved without electrical load forecasting [16].Consequently, multiple time horizons which are associated with the regulation, dispatching, scheduling, and unit commitment of the power grid are analyzed and solved using different methods.Artificial intelligence (AI) is widely applied to a variety of applications, as it can handle the complexity derived from such electrical problems.In particular, bioinspired algorithms, such as artificial neural networks or swarm intelligence, are especially effective in solving this kind of problems.In this section, a brief but comprehensive literature review of a special bioinspired algorithm, the artificial immune systems, is provided.AIS was applied in different contexts with positive results: when solving combinatorial problems [17,18], to detect intrusions in wireless sensor networks [19], or even to generate chord progressions [20].The major goal of this section is to review, identify, evaluate, and analyze the performance of AIS in power systems and model research.
Regarding the electrical context, there are plenty of proposals focusing on diverse fields.One of them is related to the control of variables and configuration of an electrical system.de Mello Honorio et al. [21] model an optimal power flow (OPF), which is a nonlinear, nonconvex, and large-scale problem with both continuous and discrete control variables, using a modified artificial immune system (AIS).The AIS makes use of hypermutation, which is responsible for local search, and receptor edition, which explores different areas in the solution space.The proposed AIS is combined with a gradient vector to improve the final results.This combination is also aimed at collecting valuable information during the hypermutation process, decreasing the number of generations and clones, and, consequently, speeding up the convergence process while reducing the computational time.Belkacemi and Feliachi [22] use a multiagent system (MAS) which follows the human immune system behavior to propose a new technique for power system reconfiguration and restoration, applied to a model of Southern California Edison's Circuit of the Future.Each element of the MAS represents a natural immunological element that interacts with the other elements to heal the body.Similarly, the MAS is able to detect and isolate faults and restore power to the affected loads taking into consideration line capacity, voltage profile, and power losses [22].de Oliveira et al. [23] present a methodology for the reconfiguration of radial electrical distribution systems to minimize energy losses making use of the bioinspired metaheuristic artificial immune system.The AISs have to plan the system operation considering both radiality and connectivity constraints and different load levels.Consequently, the AIS algorithm is adapted to accommodate the features of the problem better and to improve the search process.The algorithm developed is tested in well-known distribution systems, with very successful results.Souza et al. [24] solve the reconfiguration problem of electrical distribution systems (EDSs) with variable demand, using the artificial immune algorithm.As the reconfiguration problem with variable demand is a complex problem of a combinatorial nature, Copt-aiNet (artificial immune network for combinatorial optimization), which is a combinatorial version of the algorithm Opt-aiNet, is applied to identify the best radial topology for an EDS in order to minimize the cost of energy losses in a given operation period.A specialized sweep load flow for radial systems was used to evaluate the feasibility of the topology with respect to the operational constraints of the EDS and to calculate the active power losses for each demand level.The obtained results were compared with those in the literature in order to validate and prove the efficiency of the proposed algorithm.Souza et al. [25] also aim to solve the reconfiguration problem of EDS by comparing the results of the Copt-aiNet (artificial immune network for combinatorial optimization) and the Opt-aiNet (artificial immune network for optimization) algorithms.A specialized forward/backward radial power flow was used to evaluate each of the proposed solutions in order to determine its power losses and its feasibility regarding the operational constraints of the EDS.To validate the use of an AIS, the final results were compared with other solutions obtained with other algorithms in the literature.
Other important field of application is the forecasting of electrical variables (loads and power generation or consumption).Abdul Hamid and Abdul Rahman [26] propose an artificial neural net (ANN) trained following the behavior of an artificial immune system (AIS) to generate a short-term load forecasting model.Two sets of electrical energy demand data were used to test the capability of the proposed algorithm.The results presented in the manuscript show that the proposed AIS learning algorithm is capable of providing a forecast comparable to that of an artificial neural network with an integrated back propagation (BP) algorithm.Consequently, the AIS is an alternative learning algorithm for an artificial neural network.The work proposed by [27] is one 3 Complexity of the first studies using an integrated AIS simulation for improved forecasting of electricity consumption with random variations.They develop a new system with different algorithms, namely, AIS, genetic algorithm (GA), and particle swarm optimization (PSO), to simulate annual electricity consumptions in selected countries.The mean absolute percentage error (MAPE) is applied to evaluate the results and select the best forecasting model.A case study with data of the annual electricity consumptions for 16 countries from 1980 to 2006 is analyzed.For the selected countries, the AIS method with the clonal selection algorithm (CLONALG) shows satisfactory results when applied with simulated data and has been selected as the preferred method.Hernandez et al. [28] model a hybrid artificial immune system (AIS) combining the back propagation method with the artificial immune system, to achieve higher accuracy, lesser input load data requirement, and faster convergence.The hybrid approach is implemented, and its results are compared with a GA and a PSO.This analysis reveals that AIS solves the problem in a more efficient way than do GA and PSO.
Dudek [29] proposes a short-term load forecast model based on an AIS to predict the hourly load demand of a week.In this proposed technique, each antigen of AIS, which contains the time series load sequences (some part is a forecast sequence), is compared with historical load patterns.MAPE is also used to evaluate the performance of the proposed forecast model.The system achieves a minimum MAPE of 1.77%, which means the AIS obtains very successful results.AISs are also applied for economic optimization in an electrical environment.Dynamic economic dispatch determines the optimal scheduling of online generator outputs with predicted load demands over a certain period of time taking into consideration the ramp rate limits of the generators [30].Basu [31] presents an artificial immune system algorithm that solves a heat and power economic optimization problem.The AIS is adapted to this problem, adding new operations such as hypermutation and tournament, and is then used in a preliminary test system.
Basu [30] implements adaptive cloning, hypermutation, aging operation, and tournament selection.In order to validate the new AIS, numerical results of a ten-unit system with fuel cost function have been developed.The results obtained from the proposed algorithm are compared with those obtained from particle swarm optimization and evolutionary programming.From numerical results, it is shown that the proposed AIS provides a more efficient solution than do particle swarm optimization and evolutionary programming in terms of minimum cost and computation time.Aragón et al. [32] present an AIS-inspired algorithm, called IA EDP, which tries to solve an economic dispatch problem.It makes use of two versions of a redistribution power operator which tries to keep the solutions that it finds.The proposal is applied to eight problems taken from the literature.The results are compared with those derived from several other approaches to determine the advantages of the IA EDP against classical evolutionary computing.
This brief background leads us to the conclusion that AIS can be applied to a variety of electrical contexts with very successful results.This fact encourages us to work with a specific AIS, called Opt-aiNet, also leveraged in different papers [24,25] and to adjust it specifically to our case study.The classical Opt-aiNet usually works with a low number of variables (each individual contains about 6 variables at most) and without constraints encoded as mathematical functions.In the present work, this algorithm is adjusted to admit up to 336 variables and 25 linear constraints (inequalities and equations).

Home Energy Management Problem
In the designed case study, we consider a home electrical system that has some household appliance connected to it (Figure 1).
The context can be thought as a domestic grid with a generation part and a consumption part, connected to the power grid.As shown in Figure 1, the generation system or the PV system includes the PV generator and the battery.The consumption parts are the electric loads which contain the following appliances: a space heater, a storage water heater, and must-run services.To balance the profit of energy services between the PV system and the loads, the scheduler is connected to the grid.The scheduler aims at maximizing the profit of energy services provided in a 4 Complexity domestic energy management system through (2) OF, which is the objective function to optimize.
OF is a linear combination of four electrical factors.λ sold , λ bought , VOLL j and V pv are constants that provide the prices per unit of energy load and are given by the market.The first term λ sold P sold t represents the income from the sale of energy produced by the PV panel to the electricity grid.The second factor is the total cost of electrical energy that is bought from the network, λ bought P bought t .The value of electrical energy is not served, meaning the lo is encoded in the third part,∑ j∈ ELs VOLL j L j t shed .Finally, the spillage costs of PV panels, V s pv S pv t , are represented in the last term of the equation.
We need to balance the loads between the energy generated (the PV system P pv t , the energy provided by the battery P b,out t , and the energy bought from the power grid P bought t ) and the energy consumed, meaning the electrical loads of the different services L j t − L j t shed (heater, storage water heater, and mustrung services) and the battery charge P b,in t (3).Additionally, the power flow limitation through the distribution line is stated in (4), where f max is a constant set to 6 according to [33].
The specific definitions for all domestic appliances are described in the following subsections.
3.1.PV System.The PV system can generate the power output P pv t of the grid, which can be modelled through Equation 5.
where S refers to the spillage costs of the PV system and P pv,p (t) is the potential power generation for the PV system.P pv,p (t) is limited to maximum and minimum bands due to the prediction of the PV power generation, following (6).σ down pv and σ pv up are down and up prediction variances for the PV system, respectively, and are calculated following [34].P pred pv t is the predicted power generated by the PV system.This amount is positive or equal to zero and is limited to the actual power generation of the PV, P pv,p (t), as represented in (7).In other words, the PV system can potentially generate this power but HEMS cannot operate it because of economic and technical constraints.10represents the performance of the space heater based on the relationship between the indoor temperature and its electrical load.In (10), θ 0 is the initial indoor temperature in time t = 1, which is assumed to be equal to the desired temperature.R is the thermal resistance, and C is the thermal capacity of Equation 11 represents the limitation of the indoor temperature.In our case study, this limitation is set to 1 °C more or less than the desired temperature.Finally, due to physical factors, the loads and the load sheddings are both limited by their maximum and minimum constraints (12) and (13).
3.2.2.Storage Water Heater.The storage water heater is responsible for preserving the heat in the water tanks.The maximum and minimum limitations of the storage water heater's load are stated in (14).The maximum energy consumption of the storage water heater should be less than the maximum capacity of the tank U swh , according to (15).Finally, the maximum of the load shedding of the storage water heater is always less than the energy consumption of the appliance (16).
3.2.3.Must-Run Services.Must-run services consist of loads that should be provided quickly, and therefore, it is not easy to predict them, for example, lighting and entertainment.For the purposes of this paper, it is assumed that there is no uncertainty in predicting the electrical loads of must-run services (17).As in the storage water heater, the maximum of the load shedding L shed mrs t must always be less than the energy consumed L mrs (t) (18).
Also, the load shedding constraint is stated in (18).
o ≤ L shed mrs t ≤ L mrs t 18 3.3.Battery System.The battery system can be used to apply the charge and discharge strategies in the HEMS.A flowchart (Figure 2) is designed to operate with the battery in the domestic environment.The system aims at providing the required electrical demand, maximizing its benefits.When there is a surplus P b,in (t) of the energy generated (i.e., the PV panel generates more energy P pv (t) than the total load TL(t) demands), it is stored in the battery (C b (t)).If the battery is fully charged C b t > C max b , then it is sold to the grid P sold (t).On the contrary, the system makes use of the energy stored in the battery P b,out (t) when the electrical demand is higher than the power generation of the PV panel.Additionally, if the battery cannot provide the energy needed (i.e., is unavailable or completely discharged, C b t > C min b ), the system will buy the electricity P bought (t) from the power grid.

Experimental Setting
To assess the performance of the proposed HEMS, some parameters have been set to optimize the system.The maximum power produced by the PV system is 2 kW.The battery can store between C b min 48 and C b max 2.4 kWh.The maximum heating power of the space heater (SH) L max sh t equals 2 kW to maintain the temperature of the house within ±1 of the desired temperature (θ des 23 °C).The thermal resistance, R, of the building shell is equal to 18 °C/kW, and the capacity C equals 0.525 kWh/ °C.The energy capacity of the storage water heater (U swh ) is 10.46 kWh (180 L) which has 2 kW as maximum of heating elements L max swh .Table 1 displays the predicted data that has been used in [33].Table 2 gives the price data of the system.VOLL and spillage costs of PV power generation are shown in Table 3.
These data are used in our HEMS to optimize the function (2).The objective function is integrated into Opt-aiNet to get an optimized schedule of 24 hours in a domestic environment.Following the Opt-aiNet procedure, the initial population randomly generated, where each individual is a set of electrical values for 24 hours, must comply with the constraints modelled in the electrical management problem.For this purpose, each datum of the individual is considered as an electrical parameter to optimize for 24 hours.Initially, the parameters which only depend on some fixed boundaries ( 6), ( 7), ( 12), (14), and ( 17) are generated.Then, these parameters are used as new boundaries for those electrical parameters that depend on them (the rest of the equations are given in the model of Section 3).This methodology is recursively applied until all the parameters needed for each individual are generated.Finally, to obtain the parameters related to the battery load, the parameters previously calculated and the flowchart of Figure 2 are applied to generate the new ones.
With the individuals generated, Opt-aiNet work follows these steps: (1) Initiate N population following the method above, to respect the linear constraints and the flowchart if it is the case.
(2) Evaluate each individual according to the optimization function given in ( 2).
(3) Create N c clones of each individual.The elements of each clone should be slightly changed according to the mutation equation ( 1).
(4) For each cell or antibody, select the best clone with the highest objective value.
(5) If the mean objective of the last iteration and the present one are below a limit, then similar individuals are suppressed according to the similarity threshold t s that measures distances between two antibodies.
(6) If some individuals are suppressed, then it is needed to add a new random population.These new solutions are generated following the method given above to respect the constraints and the flowchart if that is the case.
(7) This work flow is repeated until the convergence criterion (maximum number of iterations gen).The result is one or more individuals with an optimum objective value.
As we can see, AIS contains five parameters, namely, number of individuals N, number of clones N c , similarity threshold t s , maximum number of generations gen, and the mutation parameter β.Depending on the problem, they can take several values and are essential for a correct operation.AIS needs some parameters to be set beforehand in order to optimize a problem correctly.These parameters are related to the cloning and mutation process, the suppression algorithm, and the convergence criterion.For each iteration, a number of clones N c is generated per cell.This number N c is set empirically and can influence the final results.Generally, if N c is set with a very low value, the convergence criterion can be delayed, as we are not able to find enough diversity to select better individuals for each cell.Otherwise, if too many clones are generated, the time upon convergence might be longer than expected.
We empirically set the AIS parameters according to Table 4, which gave the optimal performance in terms of fitness and time.
The next section will describe the simulations and results with Opt-aiNet configured for the presented HEMS.6 Complexity

Simulation Results
The evaluation is twofold.Firstly, it is expected that Opt-aiNet obtains positive results in solving optimization problems in the created setting and comparing them with other classical bioinspired approaches.Consequently, a comparative analysis was carried out between a classical genetic algorithm (GA) and a particle swarm optimization (PSO).Additionally, we analyzed the impact of the flowchart (Figure 2) on our system, when the battery was involved.Therefore, two strategies that represent two electrical situations are designed.In the first strategy (strategy 1), the domestic environment does not consider any variable related to the maintenance of the domestic electric charge through the electrical energy produced by the PV system.This strategy only aims at optimizing its energy benefits.In the second strategy (strategy 2), the home environment aims at supplying the electricity demand autonomously.Therefore, the surplus generated by the PV is stored in the battery.In this strategy, the electricity could be sold to the grid if the battery is completely charged.On the contrary, if the battery cannot supply all the electrical charge, then the HEMS must buy electricity from the power grid.P pv (t) = TL (t) P b,in (t) = P pv (t)−TL(t) P sold (t) = P pv (t)−TL(t)−P b,out (t) P b,out (t) = TL(t) -P pv (t) (iii) Experiment III: analysis of strategy 2 when the battery is disconnected or connected Experiment I makes a comparison between GA, PSO, and AIS.Experiment II optimizes the parameters related to the PV system, the space heater, the water heater, and the must-run services; therefore, the parameters related to the battery charge are not considered (strategy I).The results obtained from the optimization process are compared with the results that are retrieved when the parameters of the battery are included in the system, although all are set to 0. That means the battery is disconnected from the home environment but the AIS follows the flowchart to optimize the system.
Finally, experiment III performed two different analyses: when the battery was disconnected and when the battery was connected, to study the impact of this device on the system.5.1.Comparison between GA, PSO, and AIS.In this section, we aim to compare the results obtained with three different bioinspired algorithms: genetic algorithm, particle swarm optimization, and artificial immune system.The genetic algorithm (GA) is widely used in optimization problems with many configurations.In this paper, a classical approach of GA is applied so that the mutation and crossover as well as the number of generations are empirically set to 0.3, 0.8, and 2000, respectively.Additionally, the selection function chosen was the roulette algorithm.
The particle swarm optimization (PSO) was first introduced by Eberhart and Kennedy [35] and consists of a population-based optimization algorithm which is deemed to be a nature-inspired optimization methodology.PSO employs a set of particles which would move through the search space at every iteration and would calculate the fitness value at each point.After a termination condition is met, the best optimized value is selected by choosing the best value found in the history of particles.The success of PSO lies in its "velocity equation"; this equation decides on the next point in space that each particle would move to.The velocity equation can be shown as Here, V id,k+1 is the velocity of the dth dimension of the ith particle in the next iteration (k + 1st), w is the inertia of the particle, V id,k is the velocity of the dth dimension of the ith particle in the current iteration (kth iteration), c 1 is the cognitive acceleration constant, c 2 is the social acceleration constant, X pbestid,k is the position of the particle in the dth dimension at which the best solution was 8 Complexity found so far by the ith particle, X gbestd,k is the value of the dth dimension at which the best solution so far was found by the whole system, X id,k is the current position of the ith particle in the dth dimension, and c 1 and c 2 are random numbers.Using the velocity calculated, the next position to be evaluated is calculated as The above velocity equation works well when the system is under no constraints.However, when there are constraints, some of the particles might fall off the feasible region.In this case, the particles should not update their personal best when a particle is outside the feasible region.Neither should the global best be updated in case of a particle being outside the feasible boundary, having a better value than the current global best.In case a particle has not found a personal best that falls in the feasible region, the particle should rely only on global best to guide its movement.In this case, the calculation of velocity would change to However, equality constraint satisfaction is more difficult than the inequality constraint satisfaction.To solve this problem, a mending procedure is carried out at every iteration to make sure all particles satisfy the equality constraint.The mending procedure calculates the overshoot of each of the particle and adds a correction value to correct the error.The correction is equally added to each of the intervals of the particle.
In order to demonstrate the efficiency of the artificial immune system in the energy management optimization problem, we performed a comparative test with a version of constrained PSO adopted from [36] and an approach of the genetic algorithm.The goal was to predict the optimum values for each variable during 24 hours, following strategy 1 and strategy 2. The linear constraints proposed in the electrical model are applied, and subsequently, the objective function for the optimized variables is measured.
Table 5 shows the results obtained when the objective function and the energy are bought and consumed when AIS, GA, and PSO are applied with an optimal setting.
As Table 5 shows, AIS obtains slightly better results in the objective function for both strategies when both settings are optimal to solve this problem.That means AIS is a better configuration of the electrical parameters to optimize the problem stated.Likewise, AIS is able to find lower values for the amount of energy bought, which means the algorithm allows saving energy and money to the customer.The results of the AIS for the energy sold are lesser than in PSO and in GA.That could be explained because in PSO and in GA, the mean amounts of energy that are managed are greater than in AIS.However, PSO also obtained positive results (at least, better than with the classical approach of GA); therefore, we propose to make a deeper comparison with more complex problems to validate both algorithms and study the limitations of each one.

Analysis of the Energy Management Strategy.
In this section, the two strategies described below are deeply analyzed and compared.The first strategy looks for maximizing the domestic energy profit.However, the second strategy aims at maximizing energy profit and acting as an autonomous energy system.It is expected that strategy II obtains better results, as this strategy pursues the autonomous management of energy, saving more money than in strategy I.
Opt-aiNet worked with individuals or vector of 264 elements with equality and inequality constraints, as each individual contains all the variables for 24 hours.Each value corresponds to the different electric loads and powers described in Section 3 for the PV panel, the storage water heater, the space heater, and the must-run services.We run the algorithm with two different configurations, one with strategy 1, excluding all the constraints related to battery management, and one with strategy 2, including all the constraints related to battery management, but with the battery variables set to 0. Table 6 shows the results according to the fitness value of the objective function OF and the parameters of sold and bought energy.
As we can see, the value of the objective function in strategy 1 is higher than that of strategy 2. However, the transacted energy between home and power grid is lesser in strategy 1, which means that Strategy 2 allows for the autonomous management of energy at home.5.3.Impact of the Battery.In this analysis, strategy 2 is applied to study the influence of the battery in the domestic environment.In this case particularly, individuals in the AIS have 336 elements because the parameters corresponding to the battery charge and load are set as elements of optimization.Each individual is constructed following the linear constraints and the flowchart before being inserted into the population.Two different executions are made, firstly, with all the variables related to the battery management set to 0. In the second execution, the variables of the battery could change according to the corresponding equations and flowchart (Figure 2).The results obtained are shown in Table 7.
From the data in Table 7, we can see that the battery system can improve the value of the objective function.Table 7 also considers a situation in which the battery increases the amount of electrical energy sold from the smart home to the grid, and it decreases the amount of electrical energy that a home buys from the network.

Figure 1 :
Figure 1: Schematic image of domestic electrical system.

Table 4 :
Optima values set for N, N c , gen, t s , and β in both strategies.

Table 1 :
Predicted data of uncertain variables.

Table 2 :
Price data of the system.

Table 5 :
Results of the objective function and the energy bought and consumed when AIS and PSO are applied with an optimal setting.

Table 6 :
Impact of energy management strategies on the amount of sold/bought electrical energy to/from power grid and OF.

Table 7 :
Impact of battery system on the amount of sold/bought electrical energy to/from power grid and OF.