Energy Consumption Optimization and User Comfort Management in Residential Buildings Using a Bat Algorithm and Fuzzy Logic

: Energy management in residential buildings has grabbed the attention of many scientists for the last few years due to the fact that the residential sector consumes the highest amount of total energy produced by different energy resources. To manage the energy in residential buildings effectively, an efﬁcient energy control system is required, capable of decreasing the total energy consumption without compromising the user-preferred environment inside the building. In the literature, many approaches have been proposed to achieve the goals of minimizing the energy consumption and maximizing the user preferred comfort by keeping different parameters under consideration, but all these methods face some problems in resolving the issue properly. The bat algorithm is one of the most recently introduced optimization approaches that has drawn the attention of researchers to apply it for solving different types of optimization problems. In this paper, the bat algorithm is applied for energy optimization in residential buildings, which is one of the most focused optimization problems in recent years. Three environmental parameters, namely temperature, illumination and air quality are bat algorithm inputs and optimized values of these parameters are the outputs. The error difference between the environmental parameters and optimized parameters are inputs of the fuzzy controllers which give energy as output which in turn change the status of the concerned actuators. It is proven from the experimental results that the proposed approach has been effectively successful in managing the whole energy consumption management system.


Introduction
Energy is the most precious resource among all resources and the demand for energy is rapidly growing with the passage of time. There could be two possible ways to tackle the problem of growing energy demand: (1) production of additional energy and exploration of alternate resources to produce energy and (2) more efficient utilization of existing resources. The first approach is highly expensive, time consuming, and costly, and the second approach is inexpensive, more proficient and highly recommended as the efficient utilization of energy avoids the need to produce new energy. Technologies have been improved and several methods are proposed for energy consumption optimization. Energy efficiency has become one of the major concerns nowadays, impacting almost all human activities, from industrial and commercial to leisure and vacation [1,2].
In residential buildings, the energy consumption is increasing rapidly, hence efficient utilization of energy in the residential sector is an issue of high concern. Many researchers are trying to solve this problem and many attempts have been carried out for this purpose in the last decade. Three basic parameters, namely thermal comfort, air quality comfort and visual comfort should be taken into The paper is organized as follows: Section 2 presents the related work, and the proposed methodology is given in Section 3. Experimental results and discussion are presented in Section 4, the comparative analysis of the proposed algorithm with other counterpart is explained in Section 5, and in Section 6, our conclusions are presented.

Related Work
Nowadays energy management in the residential building sector has grabbed the attention of researchers and many are trying to solve it in an efficient way. Residential buildings must operate day-by-day and its facilities are associated with energy. In other words, as the facilities in a building increase, energy consumption also increases. Numerous methods have been developed to design an efficient energy conservation system for residential buildings. In [15] environmental control systems for museums, art galleries and other special buildings have been discussed in detail. Energy management in the building is an optimization problem and has multiple dimensions.
In the last decade, advancements have been reported in optimization methods for solving nonlinear optimization problems [3]. A direct search has been adopted, that may lead to accurate results [16]. In recent studies, researchers are trying to improve building environment. The central focus point for this improvement is to minimize user energy consumption and maximize user comfort, because people mostly spend their time in buildings, hence the user satisfaction determines the environmental conditions in the building. In order to achieve user satisfaction, an intelligent optimization technique for smart homes has been proposed for optimal energy management [4]. In [17], an improved optimization function has been used to maximize user comfort and minimize energy consumption in the building environment. To remove the noise from sensor readings, the Kalman filter algorithm has been used. The Kalman filter predicts the actual parameter values. The genetic algorithm and particle swarm optimization (PSO) have also been used for optimization. The results indicate that their proposed optimization function performs better as compared to PSO and GA alone.
The genetic algorithm (GA) has also been deployed to manage energy in buildings to address heating, air conditioning and controlling ventilation problems [18]. This approach has also been applied for controlling fuel cells, thermal storage and heat pumps [19]. In [7] the genetic algorithm has been deployed to solve multi-objective problems for optimal payoff characteristics optimization. The genetic algorithm was used for mixed integer and nonlinear programming problems in an energy plant in Beijing [20].
A method of inspection and forecasting to efficiently utilize the energy inspection and forecasting in smart buildings has been discussed in detail in [21]. In this paper, a method based on a feed forward neural network trained with GA has been proposed. The performance of this method was good, while the mean computation time for one forecasting behavior was 9.0572 s, the mean computation time for the same predicting behavior of the backward propagation (BP) network and RDF network were 0.0961 and 0.0494, respectively. In [22] a genetic-based programming technique has been suggested and the prediction accuracy of this proposed method was 80-83% on testing data in five different offices. The deployment of this method can be carried out to estimate the energy requirement in residential buildings. In [23] an optimized multi-layer perceptron (MLP) method has been proposed for short-term energy consumption in Korean residential buildings. In this approach, the authors developed 20 different models of MLP having different architecture to predict energy use. In [24] another method for energy prediction in residential buildings has been proposed. The proposed methodology is comprised of three stages, namely data retrieval, feature extraction, and prediction. In data retrieval, the daily basis energy consumption data is acquired from the database. In feature extraction phase, the first three statistical moments, namely mean, variance, and skewness have been calculated from the acquired data. In the last stage, prediction methods, namely MLP and random forest have been used to forecast the demand for energy in the residential building. The results show that the performance of multi-layer perceptron is better as compared to random forest algorithm.
In [25] a simulation optimization method has been proposed for efficient energy management of heating, ventilation and air conditioning (HVAC) systems. The complex interconnection of the whole HVAC system normally includes airside systems and waterside systems, the proposed optimum setting for diverse processes in response to the dynamic cooling loads and varying climate situations during a year. In [26] a GA that controls parameter optimization in parallel Hybrid Electric Vehicles (HEVs) has been used. The formulation of the optimization problem has been carried out for an electric assist control strategy (EACS) to reduce the consumption of fuel and emissions while maximizing vehicle performance. The optimization of different objective functions has been done in [27] and different algorithms are also proposed for electricity forecasting consumption based on genetic algorithm, simulated-based genetic algorithm, time series and design of experiment (DOE), analysis of variance (ANOVA) and Duncan multiple range test (DMRT). The experimental data used in this method were 131 months of real energy consumption data collected from 1994 to 2005. In [28] an evolutionary-based algorithm named robust evolutionary algorithm (REA) for tackling a heating, ventilation, and air conditioning (HVAC) simulation model has been proposed. In this paper a strategy has been developed to optimally control the inconstant air volume and air-conditioning system. The control method contains a primary control scheme of a static temperature point and two advanced methods for ensuring comfort and indoor air quality (IAQ). A method for building environment based on grid security is suggested in [29] which considers user comfort with favorable power consumption as a key factor.
In this study a methodology using a bat algorithm and fuzzy logic for optimizing user comfort index and energy savings for the building environment has been proposed. Both energy efficiency and user comfort levels have been addressed in this paper and the focus of this work is to simultaneously increase residential comfort level and decrease energy consumption by providing an optimal user comfort index and minimizing energy consumption in the building environment.

