**2. PSO**

The theory behind particle swarm intelligence (PSO) is primarily nature-inspired, emulating the behaviour of animal societies by following the member of the group that is closest to the food source, such as flocks of birds and schools of fish. For example, a flock of birds during food search will follow a member of the flock that is closest to the position of the food source (the potential solution). This is achieved because of the simultaneous interactions made with each member of the flock in search of the best position. This continues until the food source is discovered (the best solution).

The PSO algorithm follows this process in search of the best solution to a given problem. The algorithm consists of a swarm of particles in which each particle is a potential solution, which usually leads to the best solution. This best solution is known as the global best and is called *g*(*t*) or *gbest*.

After obtaining the two best values, the particle updates its velocity and positions with Equations (1) and (2):

$$w\_i(t+1) = wv\_i(t) + r\_1c\_1(P\_i(t) - \mathbf{x}\_i(t)) + r\_2c\_2(\mathcal{g}(t) - \mathbf{x}\_i(t))\tag{1}$$

$$x\_i(t+1) = x\_i(t) + v\_i(t+1) \tag{2}$$

where:

*w* is inertia;

*vi*(*t*) is the particle velocity;

*xi*(*t*) is the current particle (solution);

*Pi*(*t*) and *g*(*t*) are defined as personal best and global best, respectively;

*r*1*r*2 are random numbers between (0,1);

*c*1*c*2 are learning factors;

*i* is the *i*-th particle.

The pseudo-code (Algorithm 1) and the flowchart (see Figure 2) of the procedure are shown below.

#### **Algorithm 1** PSO

**Input:** Objective function: f*i*; lower bound: lb; upper bound: ub; population size: Np; velocity: v; dimension size: D; termination criterion: T; inertia weight: w; learning rates: *c*1 and *c*2. **Output:** Return *gbest* as the best estimation of the global optimum Initialize the controlling parameters Population = Initialize Population (Np,D,ub,lb,v) Evaluate the objective function, f*i* Assign Pbest as Population and <sup>f</sup>*pbest* as f*i* Identify the solution with the best fitness and assign that solution as *gbest* and fitness as <sup>f</sup>*gbest* **for** t = 0 to T **for** *i* = 0 to Np

```
Calculate the velocity, vi of i-th particle
     Calculate the new position, Xi of i-th particle
     Bound Xi
     Evaluate objective function fi of i-th particle
     Update population using Xi and fi
     if (fi < fpbest,i) then
          Pbest,i = Xi
          fbest,i = fi
     end if
     if (fPbest,i < fgbest) then
        gbest = Pbest,i
        fgbest = fpbest,i
     end if
     Update Inertia, w
end for
end for
```
**Figure 2.** Flowchart of PSO algorithm.
