Cost Efficient Real Time Electricity Management Services for Green Community Using Fog †

The computing devices in data centers of cloud and fog remain in continues running cycle to provide services. The long execution state of large number of computing devices consumes a significant amount of power, which emits an equivalent amount of heat in the environment. The performance of the devices is compromised in heating environment. The high powered cooling systems are installed to cool the data centers. Accordingly, data centers demand high electricity for computing devices and cooling systems. Moreover, in Smart Grid (SG) managing energy consumption to reduce the electricity cost for consumers and minimum rely on fossil fuel based power supply (utility) is an interesting domain for researchers. The SG applications are time-sensitive. In this paper, fog based model is proposed for a community to ensure real-time energy management service provision. Three scenarios are implemented to analyze cost efficient energy management for power-users. In first scenario, community’s and fog’s power demand is fulfilled from the utility. In second scenario, community’s Renewable Energy Resources (RES) based Microgrid (MG) is integrated with the utility to meet the demand. In third scenario, the demand is fulfilled by integrating fog’s MG, community’s MG and the utility. In the scenarios, the energy demand of fog is evaluated with proposed mechanism. The required amount of energy to run computing devices against number of requests and amount of power require cooling down the devices are calculated to find energy demand by fog’s data center. The simulations of case studies show that the energy cost to meet the demand of the community and fog’s data center in third scenario is 15.09% and 1.2% more efficient as compared to first and second scenarios, respectively. In this paper, an energy contract is also proposed that ensures the participation of all power generating stakeholders. The results advocate the cost efficiency of proposed contract as compared to third scenario. The integration of RES reduce the energy cost and reduce emission of CO2. The simulations for energy management and plots of results are performed in Matlab. The simulation for fog’s resource management, measuring processing, and response time are performed in CloudAnalyst.


Introduction
Electricity is categorized as a basic right or basic need for people in the world [1,2]. The increase in population and technological advancements has increased the global electricity demand, especially in last decade. The conventional power generators run on fossil fuels to fulfill the energy demand; however, a huge amount of CO 2 is released in the environment due to combustion of fossil fuels. The CO 2 pollutes the environment and causes greenhouse effect. The fulfillment of human need of energy without polluting the environment is challenging. The researchers have proposed variety of solutions for environment friendly power production, smart consumption of electricity, and intelligent mutual cooperation between supply and demand sides to optimize energy utilization.
Renewable Energy Sources (RES) help to reduce dependency on conventional power generators. Various countries have set plans to integrate RES with existing system in order to reduce load demand from conventional power generators [3,4]. The RES are preferred over conventional power systems due to cheap energy generation for a long time. The researchers proposed RES as sole power generation for commercial and residential sectors for geographic regions where energy infrastructure is not laid down [5][6][7]. RES are also integrated with existing system for economical benefits [8]. The RES on demand side reduce the dependency on conventional fossil fuel based power generators on supply side, hence reducing the emission of CO 2 . Currently, around 14% of world's power demand is being fulfilled with RES [3].
The RES are a not suitable permanent alternative of conventional power generators due to their intermittent nature [9]. However, the integration of RES based Microgrids (MGs) with existing system fulfills economical and environment friendly power demand. The Information and Communication Technologies (ICT) enables the supply and demand sides to aware of the situation to intelligently optimize the power utilization. The intelligent control of power generation, transmission, integration of distributed power generators and maintainability of power grid with ICT defines the Smart Grid (SG) [10]. Hence, a conventional power grid with the introduction of ICT is defined as SG and MGs are small scale distributed power generators [11,12]. The autonomic, sustainability, and scalability of SG has the potential to integrate cheap, environment friendly, and distributed RES based power generators. In view of this, around 179 countries, including Germany, U.S.A., and the Republic of Korea have set their target for the years 2017, 2020, and 2030 to fulfill full or part of energy demand with RES [13]. The governments offer subsidized RES to their public for social welfare to reduce the dependency on conventional power generators. However, willingness to payback was not considered consequently, in 2012 Spain stopped subsidizing on PhotoVoltaics (PV) power generators and European countries partially stopped such schemes [14,15]. Hence, energy trading strategies are inevitable to integrate RES in existing power system for the fulfillment of economical and environment friendly power demand. The researchers have proposed tools, platform and strategies to provide optimized energy management on the demand-side by evaluating and analyzing data for academic research in SG [16][17][18].
The optimized power utilization demands efficient energy management. Centralized, decentralized and distributed electricity managements are proposed by the researchers, which optimize the power utilization for proposed scenarios [19]. The analysis of collective behavior for power utilization is very complex for very short period of time or real-time in distributed and decentralized approaches. A centralized infrastructure is crucial for efficient power management for communities. The ICT has enabled the power controlling devices to communicate and manipulate at centralized computing platform (e.g., cloud) to optimize power utilization in SG [20]. Distributed and decentralized systems require centralized computing platform for analysis of various parameters for power management services [20,21]. Hence, a centralized computing platform is inevitable to provide analysis based optimized services to masses in the SG.
The cloud based platform provides on demand economical physical and virtual resources for computing services without investing for maintenance. The scalable infrastructure of cloud allows for the addition or removal of computing resources, depending on the requirements. A variety of services can be provided from single cloud infrastructure. Resource sharing and heterogeneous services provision from single platform reduce computing cost. The cloud has efficient processing and economical as compared to on-site and customized systems. However, it also has limitations, especially for the provision of real-time services. The limitations are enlisted below, • heterogeneous services and too many requests increase the Processing Time (PT) [22], • the physical long distance between end-user and physical cloud infrastructure increase the Response Time (RT) [23,24], • high computation heats the physical resources, which are cooled by high powered air-conditioning systems, which increase service cost [25], and • economical and environmental friendly huge power generation is challenging [26], especially for increasing demand of computing devices and cooling system data center is challenging [27].
The data centers of big companies, giants like Google and Facebook, have plans to installed their cloud data centers in cold regions to avoid expensive and high power cooling systems [28,29]. The long physical distance between end-users in hot regions and the physical cloud infrastructure in cold region increases the RT due to locality issues [24]. However, power applications are time-sensitive [30,31] and the real-time services from cloud infrastructure become a challenge [32]. Hence, from the literature, it is learned that the integration of renewable energy, real-time, and economical power management services for a community are challenging.
This work is an extension of our conference paper [33] in which two case studies are proposed. In this paper, three scenarios and a contract (policy) for energy trade are proposed. The contract ensures the participation of available distributed power sources with reduced cost of energy consumption. The participation of PV based RESs during the day reduce the cost of energy. A mechanism is proposed to calculate the energy that is required to provide computing services by computing resources and cooling system of a fog. A system model is proposed in which fogs of communities store energy data on cloud. The data is usable for future projects, e.g., prediction, analysis, evaluation, and feasibility, etc. The fog equipped with green (renewable) energy for a community provides near real-time response with environment friendly power management services. However, huge computing resources installed for communities of distance locations, e.g., cloud emit heat in the environment and affect it. Hence, the proposed system model is suitable for environment friendly and near real-time response.
The hierarchy of this paper is presented in following sections. Related work is given in Section 2 and, in Section 3, Proposed System Model is elaborated. Case Studies are presented in Section 4 and the Conclusion is presented in Section 5.

