In this section, the detailed steps of the proposed routing protocol MHGEER are presented.
MHGEER is an intercluster multihop dynamic routing protocol, transferring information from one CH to another in order to reach the BS. Its main goal is to ensure the load balancing in the network and to give a longlasting connectivity for all the clusters no matter how far they are located from the BS.
MHGEER is built upon three phases: clustering; data collection and aggregation; and distributed routing between CHs. The data collection and aggregation phases within each cluster are similar to LEACH [8] in its steady state phase. It might be possible to use other aggregation techniques [26, 27]; however, since this field is not the primary interest in this study, these are not detailed in this paper.
Network and energy model
In this paper, the considered sensor network is a group of sensors randomly deployed over a large area to regularly monitor the environment. Sensors are grouped into clusters in which each cluster is headed by an elected node responsible for transmitting the cluster’s data to the BS. We denote the \(i_{th}\) CH by \(H_i\) where \(i\in \{1,2, , N1\}\) and the BS by \(H_N\). Thus, the corresponding set of CHs and BS is denoted by \(H=\{H_1, H_2, ,H_{N1}, H_N\}\) where \(H = N\). Each CH \(H_i\) makes its decision to dynamically select the next hop \(H_j\) for routing (which can be another cluster head or the BS) based on a probabilistic function. The source node chooses in a stochastic way between multihop transmission through other CHs and direct transmission to the BS.
From the perspective of intercluster communication, the network consists of CHs and BS and can be modelled as a complete graph \(G=(\,N,E)\,\) where the set of vertices N represents the CHs and the BS and the edges set E represents the wireless links connecting each pair of CHs \((\,H_i , H_j)\,\) or pairs of CHBS \((\,H_i , H_N)\,\) for \(i , j \in \{1, 2, ,N1\}\). Figure 1 depicts the graph model used.
For our proposed MHGEER protocol, we assume that the considered sensor network has the following properties:

Sensor nodes are locationaware, i.e. equipped with a global positioning system (GPS) or a similar device.

The sensed information within each cluster is highly correlated and the aggregation function opted for by the CHs is the average of received values; thus aggregate packets in all CHs always have the same size.

The BS has an unlimited amount of energy.

The sensor nodes are static after being deployed in the network.

