A Novel Machine Learning-Based Price Forecasting for Energy Management Systems

: Price forecasting (PF) is the primary concern in distributed power generation. This paper presents a novel and improved technique to forecast electricity prices. The data of various power producers, Capacity Purchase Price (CPP), Power Purchase Price (PPP), Tariff rates, and load demand from National Electric Power Regulatory Authority (NEPRA) are considered for MAPE reduction in PF. Eight time-series and auto-regression algorithms are developed for data fetching and setting the objective function. The feed-forward ANFIS based on the ML approach and space vector regression (SVR) is introduced to PF by taking the input from time series and auto-regression (AR) algorithms. Best-feature selection is conducted by adopting the Binary Genetic Algorithm (BGA)-Principal Component Analysis (PCA) approach that ultimately minimizes the complexity and computational time of the model. The proposed integration strategy computes the mean absolute percentage error (MAPE), and the overall improvement percentage is 9.24%, which is valuable in price forecasting of the energy management system (EMS). In the end, EMS based on the Fireﬂy algorithm (FA) has been presented, and by implementing FA, the cost of electricity has been reduced by 21%, 19%, and 20% for building 1, 2, and 3, respectively.


Introduction
It is necessary to forecast electricity prices for the Independent System Operator (ISO) and the end-users and marketers. Generally, the profit bidders in the potential electricity market need the future electricity prices in order to earn a good profit; however, the existing electricity market has made PF more complex as it is highly deregulated and non-linear. Due to the system's non-linear and unstable behavior, accurate prediction of prices has become more complex. It also affects the bidding policies in the electricity market. The PF techniques are categorized into three classes according to their specific forecasting models: The statistical model, time-series model, and AI-based models [1]. The AI-based forecasting approach has attracted much attention in recent years. It assures a guaranteed level of accuracy of price estimation compared to unstable variations of dependent or independent variables in the statistical model. The current energy market depends on renewable energy resources because these are playing a leading role in fulfilling the energy demand. In the rising energy demand, an economical solution is needed to address persistent issues [2]. An exhaustive work concludes that renewable energy generation resources have an extensive impact on energy unit prices. The generation-side and demand-side companies are in contact to develop a steadiness between supply and demand. An optimized home energy management system (EMS) proposed in [3] computes the unit price of electricity by utilizing an RES and battery storage system. The energy unit price is determined by correspondence from generation groups with the requirement from the load-allocation bodies. The subsequent energy demand is calculated from load allocation bodies and fed to the supply side to avoid inconveniences such as an electricity shutdown.
On the other hand, the dependability and protection of the electricity system are managed by a regulatory authority to harmonize with local distribution companies. This regulatory authority also determines the energy unit price [4]. The cost-effective solution in any domain is a considerable factor. Recently, the energy unit PF has been presented, and diverse performances have also been suggested. Numerous areas, including signal processing, statistical modeling, Machine Learning (ML), big-data analysis, and Artificial Intelligence (AI), are anticipated tools [5]. An overview of the latest trends in power systems is presented in Figure 1. Several methods have been proposed to forecast load consumption and per-unit prices, such as engineering and statistical methods. Many researchers are working on AI applications such as the Artificial Neural Network (ANN), Support Vector Machine (SVM), evolutionary programming, expert system, fuzzy logic (FL), and LF-related problems.
Various steps and efforts are proposed in the latest research to meet the large gap between demands and supply. On the other hand, an approach to decision-making and medical diagnosis problems using the concept of spherical fuzzy sets is also evaluated in [11]. Moreover, electricity cannot be stored in large amounts. The construction of newer power plants is not an ultimate solution as it may lead to carbon emissions and the depletion of resources [12]. Electric utilities have realized that consumer demands cannot be met satisfactorily by adding new generating capacity alone [13]. Demand-Side Management (DSM) and Demand Response (DR) are the terms used for energy management. These deal with actions that influence consumers' energy usage patterns in peak load times [14]. It also includes decision making, implementation, and the following of activities of utilities to motivate the consumers to modify their level and pattern of electricity consumption according to the retail price [15]. Hence, the present focus of researchers is in the domain of energy management.
This article considers the data of various power producers, CPPs, PPPs, Tariff rates, and load demand from NEPRA for MAPE reduction in PF. Eight time-series and autoregression algorithms are developed for data fetching and setting the objective function as shown in Figure 2. The feed-forward ANFIS is based on the ML approach to forecast the PF by taking the inputs from time series and auto-regression algorithms. Best-feature selection is conducted by adopting the BGA-PCA approach. It reduces the repeated, irrelevant, and unnecessary data and ultimately minimizes the model's complexity and computational time. The proposed integration strategy computes the MAPE according to the steps mentioned above and obtains significant improvements.
The contributions of this paper are well accomplished and summarized.
• NEPRA, Pakistan data are considered where the PF is optimized by reducing the MAPE. • Eight time-series and autoregression algorithms are developed to fetch the dataset and set the objective function, while the proposed equations set the basis for further validation as improved results validate it. • However, feedforward ANFIS based on the ML approach is proposed. Best-feature selection is evaluated through the BGA-PCA approach.

