A QoS-Aware Machine Learning-Based Framework for AMI Applications in Smart Grids

: The Internet of things (IoT) enables a diverse set of applications such as distribution automation, smart cities, wireless sensor networks, and advanced metering infrastructure (AMI). In smart grids (SGs), quality of service (QoS) and AMI trafﬁc management need to be considered in the design of efﬁcient AMI architectures. In this article, we propose a QoS-aware machine-learning-based framework for AMI applications in smart grids. Our proposed framework comprises a three-tier hierarchical architecture for AMI applications, a machine-learning-based hierarchical clustering approach, and a priority-based scheduling technique to ensure QoS in AMI applications in smart grids. We introduce a three-tier hierarchical architecture for AMI applications in smart grids to take advantage of IoT communication technologies and the cloud infrastructure. In this architecture, smart meters are deployed over a georeferenced area where the control center has remote access over the Internet to these network devices. More speciﬁcally, these devices can be digitally controlled and monitored using simple web interfaces such as REST APIs. We modify the existing K-means algorithm to construct a hierarchical clustering topology that employs Wi-SUN technology for bi-directional communication between smart meters and data concentrators. Further, we develop a queuing model in which different priorities are assigned to each item of the critical and normal AMI trafﬁc based on its latency and packet size. The critical AMI trafﬁc is scheduled ﬁrst using priority-based scheduling while the normal trafﬁc is scheduled with a ﬁrst-in–ﬁrst-out scheduling scheme to ensure the QoS requirements of both trafﬁc classes in the smart grid network. The numerical results demonstrate that the target coverage and connectivity requirements of all smart meters are fulﬁlled with the least number of data concentrators in the design. Additionally, the numerical results show that the architectural cost is reduced, and the bottleneck problem of the data concentrator is eliminated. Furthermore, the performance of the proposed framework is evaluated and validated on the CloudSim simulator. The simulation results of our proposed framework show efﬁcient performance in terms of CPU utilization compared to a traditional framework that uses single-hop communication from smart meters to data concentrators with a ﬁrst-in–ﬁrst-out scheduling scheme.


Introduction
The advanced metering infrastructure (AMI) [1-3] is one of the core network infrastructures commonly deployed at the customer side in a smart grid (SG) [4][5][6][7][8][9]. As depicted in Figure 1, a typical AMI consists of a large number of smart meters (SMs), data concentrators (DCs), and wide-area networks (WANs), together with a metering data management IoT-based general AMI example in smart grid (redrawn from [9]).
The communication methods of the AMI network are mostly similar to those of the most recently emerged IoT communication models [15][16][17][18][19], utilizing several communication standards (cellular, WiFi, etc.), multi-layered structures (fog, edge, cloud), and protocols to provide remarkable end-to-end IoT services in the SG system with lower cost, increased coverage range, and lower power consumption. Recent developments in the leading LPWAN wireless technologies [9] such as NB-IOT [15] and long-range radio (LoRa) [16] are specially designed to enable low-power devices (e.g., SMs) to communicate over a long range with the control center (CC) for Internet-connected applications (e.g., metering, monitoring, etc.). In this way, the CC fully exploits the features of the Internet of things (IoT) to access SMs at customer premises remotely, to obtain accurate energy consumption data [20]. In particular, the CC should be able to adjust the energy supply according to the real-time demands of the consumers. Therefore, an intelligent communication system is required between SMs and the CC that will enable the SG network to handle the dynamic changes in electricity demand and supply in the electrical network.
However, given the SMs' geographic information and transmission ranges, there is a little research in the literature on how to utilize SMs as relay nodes in an n-hop manner to minimize the DC installation cost and to improve the quality-of-service (QoS) metrics with minimum communication delay in the AMI network. Several studies on key device (i.e., DC) placement have been reported which have particularly emphasized how to minimize the infrastructure cost, further boost network capacity, and extend the service coverage [21][22][23][24][25]. Alternatively, deploying SMs as relay nodes can provide a competitive solution to a number of legacy problems in existing AMI networks. Various AMI applications rely heavily on two stringent requirements in SG communication, namely, delivery of a large volume of messages and communication latency. Therefore, in potential emergency situations (e.g., blackouts, power theft, etc.), the communication network should be able to handle and deliver a large number of delay-sensitive and bandwidth-intensive messages to the CC in an efficient and reliable manner. In practice, it is observed that SMs have very limited resources (i.e., low memory, limited processing capability, and limited link capacity). Furthermore, it is imperative that the data delivery process between SMs and the CC is instant and precise for real-time control and monitoring of the SG network. Hence, if too high a workload (e.g., costly computations) is assigned, traffic congestion can occur at the SM, which can result in messages being delayed or even dropped on the way to the CC. In this case, the CC will miss detailed information from the SMs at the user side, which can result in incorrect decisions being taken by the CC regarding energy supply and demand.
Motivated by the foregoing discussion, we propose a three-tier hierarchical architecture (detailed in Section 5) which employs a clustering approach to configure the SMs into clusters of bounded radii and an optimal data delivery route with n hops, established between the SMs and the DC for major AMI applications in the network topology at the lower tier in the architecture. In this article, a modified K-means algorithm is proposed in which the optimal K-value for every cluster is decided based on the size and the number of nodes (SMs) deployed in the residential area. Further, the geographic coordinates of the nodes are used in the distance formula (haversine formula) for dual-head selection and cluster formation. During the cluster formation, dual heads, namely, a cluster head (CH) and aggregator head (AH), are selected in each cluster. The CH is used in intra-cluster as well as inter-cluster communication for relaying metering traffic between SMs and the DC, and this minimizes the number of DCs required in the AMI network. However, due to the resource-constrained nature of the SM (as CH), an AH is introduced to collect interval meter readings (IMRs) from the cluster members, aggregate these readings, and send them to the CH for onward transmission towards the CCS. This eases congestion, provides fault tolerance and reduces workload at the CH in each cluster. With this clustering topology in place, data from SMs traverse three tiers to reach the CCS and vice versa. At the lower tier, SMs generate two types of AMI traffic [24][25][26][27], namely, normal and critical traffic. The normal traffic, such as IMRs, is sent to the AH for traffic aggregation, while the critical traffic (delay-sensitive traffic) is sent directly to the CH for onward transmission. At the middle tier, the CH receives the normal and critical traffic into two different queues, schedules both types of traffic on a priority basis through the CSMA/CA and TDMA slots in the IEEE 802. 15.4g [28] MAC protocol, and sends the traffic to the DC directly or via other CHs. Finally, the AMI traffic received at the DC is forwarded to the utility CCS at the upper tier, over the Internet. For ease of understanding, important notations used in this paper are summarized in the Abbreviations.