Related Work
The SG applications are time sensitive and real-time energy management solutions are challenging, especially for masses on the demand side [30,31]. The communication between demand and supply sides in real-time ensures efficient energy utilization. Kong et al. [34], propose a radio frequency based networked communication for a community. The residents generate and store renewable energy and share with neighbors for cost efficiency. The device-to-device communication form a network, which follows the topology of SG. The optimality of channel utilization to ensure the participation of maximum mobile units with minimum transmit power of sensors is the main idea. The authors have attained significant outcomes; however, the size of maximum participants, communication delay, and their effects have not discussed in particular. In SG applications, a huge number of power users need to be updated simultaneously to change in parameters' values. For instance, pricing on the supply side is updated and the power users need to modify their usage accordingly. The huge traffic on communication medium and network nodes creates bottleneck and power users suffer from delayed information. Wang et al. [35] and Khaled et al. [36] propose 5G and 6G technologies for huge data transfer rate and high bandwidth. However, these technologies are not mature and they are under research and development phase.
Zepter et al. [37] proposed a platform in which prosumers of a community trade battery based stored energy. The batteries are charged from renewable and utility power sources. The framework allows for peer-to-peer energy trading and incentive the prosumers by giving them chance to reduce energy cost. The proposed platform allows prosumers to participate in whole sale power market. The price of prosumers' energy trade is lesser than price of the utility. The proposed peer-to-peer energy trading is implemented in a residential building in London. The study shows 20-30% reduction in electricity bills and battery storage saves almost 60%. The platform allows for each prosumers to trade the energy with peers; however, they are connected with grid power lines. The energy trade with utility and other distance power users using the power lines can increase the integration of renewable energy, efficient utilization of storage system, and maximize the incentives.
The participation of residents of a community equipped with small scale power generation units reduce the demand load on supply side. The trade of small scale energy forms self-dependent community. However, defining contract between producer and consumer is necessary. The authors in [38], proposed contract game for energy trading in SG. A direct trading contract is defined to minimize the energy cost for prosumers. A theoretical contract for deterministic environment considering short-term market is proposed, which, later extended for long-term market. In long-term, the high uncertainty of small scaled energy production is considered. The incentives for energy producers and consumers with direct contract encourage the maximum participation of producers and consumers. Qin et al. [39] also propose contract for flexible market. The objective is to have minimum communication and control responsibilities on energy operators in distribution system. The high flexible energy market is balanced with Arrow-Debreu, which encourage the traders to maximize their participation and minimize the intervention of system operators.
The authors left open questions for readers by discussing the limitations of proposed framework.
The energy trading mechanism helps to integrate renewable power with existing system for a smart community. The individual renewable power production microgrids may have significant impact to reduce maximum power cost with high integration of renewable or green energy. Chen et al. [40] propose a centralized energy management for electrical vehicles. The service maximize the incentives for maximum participation by defining the optimized choice between energy consumption and trading. The cloud provides the service for communities whenconsidering electrical vehicles, energy storage systems, and distributed renewable energy sources for customized energy pricing. The authors formulate a binary linear programming model and the performance is evaluated in experimental setups. The effects of participation of storage system, electrical vehicles, and smoothness of fluctuations for demand response of electrical vehicles are discussed in detail. The PT of the service on the cloud almost doubles for every addition of 500 participants, measured in seconds. The authors claim the significant smaller PT as compared to day-head period; however, the response time for end-power-users are not discussed. Long physical distance between cloud data center and end-users requires multiple computing network nodes. The processing on each node and data transfer (from end-user to cloud and back to end-user) cause the latency and increase the response time for end-users [41]. The time sensitive, like power applications, are prone to compromising the performance.
Cloud infrastructure is scalable and it consists of large number with huge sizes (operation capabilities) of physical computing devices. Such huge infrastructure is capable of providing high computation in fraction of time, even for the analysis of huge data [42]. The power demand of such data centers is 1.5% of world's total demand with annual growth rate at 4.3% [27]. These data centers produce equivalent heat, which is controlled by cooling systems. The cooling systems consume 30-60% of total demand of data centers [43]. Researchers have proposed various solutions to reduce energy demand for data centers. Toprak et al. [43] develop a software tool to estimate the power demand for data center with optimized cooling system. The considers location, type of building, electronic equipment, and setup environment (indoor and outdoor) of the system for energy and cost estimation. Jawad et al. [44] propose an optimization of workload in data centers in coordination with multiple power sources, e.g., batteries, renewable energy generators, diesel generators, and utility to reduce the energy cost. The authors minimize the dependency on fossil fuel based power generation for data center operations. Similarly, Xu et al. [45] propose a task scheduling algorithm that is based on enhanced reinforced learning and neural network. The job scheduling and the renewable power supplies reduce the energy cost for data centers. The summary of related work wor is described in Table 1.

