## 5 The Proposed Routing Method
### Routing Tree Based on Dragonfly Algorithm (DA-Tree)  
CTSRD creates a binary routing tree based on the dragonfly algorithm (DA-Tree) between CHs. The dragonfly algorithm must discover the best binary routing tree. Each CH transfers data packets to its parent through DA-Tree, so that these packets finally reach the base station. In this process, the task of BS is to run the DA-Tree algorithm to specify the positions of CHs in DA-Tree. In this issue, each dragonfly is a binary routing tree between CHs (i.e., a response to this issue). The routing tree creation is dependent on four parameters: the number of hops from CH to the base station, the remaining energy, the number of cluster members, and the trust level. The DA-Tree creation process involves five stages: the formation of the primary population, the DA-based tree creation, the tree evaluation, the stop condition, and the update of dragonflies. In the DA-Tree algorithm, we suppose that the BS knows the information about CHs, for example, the hop count between them and BS, their remaining energy, the number of their cluster members, and their trust level. * **Primary population formation:** This step initializes each dragonfly using a random manner. Each dragonfly is an array whose number of elements indicates the number of CHs, and each element corresponds to a CH in the routing tree. The purpose of the dragonfly algorithm is to prioritize CHs on the network and place a CH with a higher priority at the upper level of the routing tree. Note that in each dragonfly, each element specifies the priority of the corresponding CH in the network. * **DA-based routing tree creation:*
* This step describes how to create DA-Tree based on dragonflies. DA-Tree follows four rules. * Rule 1: The root of the tree is the base station. * Rule 2: According to the dragonfly, the CH with the maximum priority is the left child of BS, and the CH with the second priority is placed as the right child of the base station. * Rule 3: At each level of this binary routing tree, the leftmost CH must first determine its children. In this case, it first specifies its left child and then the right child in DA-Tree. The left child and the right child are two CHs, which have the highest and second priorities, respectively, and have not been chosen so far. * Rule 4: If two CH have a similar priority in a dragonfly, the CH with a higher trust level has a higher priority. * **Tree evaluation:** This step presents a fitness function to evaluate the formed routing trees. This function comprises four scales:  
**1. ** Number of hops to BS This scale is used in the fitness function to place CHs close to BS at the upper tree levels because these nodes consume less energy to send data to BS. **2. ** Remaining energy This parameter is considered in the fitness function to place high-energy CHs at the upper tree levels because the nodes placed at upper levels have more tasks and require a lot of energy. They must send data related to their cluster member nodes as well as data packets received from other CHs in their sub-tree to the BS. **3. ** Number of cluster members This parameter is used in the fitness function to place CHs, which connect to the small number of cluster members at upper tree levels. If there is a cluster head node that connects to many CMs, it needs a lot of energy to receive/send data packets within the cluster. Thus, it must be placed at the downer tree levels to reduce the communication overhead due to inter-cluster connections. This improves energy consumption in the network. **4. ** Trust level This scale is used in the fitness function to place the safer CHs at upper tree levels. CHs at upper tree levels have more tasks in terms of inter-cluster communications. As a result, these nodes should be safer because, if a malicious node attacks these CHs, it can cause more damage to the network performance. Finally, this fitness function is calculated based on Equation (21).