•
Our results for the PF compute the MAPE of one year by the proposed integration strategy, and the overall improvement in MAPE is 9.24%.

•
In the end, EMS based on the Firefly algorithm (FA) has been implemented, and the cost of electricity has been reduced by 21%, 19%, and 20% for building 1, 2, and 3, respectively, which is valuable in price forecasting of the energy management system (EMS).

Related Work
The forecasting medium supports establishing system models, behavior, and plans by reviewing current and past market trends. PF is the main factor of this medium, demonstrating generation capabilities, resource handling, capital cost, profit analysis, and other system plans [16]. Load estimation and price prognoses are significant factors for prime maneuver development in these viable power energy souks. Diverse methodologies exist for price and load estimation, but without feature selection, skill methodologies are inadequate. The mentioned feature selection skill deals with the modeling of intermingling structures and nonlinearities of forecast progressions. By considering technicalities and generation site plans, electricity price estimation is a more valuable chore. The energy rate is estimated with an optimistic approach based on market-side demand and predictive forecasting. Renewable energy backs the economical energy unit price. Detailed scrutiny of market data in an arithmetical manner is a fundamental requirement in this approach [17].
Many researchers forecasted the price of electricity using the ANN strategy in traditional ways. In this regard, a multi-layer feed-forward Neural Network (MFFNN), Neuro-Fuzzy, Fuzzy Neural Network, and Adaptive Wavelet Neural Network approaches based on the different analyses were used to extract selection features of price and load signals for each hour [18,19]. The electricity price varies due to dynamic variations in load demand throughout the day; therefore, this strategy minimizes the MAPE in load and price at hourly, daily, and weekly intervals [20]. With the dynamic variations in load containing high-frequency features, error is considerably increased; therefore, this research recommends Wavelet Transform to resolve this issue.
In [21], the authors used a methodology based on feature selection with mathematical and statistical modeling, utilizing the minimum block set from the input and applying a computational filtering strategy to formulate optimized PF. The research illustrated in [22] describes a trained RNN algorithm based on the Kalman Filter (KF) to forecast the load and price of electricity using one-step and nth step prediction. The proposed study practiced informative data of the European Power System (EPS) to validate the execution of the scheme. Using the time-series-based multilayer ANN-KF model increases the forecasting speed and tracking behavior, but the implementation of KF in the ANN algorithm is relatively rigid in comparison to traditional strategies.
In previous research, the AI technique has been implemented for the long-term load and PF of electricity conventionally. In [23][24][25][26], a short-term load and PF using an NN fitting tool were used to compute hourly and daily data of weather temperature and electricity load as input features. Furthermore, the generalized-RNN indicates temperature statistics and price signals as input parameters. Both techniques accurately estimate prescribed variables, but the integration of the Radial Basic Function-Neural Network (RBF-NN) and GRNN have mutual effects that declare certain computational errors. A comparative analysis of different AI approaches is compiled in Table 1, including their limitations. The authors of [5] propose a user-aware DR approach to manage residential loads. User comfort and savings are considered mainly, and user comfort is modeled as a weight factor before comfort over savings. The game is based on a modified regret-matching procedure, which has the advantage of centralized and decentralized schemes. The work can be extended with multiple energy resources in the future.
Two optimization techniques, such as the FA and harmony search algorithm, are presented in this paper. These heuristic techniques are applied to different types of appliances based on their energy consumption. Single and multiple home appliances are considered in this research. Time of Use (ToU) is used as a pricing signal in the proposed technique to calculate electrical cost [32].
In [33], a new algorithm introduces this study to solve and reduce the electricity cost problem using two metaheuristics techniques, FA and Elephant herding optimization (EHO). A scheduling process is used as an HEMC to maintain the balance between the demand and load sides. This study aims to determine the low cost by considering the maximum factors of user comfort and the average-to-peak ratio. The scheduling process and performance are evaluated by the comparative analysis of these two meta-heuristic techniques.
The primary purpose of this research is the successful implementation of FA in different areas and thus the widening scope of its potential users. Table 2 presents a comparative analysis of different methodologies related to DSM. Table 2. Comparative analysis of work related to DSM.

