Eﬃcient Resource Allocation Model for
Residential Buildings in Smart Grid using Fog
and Cloud Computing
Aisha Fatima1, Nadeem Javaid1,∗, Momina Waheed1,
Tooba Nazar1, Shaista Shabbir2, Tanzeela Sultana3
1COMSATS Institute of Information Technology, Islamabad 44000, Pakistan
2Virtual University of Pakistan, Kotli Campus 11100, Azad Kashmir
3University of Azad Jammu and Kashmir, Kotli 11100, Azad Kashmir
∗Correspondence: email@example.com, www.njavaid.com
Abstract. In this article, a resource allocation model is presented in
order to optimize the resources in residential buildings. The whole world
is categorized into six regions depending on its continents. The fog helps
cloud computing connectivity on the edge network. It also saves data
temporarily and sends to the cloud for permanent storage. Each conti-
nent has one fog which deals with three clusters having 100 buildings.
Microgrids (MGs) are used for the eﬀective electricity distribution among
the consumers. The control parameters considered in this paper are: clus-
ters, number of buildings, number of homes and load requests whereas
the performance parameters are: cost, Response Time (RT) and Pro-
cessing Time (PT). Particle Swarm Optimization with Simulated An-
nealing (PSOSA) is used for load balancing of Virtual Machines (VMs)
using multiple service broker policies. Service broker policies in this pa-
per are: new dynamic service proximity, new dynamic response time and
enhanced new response time. The results of proposed service broker poli-
cies with PSOSA are compared with the existing policy: new dynamic
service proximity. New dynamic response time and enhanced new dy-
namic response time performs better than the existing policy in terms
of cost, RT and PT. However, the maximum RT and PT of proposed
policies is more than the existing policy. We have used CloudAnalyst for
conducting simulations for the proposed scheme.
Key words: smart grid, cloud computing, particle swarm optimization,
Utilization of advanced Information and Communication Technology (ICT) in
Demand Side Management (DSM) has been considered as one of the main char-
acteristics of Smart Grids (SGs) . Bi-directional ﬂow of energy and communi-
cation has been done by SG to get information of users and to distribute energy
between consumers. The traditional grid is converted into a SG to reduce the
2 Aisha Fatima et al.
Carbon Dioxide (CO2). The number of devices have been utilized on the de-
mand side. Many new concepts including Electric Vehicles (EVs) charging and
discharging, intelligent home appliances, smart meters and so on have been used
in DSM in the SG environment .
Cloud computing is generally associated with the services of the internet. The
internet has connected to the world. Users can transfer a large amount of data
and can also enjoy new technologies and services provided by the cloud at any
time and any place . Cloud computing has provided various facilities including
minimum cost, maximum speed, high performance, and elasticity. Cloud can
be public, private or hybrid. Netﬂix, skype, emails, microsoft oﬃce 365 and
so on are the examples of cloud computing. However, there are some issues in
cloud computing: latency, and less security. To tackle aforementioned issues, the
concept of fog computing was introduced.
Fog computing concept is introduced by Computer Information System Com-
pany (CISCO) in 2014. Fog computing has emerged as a promising infrastructure
to provide elastic resources at the network edge to minimize latency and to in-
crease security. Fog computing is used to reduce the burden on cloud and for
direct communication with consumers. Communication between fog and con-
sumer is done through some communication medium (wireless, i.e., wi-ﬁ). Fog
provides local services and can be accessed without internet.
The integrated cloud-fog based environment is three-layered architecture.
Fog is an intermittent layer between cloud and end user layer. The concept
of cloud and fog is almost same. The diﬀerences are: size, distance from user,
memory, and processing. The distance of cloud from ground level is thousands
of kilometer whereas the fog must be on ground level. The services provided by
cloud computing and fog computing are: Software as a Service (SaaS), Platform
as a Service (PaaS), and Infrastructure as a Service (IaaS) .
– SaaS is the highest level of abstraction.
– It is accessed by the users through a web browser.
– SaaS provides an access to the licensed software.
– PaaS provides simplicity and convenience for consumers.
– A user can access PaaS services anywhere through a web browser.
– PaaS then charges the users for that access.
– It is a fundamental building block for cloud services.
– A cloud service provider provides the infrastructure components like data
centers, servers, storage, and networking hardware.
– The main use of IaaS includes the actual development and deployment of PaaS
Diﬀerent service providers provide diﬀerent services as shown in Fig. 1.1. SG with
cloud and fog based environment is considered. The proposed scenario is divided
Eﬃcient Resource Allocation 3
Fig. 1. Cloud and Fog Services
into three layers: SG based layer, fog layer, and the cloud layer. In each cluster,
hundred buildings are considered, a controller is used in SG layer to communicate
with fog layer. Clusters are connected to fog in the same region. The data on
fog is stored temporarily and fog sends data to the cloud for permanent storage.
Consumers have to make a proﬁle to communicate with fog. A proﬁle contains
information about consumers’ location and daily electricity usage. These proﬁles
help the fog and the cloud to maintain its data accordingly.
A cloud-fog based platform is presented in  - , where fog devices are installed
in a region between the end user layer and the cloud layer to minimize latency.
Six regions are considered on the basis of six continents to cover the whole world
. One fog in each region is used rather than two to minimize the cost . Fifty
VMs are used instead of twenty-ﬁve to increase the eﬃciency in terms of PT.
Five MGs are placed in each region to fulﬁll consumers’ requests as much as
needed to minimize RT. Three clusters instead of two  with hundred buildings
in each are considered to achieve the results closer to real-time scenario.
In this paper, SG application is integrated with the cloud-fog based environ-
ment, which covers a large area based on six continents of the world. It provides
numerous beneﬁts for SG applications such as;
– Low latency services are provided, as fog devices are placed near the end user.
– MGs are used to fulﬁll the electricity requirements of consumers.
– PSOSA is used for load balancing.
– Two hybrid service broker policies are used for the selection of fogs to entertain
requests coming from the user.
Remaining part of the paper is organized as: related work is presented in Sec-
tion 2. The proposed system model is described in Section 3. Load balancing
4 Aisha Fatima et al.
algorithms are discussed in Section 4 and service broker policies in Section 5.
However, simulation results and conclusion are drawn in Section 6 and 7.
2 Related Work
Fog computing is used as an intermittent layer between end user layer and the
cloud layer. Fog computing is used to manage renewable energy resources and is
accessible without internet. It provides true support for mobility and the Internet
of Things (IoT) devices. Fog computing brings data closer to the end user layer.
Cloud computing has some limitations for the SG, a huge number of SG devices
need enormous data storage, networking, and processing. So fog is used near the
end user layer to manage the SG resources.
Cao et al.  have proposed a cost-oriented optimization model. A Modiﬁed
Priority List (MPL) and Simulated Annealing (SA) algorithms have been used
to solve the proposed optimization model eﬃciently. Computing instance is a
minimal unit that a user can take from the cloud. On-Demand Instances (ODI)
and Reserved Instances (RI) are considered in this paper. ODI idea is like pay
as you go while in a RI; users have a relatively long-term computing demands.
RI has been declared better than ODI. However, a user has to pay the upfront
payment in RI.
In , PSO based on Service Cost Optimization (PSOSC) scheduling al-
gorithm has been proposed to schedule the tasks coming from users. PSOSC
balance a load of VMs to minimize the cost and shortens the completion time.
Task scheduling of workﬂow in the cloud is very important. However, RT has
The authors in  have proposed a new dynamic service proximity policy
for the selection of VMs. A VM having minimum latency is allocated to fulﬁll
the consumers’ need. The communication has been performed between the end
user, fog, and the cloud. However, using two fogs in the same region is quite
Simulation technology has become a powerful and useful tool in cloud com-
puting for research community . The authors have compared the two cloud
simulation tools CloudSim and CloudAnalyst. CloudAnalyst is declared the best
option if anyone wants to work particularly on service broker policy or on load
balancing algorithm as compare to CloudSim. However, CloudAnalyst is not a
comprehensive solution for all complex tasks.
The authors in  have found some common security gaps of existing fog
computing applications. Some impacts of security issues and possible solutions
have been discussed in this paper. The detailed comparison between edge com-
puting, cloudlet, and micro-data center has been given. However, the security
issue is still there for a huge number of IOT devices.
Anila Yasmeen et al.  have used cloud-fog based environment for eﬃcient
resource allocation. The author has proposed PSOSA and Cuckoo Search (CS)
for balancing the load of VMs. The proposed service broker policy has been
Eﬃcient Resource Allocation 5
used for the selection of fog to entertain the requests coming from consumers.
However, the RT and the PT is increased with the proposed service broker policy.
The authors have proposed PSO scheduling based algorithm for workﬂow
scheduling. Workﬂow scheduling is a complicated scheduling containing a set
of dependent tasks communicating with each other. Masdari et al.  have
discussed the types of PSO algorithm, their objectives, and properties. However,
load balancing of VMs is still a big problem and must be considered for eﬃcient
3 Proposed System Model
In this study, an eﬃcient resource allocation model is presented to address the
following issues: minimization of PT, RT and the overall cost of VMs, MG, and
total data transfer. The proposed structure has three layers: layer 1(SG layer),
layer 2 (fog layer) and the layer 3(cloud layer). The centralized cloud platform
is used for data storage and macrogrid availability. The world is divided into six
regions based on the continents , as graphically shown in Fig. 1.2. Each region
contains one fog that minimizes the RT and PT, three clusters and ﬁve MG.
There are 100 buildings in one cluster and each building comprises of 50 to 80
apartments. A smart meter is appended to the all apartments.
MG incorporates with renewable energy. It has it’s own power generation
resources and have small-scale power. Macrogrid produces a large amount of
electricity. Windmills, fossil fuels, water turbine, etc are the source of electricity
for macrogrids. Fog in a region is able to respond the requests of three clusters
and based on the energy demand, forward these requests to the cloud server.
MGs are situated near the clusters of buildings. However, consumers are not
permitted to communicate directly with the MGs. The requests for electricity
from clusters are sent to the fog through the controller. The fog communicates
with the MGs in the same region to fulﬁll the consumers’ need. MGs send back
an acknowledgement of the power they have. On the other hand, if they do not
have adequate power, then the fog communicates with the cloud to provide the
macrogrid facility. Proposed system model is shown in Fig. 1.3.
4 Load Balancing Algorithms
Load balancing algorithms are used for the distribution of the workload to
achieve minimum RT and PT. Round robin and throttled algorithms were used
in  to balance the load of VMs; a new load balancing algorithm (PSOSA)
is used in this scenario. A number of particles form a swarm. These particles
communicate with each other. A particle is composed of 3 vectors (x-vector, p-
vector, and v-vector). These vectors record the current location of a particle, the
best solution found so far and a direction for which particle will travel. Following
steps are performed in PSOSA load balancing algorithm .
6 Aisha Fatima et al.
Fig. 2. Regions
1. Initialize number of particle swarms, a number of tasks and a number of
Fig. 3. Proposed System Model
Eﬃcient Resource Allocation 7
2. Initialize velocity and positions of the particles.
3. Deﬁnition of adaptive functions, which includes tasks allocation strategy and
ﬁtness value to measure the merits of the allocation strategy. f(i)= ﬁtness
function and the SumCost(i) = total cost of the ith particle.
4. Compare ﬁtness value with individual extremum and global extremum.
5. Update particle’s speed and position.
5 Service Broker Policies
Resources are little bit complicated to manage. Cloud computing creates a set of
virtual resources, i.e., VMs. Service broker policies are used to route the traﬃc
coming from the end user to the fog. These policies decide which fog should deal
with consumers’ request. Following policies were used in 
A. Service Proximity Policy
– Service Proximity policy is easy to implement.
– It maintains the index table of all fogs in each region.
– The fog is selected which has minimum latency and closed to the cluster
located in the same region.
– The fog is selected randomly if all fogs in the same region have minimum
B. Optimize Response Time Policy
– It maintains the index table of all available fogs located in all regions.
– It checks the history that which fog provides best RT.
– The fog in the same region with best RT is assigned to the consumer.
C. Dynamically Reconﬁgure with Load
– This is the hybrid of service proximity policy and optimize response time.
– The fog is selected which is closed to the cluster of the same region with best
– It also provides a facility for scalability.
D. New Dynamic Service Proximity
– New dynamic service proximity policy is the extension of dynamically recon-
ﬁgure with load and service proximity policy.
– The fogs are allocated on the basis of minimum latency and already existing
traﬃc load on fog and predicts next fog to be selected.
Following are the proposed policies in this paper.
8 Aisha Fatima et al.
5.1 New Dynamic Response Time
– It is the extension of dynamically reconﬁgure with load and optimize response
– The history of all fogs is sustained in the form of an index table.
– The fog is assigned on the basis of best RT in the same region by checking the
history of all fogs.
5.2 Enhanced New Dynamic Response Time
– This is the extension of new dynamic response time and service proximity
– The RT of all fogs is maintained in a table.
– The fog having best RT and minimum latency is allocated to the request
coming from the cluster in the same region.
Table 1. Overall RT and PT
New Dynamic Proximity Policy Avg (ms) Min (ms) Max (ms)
RT 111.71 37.91 31729
PT 61.67 0.12 31682
New Dynamic Response Time
RT 98.4 36.71 33175
PT 44.29 0.05 33124
Enhanced New Dynamic Response
RT 99.05 37.92 33888
PT 44.94 0.05 33837
6 Simulations and Discussion
In this paper, CloudAnalyst tool is used for simulations. CloudAnalyst is used to
work speciﬁcally on service broker policies and load balancing algorithms. The
simulation results using PSOSA load balancing algorithm with three service
broker policies are discussed. For the experimental purpose ﬁrst PSOSA with
new dynamic service proximity  is considered and than compared it with
two proposed policies: new dynamic response time and enhanced new dynamic
Minimum requests are serviced to minimize the cost in on-peak hours. RT
is the time interval between the time, when the request is sent to fog and the
response received against that request. The total time to process a request is
known as PT. The overall RT and PT for PSOSA and service broker policies:
Eﬃcient Resource Allocation 9
new dynamic service proximity, new dynamic response time, and enhanced new
dynamic response time is shown in Table 1.1. Each fog has some VM cost, MG
cost, and data transfer cost. The grand total cost using three diﬀerent policies
with PSOSA is shown in Table 1.2.
Table 2. Cost Comparison
New Dynamic Prox-
New Dynamic Re-
Enhanced New Dy-
Total VM cost ($) 1334.25 816.01 816.01
Total MG cost ($) 266.85 163.2 163.2
Transfer Cost ($)
289.11 289.11 289.1
Grand Total ($) 1890.21 1268.32 1268.31
In this paper, an integrated fog and cloud based model is proposed to manage the
SG resources optimally. It is analyzed that energy management is very important
for both demand side and the supply side. Some service broker policies are also
used for eﬃcient selection of fog. PSOSA algorithm along with two hybrid service
broker policies is implemented. Furthermore, we observed that the overall cost of
PSOSA with new dynamic response time and enhanced new dynamic response
time is approximately 20 % better as compared to the existing policy. However
the maximum RT and PT of new dynamic service proximity is approximately 3 %
better than the proposed policies. Simulations are performed on JAVA platform
using CloudAnalyst. In future, we will extend this study for ﬁve clusters and
ellaborate system model.
1. Cao, Zijian, Jin Lin, Can Wan, Yonghua Song, Yi Zhang, and Xiaohui Wang.
“Optimal cloud computing resource allocation for demand side management in
smart grid.”IEEE Transactions on Smart Grid 8, no. 4 (2017): 1943-1955.
2. Xue, Shengjun, Wenling Shi, and Xiaolong Xu. “A heuristic scheduling algorithm
based on PSO in the cloud computing environment.”International Journal of u-and
e-Service, Science and Technology 9, no. 1 (2016): 349-62.
3. Chekired, Djabir Abdeldjalil, and Lyes Khoukhi. “Smart Grid Solution for Charg-
ing and Discharging Services Based on Cloud Computing Scheduling.”IEEE Trans-
actions on Industrial Informatics 13, no. 6 (2017): 3312-3321.
4. Itrat Fatima, Nadeem Javaid, Muhammad Nadeem Iqbal, Isra Shaﬁ, Ayesha An-
jum, and Ubed Memon, “Integration of Cloud and Fog based Environment for
Eﬀective Resource Distribution in Smart Buildings”, in 14th IEEE International
Wireless Communications and Mobile Computing Conference (IWCMC-2018).
10 Aisha Fatima et al.
5. Saman Zahoor, Nadeem Javaid, Asif Khan, Fatima j. Muhammad, Maida Zahid,
and Mohsen Guizani, “A Cloud-Fog-Based Smart Grid Model for Eﬃcient Resource
Utilization”, in 14th IEEE International Wireless Communications and Mobile
Computing Conference (IWCMC-2018).
6. Patel, Hetal, and Ritesh Patel. “Cloud Analyst: An Insight of Service Broker Pol-
icy.”International Journal of Advanced Research in Computer and Communication
Engineering 4, no. 1 (2015): 122-127.
7. Khan, Saad, Simon Parkinson, and Yongrui Qin. “Fog computing security: a review
of current applications and security solutions.”Journal of Cloud Computing 6, no.
1 (2017): 19.
8. Okay, Feyza Yildirim, and Suat Ozdemir. ”A fog computing based smart grid
model.” In Networks, Computers and Communications (ISNCC), 2016 Interna-
tional Symposium on, pp. 1-6. IEEE, 2016.
9. Anila Yasmeen, Nadeem Javaid, Obaid Ur Rehman, Hina Iftikhar, Muhammad
Faizan Malik, and Fatima J. Muhammad, “Eﬃcient Resource Provisioning for
Smart Buildings Utilizing Fog and Cloud Based Environment”, in 14th IEEE Inter-
national Wireless Communications and Mobile Computing Conference (IWCMC-
10. Sakeena Javaid, Nadeem Javaid, Sahrish Khan Tayyaba, Norin Abdul Sattar, Bibi
Ruqia, and Maida Zahid, “Resource Allocation using Fog-2-Cloud based Environ-
ment for Smart Buildings”, in 14th IEEE International Wireless Communications
and Mobile Computing Conference (IWCMC-2018).
11. Moghaddam, Mohammad Hossein Yaghmaee, Alberto Leon-Garcia, and Morteza
Moghaddassian. “On the performance of distributed and cloud-based demand re-
sponse in smart grid.”IEEE Transactions on Smart Grid (2017).
12. Chekired, Djabir Abdeldjalil, Lyes Khoukhi, and Hussein T. Mouftah. “Decen-
tralized cloud-SDN architecture in smart grid: A dynamic pricing model.”IEEE
Transactions on Industrial Informatics 14, no. 3 (2018): 1220-1231.
13. Gai, Keke, Meikang Qiu, Hui Zhao, Lixin Tao, and Ziliang Zong. “Dynamic energy-
aware cloudlet-based mobile cloud computing model for green computing.”Journal
of Network and Computer Applications 59 (2016): 46-54.
14. Chen, Shang Liang, Yun-Yao Chen, and Suang-Hong Kuo. “CLB: A novel load
balancing architecture and algorithm for cloud services.”Computers and Electrical
Engineering 58 (2017): 154-160.
15. Masdari, Mohammad, Farbod Salehi, Marzie Jalali, and Moazam Bidaki. “A survey
of PSO-based scheduling algorithms in cloud computing.”Journal of Network and
Systems Management 25, no. 1 (2017): 122-158.