Proposed Methodology
In the proposed architecture, the parameters, namely temperature, illumination and the air quality from the environment as well as from the user are entered into the BA optimizer. The main aim of the BA optimizer is to reduce the gap between the user-set parameters and the actual environmental parameters. This gap is represented by the error differences between the user-set and environmental parameters and this error difference has a direct impact on power consumption, i.e., as the error difference decreases, the power consumption is expected to decrease and vice versa. After computing the error differences, the next stage is to calculate the comfort index. The overall user comfort inside the building is the combination of three comforts, namely thermal comfort, visual comfort and air comfort. These three comforts are calculated by taking into consideration the error differences computed by the BA optimizer. The comfort index has an inverse relationship with error difference. As previously stated, the error difference is correlated with power consumption. With a decrease in error difference, the comfort index increases, which as a result makes this problem a multi-objective optimization problem in which the power consumption is minimized and comfort index is maximized. After calculation of the comfort index, the next stage is to control the status of different actuators. The fuzzy controllers (the temperature fuzzy controller, illumination fuzzy controller and the air quality fuzzy controller) get the error difference between environmental perimeters and the parameters that have been optimized. The fuzzy controller's output is the desired power for controlling the actuator status, such as cooling/heating, lighting, and ventilation. The required power is be entered to the coordinator as input, afterward; the coordinator checks the power availability from power sources and provides the power to all actuators according to the fuzzy controller status. Fuzzy controllers take both the BA optimized values and environmental perimeters (temperature, illumination, and air quality). The fuzzy controllers' output values depend on the error difference between environmental perimeters (temperature, illumination and air quality) and the BA optimized (temperature, illumination and air quality) values. The basic purpose of BA optimization is the minimization of error differences between values of environmental parameters and actual parameters. Without applying the BA optimization procedure, the error differences are high, which eventually generates higher output values causing higher energy consumption. The optimization process decreases the error difference which ultimately decreases power consumption. The block diagram for proposed building energy management system is shown in Figure 1.

Optimization Using Bat Algorithm
The bat algorithm (BA), suggested by Yang in 2010, is a meta-heuristic algorithm based on the echolocation properties of bats. Echolocation helps bats in their flying and hunting behavior. This property makes bats able to move and helps them to distinguish different types of insects even in complete darkness. The following three generalized rules were used by Yang [30] when implementing the bat algorithm: (1) For the distance sensing all bats use echolocation and they have also the potential to distinguish the difference between background barriers and food/prey in some dreamlike way. (2) Bats fly in a random manner with velocity at position with a fixed frequency f varying wavelength ʎ and loudness to search for prey. They have the ability to regulate the wavelength of their emitted pulses automatically and adjust the rate of pulse emission r in the range [0, 1], depending on the proximity of their target.
(3) While the loudness can vary in numerous ways, we undertake that the loudness ranges from a huge to a smallest constant value .
The pseudo code of the bat algorithm is given in Figure 2.