Work
Key Contribution Limitations [34] The techniques of scheduling residential appliances are presented in this study. This study is classified into two techniques such as meta-heuristic techniques and heuristic techniques.
With the widespread use of home appliances, residential consumers need to improve the strategies for scheduling appliances. [3] This paper presents DSM architecture models and algorithms based on customers behavior and smart appliances integration Implementations need to be done [5] Proposes autonomous Game theory DR systems to minimize the cost of power generation. Game theory can be an alternate to DSM [35] This study aims to consider the factor of maximizing user comfort, peak-to-average ratio (PAR), and the low cost by considering firefly optimization (FF).
Both algorithms performed a comparative analysis of the separately implemented version to evaluate the process of scheduling devices and improve their performance.
[36] A swarm FA implemented except meta-heuristic algorithm for a cost-effective solution The algorithm lacks local optimism [33] Two meta-heuristics techniques FA and EHO is utilized for the scheduling process in a HEMC to maintain the balance between the demand and load side Due to the integration of two meta-heuristics techniques, but the scheduling rate is low. [37] A comprehensive overview of the swarm intelligence of FA is performed to express performance capabilities to encourage new researchers and developers to implement it in future works.
The implementation of FA is simple and highly efficient in solving problems. [38] The scheme used to calculate the electrical cost in this proposed system is CPP using a Meta-heuristic algorithm HSA perform better than FA in terms of PAR and electricity costs [39] Applied on different types of appliances in single or multiple homes based on their energy consumption using FA and harmony search algorithm ToU is used as a pricing signal in the proposed technique for the calculation of the electrical cost [40] The proposed strategy reduces peak load and the cost by compromising the comfort of the household consumer.
Optimization is performed using a multi-objective GA Decreases the peak load and also reduces the utility bill [41] This article focuses on maximizing the use of renewable energy resources using different heuristic techniques Provide consistency in daily profit and low runs. [42] A concessional and maximum energy consumption schedule uses the GA to reduce and production costs and improve the efficiency factor at the utility and consumer level.
It is used over the single objective, which benefits consumers with intelligent load scheduling [43] The author compares the performance of the HEMC, and this controller is designed for energy consumption scheduled based on the heuristic algorithm.
The heuristic technique, such as the GA-based energy management controller, performs more efficiently than other heuristic techniques.

Proposed Framework for Price Forecasting
This section is based on the proposed PF techniques and framework.

Time Series and Autoregression Method
The time-series-forecasting model is proposed in [44], and nine regression algorithms are introduced for the LF. In this model, time series and auto-regression methods are taken into consideration for PF. Eight models are computed, where three are AR level-1, one is exponential smoothing, and three are AR level-II.
Level I Auto-regression Model (AR1) Variation in price demand: Peak hour P(t−1), off-peak hour P(t−2), and special holidays or weekend P(t−3):

Level I Auto-regression Model (AR2)
AR2 is modeled by adding the month auto-regression term M k,t where k = 1, . . . ,12, as there are 12 months in a year.

Level I Auto-regression Model (AR3)
The AR3 model has an extra auto-regression term in annual, γ k A k,t and for the seasons of the year M k,t where k = 1, . . . ,12.

Support Vector Regression (SVR)
This regression forecasts P t by considering the inputs P t−1 , P t−2 , and P t−3 for each month 12 ∑ k=1 α k M k,t of the annual forecasting.

Exponential Smoothing Method
This model is used where there is no monthly pricing, where α = smooth constant, P t−1 = previous pricing, and F t−1 = PF demand.