Authors Proposed Solution Limitations
Kong et al. [34] Radio frequency based device-to-device communication following the topology of grid. The residents of the community are allowed to generate and trade renewable energy in peer-to-peer fashion.
The number of participants and effects of communication delay on energy trade are essential to identify.
Zepter et al. [37] Proposed a platform for prosumers to trade battery based energy while connected with utility power lines. Prosumers participate in whole market and peer-to-peer trade is perfromed The platform has potential to increase the energy trade by introducing centralized computation for cost efficient energy utilization. Moreover, prosumers may trade with more suitable distant consumers.
Zhang et al. [38] Game based energy contract for prosumers is proposed to encourage maximum participation by signing direct contract.
The contract is proposed for small scale environment.
Qin et al. [39] Proposed energy contract for flexible market.
The authors left open questions for identification of possible limitations.
The minimum intervention of system operators, controllers and reduced communication lead to security issues.
Chen et al. [40] Proposed cloud based centralized energy management service. The integration of renewable energy from electrical vehicles and storage systems is maximized by incentivizing using power trade mechanism.
The processing time increases with the increase of participants which increase the response delay. The delayed response has negative effect on the system.
Toprak et al. [43] and Jawad et al. [44] In [43], a software tool is proposed to estimate power demand by data center with optimized cooling system. In [44], optimization of workload in data center considering various power source, e.g., renewable power and fossil fuel based power generators The software based tool may not include all parameters required for energy optimization, e.g., as authors did in [44]. However, method in [44] may require some software or simulator to estimate the cost.
Xu et al. [45] Proposed reinforced learning technique to schedule the tasks on computing resource in data center. Authors proved reduced energy consumption with efficient resources allocation for computation.
The authors did not discuss the load of tasks for suitable efficiency of scheduling of job The limitations of energy management services for communities in the literature encourage to propose a system with real time power management service for communities. In this paper, a fog based system model is proposed, which allows end-power-users to directly communicate with the fog. The communication takes place on high bandwidth (4G and 5G) wireless medium. The network latency with 5G reduced to almost zero; however, the execution time depends on the computing devices. The efficient resource utilization algorithms reduce the execution time and consume efficient energy. The fog performs energy management for the residents of a community. Three scenarios are proposed to evaluate the cost efficient energy usage for community and fog's data center. A mechanism for calculating the power required for running of computing resources to execute the service and cooling system for fog's data center is proposed. Lastly, a contract is proposed to ensure the participation of renewable power generators and the utility.