Optimization Using Bat Algorithm
The bat algorithm (BA), suggested by Yang in 2010, is a meta-heuristic algorithm based on the echolocation properties of bats. Echolocation helps bats in their flying and hunting behavior. This property makes bats able to move and helps them to distinguish different types of insects even in complete darkness. The following three generalized rules were used by Yang [30] when implementing the bat algorithm: (1) For the distance sensing all bats use echolocation and they have also the potential to distinguish the difference between background barriers and food/prey in some dreamlike way. (2) Bats fly in a random manner with velocity v i at position x i with a fixed frequency f varying wavelength L and loudness A 0 to search for prey. They have the ability to regulate the wavelength of their emitted pulses automatically and adjust the rate of pulse emission r in the range [0, 1], depending on the proximity of their target. (3) While the loudness can vary in numerous ways, we undertake that the loudness ranges from a huge A 0 to a smallest constant value A min .
The pseudo code of the bat algorithm is given in Figure 2. The bat algorithm is advantaged over other optimization algorithms due to the reasons given below: i.
BA implementation is simple and required less programming efforts. ii. BA is flexible and has the ability to provide the solution for almost all optimization problems [31].
iii. The deployment of the BA algorithm has been done in numerous areas of optimization, such as classification, feature selection, scheduling, data mining, etc. [31].
The major steps of bat algorithm for the energy consumption optimization problem in the smart home are described in the following section: Step 1: (1) Number of parameters (D): This indicates the size of the parameters that need to be optimized.
Here in this study we have three parameters to be optimized which are temperature (T), illumination (L) and air quality (A). algorithm has been tried for the different number of generation to discover the ideal generation size to find the preeminent performance result. (6) Loudness (A0) and Pulse rate (r0) initialization: Both loudness and pulse rate are initially set to 0.5, where the pulse emission is represented loudness A0 is used to search for prey. The bat algorithm is advantaged over other optimization algorithms due to the reasons given below: i.
BA implementation is simple and required less programming efforts. ii.
BA is flexible and has the ability to provide the solution for almost all optimization problems [31]. iii.
The deployment of the BA algorithm has been done in numerous areas of optimization, such as classification, feature selection, scheduling, data mining, etc. [31].
The major steps of bat algorithm for the energy consumption optimization problem in the smart home are described in the following section: Step 1: (1) Number of parameters (D): This indicates the size of the parameters that need to be optimized.
Here in this study we have three parameters to be optimized which are temperature (T), illumination (L) and air quality (A). The algorithm has been tried for the different number of generation to discover the ideal generation size to find the preeminent performance result. (6) Loudness (A 0 ) and Pulse rate (r 0 ) initialization: Both loudness and pulse rate are initially set to 0.5, where the pulse emission is represented loudness A 0 is used to search for prey.
Step 2: new solution generations: (1) Adjusting the frequency: the frequency is adjusted by using the Equation (1): where β ∈ (0, 1) represents the uniform distribution. In implementation, the f min is set 0 and f max to 1, hence initially the frequency is assigned randomly by each bat with uniform distribution in [ f min , f max ]. (2) Updating the velocity: the velocity is updated by using the Equation (2): where v t i represents the new velocity of bat i at the time step t, and x * signifies the existing global top solution. The frequency f i of ith is used for adjusting the velocity v t i for movement of bats to x t i position. (3) Updating the locations/solutions: The location updating carried out by using Equation (3): where x t i is the new position of the bat, x t−1 i is the current position of the bat. The new solution is generated by updating the velocity, and adjusting the frequency.
Step 3: (Local search solution): (1) Best solution selection: the best solution is chosen among all current best solutions.
(2) Generation of the local solution around the best solution: The selection of the best solution is carried out around the best solution using Equation (4): where ε is an arbitrary lie between [1, −1] and A t represent the average loudness of entire bats in iteration t.
Step 4. Loudness and the pulse emission rate: As the bat tends closer to the target/prey the loudness and pulse rate emission r updated accordingly. Loudness A is decreased while pulse emission rate r is increased by using (5) and (6): Step 5. Optimal Solution. In the proposed approach we must maximize the value of comfort index formulated in Equation (7). The best fitness value is updated as global best.

Comfort Index
The mathematical formula for comfort index is given in Equation (7) [4,11]: where comfort is the total user comfort and it lies between [0, 1]. The user defined factors are α 1 , α 2 and α 3 that are used to solve any possible clash between three comfort features namely, temperature, illumination, and air quality. The value of these factors falls in the range between [0, 1], and the sum of these values must be always equal to 1(α 1 + α 2 + α 3 = 1). In Equation (7), e T , e L and e A represent the error difference between the optimized temperature and the environmental temperature, error difference between the optimized illumination and the environmental illumination and the error difference between optimized air quality and environmental air quality respectively. In the proposed work the user comfort is based on three parameters namely thermal comfort, air quality, and illumination. T s , L s and A s represent the user set temperature, user set illumination and user set air quality, respectively. We compute user comfort by integrating these three comfort parameters using Equation (7). The above formula for user comfort is based on our previous work [1,2,17]. Further user comfort formula can be generalized for any number of parameters as given in Equation (8) below: where α i represents user preferences for P i parameters. A user has to specify his/her preference level for each parameter in terms of a min and max acceptable range. Our optimization formula tries to achieve optimal values for each parameter within the user desired range while minimizing overall energy consumption. In this paper, experiments are performed by setting the alpha values as: The α 1 , α 2 , and α 3 relationship indicate the relative importance of each parameter temperature, air quality and illumination. For instance, assigning α 1 = α 2 = α 3 = 0.333 would mean that for users, all indoor parameters are of same importance. However, if the user specifies some different combination e.g., α 1 = 0.6, α 2 = 0.2, α 3 = 0.2 then this means that indoor temperature settings are three times more important for the user as compared to air quality and illumination. We believe that this approach makes the model flexible and gives freedom to the user to specify any desired combination. The structure diagram for proposed building energy management model is illustrated in Figure 3. Equation (7). The above formula for user comfort is based on our previous work [1,2,17]. Further user comfort formula can be generalized for any number of parameters as given in Equation (8) below: where represents user preferences for parameters. A user has to specify his/her preference level for each parameter in terms of a min and max acceptable range. Our optimization formula tries to achieve optimal values for each parameter within the user desired range while minimizing overall energy consumption. In this paper, experiments are performed by setting the alpha values as: = 0.3, = 0.3, and = 0.4. The , , and relationship indicate the relative importance of each parameter temperature, air quality and illumination. For instance, assigning = = = 0.333 would mean that for users, all indoor parameters are of same importance. However, if the user specifies some different combination e.g., = 0.6, = 0.2, = 0.2 then this means that indoor temperature settings are three times more important for the user as compared to air quality and illumination. We believe that this approach makes the model flexible and gives freedom to the user to specify any desired combination. The structure diagram for proposed building energy management model is illustrated in Figure 3.  This formula has the ability to adopt new parameters if increased. The decision of consideration of parameters is important keeping in view the flexibility of system we have left the selection of parameters up to the user. As this work is based on our previous work hence once again three parameters including temperature, illumination, and air quality have been considered. In future studies, we will increase the number of parameters in order to test the variations and success of the bat algorithm. The next step is the selection of upper and lower bounds to select the desired user comfort range. The selection of bounds can be manually adjusted; in this study, we have selected upper bound for temperature (T max ) as 78, for illumination (L max ) 880 and for air quality (A max ) 880. The selection of lower bound is also as important as the selection of upper bound because a certain range can ease the bat algorithm for the exact optimization of parameters. The lower bound for temperature (T min ) has been selected as 68, for illumination (L min ) as 720 and for the air quality (A min ) as 700. These ranges can be selected as per user choice. The population size has been selected as 40 for this study. The readings have been carried out with 100 iterations to find the optimal values.