Level II Auto-regression Model (AR1)
In level-II, the model is applied to the data of the same series as AR1; however, the price values and residential values from customer demand modeled in the exponential smoothing method are added.

Level II Auto-regression Model (AR2)
In level-II, the model is applied to the data of the same series as AR2; however, price values and residential values from customer demand modeled in the exponential smoothing method are added.

Level II Auto-regression Model (AR3)
In level II, the model is applied to the data of the same series as AR3; however, the demand values and residential values from customer demand modeled in the exponential smoothing method are added.
Eight time-series and autoregression algorithms in Equations (1)-(14) are developed as a training of dataset and set the objective function. The proposed equations set the basis for further validation where linear and nonlinear parameters are segregated as shown in Figure 2. However, feedforward ANFIS based on the ML approach is considered to take inputs from autoregression models and data set.

Machine Learning Approach of Proposed Feedforward ANFIS
The model is further validated by the ML approach for implementing ANN, a computer model influenced by the brain and nervous system in animals or humans. The ANFIS model is presented in [45], and we modified it according to our requirement as the five stages were computed. An algorithm that uses an unmonitored training data principle to construct a load-temperature relationship is used to forecast 24 hours of load. This method uses real-time data as error-correcting function input, and simulation findings reveal that an acceptable mean absolute error percentage is better than the conventional method. In this regard, the proposed system is validated with a Feedforward Artificial Neural Network of one-year LF data. The proposed Feedforward ANFIS model consists of five stages as shown in Figure 3, where Random Forest training schemes are taken into account, and the training process is given as follows. Stage 1: In this stage, the fuzzy fiction layer simply transmits the received signal of any node to another layer. Each node for the linguistic parameter declares a member function-the output estimation of electricity price on an hourly, weekly, and monthly basis. The price estimation mainly includes power consumption statistics during the peak load time, off-peak load time, and dynamic weather conditions. The exponential methodology and level-2 AR methods are considered in Equations (15)- (18).
where P y−i , P t , P t and P t,SVR are the inputs to the nodes as shown in Figure 3 and µA i is a member function.
A is a linguistic parameter that is linked with the node function.
The µA in the model is chosen based on Equation (19): where a i and c i are the set of premise parameters. Stage 2: At this stage, the rule layer is employed, which simplifies the member function of PF and minimizes the burden on nodes by processing the training dataset. The node's output expresses the firing strength of each rule and is obtained by the membership functions illustrated by Equation (20).
Stage 3: Here, the normalization layer computes the ratio of firing strength of the relative rule to the sum of firing strengths of preceding rules. Each node at this stage is a fixed node named N. The output is given by Equation (21).
Stage 4: At this stage, the defuzzification layer evaluates the output for each rule by taking the product of normalized firing strength from the previous stage and the first-order Sugeno Model. The nodes at this stage are based on adaptive nodes.
where w n is the output of stage 3, and k n , l n , and m n are the parametric set. Stage 5: Finally, the sum layer computes the total output for the proposed model. The calculation is conducted based on the output values of each rule. There is a single node here that computes the overall output. The overall output is computed in a single node shape, as illustrated in Figure 2 and given in Equation (23).
It has been observed that the ANFIS model declares the final output for a given premise by representing a linear combination of consequent parameters.

BGA-PCA for Feature Selection
In this paper, feature selection eliminates the extraneous and redundant data, improving accuracy and reducing PF computation time. In this proposed model, the feature selection is based on BGA by the blend of PCA. The main objective of BGA is a minimization of MSE as a loss function for the ML approach that is formulated Equation (25) as: where T is a vector function of price estimation and n is a training sample or assumption for forecasting. The term 1 defines the values that have to be chosen, and 0 defines the values that have not been chosen for the chromosome assessment. Thus, each irritation of the BGA-PCA feature-selection method decreases the MSE and finds the best objective function value. The parameters considered for BGA are presented in Table 3.

Proposed Integration Strategy
The PF approach is based on time series and the auto-regression model, the ML method, and the proposed feature selection scheme. In this section, the forecasting is further optimized by reducing MAPE. Therefore, all approaches are integrated into this part where data fetching and modeling of time series and auto-regression model are considered while the sequence of simulation is shown in Table 4. One-year data of twelve months with the transformation of weekly data, ML, and feature selection are not considered as a final decision because the integration strategy looks toward the best algorithm of the related week of each month. Moreover, the MAPE calculations are modified as computed for the integration strategy in [46]. We computed the MAPE of PF for each month as follows.
where f it f un (t) is a function taen from feature selection concerning time t, P a is the actual price, and w m is weeks per month. The average MAPE is then further calculated as:

Step 3:
Generate random estimation for feedback ANFIS model consists of five stages.

Step 4:
Evaluate feature selection with BGA-PCA as per Equation (11) Step 5: Compute (Ti − Pt) 2 for the different objective function of P(t).
Step 6: Compute MAPE i for 12 months Step 8: Compute MAPE avg Step 9: Plot the Figures for MAPE of 12 months

PF Model Evaluation
In this section, the time-series and auto-regression models are considered for MLbased feature selection, BGA-PCA. Furthermore, the integration strategy technique further validates it. For this purpose, 12 power producers, such as RES, Hydel Power, Gas Power, RNLG, imported coal, local coal, residual fuel oil, bagasse, uranium, RNLG new, imported power, CPP per kWh of each month, PPP per kWh of each month, and load demand of each month are taken into consideration as the input dataset.
The data from NEPRA are taken for the estimation of PF for twelve months. The proposed work and Random Forest training scheme are shown in Figure 4 as systematized as follows: Time series and auto-regression algorithms are developed to fetch the dataset and set the objective function for proposed Equations (1)- (14). According to these equations, eight AR methods fetch the dataset by different linear and non-linear parameters.
The preprocessing of the AR method, where four types of data are fed to feedback ANFIS, contains linear data of Level-1 AR models as shown in Figure 2.
The time-series AR data have been considered an input to the proposed Feed-forward ANFIS and the overall output of Feed-forward ANFIS is computed in Equations (14)- (24). w 1 , w 2 , w 3 , w 4 , w 5 , and w 6 are the six best weights obtained from the ANFIS model. For example, weights are w 1 = 60%, w 2 = 50%, w 3 = 40%, w 4 = 30%, w 5 = 20%, and w 6 = 10%, respectively. Then the new weights according to Equation (7) (23) and (24), where f n is the forecasting parameter of each weight according to week, weekend, month, and year, are the parameters computed in Equations (1)- (14). Assuming that f n is 30, 25, 20, 15, 10, and 5, then the forecast weights are computed as: f = (0.28 × 30) + (0.23 × 25) + (0.19 × 20) + (0.14 × 15) + (0.09 × 10) + (0.04 × 5) ≈ 21.15. BGA-PCA for feature selection is used to eliminate the extraneous and redundant data that can improve the accuracy and reduce the computation time. The main objective of BGA is minimization as the loss function is computed in Equation (25). The BGA-PCA algorithms have removed the extra parameters, repeated terms, and irrelevant data with the given simulation parameters in Table 3. MAPE calculation for the integration strategy is computed for each month, and the average MAPE calculation is performed in Equations (26) and (27), respectively. As per the MAPE calculation in Table 5, the MAPE of July 2019 is 5.56 as calculated from Equation (13). The weekly coefficient from different algorithms C i are 30%, 24%, 19%, 15%, 8%, and 4%. The integration strategy computed by the minimum MAPE as per Equations (28) and (29) is MAPE o f July 2019 = 0.3 * 5.56 + 0.24 * 5.52 + 0.19 * 5.6 + 0.15 * 5.54 + 0.08 * 5.59 + 0.04 * 5.57 = 5.55. Similarly, the MAPE of each month is calculated as given in Table 5. The flow chart of the proposed framework PF is presented in Figure 4.
PF improvement for the MAPE of each month is calculated in The overall improvement percentage can be calculated by:

EMS Model Evaluation
For the implementation of EMS, different kinds of loads have been selected for these buildings, as shown in Table 6. These loads are commonly used appliances in houses, industrial machines, or commercial instruments. Then the time of operation is selected by turning devices on and off in each interval. Building 1 This building mainly contains household appliances as shown in Table 7. Here the first column contains the name of the load. The second contains watt rating, the third contains the probability of the on-time of the load, the fourth column contains the off time of the load, and the fifth column contains the number of times devices are turned on in each house. The percentage of generation by different power producers with CPPs, PPPs, and load demand is presented in Table 6. Building 2 Building 2 has been selected to represent the commercial industry. This is because it contains all high-power loads. The details of loads used by consumers in building 2 are expressed in Table 8.