Proposed System Model
A systematic overview of proposed system in given in Figure 1. The residents of each community have two power supplies; RES based MG and the utility for demand of their homes. The MG is placed in the vicinity of respective community to reduce power losses. The utility is used for backup when the MG is down or to be used with other power sources under the contract signed between utility and end-power-users. The energy management services for residents of the communities are provided by the respective fogs. The physical setup of each fog is installed near or within the respective community, so that each resident has direct access (at first hop) to the computing resources. The energy management services or programs are installed in the fogs, which are run on virtual machines. The virtual resources are programs that mimic physical machines and they are used to share physical resources. The resource sharing reduces the computing cost for the services as well as efficient utilization of the physical computing resources. The residents of a community request the fog for the power management services. Each request is entertained in fog and responded back via 4G or 5G wireless and wired technologies. Each fog is connected with a cloud via Internet for data storage, which can be analyzed for future and other related to power projects.
In this paper, three scenarios are considered for the proposed system model. In first scenario, the power for the physical computing resources of fog is only supplied from the utility. The community is also dependent on utility power supply. In the second scenario, a fog has two power supplies; renewable electricity from the community and from the utility. In the third scenario, the fog owns RES based MG (FMG); it also connected with communal MG and with the utility. The cost of utility power fluctuates depending on demand; however, it is always higher when compared to RES based power. The RES generate energy from free natural sources, e.g., wind, sun, etc., while, utility generates expensive electricity by running fossil fuel based power generators. The increasing power demand increases electricity cost due to greater fuel consumption. The fuel combustion releases CO 2 , which pollutes the environment. Hence, generating expensive power by damaging the environment. A contract based energy trade is also proposed to integrate all power sources, e.g., utility, MG, and FMG to fulfill power demands of the community and fog's data center.  The innovation of this paper is highlighted by comparing the identified problems of existing research and proposed solution in Table 2.

Problems Identified Proposed Solution
Chen et al. [22], proposed cloud based energy management model. The PT increases with the increase of customers (e.g., from 500 to 1500 customers), moreover; authors do not discuss the effects of RT.
Fog based energy management model is proposed. The end-users are directly connected with the fog for power management services. The computing resources of fog are sufficient for requests of 300 SHs to process and response in near real-time.
Miodrag et al. [24], validate the efficiency of fog based monitoring and control service in SG as compared to cloud. Authors claim potential of fog based system with real-time monitoring and controlling in SG. However; prime focus is communication protocol for real-time monitoring.
Fog based energy management services, PT and RT are computing for a community of 300 SHs.
Saeed et al. [25] propose game based thermal aware resource allocation in data center (cloud) to reduce the emission of thermal energy due to high computation. Authors claim the proposed technique avoid creating hotspots as compared to counterpart strategies. The services run by the data center and possible amount of thermal energy produced are not discussed.
A mechanism to calculate the amount energy produced due to computation in fog's data center explained. Moreover, the relationship between energy produced due to computation and power required for cooling system for power management services is proposed.