Fuzzy Controllers
First, the term fuzzy logic introduced in 1965 by Zadeh [32], it is a procedure of several valued logic. Fuzzy logic is a form of many-valued logic in which the truth values of variables may be any real number between 0 and 1. In Boolean logic, the variable truth values may be either 0 or 1, these values are called crisp values. Fuzzy logic is used to tackle the notion of incomplete truth, where the truth value lies between totally true and totally false [33]. The complete structure of fuzzy logic is shown in Figure 4, and consists of fuzzifier, knowledge base, inference engine, and defuzzifier modules. Inputs to the fuzzifier are numerical values and it produces the fuzzy values by applying Membership Functions (MFs). The evaluation of all rules in the knowledge base is carried out, and then the aggregate of each MF value is calculated using a maximum operation. The defuzzification method has been carried out by conversion of fuzzy values to non-fuzzy values using the centroid method. In the proposed methodology we have used three fuzzy controllers, namely temperature fuzzy controller, illumination fuzzy controller and air quality fuzzy controller. The input to the temperature fuzzy controller is the error difference between actual temperature and optimized temperature, illumination fuzzy controller inputs is the error difference between actual illumination and optimized illumination and similarly input to the air quality fuzzy controller is the error difference between actual air quality and optimized air quality. The output of temperature fuzzy controller, illumination fuzzy controller, and air quality fuzzy controller is the required power for cooling/heating (temperature fuzzy controller), lighting (illumination fuzzy controller), and CO 2 concentration. parameters up to the user. As this work is based on our previous work hence once again three parameters including temperature, illumination, and air quality have been considered. In future studies, we will increase the number of parameters in order to test the variations and success of the bat algorithm. The next step is the selection of upper and lower bounds to select the desired user comfort range. The selection of bounds can be manually adjusted; in this study, we have selected upper bound for temperature (Tmax) as 78, for illumination (Lmax) 880 and for air quality (Amax) 880. The selection of lower bound is also as important as the selection of upper bound because a certain range can ease the bat algorithm for the exact optimization of parameters. The lower bound for temperature (Tmin) has been selected as 68, for illumination (Lmin) as 720 and for the air quality ( ) as 700. These ranges can be selected as per user choice. The population size has been selected as 40 for this study. The readings have been carried out with 100 iterations to find the optimal values.

Fuzzy Controllers
First, the term fuzzy logic introduced in 1965 by Zadeh [32], it is a procedure of several valued logic. Fuzzy logic is a form of many-valued logic in which the truth values of variables may be any real number between 0 and 1. In Boolean logic, the variable truth values may be either 0 or 1, these values are called crisp values. Fuzzy logic is used to tackle the notion of incomplete truth, where the truth value lies between totally true and totally false [33]. The complete structure of fuzzy logic is shown in Figure 4, and consists of fuzzifier, knowledge base, inference engine, and defuzzifier modules. Inputs to the fuzzifier are numerical values and it produces the fuzzy values by applying Membership Functions (MFs). The evaluation of all rules in the knowledge base is carried out, and then the aggregate of each MF value is calculated using a maximum operation. The defuzzification method has been carried out by conversion of fuzzy values to non-fuzzy values using the centroid method. In the proposed methodology we have used three fuzzy controllers, namely temperature fuzzy controller, illumination fuzzy controller and air quality fuzzy controller. The input to the temperature fuzzy controller is the error difference between actual temperature and optimized temperature, illumination fuzzy controller inputs is the error difference between actual illumination and optimized illumination and similarly input to the air quality fuzzy controller is the error difference between actual air quality and optimized air quality. The output of temperature fuzzy controller, illumination fuzzy controller, and air quality fuzzy controller is the required power for cooling/heating (temperature fuzzy controller), lighting (illumination fuzzy controller), and CO2 concentration.

Coordinator Agent
The input to the coordinator agent is the desired power from fuzzy controllers for the cooling/heating, lighting, and ventilation. The coordinator agent provides the power available from power sources. Equation (9) is used to compute the total required power:

Coordinator Agent
The input to the coordinator agent is the desired power from fuzzy controllers for the cooling/heating, lighting, and ventilation. The coordinator agent provides the power available from power sources. Equation (9) is used to compute the total required power: TRP = RPT + RPL + RPV (9) where TRP is the total required power, RPT is the required power for cooling/heating, RPL is required power for the lightening system and RPV is required power for ventilation.