Building 3
Building 3 has been selected as the residential building. It contains all midrange loads, as shown in Table 9. The details of the loads follow. This building contains 808 devices. Therefore, to create the composite system, a large number of devices have been used. Since a large building may contain these devices, this table has been used as input data for the proposed FA. First of all, the selection of appliances is conducted, and then the following is a sequence of the algorithm as per Figure 5:

•
First it captures the on-time of each appliance after initialization.

•
The duration of the run-time of every appliance is the load duration. • Load power rating is also used as input in vector form.

•
Cost of electricity so that a per-month bill can be calculated. This cost varies from country to country. • Peak hour details are also necessary. This is because peak hour cost affects three-phase connection customers, not single-phase connection customers in Pakistan. However, still, it is required because most of the users are three-phase connection customers and load on the national power grid is high at peak hours. • All the above parameters are used as input for the FA. These variables are modeled based on model equations presented in Section 5.

•
Next, the output of the firefly block is generated. It is useless until it is proven fruitful. So to create a closed-loop system, unscheduled load parameters are generated.  (9) is satisfied, then the output is generated. This output contains DSM data that can be used to reduce electricity bills and power peaks in demand.

Methodology
The proposed system is based on EMS using firefly. The EMS model presented in this paper is deterministic. The basic parameters used in this paper are fixed, such as power ratings of every piece of equipment used in the houses, peak hours in which the price of all power drawn is higher, and the price of electricity.
All the appliances that cannot be controlled, for example, lights, etc., cannot be scheduled because if the duration of higher electricity cost is ongoing, users cannot turn off all their lights or the fans. The only freedom, in this case, is to turn off the lights and fans in those areas where no one is sitting, and maximum conservation policies are adopted.
The second category of the load is air conditioning appliances in which our power management and proposed techniques can be applied. These appliances can also not be shifted temporarily. Usually, there are two types of air conditioning systems. One is HVAC, and the other one is local air conditioning units installed in each house. Usually, HVAC control is difficult compared to individual units because it draws a large current and will cool an entire building even if one does not need it. However, on the other hand, the tiny air conditioning units can be used to conserve power by shifting their cooling temperature levels, and in this way, they will trip and conserve the power.
This paper considers the following vectors as considered in [47], and we modified them to design the model equation for the Firefly-based power management system proposed in this paper.
The set of appliances that can be shifted have been represented as: The power ratings of each appliance are expressed as: The point that each appliance is turned on is expressed as: For the representation of time slots in 24 h, the following vector has been used: The above vectors represent the model presented in this paper for EMS using the FA.
This is a straightforward model that can be used for power optimization. To manage the peak hour issues in the proposed system, a separate vector has been created in which two elements exist as this vector as: Here, T1 = Peak Hours and T2 = Off-peak hours. The concept of peak hours has been introduced in the proposed system to encourage people to save electricity. During peak hours, all residential users utilize electricity, and therefore, the electrical stress on the power grid increases in this time. The higher cost is applied to all the power consumed in peak hours to discourage users from turning on all high-power devices at this time.
For an electricity cost reduction for the consumers, the following model equation will be used in the proposed paper.

Total Cost reduction in Bill
So, if we minimize the above equation, then the total cost will be reduced. Here, Cn represents the cost vectors, which consist of the bills of individual appliances. Now, when we schedule loads, the customer must not be dissatisfied with arrangements. So, there must be a satisfaction model. Therefore, if we minimize ∑ a / ∈ A Ds (Ds = Discomfort level) then the customer will bear arrangements. So Here, two parameters can be operated by the customer. One is the start time and the other is off time, and (ast) and (βend) are the start and end times of each appliance set by users to finish the task. Here Ts is the start time and L is the time interval for each appliance to complete the task.
The main objective is to minimize the peak load. For this purpose, the following model can be used.
This means that after scheduling, the load must be less than or equal to the actual load. However, the following condition must be validated for the objective to be complete: The above condition validates that if the scheduled power drawn is less than the actual load in peak hours, it reduces the overall cost and system capacity to handle the maximum load.

Firefly Algorithm
Xin-she-young developed FA in [48,49]. FA is a specific rule algorithm that effectively seeks the finest solution in local research. There are two basic variables of FA, namely attractiveness and emission of light. There are three basic steps followed in FA:

1.
At the same time, the firefly is attracted to the most attractive FA.

2.
In the second step, the attraction is proportional to the flashing light.

3.
In the last step, the coefficient value is used to control the intensity of the light.
The firefly is attracted to another firefly with a brighter flashlight than its own, as presented in [50]. An explanation of the Pseudocode of the FA can be found in [50] where the authors specify the light intensity value, initialization of light intensity, light absorption stability, and distance between two fireflies. The flowchart of FA is shown in the following Figure 6.

Results Discussion
The MAPE of July-2019 without the proposed integration is 6.12%, and after feature selection and the proposed integration model, the MAPE is optimized to 5.56%. Thus, the overall improvement of the proposed model is 9.15%. Similarly, the MAPE of August-2019 without the proposed integration is 6.87%, and after feature selection and the proposed integration model, the MAPE is optimized to 6.26%. Thus, the overall improvement of the proposed model is 8.88%. Figure 7 illustrates the actual vs. forecasted price of electricity for July and August 2019 with an average MAPE of each month.
The MAPE of September-2019 without the proposed integration is 5.10%, and after feature selection and the proposed integration model, the MAPE is optimized to 4.61%. Thus, the overall improvement of the proposed model is 9.61%. The MAPE of October-2019 without the proposed integration is 5.38%, and after feature selection and the proposed integration model, the MAPE is optimized to 4.87%. Thus, the overall improvement of the proposed model is 9.48%. Figure 8 illustrates the actual vs. forecasted price of electricity for September and October 2019 with the average MAPE of each month.  The MAPE of November-2019 without the proposed integration is 5.46%; after feature selection and the proposed integration model, the MAPE is optimized to 4.94%. Thus, the overall improvement of the proposed model is 9.52%. The MAPE of December-2019 without the proposed integration is 5.44%, and after feature selection and the proposed integration model, the MAPE is optimized to 4.92%. Thus, the overall improvement of the proposed model is 9.56%. Figure 9 illustrates the actual vs. forecasted price of electricity for November and December 2019 with the average MAPE of each month.
The MAPE of January-2020 without the proposed integration is 5.24%; after feature selection and the proposed integration model, the MAPE is optimized to 4.74%. Thus, the overall improvement of the proposed model is 9.54%. The MAPE of February-2020 without the proposed integration is 6.74%, and after feature selection and the proposed integration model the MAPE is optimized to 6.14%. Thus, the overall improvement of the proposed model is 8.90%. Figure 10 illustrates the actual vs. forecasted price of electricity for January and February 2020 with the average MAPE of each month.  The MAPE of March-2020 without the proposed integration is 6.88%, and after feature selection and the proposed integration model, the MAPE is optimized to 6.27%. Thus, the overall improvement of the proposed model is 8.87%. The MAPE of April-2020 without the proposed integration is 4.95%, and after feature selection and the proposed integration model, the MAPE is optimized to 4.47%. Thus, the overall improvement of the proposed model is 9.70%. Figure 11 illustrates the actual vs. forecasted price of electricity for March and April 2020 with an average MAPE of each month.
The MAPE of May-2020 without the proposed integration is 6.93%, and after feature selection and the proposed integration model, the MAPE is optimized to 6.32%. Thus, the overall improvement of the proposed model is 8.80%. The MAPE of June-2020 without the proposed integration is 7.03%, and after feature selection and the proposed integration model, the MAPE is optimized to 6.41%. Thus, the overall improvement of the proposed model is 8.82%. Figure 12 illustrates the actual vs. forecasted price of electricity for May and June 2020 with an average MAPE of each month.  In this section, the proposed system is discussed. This paper presented the FA-based EMS technique and achieved all the objectives. Figure 13 presents the overview of the FA regarding the cost of electricity related to its time slot. Here, the two-stage tariff plan has been used. Figure 13 shows the tariff plan implemented in the proposed system. The y-axis shows the tariff rate in Pkr and the x-axis shows the time slots. It is a standard two-level tariff plan. In 24 h, approximately 3 to 4 h are considered peak hours, from 7 pm to 11:00 p.m. In these peak hours, the price is approximately double. Due to this, all consumers utilize maximum appliances at this stage. Therefore, electricity demand is also higher at this time. To encourage power conservation, these tariff plans have been introduced so that in peak hours', customers must conserve electricity so that the cost of electricity and electrical stress on the national grid can be reduced.  Figure 14a presents the energy management of building 1 with and without FF. The y-axis shows the power consumption in kilowatt-hour and the x-axis shows the time slots. Here, the blue line represents the unscheduled load, while the red line is the scheduled load with firefly. In this graph, peak load has shifted from 1700 kw to 1100 kw. It reduces the peak load by 35%. It will also reduce the demand for power source capacity. Figure 14b illustrates the energy management of building 2 with and without FF. The y-axis shows the power consumption in kilowatt-hour, and the x-axis shows the time slots. Here, the peak of the load was at 2100 kw, but the proposed system shifted it to 1600 kw. So, in building 2, an overall 24% reduction in peak load has been observed. Figure 14c shows the energy management of building 3 with and without FF. The y-axis shows the power consumption in kilowatt-hour, and the x-axis shows the time slots. Here it can be seen that the maximum peak in building 3 occurs at 2300 kw. Therefore, the proposed system rescheduled the load and shifted it to 1600 kw. This is a 30% reduction in peak demand. Figure 14d exhibits the total energy management of all buildings and the objective of the proposed system. The y-axis shows the power consumption of all buildings in kilowatthour and the x-axis shows the time slots. Here, the unscheduled load is blue, while the second graph is an FA-based managed graph. As discussed earlier, the main objectives of the proposed system are to reduce the electricity cost and trigger peak reduction. The figure clearly explains that unscheduled load has various peaks. So, it has a higher cost per kilowatt-hour. However, the FA has managed this unscheduled load in such a way that its peaks are reduced.