All nodes in the network are homogeneous and energyrestricted.
A simplified dissipation energy model is used, similar to the one proposed in [8]. The energy required to transmit an lbit message over a distance d is computed using the following equation:
$$\begin{aligned} E_{Tx}= {\left\{ \begin{array}{ll} E_{elec} \times l + \varepsilon _{fs} \times l \times d^2, &{} \quad \text {if}\ d\le d_0 \\ E_{elec} \times l + \varepsilon _{mp} \times l \times d^4, &{} \quad \text {if}\ d > d_0. \end{array}\right. } \end{aligned}$$
(1)
where \(E_{elec}\) is the radio electronics energy, \(\varepsilon _{fs}\) and \(\varepsilon _{mp}\) are the transmitter amplifiers corresponding, respectively, to the free space propagation model (\(d^2\) power loss) and the multipath fading propagation model (\(d^4\) power loss) depending on the transmission distance d. The \(d_0\) parameter is the threshold distance and can be computed by:
$$\begin{aligned} {d_0}= \sqrt{\frac{\varepsilon _{fs}}{\varepsilon _{mp}}}. \end{aligned}$$
(2)
To receive an lbit message, the energy expended is:
$$\begin{aligned} E_{Rx}= E_{elec} \times l. \end{aligned}$$
(3)
The energy required to transfer data from a CH node \(H_i\) to another \(H_j\), i.e. the transmission cost of the connection \((\,H_i,H_j)\,\), is denoted by \(e_{i,j}\) and given by the following expression:
$$\begin{aligned} e_{i,j}= E_{Tx}(i)+E_{Rx}(j) \end{aligned}$$
(4)
The residual energy of a node \(H_i\) is denoted by \(e_i\).
Clustering phase
The BS is in charge of the network clustering. This is a centralized process where the BS, at the beginning of the algorithm, divides the network into \((N1)\) groups and assigns the role of CH to the node with the highest energy level in each cluster. Then, at each round, the role of CH is given to another node within each cluster. In this paper, the clustering is static and settled by a centralized Kmeans algorithm [28, 29] where formed clusters remain fixed during the whole process. It is worth noting that the percentage of CHs in the network depends on several parameters chosen at the deployment of the network, the most important of which are the network topology and the chosen k value (for the Kmeans algorithm) that satisfies the properties requested by the application using this WSN.
More specifically, the clustering process is built upon two steps:

1.
Centralized clustering Each sensor node sends, initially, its position and energy level to the BS. This latter uses this positions to partition the network into dense clusters using the Kmeans technique. It also takes advantage of the information about the nodes’ energy to designate all the CHs in the network. Then, the BS directly transmits the clustering results back to each single node. In fact, depending of the nature of nodes, if the node is a member node, the BS directly sends an \(H_k\) parameter corresponding to the identity of the CH in the cluster k to which the node belongs where \(k \in [1,\ldots ,N1]\); otherwise, if the node is a CH node, the BS directly sends it, along with the \(H_k\) parameter, the set of other CHs, their energy levels and their distances to this CH. The centralized process of network clustering is illustrated in Fig. 2.
The Kmeans algorithm randomly sets a first partition of K clusters, which are represented by their centroids. Then, it processes the unsupervised algorithm with the objective of minimizing the distance between each data point and its nearest center. This technique provides a very high density in each cluster and guarantees that all member nodes within each cluster are close to each other. This closeness provides reliable information detection in the zone monitored by the cluster even after the death of several nodes in charge of an alternative zone. Moreover, given that an active CH is close to its neighbors, it consumes less energy during intercluster communication.

2.
Cluster head declaration
At each node, if the \(H_i\) received from the BS corresponds to its own identity, it recognizes itself as the CH, creates a TDMA schedule for data transmission coordination within the cluster and broadcasts it to its member nodes. If this is not the case, then the node recognizes itself as a nonCH, and waits for a delay time D to ensure that all the CHs in the network have received the information about their selection and are prepared to receive joining requests from other nodes in their cluster. Then, this nonCH sends a JOIN message to the CH and waits for the transmission schedule.
After completing the CHs declaration within each cluster, the member nodes transmit sensed data as well as their residual energy level to their CH according to the schedule and then turn OFF their radios to reduce their energy consumption. The role of CH is examined in order to ensure the most lasting node takes the lead for its cluster at the beginning of the next round. In fact, each CH compares the stored energy values of its member nodes with its own and selects the node having the greatest remaining energy as the new CH. If the current CH does not find a node with a greater energy level than itself in the cluster, it remains the CH for the next round. Then, each CH aggregates the data and the new CH identity \(H_k\) of its cluster k in one packet and sends it to the BS through the multihop intercluster routing backbone.
At the end of the data routing phase, member nodes turn ON their radios and wait to receive the new \(H_k\) identity from their previous CH. Meanwhile, the BS directly transmits to each new CH of the next round the set of other new CHs, their energy levels and their distances to this CH. This means each CH is aware of the other CHs in the network and prepared for the selection process detailed later in the routing phase. Thus, the declaration of CH is a distributed process among member nodes and a centralized process among CH nodes for the rest of the operational network time. Figure 3 shows the flowchart for the CH declaration in the network.
Routing phase
In this section, we describe a new intercluster routing protocol between the N members of the vertices set of our graph G, i.e. a route from the set of the CHs to the BS in a single period.
As explained above, at the beginning of each period, each cluster head \(H_k\) of the cluster k is informed by the BS during the clustering phase about other CHs in the network, their locations and their energy levels. When \(H_k\) wants to route its data to the BS, it launches an agent \(A_k\) to carry data and find a path to the BS. We can denote the track of the agent in this path as \(pth_k\) which is built by sequentially adding the index of the CH node chosen by \(A_k\). Thus, the complete path will be \(pth_k^c = \{k,i,j,\ldots ,N\}\) starting from node \(H_k\) and finishing at the BS (i.e. \(H_N\)) where \(i, j \in \{1,\ldots ,N1\}\setminus k\). \(A_k\) is also equipped with a memory table \(tab_k\) in which it stores the already visited nodes, their energy levels and the link cost.
\(A_k\) makes the choice of the next CH node according to a probabilistic rule \(p^k(i,j)\) ensuring network route exploration and efficient data transmission that balance the load distribution. \(p^k(i,j)\) is calculated as follows:
$$\begin{aligned} p^k(i,j)= {\left\{ \begin{array}{ll} \dfrac{\displaystyle \left( \frac{1}{\tau _{i,j}}\right) ^\alpha \times (\eta _{i,j})^\beta }{\displaystyle \sum \limits _{\begin{array}{c} n \in \{1,\ldots ,N\} \\ n \notin pth_k \end{array}^{~}} \left( \frac{1}{\tau _{i,n}}\right) ^\alpha \times (\eta _{i,n})^\beta }, &{} \quad \text {if}\ j \notin pth_k \\ 0, &{} \quad \text {otherwise} \end{array}\right. } \end{aligned}$$
(5)
where \(p^k(i,j)\) is the probability of agent \(A_k\) moving from \(H_i\) to \(H_j\), N is the set of CHs in our network (graph). \(\tau _{i,j}\) represents the pheromone trail value associated with the edge \((H_i,H_j)\) and indicates the track taken. It is used and updated by the algorithm during the routing phase. \(\eta _{i,j}\) represents the visibility of the edge \((H_i,H_j)\). It assigns to each connection in the path a heuristic value called the heuristic information depending on the current routing round. The terms \(\alpha\) and \(\beta\) are constants that determine the relative weight of the pheromone values and the heuristic (visibility) values.
From a general perspective, the pheromone associated with the edge joining CHs \(H_i\) and \(H_j\), \(\tau _{i,j}\) is updated during the lifespan of the network as follows (it will be refined from the perspective of an agent \(A_k\) below in formula 12):
$$\begin{aligned} \tau _{i,j} = \tau _{i,j} + \sum _k \varDelta \tau ^k_{i,j} \end{aligned}$$
(6)
where \(\varDelta \tau ^k_{i,j}\) is the quantity of pheromone laid on edge \((H_i,H_j)\) by all the crossing agents \(A_k\). It is calculated as follows:
$$\begin{aligned} \varDelta \tau ^k_{i,j} = \frac{E_{avr}E_{min}+m}{e_i} \end{aligned}$$
(7)
where \(E_{avr}\) and \(E_{min}\) are respectively the average and the minimum energy levels of all edges, stored in \(tab_k\), that belong to the complete path \(pth_k^c\) (i.e. the path from \(H_k\) to the BS). m is a small positive constant to avoid depositing a null pheromone amount in the particular case where the path is only one edge to the BS (otherwise the agent will continue choosing that particular path all the time and the algorithm detailed below will be blocked).
In summary, a small quantity of pheromone deposited at \((H_i, H_j)\) indicates that this connection belongs to an energy balanced path \(pth_k^c\) (which will be denoted hereafter as \(EB_k\)) and is initiated by a resourceful sensor node \(H_i\) (whose residual energy is \(e_i\)).
The visibility function is given by:
$$\begin{aligned} \eta _{i,j}=\frac{e_j}{e_{i,j}} \end{aligned}$$
(8)
where \(e_j\) and \(e_{i,j}\) are defined earlier in “Network and energy model” section. We favor, with this formula, transitions toward nodes with high residual energy connected by low transmission cost edges.
In the selection probability \(p^k(i,j)\), we multiply the heuristic value \(\eta _{i,j}\) by the inverse of the corresponding pheromone \(\frac{1}{\eta _{i,j}}\) on the edge \((H_i, H_j)\). In this way, we favor the choice of edges that have a smaller amount of pheromone, i.e. less visited edges where there has been low traffic transfer.
Initially, the pheromone value \(\tau _{i,j}\) is set to a small positive constant \(\tau _{cte}\). The CH \(H_k\) that wants to route its data to the BS creates an agent \(A_k\). This latter, moving from an \(H_i\) to an \(H_j\), stores in its memory table \(tab_k\) the visited vertex node \(H_j\), its residual energy \(e_j\) and the link cost \(e_{i,j}\) between the two vertices. It continues in the same way from one CH to another until it reaches the BS. It transfers to it the carried information containing the sensed data, the complete list of nodes visited (\(tab_k\)) and the decisions of the new CHs in each cluster calculated in the clustering phase. The BS calculates \(EB_k\) using the data extracted from \(tab_k\) carried by agent \(A_k\) as follows:
$$\begin{aligned} EB_k=E_{avr}E_{min}+m \end{aligned}$$
(9)
where,
$$\begin{aligned} E_{avr}= & {} \frac{\sum _{e_{i,j}\in tab_k} e_{i,j}}{pth_k^c1} \end{aligned}$$
(10)
$$\begin{aligned} E_{min}= & {} \min _{e_{i,j} \in tab_k} e_{i,j} \end{aligned}$$
(11)
Next, agent \(A_k\) is destroyed and the BS proceeds with a pheromone update for all CHs by depositing the calculated amount of the pheromone trail at each edge in \(tab_k\) in reverse. In fact, each \(H_i\) in the complete path \(pth_k^c\) receives \(EB_k\) directly from the BS, computes \(\varDelta \tau _{i,j}\) based on its energy level \(e_i\) using formula 7 and then updates its pheromone value by:
$$\begin{aligned} \tau _{i,j} =\tau _{i,j} + \varDelta \tau ^k_{i,j} \end{aligned}$$
(12)
Pheromone placed on the edges acts as a distributed longterm memory: this memory is not stored locally within the individual agents, but is distributed on the edges of the graph. This allows an indirect form of communication [30].
The routing table \(Rout_i\) for node \(H_i\) is obtained by integrating actual pheromone trail values \(\tau _{i,j}\) and heuristic values \(\eta _{i,j}.\)
Therefore, the pheromone value of each CH node, when visited by a new agent, is stored and updated by the BS at the end of data transmission. The BS is in charge of this task thanks to its unlimited energy, which reduces the energy consumption of the CH nodes.
The same routing process of the aggregate data to the BS is applied within each cluster by the CH, in each single round. Each source creates an agent traversing a certain path and chooses the edge with higher probability, then sends data to the nexthop, saves it in its list table and continues this way until it reaches the BS.
Each agent created both explores the route and transfers the data stored in its memory. Decisions relating to the next hop and the action of transmitting data are achieved locally and pseudosimultaneously by the agents at each CH of the vertices set H of our graph. This allows the system to save more energy and promotes the distributed aspect of the routing protocol. The whole routing algorithm protocol is shown in Algorithm 1 where i and j are indexes from \(\{1, 2,\ldots , N\}\) referring to the set of CHs \(\{H_1,H_2,\ldots ,H_{N1}\}\) and BS(\(H_N\)).