# Comparison Study of the PSO and SBPSO on Universal Robot Trajectory Planning
## 2 Materials and Methods
### Serendipity-Based Particle Swarm Optimization
```

Initialization:

01: initialize swarm speed and position

02: initialize speed and position of the Girl Scouts

03: while stop criteria not satisfied of the

loop.1:

04: for all particle i in S do

05: calculate fitness value

Condition:

06: if fit(\(x_{\text{id}}\)) \(<\) fit(pBest\({}_{\text{i}}\)) then pBest\({}_{\text{i}}\gets x_{\text{id}}\)

07: end if

08: end for

Function:

09: best\({}_{\text{swarm}}\leftarrow\) get Best Particle Swarm()

loop.2:

10: for all Girl Scout k in S do

function:

11: determine fitness value

condition:

12: if fit(Girl scout\({}_{\text{kd}}\)) \(<\) fit(pBest\({}_{\text{kd}}\)) then pBest\({}_{\text{kd}}\leftarrow\) Girl scout\({}_{\text{kd}}\)

13: end if

14: end for

function

15: best\({}_{\text{Girl Scout}}\leftarrow\) getBest Girl Scout()

condition:

16: if fit(best\({}_{\text{swarm}}\)) \(<\) fit(best\({}_{\text{Girl Scout}}\)) and fit(best\({}_{\text{swarm}}\)) \(<\) fit(gBest) then gBest \(\leftarrow\) best\({}_{\text{swarm}}\)

17: else if fit(best\({}_{\text{Girl Scout}}\)) \(<\) fit(best\({}_{\text{swarm}}\)) and fit(best\({}_{\text{Girl Scout}}\)) \(<\) fit(gBest) then gBest \(\leftarrow\) best

Girl Scout

18: end if

19: end if

20: creates \(n\) adjacent points (AP) using Equation (15)

loop.3

21: for all AP of the

22: define \(n\) director vectors \(\overset{\rightarrow}{d}\) using Equation (16)

23: for each vector \(\overset{\rightarrow}{d}\) do

24: Create two IP using Equation (17)

25: end for

26: end for

27: gBest \(\leftarrow\) getBest Inspection Point()

Loop.4

28: for all particle i in S do

29: determine speed using Equation (11)

30: update position using Equation (12)

31: end for

Loop.5

32: for each Girl Scout k in S do

33: calculate speed using Equation (13)

34: update position using Equation (14)

35: end for

36: if (swarm stagnated) and (swarm converged) then Resets Girl Scout Position and Speed

37: end if

38: end while In Figure 1, the direction of each of the straight lines is stochastic, since they connect the gBest to the inspection point tools. During all iterations, the lines have a reasonable perception of the behavior of the fitness function, even in an n-dimensional space. Again, the swarm particles' velocity is calculated, and the scout particles' position is updated (lines 32-35). Finally, the program assesses the swarm's state in terms of premature convergence and stagnation (row 36). The SBPSO restarts the position and velocity of the scout particles in (line 38):

### Methods for Detecting Premature Convergence

The PSO algorithm is a mechanism that can generate good trajectories in a short amount of time. However, the algorithm runs the risk of prematurely converging. The swarm will be converged prematurely when the solution proposal approaches a good location instead of the problem being optimized. Premature convergence is caused by a decrease of variety in the search space, which enables the swarm to become stagnant. After premature convergence begins, the particles continue to shut on each other in a very small region of the search space [27]. In order to avoid swarm stagnation, three strategies for detecting early convergence are proposed in [28]:

1. Determines the greatest Euclidean distance between the gBest particle and a swarm particle. When this distance is smaller than a threshold distance termed \(\delta\) stag, stagnation develops. Equation (17) is a form to present it: \[V_{id}^{(t+1)}=X_{id}^{t}+x_{id}^{(t+1)} \tag{12}\]2 (17) where \(\|e\mathrm{i}_{\mathrm{j}}-e\ast_{\mathrm{i}\mathrm{j}}\|\), is the Euclidean distance between the gBest particle and a particle of the swarm in iteration j. \(\mu_{\mathrm{min}}\) and \(\mu_{\mathrm{max}}\) represent the minimum and maximum of particle I, respectively. 2.