Load Management
Although some of the load peaks are greater than the unscheduled load, the overall effect of the proposed system has reduced the electricity cost. An unscheduled load requires a 5400 KW power source, while a DSM-based load requires only a 3500 KW source. This means a total 35% peak reduction has occurred. Furthermore, cost and electrical stress on the national grid have been reduced.  Figure 15a presents the power cost comparison of building 1. The purple color represents a firefly-based scheduled load in this graph, while the black colored bar represents an unscheduled load. It is visible that FA reduced the cost of electricity per day from 190,000 Rs to 150,000 Rs, which is a 21% reduction in the bill for building 1. Figure 15b shows the power cost comparison of building 2. The y-axis shows the cost, and the x-axis shows the time slots. It is visible that FA reduced the cost of electricity per day from 210,000 Rs to 170,000 Rs, which is a 19% reduction in the per-day bill. Figure 15c illustrates the power cost comparison of building 3. The y-axis shows the cost and the x-axis shows the time slots. It is visible that FA has reduced the cost of electricity per day from 250,000 Rs to 200,000 Rs, which is a 20% reduction in the bill for building 3. Figure 15d presents the cost of electricity of three buildings in a single day. The y-axis shows the cost and the x-axis shows the time slots. The application of the proposed system for the DSM reduced the electricity cost from 650,000 Rs to 520,000 Rs approximately, which is approximately a 20% cost reduction and power saving.

Conclusions and Future Studies
PF is a crucial aspect for better planning and operation of power generation systems, as is the EMS proposed in the second part of the paper. A new combinational forecasting model based on time-series and auto-regression algorithms, ML-based feedback ANFIS, and a BGA-PCA algorithm is proposed for the best feature selection. This paper presents a novel time-series and auto-regression algorithm for analyzing the larger and more complex historical data. The time-series AR model is further validated by the ML-based feedback ANFIS model, where eight stages are computed. The BGA-PCA approach for attaining the best feature selection is evaluated and attained more optimized results. A remarkable improvement in MAPE of less than 10% in overall performance and an average MAPE of 9.24 has been achieved by a proposed integration that is significantly improved compared to previous ones. This model can optimize the performance of power grids by predicting the optimized PF and can overcome the problems related to the planning and operation of the smart grid.
Price and load forecasting are considered the main features of the revolutionary smart grid system, which helps to enhance electricity generation in a decentralized grid network. Providing reliable and uninterruptable electricity supply during peak hours facilitates the generation system by providing essential information on load and price forecasting. Therefore, this paper has made an effort to minimize peak load demand by load and PF analysis through the Machine-Learning approach.