Contributions
Considering the knowledge gap in the literature, there are five main contributions in this article. Firstly, this study primarily aims to use SMs as relay nodes (CH, AH) to maximize the coverage and connectivity requirements of all SMs in the AMI network. Secondly, the proposed heuristic improves the QoS of different AMI applications through priority-based scheduling schemes. Thirdly, this study intends to mitigate the hotspot problem of the DC to meet the robustness requirement by uniformly distributing the workload between the CH and AH to ensure service availability when a DC fails. Fourthly, the proposed hierarchical topology minimizes the total number of DCs required, which substantially reduces cost [29] in terms of the purchase and installation of new DCs and electric poles. Finally, extensive performance evaluation and simulation results obtained through different scenario-based experiments demonstrate the significance and verification of the proposed framework for AMI applications.

Paper Organization
The rest of the article is structured as follows. Section 2 presents a review of the recent literature on AMI applications in SGs. Section 3 describes the problem. The proposed framework is mathematically formulated in Section 4. In Section 5, we describe in detail the proposed three-tier hierarchical architecture for AMI applications. Section 6 presents the numerical and simulation results. Finally, Section 7 concludes the paper.

Literature Review
This section briefly describes the recent research efforts that are most relevant to our proposed scheme in this article. Our research work was mainly inspired by two major concepts in the literature: the QoS requirement of AMI applications and cluster-based hierarchical routing for increasing the coverage of AMI devices in SGs. However, due to the resource constraints of AMI devices, designing an efficient routing architecture for AMI applications in SGs has always presented a challenge for researchers and industry.
In [24][25][26], an optimal data aggregation point (DAP) placement problem was formulated and solved. The network model in [24] uses modified K-means on electric pole locations for DAP placement, and all devices communicate over a single hop to extend the network coverage. However, the QoS for AMI traffic was not considered in this study, and the one-hop communication limits the transmission ability. The work was extended in [25], where a greedy algorithm is used to identify pole locations suitable for DAP placement, and Dijkstra's algorithm is used to identify reliable routes for SMs in the network. In this study, the CH works as a DC in the clustering topology, with QoS support for various types of AMI traffic. However, the CH is fixed and burdened with a heavy workload, which may lead to the bottleneck problem (i.e., the CH receives more work requests than it can process at its maximum throughput capacity), because CH rotation is not considered in the study. Following this work, power line communication (PLC) technology was used for scheduling the delay-sensitive data of SMs in [26], using priority-based carrier sense multiple access/collision avoidance (CSMA/CA) and queuing analysis, such that minimum installation costs are guaranteed, together with traffic reliability. However, PLC has significant technical issues (channel distortion, noise, interference, and a low data rate) which limit its adoption in SG networks.
The authors in [27,30] addressed the DAP placement problem together with the QoS requirements for the AMI scenario. In [27], the author considered a wireless neighborhood area network (NAN) where a large number of SMs are divided into groups to communicate over a single hop to a DC that is connected via wired backhaul to the CC. The proposed analytical model ensures certain QoS metrics for demand-response applications in the communication network. However, the work presented needs to ensure certain latency requirements for different types of AMI traffic. Similarly, in [30], the optimization problem is formulated to minimize the cost of DAP by grouping SMs into clusters such that the risk of inter-network cascading failures due to DAP failure is avoided in the power network.
The authors in [31] developed a K-means-based method to select poles to deploy a fixed number of DCs in a multi-hop radio-frequency mesh AMI network. The objective was to minimize the transmission delays by limiting the number of hops that the SM traffic needs to traverse through to reach the selected DCs. However, their work ignores the congestion delay occurring at each hop. The studies presented in [32,33] developed optimization models that focus on design parameters such as coverage and capacity in a cost-effective manner. The heuristic in [32] uses a near-optimal clustering topology for the deployment of SMs with a bi-directional hybrid communication (wireless-fiber) system for the integration of smart microgrids. The authors in [33] proposed an evolved network architecture considering SMs, universal DAPs, BS, and an optimal route map based on wireless heterogeneous networks (WHNs) to achieve connectivity and coverage of SMs with the optimum use of technological resources.
In [34], an optimization problem is formulated to assist device-to-device (D2D) cellular communications in clusters and to efficiently allocate resources to guarantee QoS and maximize spectral efficiency in the AMI. Since cellular service (bandwidth) is shared with mobile users, this may affect the network performance and may create congestion in the network. The authors in [35,36] investigated the DAP placement problem and analyzed it using cluster-based algorithms aimed at reducing the maximum and average distance between SMs and the DAP. A stochastic geometry-based model was applied to power grids in [37,38], in order to achieve two objectives: optimized phasor measurement units (PMUs) allocation and interdependent communication power networks. The power grid in [37] is clustered using a K-means algorithm to construct trees based on the physical buses, such that redundant SM allocations are avoided and certain financial budget and technical constraints are met. The work in [38] demonstrates tight coupling between the power grid and the communication network using stochastic geometry. The mathematical formulation satisfies the packet-drop-ratio and queuing-delay constraints on communication nodes (CNs) by using a dynamic priority-based queuing model.
In [39], a proportioned strategy was adopted to optimize collectors and router positions jointly in multi-hop radio-frequency mesh networks, to reduce the running time for highly dense networks as well as to minimize the effect on QoS metrics. The authors in [40] developed a two-hop evolutionary aggregation approach (EAA) using a clustering technique for a wireless remote-metering network. The model aims at full coverage and connectivity of SMs, while the infrastructure cost is minimized by reducing the number of local data aggregation centers. The model proposed in [41,42] exchanges metering and control information between SMs and the CC using a multi-hop method with hybrid communication technologies in a NAN to achieve message integrity and minimize the communication and computational overhead incurred during SG communication. Finally, the proposed approach in [43] divides the data reporting process into two stages: online and offline. Considering that SMs have limited computational and bandwidth ability, most of the costly computations are pre-processed in the offline phase to avoid the efficiency bottleneck of SMs in SG communications. In addition, the authors improved the communication efficiency by performing dynamic cluster formation such that the online electricity usage reports of all SMs could be received by the CC in a fast and secure manner.
We summarize the above discussion in two main parts. Firstly, most of the recent studies have specifically addressed the DAP placement problem as a communication problem. Secondly, this problem can be solved through optimal workload partitioning based on a clustering algorithm to improve the performance of the AMI network. We present a generalized classification and comparison of recently proposed AMI schemes in Table 1.

