# Routing Enhancement in MANET Using Particle Swarm Algorithm
## 3 The Proposed Method  
EPSO proposes a routing algorithm that uses traditional PSO to select the most appropriate path. In MANETs, routes are updated dynamically due to frequent position and velocity updating. EPSO is used in the MANET protocol to maximize the performance by enhancing the path selection in MANET. The following EPSO methodology is applied in this study to enhance the performance of the MANET routing protocols:  
1. Initialize the parameters of the PSO algorithm. 2. Look for the best parameters for the MANET routing protocols. 3. Select the best routing path for the MANETs. 4. Evaluate the MANET performance. In EPSO, each particle represents a potential routing path from a source node to a destination. Each particle is represented as a sequence of nodes from the source to the destination. For instance, a particle might be [S, B, C, D], where S is the source, D is the destination, and B and C are intermediate nodes. The fitness function evaluates the selection path; it is calculated for each particle based on its position and velocity. The proposed model enhances the PSO algorithm by modifying the fitness function as seen in Algorithm 1. The fitness function in the EPSO takes into account the distance between nodes, in the case of various paths, the path that has the least distance will be selected. It also considers energy consumption and the delay in path selection to increase the network performance. Energy consumption is the total energy consumed along the selected path. The delay is the total time needed to move data between the source and destination. The modified fitness function is calculated using the following equation:  
\[Fitness=\sum_{i=1}^{N}\left(P_{i}+D_{i}+Dis\right) \tag{3}\]  
where \(N\) is the number of nodes in the path, \(P_{i}\) is the total consumed power from source node to the \(i\)th node, and \(D_{i}\) is the total delay from source node to the \(i\)th node. Dis is the total distance between the source S and destination D, calculated using the Euclidean distance formula represented in Equation (4). \[Dis=\sqrt{(x_{i}-x_{i+1})^{2}+(y_{i}-y_{i+1})^{2}} \tag{4}\]```
Input: \(Max_{iter}\gets Maximum\) number of iteration \(u_{p},l_{b}\gets Upper\) bound and lower bound \(c_{1},c_{2}\leftarrow\) Cognitive parameter and Social parameter \(I\gets Population\) size \(S\leftarrow\) Source node \(D\gets Destination\) node Output:  The path from the source node S to the destination node D that achieves the minimum fitness value. Begin:  Randomly initialize particle position X and particle velocity V vectors. Initialize the personal best solution(\(P_{best}\)) to its initial position for each particle. Initialize the global best solution(\(G_{best}\)) to the position with the minimum fitness value. \(i=1\) while\(i<Max_{iter}\)do  Set the first node in the path X1 to the source node \(S\). forj = 2 to I do  Update particle velocity using Equation (1). Update particle position using Equation (2). iff(\(X_{i}\)) \(>f(P_{best})\)then \(P_{best}=X_{i}\) endif if\(X_{i}\ =\ D\)then  Destination is reached; exit the for loop. endif endfor  Update the global best solution (\(G_{best}\)) to the position with the minimum fitness value using Equation (3). \(i=i+1\) endwhile End
```

**Algorithm 1** Pseudocode of proposed PSO

### An Illustrative Example

Figure 1 shows a demo network used to describe the proposed PSO algorithm used to find a route. Consider that node 8 is the source and node 2 is the destination. At the beginning of PSO, we defined particles, where each particle is the problem solution. In our algorithm, each particle is a potential route. For instance, we have three particles; the first particle takes a position in the source node. At the beginning, the particle's velocity is zero. The algorithm checks the neighbors of the source node and chooses a random node from the neighbor's list. First, it selects node 5 from the neighboring list and checks whether it has reached the destination node; node 5 is not the destination.