Building Actuators
Building actuators are electronic devices used inside the building that consume energy, i.e., AC (for cooling), heater (for heating), and freezer/refrigerator (cooling). The status of these actuators changes according to the error difference between environmental parameters and the BA-optimized parameters.

Experimental Results and Discussion
All the implementation and experimental work of this study were carried out on an Intel(R) Core(TM) i5-3570 CPU @ 3.40 GHz with Matlab 2010a installed on it. The implementation of fuzzy logic is done using the fuzzy logic toolbox.
We have performed different numbers of experiments to find the optimal parameters for the BA. With the following parameters, we get the best results, which are reported in this paper. The bats population size in a single generation was set to 40 with α = 0.7, γ = 0.7, initial rate of pulse emission r 0 (i) was set to 0.5 and initial loudness A 0 (i) was also set to 0.5. We have used f min = 0 , and f max = 1. Maximum number of generations was set to 100.
The purpose of this study is twofold (a) to increase user comfort and (b) to minimize energy consumption. First for each of the three parameters, if the value of the parameter is in the range of user comfort, BA does not make any change to the values of the parameter, but when the values of the parameters are outside the comfort zone of the user, BA optimizes the values to bring them to the user comfort zone. The values of the parameters within the comfort zone for temperature, illumination, and air quality have been already discussed. The second objective of the BA optimization algorithm is the minimization of power consumption which has been obtained by minimizing the error difference between user set parameters and the environmental parameters.
The error difference between the user set temperature and BA optimization temperature is fed to the temperature fuzzy controller which provides the required power for temperature as output. The status of cooling/heating is changed according to the error difference. Illumination fuzzy controller takes the error difference between user illumination and the BA optimized illumination as input and the minimum required power for illumination is the output of the illumination fuzzy controller. The status of lighting actuator is changed according to the error difference. Similarly, the air quality fuzzy controller takes the error difference between user air set air quality and the BA optimized air quality as inputs and the output is the required minimum power for ventilation. The status of air quality is changed according to this error difference.

Temperature Control Process
The temperature control process consists of few major components to manage user preferred temperature inside the building. The optimization algorithm (BA) performs the process of optimization of temperature parameter. If the temperature value is not in the preferred range, BA brings that value inside the range. Figure 5 shows the user set temperature, the environmental temperature and BA optimized temperature parameter values. After optimization, the error difference between the environmental temperature and the BA optimized temperature is calculated, which is entered as input to the temperature fuzzy controller. The required power for the cooling/heating system is the output of the temperature fuzzy controller. The status of the cooling/heating actuators is changed according to error differences between the real environmental temperature values and BA optimized temperature values. The required power for actuator status is the output of the temperature fuzzy controller. Figure 6 shows the structure diagram for the temperature fuzzy controller. The input/output membership functions are represented in Figure 7. In the figure, the term represents the error difference between environmental temperature and the BA optimized temperature and the RPT represents required power for heating/cooling. After optimization, the error difference between the environmental temperature and the BA optimized temperature is calculated, which is entered as input to the temperature fuzzy controller. The required power for the cooling/heating system is the output of the temperature fuzzy controller. The status of the cooling/heating actuators is changed according to error differences between the real environmental temperature values and BA optimized temperature values. The required power for actuator status is the output of the temperature fuzzy controller. Figure 6 shows the structure diagram for the temperature fuzzy controller. After optimization, the error difference between the environmental temperature and the BA optimized temperature is calculated, which is entered as input to the temperature fuzzy controller. The required power for the cooling/heating system is the output of the temperature fuzzy controller. The status of the cooling/heating actuators is changed according to error differences between the real environmental temperature values and BA optimized temperature values. The required power for actuator status is the output of the temperature fuzzy controller. Figure 6 shows the structure diagram for the temperature fuzzy controller. The input/output membership functions are represented in Figure 7. In the figure, the term represents the error difference between environmental temperature and the BA optimized temperature and the RPT represents required power for heating/cooling. The input/output membership functions are represented in Figure 7. In the figure, the term e T represents the error difference between environmental temperature and the BA optimized temperature and the RPT represents required power for heating/cooling.  In these rules, denotes the error difference between environmental temperature and the BA optimized temperature. Seven membership functions are defined in (input variable for the temperature fuzzy controller). The output variable RPT for the temperature fuzzy controller represents the output energy generated by temperature fuzzy controller for cooling/heating temperature. Input variable ( ) has seven membership functions, these membership functions are labeled as NB, NM, NS, ZE, PS, PM, PB that are abbreviated for negative big, negative medium, negative small, zero error, positive error, positive small, positive big respectively. The output variable has also seven membership functions that are labeled as RNB, RNM, RNS, RZE, RPS, RPM, RPB that are acronyms for required negative big, required negative medium, required negative small, required zero error, required positive small, required positive medium, and required positive big. According to the rule defined above for fuzzy controller temperature if the input error is negative big (NB), the required power would be negative big (NB), and if the error difference is positive big (PB) the output required power would be positive big (PB). Accordingly, the NB denoted minimum required power for heating and cooling and RPB represents the maximum heating/cooling power. The rules for temperature fuzzy controller are as follows and these are graphically represented in In these rules, e T denotes the error difference between environmental temperature and the BA optimized temperature. Seven membership functions are defined in e T (input variable for the temperature fuzzy controller). The output variable RPT for the temperature fuzzy controller represents the output energy generated by temperature fuzzy controller for cooling/heating temperature. Input variable (e T ) has seven membership functions, these membership functions are labeled as NB, NM, NS, ZE, PS, PM, PB that are abbreviated for negative big, negative medium, negative small, zero error, positive error, positive small, positive big respectively. The output variable has also seven membership functions that are labeled as RNB, RNM, RNS, RZE, RPS, RPM, RPB that are acronyms for required negative big, required negative medium, required negative small, required zero error, required positive small, required positive medium, and required positive big. According to the rule defined above for fuzzy controller temperature if the input error is negative big (NB), the required power would be negative big (NB), and if the error difference is positive big (PB) the output required power would be positive big (PB). Accordingly, the NB denoted minimum required power for heating and cooling and RPB represents the maximum heating/cooling power. After applying the fuzzy rules shown in Figure 8, the required power for controlling the status of the cooling/heating system is the fuzzy controller output. The essential power for the temperature control system is calculated by considering the temperature parameters optimization and the fuzzy rules. The calculated power for temperature control based on these parameters is shown in Figure 9 for the temperature control process.