Problem Description
In this article, we consider the coverage and QoS issues of AMI applications in an SG network. The optimization problem is described as follows.
In an AMI network, the DC has limited transmission range and a capacity constraint that allows connection of up to a maximum of 2000 [44] SMs. When the residential area (RA) becomes too large, there will be some SMs outside the radio range of a single DC centered at the RA. Since data from all SMs are routed towards a single DC, it suffers from a higher workload, leading to a hotspot in the SG network. Further, to satisfy the need for full coverage of all SMs and to transfer an optimum percentage of metering traffic to the utility CC within the recommended latency range [4,5] while ensuring stringent QoS and robustness requirements, a reliable and cost-efficient AMI infrastructure is required.
For instance, AMI applications such as interval meter reading may tolerate a delay of up to a few minutes, whereas remote control commands have stringent latency requirements, especially during peak hours. Therefore, data from these delay-sensitive applications need prioritization and availability of the communication network between SMs and the CCS. Furthermore, the DC and SMs have limited resources (e.g., processing, storage, and bandwidth), and thus high resource utilization in these devices will cause congestion and communication interference during peak hours. In such situations, device shutdown or failure (bottleneck) occurs due to which packets (data) may be delayed or even dropped in the communication network. Therefore, a uniform workload distribution strategy is needed to mitigate the hotspot (bottleneck) problem in case of communication failures and defects in SMs and DCs, to maintain the robustness in the network, and to maintain the QoS requirement of AMI applications.
We attempted to solve the optimization problem by logically partitioning the RA into a set of disjoint clusters with bounded radii, to fulfill the connectivity and coverage requirements of AMI applications in the SG communication network. We defined algorithms to construct a hierarchical clustering topology and to fulfill the robustness requirements for dual-head (CH and AH) selection and rotation. Further, we developed a queuing model in which different priorities are assigned to each item of the critical and normal AMI traffic based on its latency and packet size, to ensure the QoS requirement in the AMI network.

Problem Formulation
As discussed earlier, the optimization problem is formulated as follows. Given the geographic locations, the latency requirements of different types of AMI traffic, and the radio range of the DC and SMs, the coverage maximization dual-head placement (CMDP) problem is to fully extend the coverage and connectivity of AMI network, denoted as C, by selecting a set of dual heads (N DH ⊂ N SM ) in each cluster, subject to the QoS and robustness constraints.
The decision variables x i,j , y k i,j , z i are introduced in the optimization problem. The binary variable x i,j indicates that each SM i ∈ N SM is connected to a single DC j ∈ N DC . The binary variable y k i,j indicates that metering data of each SM i are passed through a dual head k towards DC j, where z i represents the fact that SM i is assigned to at least one dual head in a cluster. Recall that R T , H max and C UB are the upper bounds on the transmission radius, the maximum number of hops allowed to reach the DC, and the capacity constraint of the DC and cluster, respectively. The notations in the problem formulation are described in the Abbreviations. The CMDP problem is mathematically formulated as follows.
The objective function in Equation (1) describes the coverage and connectivity requirements of each SM in the AMI network that are fulfilled with multiple dual heads in order to relay traffic between SMs and the DC such that the network coverage is maximized. In Equation (2), optimal deployment of the georeferenced SMs and DC is ensured at the RA. Equation (3) fulfills the connectivity requirement such that the haversine distance d i,j between any two devices is less than or equal to the allowable wireless transmission range (R T ). Equation (4) ensures that each SM is exclusively connected to one DC via a CH or AH. Equation (5) specifies that dual heads are allocated to SMs in each cluster. Equation (6) restricts the maximum number of hops to H max in the route of the topology. With a limit on the hopping depth, the packet loss and n-hop delay [6] are minimized. Equation (7) ensures that the AMI traffic received with an average λ i [5] from SMs is less than the offered µ j of the DC. Equation (8) ensures that maximum connections do not exceed the capacity limit (C UB ) of the DC. The last condition indicates that x i,j , y k i,j , z i are binary variables.

