## 5 Energy Optimization Approach Based on MAC/Routing Cross-Layer (EOAMRCL)
### Clusters Formation Phase (Network Layer)  
Before the start of each iteration in Algorithm 2, every node transmits its remaining energy to the BS. Upon receiving the energy levels from all nodes, the BS calculates ARE and selects nodes with a probability higher than \(P_{threshold}\) to become candidate CHs. The BS then implements our proposed EOAMRCL approach, forming a set of wolf vectors from the group of nodes with a probability above \(P_{threshold}\). These wolf vectors consist solely of nodes eligible to be CHs, as shown in Figure 5.  
The fitness value of each wolf vector is then calculated using Equation (5). \[Fitness=w_{1}\cdot f_{1}+w_{2}\cdot f_{2}+w_{3}\cdot f_{3} \tag{5}\]  
Thus, the best wolf is the one with the lowest fitness value. In this context, \(w_{1}\), \(w_{2}\), and \(w_{3}\) are constants in a user-defined function, with the requirement that \(w_{1}+w_{2}+w_{3}=1\), used to determine the contribution of each sub-objective, \(f_{1}\), \(f_{2}\), and \(f_{3}\). In our experiments, we set the weight values as follows: \(w_{1}=0.45,\ w_{2}=0.45,\ w_{3}=0.1\). These weights ensure equal importance is given to both inter-cluster and intra-cluster distances while using energy as a tie-breaker in case of equal distances. The sub-objective \(f_{1}\) is calculated as the normalized sum of the distances between each CH in the wolf vector and all other nodes in the network, as shown in Equation (6):  
\[f_{1}=\frac{1}{MD\times N_{CH}\times n}\sum_{i=1}^{N_{CH}}\sum_{j=1}^{n}\left\{ \begin{array}{ll}dist\big{(}CH_{i},S_{j}\big{)},&S_{j}\text{ { close to CH}}_{i}\\ 0,&\text{otherwise}\end{array} \right\}, \tag{6}\]  
where the following is true:  
Figure 5: Construction of wolf vectors from eligible CHs. * \(MD\) represents the maximum distance between two sensors;
* \(N_{CH}\) represents the number of CHs in the wolf vector;
* \(n\) represents the total number of nodes;
* \(CH_{i}\) represents the clusterhead;
* \(S_{j}\) represents the regular sensor node;  
To calculate \(dist\big{(}CH_{i},S_{j}\big{)}\), we use the Euclidean distance between two nodes, A and B, as shown in the following Equation (6). \[dist(A,\ B)=\sqrt{\left(x_{A}-x_{B}\right)^{2}+\left(y_{A}-y_{B}\right)^{2}}, \tag{7}\]  
where \(\left(x_{A},y_{A}\right)\), \(\left(x_{B},y_{B}\right)\) are the coordinates of A and B, respectively. The sub-objective \(f_{2}\) represents the normalized sum of the distances between each CH in the packet and the BS, as shown in Equation (8):  
\[f_{2}=\frac{1}{MD\times N_{CH}}\sum_{i=1}^{N_{CH}}dist(CH_{i},BS) \tag{8}\]  
The sub-objective \(f_{3}\) represents the negative normalized total remaining energy of the CHs within the wolf vector, as shown in Equation (9):  
\[f_{3}=\frac{-1}{E_{0}\times N_{CH}}\sum_{i=1}^{N_{CH}}E_{CH_{i}}, \tag{9}\]  
where \(E_{CH_{i}}\) represents the remaining energy of \(CH_{i}\). Our process of updating and calculating new wolf vector is systematically guided by GWO. This connection to a proven optimization algorithm lends our work credibility and relevance within the field of optimization [44]. ```
1. Input: Probability threshold \(P_{threshold}\);
2. Form wolf vectors from the group of nodes with probability greater than \(P_{threshold}\);
3. Initialize alpha (\(\alpha\)), beta (\(\beta\)), and gamma (\(\gamma\)) wolf vectors with the best fitness values using Equation (5);
4. While (\(t<l_{max}\)) Do



### Algorithm Complexity Analysis

The cluster formation phase algorithm, which integrates the GWO method, is designed to select the optimal CHs based on fitness values. The computational complexity of our algorithm can be summarized as follows:

* Initialization: Forming wolf vectors from the group of nodes involves evaluating the probability of each node, leading to a complexity of O(\(W\cdot n\)) given \(n\) nodes. Initializing the alpha, beta, and gamma wolf vectors requires selecting the top three fitness values, which is O(\(W\cdot n\)) due to sorting;
* Main Loop: The outer while loop runs for a maximum number of iterations \(t_{max}\).