Illumination Control Process
The illumination control process consists of few major components for managing user's preferred lighting system inside the building. The optimization algorithm (BA) performs the process of optimization of illumination parameter. If the illumination value is outside the preferred range, the BA brings that value inside the range. Figure 10 shows the user set illumination, the environmental illumination, and BA optimized parameter values. After applying the fuzzy rules shown in Figure 8, the required power for controlling the status of the cooling/heating system is the fuzzy controller output. The essential power for the temperature control system is calculated by considering the temperature parameters optimization and the fuzzy rules. The calculated power for temperature control based on these parameters is shown in Figure 9 for the temperature control process. After applying the fuzzy rules shown in Figure 8, the required power for controlling the status of the cooling/heating system is the fuzzy controller output. The essential power for the temperature control system is calculated by considering the temperature parameters optimization and the fuzzy rules. The calculated power for temperature control based on these parameters is shown in Figure 9 for the temperature control process.

Illumination Control Process
The illumination control process consists of few major components for managing user's preferred lighting system inside the building. The optimization algorithm (BA) performs the process of optimization of illumination parameter. If the illumination value is outside the preferred range, the BA brings that value inside the range. Figure 10 shows the user set illumination, the environmental illumination, and BA optimized parameter values.

Illumination Control Process
The illumination control process consists of few major components for managing user's preferred lighting system inside the building. The optimization algorithm (BA) performs the process of optimization of illumination parameter. If the illumination value is outside the preferred range, the BA brings that value inside the range. Figure 10 shows the user set illumination, the environmental illumination, and BA optimized parameter values. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the lighting system is the output of the fuzzy controller. The lighting actuator status is changed according to the error differences between the actual environmental parameters and the BA optimized parameters. The structure diagram for illumination fuzzy controller is illustrated in Figure 11.  Figure 11. Structure diagram for illumination fuzzy controller.
The input/output MFs are illustrated in Figure 12. In the figure, the represents the error difference between environmental illumination and BA optimized illumination and RPL represent required power for lighting. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the lighting system is the output of the fuzzy controller. The lighting actuator status is changed according to the error differences between the actual environmental parameters and the BA optimized parameters. The structure diagram for illumination fuzzy controller is illustrated in Figure 11. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the lighting system is the output of the fuzzy controller. The lighting actuator status is changed according to the error differences between the actual environmental parameters and the BA optimized parameters. The structure diagram for illumination fuzzy controller is illustrated in Figure 11.  Figure 11. Structure diagram for illumination fuzzy controller.
The input/output MFs are illustrated in Figure 12. In the figure, the represents the error difference between environmental illumination and BA optimized illumination and RPL represent required power for lighting. The input/output MFs are illustrated in Figure 12. In the figure, the e L represents the error difference between environmental illumination and BA optimized illumination and RPL represent required power for lighting.  In these rules, the error difference between the environmental illumination and the BA optimized illumination is input to the illumination fuzzy controller. The illumination fuzzy controller on based on these inputs generates the energy as output. The input and output variables are represented by and RPL correspondingly. The input variable of illumination fuzzy controller has five membership functions that are labeled as high small (HS), medium small (MS), big small (BS), OK, small high (SH) and high (H), so as we go from HS towards H, the error difference increases, and vice versa. The required power for lighting (RPL) output variable has also five membership functions that are labeled as RHS, RMS, RBS, ROK, RSH, and RH. According to the first rule in above rules for illumination fuzzy controller, if the error difference is low then minimum power would be required for the lighting system. Similarly, according to the last rule, if the error difference is high then maximum power would be required for the lighting system. In these rules, the error difference between the environmental illumination and the BA optimized illumination is input to the illumination fuzzy controller. The illumination fuzzy controller on based on these inputs generates the energy as output. The input and output variables are represented by e L and RPL correspondingly. The e L input variable of illumination fuzzy controller has five membership functions that are labeled as high small (HS), medium small (MS), big small (BS), OK, small high (SH) and high (H), so as we go from HS towards H, the error difference increases, and vice versa. The required power for lighting (RPL) output variable has also five membership functions that are labeled as RHS, RMS, RBS, ROK, RSH, and RH. According to the first rule in above rules for illumination fuzzy controller, if the error difference is low then minimum power would be required for the lighting system. Similarly, according to the last rule, if the error difference is high then maximum power would be required for the lighting system. After applying the fuzzy rules shown in the Figure 13, the required power for controlling the status of the lighting system is the output of the illumination fuzzy controller. The necessary power for illumination control system is calculated by considering the illumination parameters' optimization and the fuzzy rules explained earlier. The calculated power for lighting system control based on these parameters is shown in Figure 14 for illumination control process. Figure. 14. Power consumption for illumination with BA optimization and without BA optimization.