Proposed Three-Tier Hierarchical Architecture
In this section, a three-tier hierarchical architecture is proposed that is different from the current schemes in the literature and represents a realistic AMI scenario, as depicted in Figure 2. The tree-tier architecture comprises a lower tier, a middle tier, and an upper tier. To maximize the design efficiency with regard to the context, a cooperative relaying strategy (dual head) is adopted in the clustered view of the AMI network such that the coverage is maximized, and the required QoS and robustness are ensured using different channel and queuing scheduling schemes. The network model and the proposed algorithms in this study are discussed in detail in the following subsections.
adjacency matrix G = (V, E), also called a direct connectivity graph, where each v ∈ V denotes (SMs, DC) having a symmetric transmission range R , while a wireless link between any two denoted by an edge e (u, v) ∈ E. Subsequently, this model uses the haversine formula [32] [45] is used as the propagation model best suited to outdoor areas.
We make the following few reasonable assumptions to simplify our network model: All devices are georeferenced and pre-configured with a unique ID; All SMs are restricted so that data are not sent directly to the DC; Each SM is aware of the identity of the cluster to which it belongs; All devices are fully synchronized with the utility CCS; Security aspects are not considered here.

Hierarchical Cluster Formation
In this section, we describe the design methodology adopted in this article to construct the p clustering topology at the lower tier for AMI applications in an SG. In addition, to ensure full cove AMI network, we must consider the capacity constraint and transmission radius R of the DC.
limited transmission radius, there will be some SMs outside the transmission circle of the DC if R RA needs to be partitioned into a number of uniform-sized disjoint kxk cells, each referred to as predefined square number [46] obtained using knowledge of N , R , R , and the dimensions ( well as addressing the coverage requirement, the reason behind such partitioning is to effectively data transmissions towards the DC and uniformly distribute the workload of the DC between the the QoS and robustness requirements are met. Once the formation of cells is completed, Algorithm a set of header nodes (here, SMs) in each cell using a modified K-means algorithm based formulation. Initially, the SM closest to the centroid in each cell is selected as the CH. The criteri

Network Model
In the proposed AMI architecture, the network model needs four main components (IoT nodes) in the deployment of the network topology: the SMs, the DC, the central gateway (acting as a router), and the CCS at the CC's premises, all provided with an uninterrupted power supply. To model the network, we consider square-shaped georeferenced RAs where N SM homogeneous SMs are evenly distributed and randomly deployed at low altitudes in homes, building the targeted AMI scenario. Further, we assume that a DC is installed by the utility provider at the center of the RA that is connected through bi-directional wireless links to a subset of SMs and to the utility CCS at the CC through a central gateway. The CCS has up-to-date information on all registered devices in the AMI network, stored in a database. The RA is partitioned into logically non-overlapping clusters that employ a dual-head method, where the cluster head (CH) is mainly used for relaying traffic and the aggregator head (AH) is used for traffic aggregation. Using SMs as intermediate heads, a near-optimal route map for SMs-CH-DC and SMs-AH-CH-DC is obtained in the clustering topology towards the utility CC gateway over the Internet. The proposed clustering topology is modeled over an adjacency matrix G = (V, E), also called a direct connectivity graph, where each v ∈ V denotes the set of all vertices (SMs, DC) having a symmetric transmission range R T , while a wireless link between any two vertices (u, v) ∈ V is denoted by an edge e (u, v) ∈ E. Subsequently, this model uses the haversine formula [32] to calculate the single-hop distance denoted by d u,v between each pair of vertices at the lower tier that is represented by a distance matrix D. Hence, two neighbors u, v ∈ V are a single hop away in a cluster if and only if R u ≥ d u,v ∧ R v ≥ d v,u . In addition, a maximum of H max hops are allowed in the route map towards the DC, to ensure the connectivity requirements of all SMs in the network are met. Further, each vertex v ∈ V is equipped with IEEE 802.15.4g [28]. Similarly, the DC supports two interfaces: IEEE 802.15.4g for internal traffic and LoRa for the outbound traffic towards the centralized gateway of the CC. The Walfisch-Ikegami model [45] is used as the propagation model best suited to outdoor transmission in urban areas.
We make the following few reasonable assumptions to simplify our network model: • All devices are georeferenced and pre-configured with a unique ID; • All SMs are restricted so that data are not sent directly to the DC; • Each SM is aware of the identity of the cluster to which it belongs; • All devices are fully synchronized with the utility CCS; • Security aspects are not considered here.

Hierarchical Cluster Formation
In this section, we describe the design methodology adopted in this article to construct the proposed hierarchical clustering topology at the lower tier for AMI applications in an SG. In addition, to ensure full coverage of all SMs in the AMI network, we must consider the capacity constraint and transmission radius R T of the DC. However, due to the limited transmission radius, there will be some SMs outside the transmission circle of the DC if R T < R RA , and then the RA needs to be partitioned into a number of uniform-sized disjoint kxk cells, each referred to as a cluster. Here, k is a predefined square number [46] obtained using knowledge of N SM , R T , R RA , and the dimensions (L × W) of the RA. As well as addressing the coverage requirement, the reason behind such partitioning is to effectively reduce the number of data transmissions towards the DC and uniformly distribute the workload of the DC between the CH and AH such that the QoS and robustness requirements are met. Once the formation of cells is completed, Algorithm 1 proceeds to select a set of header nodes (here, SMs) in each cell using a modified K-means algorithm based on the optimization formulation. Initially, the SM closest to the centroid in each cell is selected as the CH. The criterion for the selection of the AH is an SM in the vicinity of the CH. Further, only those SMs in each cell will be selected as the CH and AH whose distance to the centroid is less than or equal to a certain distance threshold D TH , appropriately set to achieve optimal performance. To improve the robustness at the lower tier, when unexpected failure of the dual head is detected or its timer expires, the role of the dual head is rotated among the SMs relatively close to the mid-point based on D TH in every cell. The information on the newly selected dual head is shared among all cluster members and the adjacent neighborhood CHs. Finally, the set of CHs, together with the DC, constructs an optimal route map towards the CCS central gateway, as shown in Figure 2. We modified the traditional K-means algorithm to use the haversine distance metric to efficiently partition the residential area under consideration with regard to dual-head selection and to construct the optimal route map for AMI applications in the SG network. Our modified K-means clustering technique yields promising results compared to the previously proposed methods in the literature, achieving full coverage, robustness and the QoS requirements of the AMI applications. Furthermore, our proposed framework can also be adapted to other communication technologies (either wired or wireless). The pseudocode for Algorithm 1 is given below.
Algorithm 1 for dividing the residential area into virtual clusters.

Input:
K, R RA , R T , L, W, V, C UB , DC 1: if N row (w) * N col (l) == K then 8: for k = 1 to K then 9: set randomly − uniformly select k SMs from each C K to initialize c k centers 10: Run modified K − means algorithm such that to maximize CDMP in (1) 11: Update until c k centroids of C K clusters are chosen 12: C K ← c k 13: repeat return Display "The RA needs no partitioning and is already optimal" 29: endif 30: End Output: Save cluster to C K , centroid to c k In Algorithm 1 above, the first step that the DC performs in lines 3-6, is to partition the RA into K clusters in order to achieve the objective function expressed in (1), based on the upper-bound capacity (DC.C UB ), that is, to fulfill the constraint of Equation (8) and the transmission radius (R T ) constraint (Equation (3)) of the DC to ensure that all the SMs are connected to at least one DC in the AMI network, that is, to fulfill the constraint of Equation (4). Next, in lines 7-25, the modified K-means algorithm is used, c k centroids (as CHs) in all clusters C K are chosen, and the SMs are associated based on the shortest distance to the closest centroid of the cluster, to satisfy the constraints of Equations (2) and (5). The output of the Algorithm 1 is obtained in line 26 and includes the clusters (C K ) along with their corresponding centroids (c k ). The else lines [27][28][29] show that the network configuration already meets the optimal connectivity requirement. In order to ensure QoS and reduce the AMI traffic in the network, we propose Algorithm 2, whose pseudocode and other details are given below. for k = 1 to K then 4: Determine the c k by calling Algorithm 1 5: repeat In Algorithm 2 above, a subset of SMs from all cluster members (C K .length) based on a threshold distance (D TH ) from each centroid (c k ) is calculated, added to a priority queue (PQ), and then sorted (lines 2-18). Only SMs from the PQ take part in CH and AH selection. The newly selected CH (c k ) and AH (a k ) information is shared with cluster members through a NotifyMSG message, and cluster members send JoinMSG messages to dual heads to obtain the optimal route map in each round (lines 20-28). Further, the maximum-hops constraint in Equation (6) is checked in lines 29-35. To meet the robustness requirement in the network topology, lines 37-44 are used to rotate the role of the dual head in cases of unexpected failures or once the maxTime expires for each round. In line 45, Algorithm 2 returns the output that includes the sets of dual heads (CH, AH) and the optimal valid route map for each cluster. Finally, once the cluster formation, dual-head selection and a near-optimal route map are obtained, we move on to the transmission phase of AMI applications.

Transmission of AMI Applications
In this section, we give details of the AMI application's transmission in the proposed IoT-based three-tier hierarchical architecture which consists of a lower tier (intra-cluster), a middle tier (inter-cluster), and an upper tier where the metering data is forwarded by the DC towards the CCS and vice versa. In this article, we consider two traffic classes in AMI applications [4,5], generally categorized as normal and critical classes. The normal traffic consists of IMRs, on-demand meter readings (ODMRs), and on-demand reading responses (ODRRs). The IMR represents the customer electricity consumption typically captured at every fixed-length interval (e.g., 5-60 min). The ODMR is the meter-reading demand for the customer SM sent by the utility CCS that may be used for load forecasting and a demandresponse program. The ODRR is the SM response sent to the CCS. Similarly, the critical traffic consists of remote-control commands (RCCs), power-control commands (PCCs), and alert notifications (ANs). Moreover, RCCs include remote disconnect/reconnect, PCCs include load-control signals, and ANs comprise meter tampering and similar messages. Table 2 shows the characteristics of AMI applications that require a reliable and prioritybased transmission based on their latency requirement in the SG communication network. In Table 2, ToT stands for type of traffic, ToA for type of AMI application, Pkt-Size for packet size, L R for recommended latency, and FG for data generation frequency per day. In the lower-tier transmission, each cluster member is aware of the AMI applications, and the ToT and ToA fields in the outgoing packets P = {1, 2, ... n} are set for each destination head (CH, AH). The destination head receives one or more packets; each follows a Poisson arrival process [26]. The CH places the normal traffic into the lowpriority normal queue (NQ) and the critical traffic into the high-priority critical queue (CQ), as shown in Figure 2. The CH assigns a T P to each packet in these queues based on the packet size and recommended latency, using the following equation.
where T G denotes the generation time (recent or early) of the metering application. It should be noted that the critical-class-related data must be transmitted within the recommended latency range of the AMI application for immediate response in the SG communication network. The CH will check and compare the T P values of the packets in both queues, and the highest-priority packet is forwarded first to the nearest CH or directly to the DC for further processing at the middle tier, assuming that the service rate is higher than the arrival rate to satisfy Equation (7). Similarly, the IEEE 802.15.4g standard [28] uses two types of channel-access periods within each frame, namely, a contention access period (CAP) and contention-free periods (CFPs), to avoid traffic congestion and co-channel interference between the CH and DC, to further improve the QoS and avoid unnecessary packet dropping in the network. The normal traffic is scheduled through the CAP slots using the CSMA/CA schedule while the critical traffic is sent via the CFPs slots using the TDMA schedule, to avoid channel allocation conflict. The available time slots per frame in the CAP and CFP periods of the MAC protocol, which are denoted by N CSMA and N TDMA , respectively, can be computed using the following equations: where β f is the total available spectrum, β g is the guard band used to separate the channels, that is, to avoid channel overlapping, N SM is the number of SMs (users) separated according to time, and β c is the bandwidth of a channel in the spectrum. Finally, in the upper-tier transmission, the DC forwards the pre-processed classified AMI data through the SG communication core network (Internet) to the CCS. After the metering data is further classified, processed, and analyzed, relevant responses, e.g., commands, are sent back to the SMs in the manner established by Algorithms 1 and 2, using the IoT-based communication network in the SG.

Design and Implementation
This section gives details of our three-tier hierarchical architecture and its design and implementation for the SM infrastructure. In the following subsections, we discuss the geographical area assumed for our network model and the simulation setup details, and discuss the numerical and simulation results obtained for the considered scenarios.

Geographical Area Assumption
We designed our network model using realistic geographic information over the map of Mansehra, KPK, Pakistan, where each residence is considered as a single SM and a transformer pole is at the center of the RA for the DC location. The geographic coordinates (longitude and latitude) of each device were found by visual search using OpenStreetMap [47] and cross-checked by comparing with the dataset taken from Google Maps [48]. In addition, the dataset was stored in the MS SQL server database at the cloud server, which is a key requirement in Algorithms 1 and 2 to configure the proposed clustering topology at the lower tier. The communication technology (Wi-SUN) adopts PHY layer multi-rate and multi-regional frequency shift keying (MR-FSK), which operates in the frequency band 902-928 (US) [28] with 129 channels and is compatible with the 2.4 GHz industrial, scientific, and medical (ISM) band (Wi-SUN router) with a maximum transmission rate of 50-200 kbps. The transmission radius of all SMs and the DC is set to 500 m in the configured topology. These devices are deployed in an area of approximately 1 km 2 . For those SMs which cannot communicate directly with the DC, their metering data is relayed via CHs to the DC with the limit on the maximum number of wireless hops (H max ) set to 2 or 3. We adopted the traffic specifications listed in Table 2 both for normal and critical traffic.

Simulation Setup
The Eclipse IDE and the CloudSim simulator [49] were used to model both the hardware entities (hosts, network topology, data centers) and software entities (virtual machines (VMs), brokers, cloudlets) in the cloud infrastructure for real-time AMI applications in the SG. This was accomplished by extending the Java classes offered in CloudSim for the mentioned entities, according to the simulation requirements. The events are fired for communication at specified time intervals and randomly, that is, the simulation is event-driven according to the real case scenarios. Cloudlets are created by data center brokers and AMI traffic is managed between SMs and the cloud applications by these message brokers using publish/subscribe protocols. In addition, these brokers control the VMs and execute each cloudlet on the VMs according to the selection algorithm (e.g., spaced-shared policy), considering the resources of the physical hosts in the data center. In this simulation, we used a two-tier broker architecture: the first tier receives the incoming traffic from the local SMs network at the DC and the second tier receives the incoming traffic from the connected DCs at the cloud gateways. The details of the network nodes are given in the Topology.brite file at the data center, as listed in Table 3, and are similar to the network model in Section 5.1. In addition, the detailed configuration of the cloud server is given below in Table 4. Similarly, web interfaces were implemented using VS code (Java script) and node.js, relying on a set of REST APIs (CustomerInfo, MeterInfo, BlackListMeters, MeterRead, BillInfo, etc.), which enabled all the IoT nodes to communicate and allowed remote access to IoT applications. Here, we used REST APIs to pass (push) all the metering data in JSON format between the SMs and the remote CCS (cloud REST server) over the Internet, using HTTP 1.1 POST methods. The simulation was run for 60 min (i.e., 1 h) and we took an average of 10 simulation runs. Thus, the IMR data was sampled four times, whereas the other metering data was assumed to be sent only once in the simulation period.

Scenario Description
In this simulation, we considered two different scenarios for AMI applications with different network topologies and queuing models. Scenario-1 was based on our proposed network model with a priority-based scheduling scheme. In Scenario-2, we considered a clustering topology with single-hop communication to the DCs based on Wi-SUN technology and a FIFO scheduling scheme (default).

Performance Evaluation
The performance of our simulation model was analyzed and compared in two scenarios for satisfying the stringent QoS requirement of AMI applications. In the simulation model, the incoming REST API requests (e.g., HTTP POST requests) were routed dynamically in the form of cloudlets to the cloud for accessing cloud applications. Furthermore, the cloud server dynamically allocated the available resources (i.e., VMs, RAM, BW, and CPU) to these incoming cloudlets. To compare the performance of the two scenarios (Section 6.3) based on allocation policies (FIFO and priority-based), we evaluated a varying number of cloudlets (40-120) and measured the resources (computation time) utilized by each cloudlet in the simulation environment.

Numerical and Simulation Results
Prior to all the simulation experiments, we studied the impact of the required number of DCs on the clusters in each scenario to cover all the SMs. The numerical results obtained from the network model are shown in Figures 3 and 4. In order to achieve 100% coverage of the AMI network in both scenarios, we can observe that the required number of DCs is lower for the dual-head relaying strategy in Scenario-1. In contrast, the number of required DCs is substantially higher in Scenario-2, due to the traditional non-cooperative relaying strategy for AMI applications.
Furthermore, the results demonstrate that the network model in Scenario-1 satisfies the target coverage of the SMs and contributes substantially to reducing the overall cost in terms of deployment and purchase of DCs in the AMI network, as shown in Figure 4. For example, for K = 16, Scenario 1 requires only 20% of the number of DCs required by Scenario 2; that is, Scenario-1 consistently utilizes a lower number of DCs than Scenario-2, due to our proposed Algorithms 1 and 2. Hence, the comparison here shows that the proposed three-tier architecture in Scenario-1 with a cooperative relaying strategy (dual-head strategy) decreases the number of DCs required and offers more benefits than Scenario-2 with a non-cooperative relaying mode. It also achieves 100% coverage of SMs for AMI applications in the SG. Furthermore, the results demonstrate that the network model in Scenario-1 satisfies the target cov contributes substantially to reducing the overall cost in terms of deployment and purchase of DCs as shown in Figure 4. For example, for K = 16, Scenario 1 requires only 20% of the number of DCs 2; that is, Scenario-1 consistently utilizes a lower number of DCs than Scenario-2, due to our pr and 2. Hence, the comparison here shows that the proposed three-tier architecture in Scenariorelaying strategy (dual-head strategy) decreases the number of DCs required and offers more ben with a non-cooperative relaying mode. It also achieves 100% coverage of SMs for AMI application In addition, Figure 4 compares the purchase cost of DCs in each scenario. For instance, we can se of DCs increases, the purchase cost in Scenario-2 is five times higher than in Scenario-1. Thus, the in Scenario-1, clearly outperforming Scenario-2 in the deployment cost of DCs. Next, the perf scenarios were evaluated by five simulation experiments, with parameters summarized in Table 5    Furthermore, the results demonstrate that the network model in Scenario-1 satisfies the target cov contributes substantially to reducing the overall cost in terms of deployment and purchase of DC as shown in Figure 4. For example, for K = 16, Scenario 1 requires only 20% of the number of DCs 2; that is, Scenario-1 consistently utilizes a lower number of DCs than Scenario-2, due to our pr and 2. Hence, the comparison here shows that the proposed three-tier architecture in Scenario relaying strategy (dual-head strategy) decreases the number of DCs required and offers more be with a non-cooperative relaying mode. It also achieves 100% coverage of SMs for AMI application In addition, Figure 4 compares the purchase cost of DCs in each scenario. For instance, we can s of DCs increases, the purchase cost in Scenario-2 is five times higher than in Scenario-1. Thus, the in Scenario-1, clearly outperforming Scenario-2 in the deployment cost of DCs. Next, the perf scenarios were evaluated by five simulation experiments, with parameters summarized in Table   Table 5. Detailed configuration of simulation experiments.  In addition, Figure 4 compares the purchase cost of DCs in each scenario. For instance, we can see that as the number of DCs increases, the purchase cost in Scenario-2 is five times higher than in Scenario-1. Thus, the cost reduction is 80% in Scenario-1, clearly outperforming Scenario-2 in the deployment cost of DCs. Next, the performances of the two scenarios were evaluated by five simulation experiments, with parameters summarized in Table 5.  Figure 5 shows the simulation results of Experiment 1 for the first scenario in terms of computation time (milliseconds) utilized for scheduling the critical traffic items based on their priorities. These results were obtained from the data center using the CloudSim simulator.  All the experimental results of the two scenarios obtained by CloudSim are shown in Table 6. Table 6    All the experimental results of the two scenarios obtained by CloudSim are shown in Table 6. Table 6 presents the total time taken by all cloudlets in a given experiment by summing the start time and finish time for all cloudlets in the experiment and calculating the total computation time and waiting time from the measurements presented in Figure 5. The sum of the computation time and waiting time in each experiment is used to evaluate the performances of the two scenarios. Figure 6 shows the total computation time with a varying number of cloudlets in the two scenarios. We see that the total computation time in Scenario-2 increases dramatically as the number of cloudlets increases. However, the total computation time incurred in Scenario-1 shows that the critical traffic is processed in less time, demonstrating its computational efficiency and scalability in large-scale networks.
Similarly, Figure 7 shows the total waiting time for different numbers of cloudlets in each experiment in the two scenarios. We note that when the number of cloudlets increases from 40 to 120, as shown in Table 5, based on the number of requests per SM made in each experiment, the total waiting time of Scenario-2 increases significantly compared to the waiting time of Scenario-1. The comparison reveals that the tasks in Scenario-1 are processed at a very high speed and spend less time in the queue, due to the priority-based scheduling.   Similarly, Figure 7 shows the total waiting time for different numbers of cloudlets in each ex scenarios. We note that when the number of cloudlets increases from 40 to 120, as shown in Table 5     Similarly, Figure 7 shows the total waiting time for different numbers of cloudlets in each ex scenarios. We note that when the number of cloudlets increases from 40 to 120, as shown in Table 5, of requests per SM made in each experiment, the total waiting time of Scenario-2 increases signi the waiting time of Scenario-1. The comparison reveals that the tasks in Scenario-1 are processed and spend less time in the queue, due to the priority-based scheduling. The computation and waiting times of the simulation experiments are averaged in Table 7 computation and waiting time per cloudlet for a comparative analysis of the two scenarios. For e The computation and waiting times of the simulation experiments are averaged in Table 7 to give the average computation and waiting time per cloudlet for a comparative analysis of the two scenarios. For example, 40 cloudlets are used in Experiment 1 (refer Table 5), hence we divide the computation and waiting times in Table 6 to obtain the average computation and waiting times per cloudlet, that is, for Scenario-1 Experiment 1, average computation time = 81.73/40 = 2.04325 ms, and average waiting time = 1334.38/40 = 33.3595 ms.  Figure 8 plots the effect on the average computation time in the two scenarios when the number of cloudlets varies. We see a linear increase in the average computation time for different numbers of cloudlets in Scenario-1. In contrast, the average computation time is significantly increased in Scenario-2 for cloudlet completion. The numerical results in Table 7 obtained in the simulation experiments show that the sum of the average computation and waiting times for Scenario-1 is almost 10 times better for time of execution and completion of tasks than that for Scenario-2, demonstrating the computational efficiency of Scenario-1, especially in large-scale AMI networks.      Figure 9 plots the effect of the number of cloudlets on the average waiting time in the two scenarios. We note that the Scenario-1 gives better performance compared to the average waiting time for the tasks in Scenario-2. The main reason is that Scenario-2 schedules the heavy cloudlets first and queues the high-priority cloudlets with a small size, which are scheduled afterwards, and this greatly affects the average waiting time. In short, we can see from Figure 9 that as the number of cloudlets increases, the average waiting time drops by 84% in our proposed model, compared with Scenario-2.

Conclusions
In this article, we proposed a QoS-aware machine-learning-based framework for AMI applications framework incorporates a three-tier hierarchical architecture based on IoT technology and a clo enables the control center to remotely access and monitor the SMs in residential areas. In order to QoS and coverage requirements, we formulated a mathematical optimization problem. We mod means algorithm to construct a hierarchical clustering topology for bi-directional communicatio DCs. We proposed algorithms for defining the network topology and dividing the residential area and for dual-head (CH and AH) selection and rotation for optimal route formation. It was observ K-means algorithm provided a near-optimal solution within the proposed framework for AMI a network.
Further, we developed a queuing model in which different priorities were assigned to each item o AMI traffic based on its latency and packet size. The network model clearly defines the cove technique, the number of DCs required, and the fixed number of hops between SMs and the DC over the Internet to the utility provider's control server. Furthermore, we used a queuing mode AMI applications and used two different scheduling schemes in two scenarios (corresponding to tw contrasting features in the simulation. The first scenario/framework was based on our proposed n priority-based scheduling scheme, while the second scenario/framework considered a clustering t hop communication to the DCs and a FIFO scheduling scheme. The numerical results showe framework with a three-tier hierarchical architecture utilized a smaller number of DCs, which con to reducing the overall purchase cost by up to 80%, while still providing full coverage and conne and DCs. Furthermore, we described a set of simulation experiments for different configurations to estim performance of the two scenarios using the CloudSim simulator. The simulation results obtained in showed that our proposed model efficiently utilized the CPUs in terms of processing time, due scheduling scheme. In summary, the proposed framework performed better than the traditional f 2). These results show the suitability of our proposed framework for AMI applications in an SG n Our future work will focus on developing lightweight security schemes to ensure the pri confidentiality of metering data in the SG.

Conclusions
In this article, we proposed a QoS-aware machine-learning-based framework for AMI applications in SGs. The proposed framework incorporates a three-tier hierarchical architecture based on IoT technology and a cloud environment that enables the control center to remotely access and monitor the SMs in residential areas. In order to satisfy the stringent QoS and coverage requirements, we formulated a mathematical optimization problem. We modified the existing K-means algorithm to construct a hierarchical clustering topology for bi-directional communication between SMs and DCs. We proposed algorithms for defining the network topology and dividing the residential area into virtual clusters, and for dual-head (CH and AH) selection and rotation for optimal route formation. It was observed that the modified K-means algorithm provided a near-optimal solution within the proposed framework for AMI applications in the SG network.
Further, we developed a queuing model in which different priorities were assigned to each item of critical and normal AMI traffic based on its latency and packet size. The network model clearly defines the coverage area, clustering technique, the number of DCs required, and the fixed number of hops between SMs and the DC that finally connects over the Internet to the utility provider's control server. Furthermore, we used a queuing model for transmission of AMI applications and used two different scheduling schemes in two scenarios (corresponding to two frameworks) with contrasting features in the simulation. The first scenario/framework was based on our proposed network model with a priority-based scheduling scheme, while the second scenario/framework considered a clustering topology with single-hop communication to the DCs and a FIFO scheduling scheme. The numerical results showed that our proposed framework with a three-tier hierarchical architecture utilized a smaller number of DCs, which contributes substantially to reducing the overall purchase cost by up to 80%, while still providing full coverage and connectivity between SMs and DCs.
Furthermore, we described a set of simulation experiments for different configurations to estimate and analyze the performance of the two scenarios using the CloudSim simulator. The simulation results obtained in all five experiments showed that our proposed model efficiently utilized the CPUs in terms of processing time, due to the priority-based scheduling scheme. In summary, the proposed framework performed better than the traditional framework (Scenario-2). These results show the suitability of our proposed framework for AMI applications in an SG network.
Our future work will focus on developing lightweight security schemes to ensure the privacy, integrity, and confidentiality of metering data in the SG.