Problems Identified Proposed Solution
Authors in [46] propose VM placement technique to reduce carbon emission from cloud data centers. Green energy is beneficial to reduce carbon, however; huge platform of cloud requires an agreement between users and cloud service providers. Authors claim reduced energy cost, reduce emission of carbon and suggest integration of green energy for cloud data center. However, agreement of integration of green energy is not proposed.
A modified honey bee colony optimization technique is used to balance the load on VMs to enhance the computing efficiency. An agreement (contract) is proposed to integrate utility (fossil fuel based power generator), RESs based MG for community and FGM. The contract reduce energy cost and encourage the integration of renewable energy with incentives to the participants.
Thiago et al. in [27] conducted an intensive survey on energy efficiency and demand response for small and medium data centers. Authors claim that large data center have potential to participate in energy efficient demand response program; however, small and medium data centers are more adoptive for the program. The violation of energy policies by energy consumers also have negative impact.
Proposed system model with energy management services validate the claim of suitability of medium (fog's) data centers for energy efficiency. Moreover, the proposed energy contract runs on the fog as service, which avoid the interruption of end-power-users.
The authors in the above articles in this column discuss either computing platform or energy management. None of the author has proposed efficient solution for considering both.
In this paper, a system model is proposed for energy management service for community of 300 SHs. Energy management services are proposed considering different power sources to reduce energy cost by integration of green energy and incentive policy. The power demand for computing environment is calculated and fulfilled with multiple power sources with minimum cost.

Problem Formulation
In first scenario, the electricity demand of the community and the fog is fulfilled from utility. If the size of community is H number of Smart Homes (SHs) (H = {h 1 , h 2 , h 3 , ..., h H }) and the total power demand in a given time t is the sum of load of all homes (L t H = {l t h1 + l t h2 + l t h3 , ..., l t hH }). The total electricity cost (T t ct ) of the community is calculated with Equation (1). The cost of power consumption of a fog depends on the load demand for computing resources and cooling or air conditioning system. The energy cost of the fog is calculated with Equation (2).
where, T t f is total cost of the fog, U t p is utility price, L t cr is load of computing resources, and L t ar is the load of air conditioning system at time t.
In second scenario, the surplus renewable energy of communal MG (S t ct ) is bought for the fog. S t ct is the difference of energy produced by MG M t E and the total community demand C t D at time t, as shown in Equation (3).
The energy demand by a fog (F t D ) for time t is the sum of load of L t cr and L t ar . The energy price of MG (M t p ) is cheaper than the utility (U t p ). The S t ct is traded with the fog or with the utility or both of these.
then, remaining load for the fog is bought from the utility at U t p . Similarly, then, remaining power of surplus energy is sold to the utility at electricity price of the MG M t p .
then, all of the surplus energy is only bought by the fog at MG's price (M t p ). In third scenario, the fog also owns RES based MG to ensure greener computing for fog services. The fog's computing performance varies the energy demand; moreover, the power output of FMG is also affected by natural sources, e.g., intensity of sun light, wind force, etc. The varying power demand by the fog and fluctuated power production by the FMG might have imbalanced energy generation. The imbalance is cured by trading the surplus energy −S t f with the community or with the utility; however, deficient power (S t f ) is bought from the community MG or from the utility. The Equation (7) shows the surplus energy of FMG, where F mg is FMG's produced energy.
The relationships among prices of electricity for FMG (F t p ), community MG, and the utility are given in Equation (8).
The fluctuated power generation from MGs and varying energy demand by the fog constitute three situations. In the first situation, the power generation of FMG L t f is greater than fog demand as given in Equation (9). In this condition, surplus FMG's is traded with the community or with the utility. In the second situation (Equation (10)), FMG generates less power than demand of the fog. In this condition, the remaining energy is bought from the community MG or from the utility. However, the green power of community MG is preferred over the utility due to lesser price than electricity price of the utility. In third situation (Equation (11)), FMG's power generation is equal to the energy demand by the fog. The whole energy is utilized to fulfill fog's power demand.
It is stated earlier that the fog's physical resources are shared by creating virtual resources on them. The virtual resources are computer programs, which mimic the actions of a machine; hence, also known as Virtual Machine (VM). These programs continue to run on the physical resources, even in the idle condition. The energy consumed by physical resources is calculated by measuring the execution of Millions of Instructions Per Second (MIPS). The actual energy consumption is measured by observing the active and idle states of VMs. An idle VM consumes 60% energy of active state [47]. The energy required during active state is 10 −8 × (MIPS) 2 Joules per Million Instructions (J/MI). The mechanism of efficient resource allocation optimizes the energy consumption by computing resources. Various techniques have been proposed to efficiently allocate the VMs [46,[48][49][50].
The power that is required to run VMs (in idle and active states) is converted into an equal amount of heat energy [51]. The thermal heat surround the servers in data center and increase the temperature, which compromise the performance of physical computing resources. The performance of hardware affect the computing performance, which compromises the service execution. The cold air is passed through server nodes in the data center to cool down the computing devices. The phenomenon of heat circulation or thermodynamics in the environment of data center is explained in detail in [25,52].

Contract for Energy Trade
In the case of multiple power generators, one of them can have maximum participation, which affects the contribution of other generators. For example, in the third scenario, if community MG fulfills the whole power demand of the community and fog's data center then the participation of the utility is idle. In view of this, to ensure the participation of all participants, an efficient energy contract is necessary to be defined. In proposed system model, during the day, community MG generates maximum power. The part of it is traded within the community, with fog's data center and the remaining is sold to the utility. Gai et al. [53] propose approximate maximum estimate model to estimate the maximum value for tradable energy of a certain time-slot. However, in this paper, a fixed percentage of MG's energy is proposed to trade for every time-slot. The maximum threshold (α max ) to trade within the community is 65% of MG's total produced energy (M t E ) for every time-slot (hour). The remaining power is sold to the utility and to the fog's data center. The amount of power from community MG to be traded with the utility and the fog (E t Tu f ) is found with Equation (12). where, The cost of power trading is the product of amount of energy traded and the price M p (from Figure 2) as shown in Equation (14). The E t Tu f energy of community MG is sold to the utility and the fog's data center at M p price. The cost (C t Tu f ) of energy trade with utility and the fog is calculated with Equation (14).
The fog only buys energy when FMG is unable to fulfill the demand or when S t f > 0 with Equation (7). If S t f > E Tu f , then E Tu f is bought from the community MG and remaining (S t f − E Tu f ) is bought from the utility. The energy bought for fog's demand (F D ) is the sum of FMG's energy, the amount of power bought from community MG (∆E Tu f ), and amount of energy bought from the utility (∆E u ), as given in Equation (15). where, and ∆E Tu f is amount of energy which is bought complete when S t f > E Tu f to fulfill F t D . Where, F D = L t cr + L t ar . The cost of fog's demand C FD is calculated with Equation (17), The total energy cost for community MG (C cmg ) is computed with Equation (18). However, C Tu f is excluded from the power cost of the community as incentive.
The utility energy cost depends on the cost of the amount of energy produced from fossil fuel based generators (∆C f uel ), cost of energy bought from the community MG (∆C cmg ), and the cost of amount of energy bought from FMG (∆C f mg ), as computed with Equation (19). The cost of fossil fuel based energy depends on amount of fuel consumed to produce desired (for demand) electricity, while considering factors, like heating and fuel cost, etc. This is calculated with quadratic function, as given in Equation (20) [54].
where, a, b, and c are the coefficients of heat and amount of fuel, etc., which effect the throughput (U out ) of fuel generator. The integration of green energy (e.g., Equations (13) and (15)) compels the utility to generate lesser power than the total demand. The utility runs fossil fuel based power generators (e.g., diesel), which emit CO 2 . Lesser power generation reduces the running of the generators as a result emission of CO 2 is reduced. In this paper, the utility power pricing U p for a day is considered, as given in Figure 2.
During the day, the fog stores surplus green energy and sells remaining (more than demand and storage). After the sun-set stored energy is utilized for computing and cooling systems. The storage capacity ST cap is greater than F D . In addition to this, the community relies on the utility power supply after the sun-sets. From the load basis of the community in Figure 3, the power demand of the community gradually reduces after the 20th and before the sixth hours. Hence, the power demand that is fulfilled from the utility during these hours is almost less than the demand during the day from the utility (after the integration of 35% of RES energy).

Case Studies
In this paper, the size of community for all three scenarios is considered 300 SHs. The power demand of each home ranges 0.5 to 1.5 of smart home demand basis given in Figure 3 [55]. In second and third scenarios, the average PV power that is required for a home is 0.4 to 1.4 of power basis given in Figure 4 [55]. The capacity of community MG is the sum of PV power generation of all SHs in the community. In the third scenario, the surplus energy of FMG is stored in energy storage system to be utilized after sunset. However, during the day the surplus energy is traded with the community or with the utility. The utility energy price for every hour of the day is taken from [55]. The community MG trades power at 70% of the utility prices and FMG trades at 50% of the utility prices as shown in Figure 2 to encourage the maximum integration of green energy with the utility. The energy management services of proposed scenarios run on the fog. The specifications of the fog are given in Table 3.  In this paper, CloudAnalyst and Matlab are used for the simulation of case studies. In CloudAnalyst PT and RT for the requests generated from the community residents are measured. The fog data center and the community belong to the same region; however, Internet characteristics are defined according to the choice of generation of technology (e.g., 4G, 5G, etc.) and the system model. In proposed case studies, 4G and 5G based data transfer rates (Million Bits Per Second (Mbps) and Giga Bits Per Second (Gbps), respectively) are implemented. Matlab is used to simulate the energy use by the community and the fog for all three scenarios. Moreover, the results are also plotted using Matlab. Figure 5 shows the flow of implementation of whole process. The SHs of the community sent requests every hour for energy management to the fog. The requests are allocated to VMs by balancing the load on them using intelligent load balancer, e.g., modified honey bee colony optimization. The load is shifted from higher loaded VMs to the lesser loaded VMs. The VMs mimic the function of a physical machine hence, each VM runs energy management program independently. The VMs enhance the computational efficiency of a single physical computing unit. The parallel execution of VMs with balanced load of requests (tasks) reduce the overall PT. In this paper, four energy management scenarios were performed in case studies. In first scenario, Equations (1) and (2) are used to calculate the energy cost of fog, e.g., computing cost and cost of cooling system, respectively, by evaluating power demand and energy pricing (of utility). In second scenario, VMs find the difference of community power demand of energy produced by the MG with Equation (3), which helps to manage energy by trading or buying or self-sufficient following the conditions of Equations (4)- (6). In the third scenario, unlike second scenario, fog owns a MG. Equation (7) finds the difference of fog demand and load of FMG. The pricing for energy trade must follow the condition given in Equation (8). The conditions given in Equations (9)-(11) help to trade power of FMG to fulfill fog demand. In contract based energy trade, the Equation (12) calculates the MG's trading amount of energy with the fog and the utility. Equation (13) finds the amount of MG's energy utilized within the community. Equation (14) calculates the cost of MG's trading energy. The fog's power demand is fulfilled with Equation (15) following Equation (16). The fog's power demand is fulfilled from different power sources; hence, the energy cost is calculated with Equation (17). The total energy cost community MG is calculated with Equation (18); however, the cost traded within the community is utilized as incentives. The proposed contract integrates the power generated by FMG and MG with its own generation and reduces the production cost calculated with Equation (19). Each VM runs services of the scenarios following the proposed equations and respond the power users (SHs).

Request=300
Time=Hourly (1-  In the proposed system model, unlike cloud, the physical infrastructure of fog and power users in the community are at the first hop. In cloud based infrastructure there are multiple computing nodes between end-users and cloud's data centers. Hence, cloud based infrastructure has high network latency as compared to fog's infrastructure. The requests sending time from the power users to the fog for energy management service is near real-time. The communication medium also affects the network latency. The data transfer rate of 5G is 100 times that of 4G [56,57]. Hence, requests sending with 4G is measured in milliseconds (ms), while, with 5G, it is measured in microseconds (µs). There is virtually no time delay with 5G; however, with 4G huge data may take longer time (e.g., in seconds or minutes). Once the request is sent to the fog, the processing time depends on the computing devices, architecture, and type of service. The simulation results are given in Table 4. The simulations of 7200 requests from the community in a day require an average of 0.48 ms to process the service. A modified honey bee colony optimization algorithm [58] is used to efficiently allocate the virtual resources. Hence, it is assumed that, during the processing, all VMs were in active state. The maximum time taken by a VM (T vm ) is the total execution time (T et ) divided by the total number of VMs Equation (21).
where, T et = 7200 × 0.48 = 3456 ms (22) and When considering the speed of a VM given in Table 3, 6.912 Millions of Instructions (MI) are executed in 3456 ms. Using the Equation (2) of [47], each MI requires 10 6 Joules of energy when a VM is active. Hence, a total of 5 × 10 6 Joules is required for service execution in 3.456 minutes when VMs are active. The rest of the time VMs remain inactive and consume 60% of active state, as discussed above (1247 × 10 6 Joules). The total energy that is required for the fog is the sum of energy required by VMs during active and inactive states. According to the law of conservation of energy, the amount of power consumed is converted into equal amount of thermal (Joules) energy [51]. Hence, the amount of thermal Joules produced during the active and inactives states of VMs requires an equal amount of power (L cr ).
Various factors, e.g., indoor and outdoor temperature, power demand for cooling the data center, and execution of servers in the data centers, etc., are considered for designing the cooling system of data center [43]. A big portion of budget is spent on cooling the system of the data center [59]. In the proposed case studies, it is assumed that equal budget is allocated for cooling system, which defines the cost that is required for power consumed for execusion of requests. The cost of the cooling system is measured by the amount of required power load multiply by the energy price of the power supplier, e.g., the utility, MG, etc. The efficiency of cooling system is measured in BTU (British Thermal Unit), which is equal to 1055 Joules [60]. In this paper, it is assumed that the initial state of temperature of the data center should be maintained. Accordingly, the number of thermal Joules produced requires equal amount of power for cooling system to neutralize the change of heat in the data center. Hence, the total power that is consumed by the fog is the sum of energy required for computation (L cr ) and cooling or air conditioning system (L ar ). The energy management service is executed every hour in the day. The energy demand by the fog is also equally divided for every length of time t, e.g., t = 1 h.
The total power demand of community residents and the fog is given in Figure 6. In the first scenario, the community and the fog only consume power from utility. The utility prices depend on the power demand; the higher the demand, the higher the energy prices, as shown in Figures 2 and 6. In the second scenario, the community has PV based MG. The power of MG is supplied to the community at 30% lesser price as compared to the utility. The community demand is greater or lesser than MG's power generation. The power produced more than the demands of the community and the energy of FMG is sold to the utility to incentivise the community. In the proposed case studies, for the third scenario, the community fulfills the demand similar to second scenario. However, surplus renewable or green energy is first sold to the fog when FMG is unable to fulfill its demand; otherwise, it is sold to the utility. The FMG fulfills the demand of fog and surplus power is sold to the community when demand is greater than MG's generation. In second and third scenario, the fog minimizes the energy cost by consuming green energy. However, in third scenario, fog reduces energy cost by consuming power either from FMG or MG as well as combined energy from FMG, MG, and the utility. The trade of surplus energy of MG reduces the community power cost. Similarly, the trade of FMG's surplus energy reduces the power cost for the fog. The surplus energy of FMG of last two hours (e.g., 19th and 20th hours) is stored in batteries to be utilized after sun-set. In Figure 7, the cost of power consumption by the utility and the fog in first scenario is the highest when compared to second and third scenarios. The cost in first and second scenarios are the same before the sixth and after the twentieth hours. The cheap energy of MG and trade of surplus power of MG with utility and the fog reduce the significant cost for the community during the day. The simulations show the lowest power cost for third scenario. The energy from MG and FMG are utilized for the community and for the fog; however, the remaining power is bought from the utility. The trade of surplus energy from MG and FMG help to reduce the extra cost as compared to first and second scenarios. In Figure 7, the cost with third scenario after 20th hour until the 23rd hour is less than other scenarios. The stored surplus energy of FMG is utilized after 20th hour (after sun-set).

Case Study: Energy Trade
The proposed contract is simulated for third scenario in which community and fog own their renewable MGs as well as they are connected with the utility. According to the contract, 65% of produced energy of community MG is traded within the community and the rest is sold to the utility. However, deficient power demand is bought from the utility and the FMG. The power demand for fog's data center is fulfilled with FMG and surplus power is sold to the utility. From Equation (15), power is not bought from the utility and community MG for the fog. Hence, in Figure 8, the amount of energy that is bought from the utility, FMG, community MG for community demand and amount of power sold to the utility from community MG is shown. During the day, the PV power is utilized (consumption and trade) and after sun-set the power from the utility is utilized. From Figure 6, the community's power demand is maximum during the day. Accordingly, the renewable energy trade, according to the contract, reduces the fossil fuel based power generation by the utility. The community is incentivised by reducing energy cost due to power trading of community MG.
The cost for power demand of the community with third scenario and with the proposed contract are shown in Figure 9. The renewable power is generated free of cost due to natural sources, e.g., sun light. However, the infrastructure and maintenance have cost, which are earned by providing cheaper energy. Hence, the energy sold out of the community is the incentive for the community. The contract based power utilization in the community is cost efficient as compared to the third scenario. The third scenario in Figure 7 has lesser cost for three hours when compared to first and second scenarios after 20th hour due to stored energy utilization of FMG. Similar is the case with contract cost in Figure 9; however, the contract cost is more efficient when compared to the third scenario due to energy trade incentives.

Summary of Proposed Solution
The cloud based energy management services suffer from latency issues. Multiple nodes between end-users and physical computing environment increase the RT. However, SG applications are time sensitive. In the proposed system model presented in Figure 1, end-power users (community) are directly connected with the fog, which reduces the network latency. The efficient resource utilization of computing resources reduces the PT. Hence, reduced network latency and PT provide a time efficient energy management service to the community. The results of efficient computing resources utilization and direct connectivity of the community with fog advocate the near real-time response of energy management. In this paper, three scenarios are proposed to fulfill the energy demand of the community and the fog's data center. The simulation results show that the integration of RES based MGs reduce the energy cost. The energy trade of surplus energy reduces more cost for end power users due to incentives. In the third scenario, apart from the utility, the fog and community also own RES based MGs. Hence, the results show that third scenario has the more cost efficient energy for the community and the fog. However, the proposed contract ensures the participation of all power sources. The results advocate the cost efficient energy is provided to the community and to the fog's data center as compared to third scenario. Hence, the proposed energy contract ensures the integration of RES with minimum cost for power users, e.g., the community and the fog's data center. The summarized mapping of limitations of exiting solutions and results validation of proposed solution is given in Table 5. Load on computing resources are balanced intelligently (e.g., Modified Honey Bee Colony Optimization) for efficient utilization. The Table 4 shows very small average PT due to efficient resource utilization L3.2 Increase service cost: high power demand due to computation and cooling system(s)

S3.2
Installed RES based FMG and connect with community MG for cost efficient power supply. The Figure 7 shows the cost efficient power in third scenario and in Figure 9 the contract based energy is cost efficient due to RES based MGs.

L4
Expensive fossil fuel based power supply from the utility S4 Contract for energy trade is proposed to integrate utility, MG and FMG cost efficient and environment friendly power supply. The Figure 8 shows integration of renewable energy during day to fulfill power demand. The Figure 9 shows that contract based energy consumption is more cost efficient as compared to third scenario

Conclusions
In this paper, a fog based system model is proposed for the community to provide near real-time energy management service. The high bandwidth of 5G almost nullifies the data transfer delay. However, with 4G, a minute delay is observed due to 100 times lesser data transfer capacity as compared to 5G. The efficient resource allocation technique, like MHBC, minimizes the PT. The reduced data transfer delay and reduced PT minimize the RT for residents of the community. Three scenarios are proposed to analyze the cost efficiency of power utilization by the integration of green energy. In the first scenario, the community and the fog are connected with the utility only. The power generators of the utility run on expensive and environment unfriendly fossil fuel. In second scenario, the community has PV based MG along with the utility. The community's demand is fulfilled with green (MG's) energy. The surplus energy is traded with fog and the utility; however, deficient power is bought from the utility. In the third scenario, the community and fog have their respective PV based MGs along with the utility. The surplus energy of FMG is traded with the community or with the utility. The simulations of case studies show that the third scenario is more cost efficient as compared to first and second scenarios. The integration of green energy reduces power consumption cost for the community and reduce the power demand from the utility. The storage of green energy reduces the additional cost for the fog after the sun-set. The green data center of the fog and the community with green MG in the third scenario save up to 1.2% and 15.09% of energy cost as compared to second and first scenarios, respectively. In this paper, the proposed energy contract ensures the participation of all stakeholders and it is 6.54% more cost efficient for the community as compared to third scenario.
We recommend proposed distributed centralized energy management system model instead of cloud based centralized system. The heating of huge data centers of cloud in cold region affects the environment. However, distributed small data centers with green energy have a negligible impact on the environment. It is studied that the potential of integration of green energy with existing system is high when friendly energy policies are defined. For example, an individual renewable power producer can fulfill the demands of his neighbors or trade with the utility. However, in a community the trust building among producers and consumers need to be ensured by defining power trade policy. In the future, block chain based trust building mechanism among prosumers, consumers and power utility in a community shall be considered. Moreover, the power economy sharing approach should be considered to form communal MG out of existing renewable power generators among the prosumers.