Air Quality Control Process
The air quality control process consists of few major components for managing user's preferred ventilation system inside the building. The optimization algorithm (BA) performs the process of optimization of air quality parameter. If the parameter's value is outside the preferred range, the BA brings that value inside the range. Figure 15 indicates the user set air quality, the environmental air quality, and the BA optimized air quality values. After applying the fuzzy rules shown in the Figure 13, the required power for controlling the status of the lighting system is the output of the illumination fuzzy controller. The necessary power for illumination control system is calculated by considering the illumination parameters' optimization and the fuzzy rules explained earlier. The calculated power for lighting system control based on these parameters is shown in Figure 14 for illumination control process. After applying the fuzzy rules shown in the Figure 13, the required power for controlling the status of the lighting system is the output of the illumination fuzzy controller. The necessary power for illumination control system is calculated by considering the illumination parameters' optimization and the fuzzy rules explained earlier. The calculated power for lighting system control based on these parameters is shown in Figure 14 for illumination control process. Figure. 14. Power consumption for illumination with BA optimization and without BA optimization.

Air Quality Control Process
The air quality control process consists of few major components for managing user's preferred ventilation system inside the building. The optimization algorithm (BA) performs the process of optimization of air quality parameter. If the parameter's value is outside the preferred range, the BA brings that value inside the range. Figure 15 indicates the user set air quality, the environmental air quality, and the BA optimized air quality values.

Air Quality Control Process
The air quality control process consists of few major components for managing user's preferred ventilation system inside the building. The optimization algorithm (BA) performs the process of optimization of air quality parameter. If the parameter's value is outside the preferred range, the BA brings that value inside the range. Figure 15 indicates the user set air quality, the environmental air quality, and the BA optimized air quality values. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the ventilation system is the output of air quality control system. As the input values, the air quality fuzzy controller is changed its output is also changed and ventilation actuator status is changed accordingly. The structure diagram for the air quality fuzzy controller is shown in Figure 16. The input/output MFs are illustrated in Figure 17, where the represents the error difference between environmental air quality and BA optimized air quality and the RPV represent require power for ventilation. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the ventilation system is the output of air quality control system. As the input values, the air quality fuzzy controller is changed its output is also changed and ventilation actuator status is changed accordingly. The structure diagram for the air quality fuzzy controller is shown in Figure 16. After optimization, the error difference between the environmental illumination and the BA optimized illumination is calculated which is entered as input to the illumination fuzzy controller. The required power for the ventilation system is the output of air quality control system. As the input values, the air quality fuzzy controller is changed its output is also changed and ventilation actuator status is changed accordingly. The structure diagram for the air quality fuzzy controller is shown in Figure 16. The input/output MFs are illustrated in Figure 17, where the represents the error difference between environmental air quality and BA optimized air quality and the RPV represent require power for ventilation. The input/output MFs are illustrated in Figure 17, where the e A represents the error difference between environmental air quality and BA optimized air quality and the RPV represent require power for ventilation. In the above rules, denotes the error difference between environmental air quality and the air quality optimized by BA. The is the input variable to air quality fuzzy controller. The air quality controller generates the energy as output based on these inputs. The outcome of the air quality fuzzy controller is denoted by RPA. The input variable for air quality is comprised of five membership functions the labeling for these membership function is carried out as LOW, OK, small high (SH), low high (LH) and HIGH.  In the above rules, e A denotes the error difference between environmental air quality and the air quality optimized by BA. The e A is the input variable to air quality fuzzy controller. The air quality controller generates the energy as output based on these inputs. The outcome of the air quality fuzzy controller is denoted by RPA. The input variable for air quality is comprised of five membership functions the labeling for these membership function is carried out as LOW, OK, small high (SH), low high (LH) and HIGH. The rules for illumination fuzzy controller are as follows and these are represented in Figure 18: In the above rules, denotes the error difference between environmental air quality and the air quality optimized by BA. The is the input variable to air quality fuzzy controller. The air quality controller generates the energy as output based on these inputs. The outcome of the air quality fuzzy controller is denoted by RPA. The input variable for air quality is comprised of five membership functions the labeling for these membership function is carried out as LOW, OK, small high (SH), low high (LH) and HIGH.  The LOW denotes the minimum error difference between environmental air quality and BA optimized air quality, so as we go from LOW towards HIGH, the error difference increases and vice versa. According to the first rule in air quality fuzzy control rules if the input air quality is minimum the desired output power would also be minimum, so LOW denotes the minimum difference between environmental air quality and the optimized air quality. After applying the fuzzy rules shown in Figure 18, the required power for controlling the status of the ventilation system is the output of the air quality fuzzy controller. The required power for ventilation control system is calculated by considering the air quality parameters' optimization and the fuzzy rules explained earlier. The calculated power for ventilation system control based on these parameters is shown in Figure 19 for the ventilation control process. The LOW denotes the minimum error difference between environmental air quality and BA optimized air quality, so as we go from LOW towards HIGH, the error difference increases and vice versa. According to the first rule in air quality fuzzy control rules if the input air quality is minimum the desired output power would also be minimum, so LOW denotes the minimum difference between environmental air quality and the optimized air quality. After applying the fuzzy rules shown in Figure 18, the required power for controlling the status of the ventilation system is the output of the air quality fuzzy controller. The required power for ventilation control system is calculated by considering the air quality parameters' optimization and the fuzzy rules explained earlier. The calculated power for ventilation system control based on these parameters is shown in Figure 19 for the ventilation control process. The total power consumed by temperature, illumination and air quality for BA optimization and without applying the optimization algorithm is shown in Figure 20. The comfort index values obtained by using BA optimization and without optimization are shown in Figure 21. The figure illustrates that the BA-optimized values are higher than without The total power consumed by temperature, illumination and air quality for BA optimization and without applying the optimization algorithm is shown in Figure 20. The LOW denotes the minimum error difference between environmental air quality and BA optimized air quality, so as we go from LOW towards HIGH, the error difference increases and vice versa. According to the first rule in air quality fuzzy control rules if the input air quality is minimum the desired output power would also be minimum, so LOW denotes the minimum difference between environmental air quality and the optimized air quality. After applying the fuzzy rules shown in Figure 18, the required power for controlling the status of the ventilation system is the output of the air quality fuzzy controller. The required power for ventilation control system is calculated by considering the air quality parameters' optimization and the fuzzy rules explained earlier. The calculated power for ventilation system control based on these parameters is shown in Figure 19 for the ventilation control process. The total power consumed by temperature, illumination and air quality for BA optimization and without applying the optimization algorithm is shown in Figure 20. The comfort index values obtained by using BA optimization and without optimization are shown in Figure 21. The figure illustrates that the BA-optimized values are higher than without The comfort index values obtained by using BA optimization and without optimization are shown in Figure 21. The figure illustrates that the BA-optimized values are higher than without optimization which indicates that the BA offers a better comfort index to the occupant. The figure also indicates fluctuations in BA algorithm which is higher than that of without optimization.

Comparative Analysis of Optimization Results Bat Algorithm with Genetic Algorithm and Particle Swarm Optimization
Ali et al. in [2] deployed particle swarm optimization and genetic algorithm for energy consumption minimization and maximization of user comfort using the same data set used in this study. In the proposed work the power consumption comparison (for temperature control, illumination control, and humidity) of the BA algorithm with genetic algorithm and particle swarm optimization algorithm has been carried out. Here in this section, a comparison of the power consumption for temperature control, illumination control and air quality control have been carried out. The power consumption for temperature control by the BA algorithm is high as compared to the power consumption by the genetic algorithm and particle swarm optimization. The power consumption for both the illumination control and the air quality control by BA is less as compared to both the genetic algorithm and particle swarm optimization. The power consumed in total by BA is less than the power consumption of genetic algorithm (GA) and particle swarm optimization, as given in Table 1. It is evident from the facts and figures given by the authors of [2] and our proposed model that BA algorithm consumes less power as compared to the genetic algorithm and particle swarm optimization. The reason behind this lower consumption of power is that the BA provides more optimal parameters as compared to GA and PSO. The authors of [2] described that the results provide by using PSO algorithm are smooth, but the GA algorithm results show more fluctuations. As the objective of this study is twofold, that is to minimize the user comfort and maximize user comfort, the proposed work for energy consumption performs well as proved. The minimum value for comfort index by using the BA algorithm is more compared to the minimum value provided by using both PSO and GA. As a result, it can be concluded that the BA algorithm is more effective to maximize user comfort as compared to GA and PSO.

Comparative Analysis of Optimization Results Bat Algorithm with Genetic Algorithm and Particle Swarm Optimization
Ali et al. in [2] deployed particle swarm optimization and genetic algorithm for energy consumption minimization and maximization of user comfort using the same data set used in this study. In the proposed work the power consumption comparison (for temperature control, illumination control, and humidity) of the BA algorithm with genetic algorithm and particle swarm optimization algorithm has been carried out. Here in this section, a comparison of the power consumption for temperature control, illumination control and air quality control have been carried out. The power consumption for temperature control by the BA algorithm is high as compared to the power consumption by the genetic algorithm and particle swarm optimization. The power consumption for both the illumination control and the air quality control by BA is less as compared to both the genetic algorithm and particle swarm optimization. The power consumed in total by BA is less than the power consumption of genetic algorithm (GA) and particle swarm optimization, as given in Table 1. It is evident from the facts and figures given by the authors of [2] and our proposed model that BA algorithm consumes less power as compared to the genetic algorithm and particle swarm optimization. The reason behind this lower consumption of power is that the BA provides more optimal parameters as compared to GA and PSO. The authors of [2] described that the results provide by using PSO algorithm are smooth, but the GA algorithm results show more fluctuations. As the objective of this study is twofold, that is to minimize the user comfort and maximize user comfort, the proposed work for energy consumption performs well as proved. The minimum value for comfort index by using the BA algorithm is more compared to the minimum value provided by using both PSO and GA.
As a result, it can be concluded that the BA algorithm is more effective to maximize user comfort as compared to GA and PSO.

Conclusions
This paper addressed the issue of maximizing user comfort and minimizing power consumption in residential buildings using a bat optimization algorithm and fuzzy controllers. The proposed system architecture comprises different components, such as environmental parameters (temperature, illumination, and air quality), BA optimizer, fuzzy controller, comfort index, fuzzy controller and various kinds of actuators. Inputs to the BA optimizer are environmental parameters (temperature, illumination, and air quality) and user-set parameters (temperature, illumination, and air quality). The optimizer parameters (temperature, illumination, and air quality) are the outputs of the BA optimizer. Inputs to the fuzzy controllers are environmental parameters and the BA optimizer parameters and the required power for actuators are its output. The calculation of total power required is carried out by coordinator agent which checks whether the required power send fuzzy controller is available or not. The statuses of the actuators are changed according to this power sent by the fuzzy controllers. The user comfort index has been increased and the power consumption has been decreased.