# Trajectory Planning and Optimization for a Par4 Parallel Robot Based on Energy Consumption
## 4 Trajectory Optimization Based on GWO
### Grey Wolf Optimizer  
The GWO algorithm is a new intelligent algorithm, proposed in 2014 [38]. Because of its features of simple operational structure, high search efficiency, and ease of understanding and programming, it has been widely employed in all walks of life since it was proposed [39; 40; 41].  
The GWO algorithm aims to simulate the group hunting behavior of grey wolves [38]. In GWO, the prey represents the optimal solution, and the process of optimization can be understood as catching the prey. Generally, there are three grey wolves in leadership roles, named [PERSON] \(\alpha\), [PERSON] \(\beta\) and [PERSON] \(\delta\), and there are many searching wolves, all called Wolf \(\omega\), whose number is often in dozens. During the process of catching the prey, [PERSON] \(\alpha\) is the wolf closest to the prey, [PERSON] \(\beta\) the further away, and [PERSON] \(\delta\) further away again. The positions of the three leader grey wolves are always taken as a reference for [PERSON] \(\omega\) to carry out the hunting search behavior. Until all Wolves \(\omega\) complete the hunting search behavior with their own positions updated, the position of [PERSON] \(\alpha\), [PERSON] \(\beta\) or [PERSON] \(\delta\) can be updated as long as the solution of Wolf \(\omega\) is better than theirs. In each iteration, Wolf \(\alpha\) always represents the optimal solution, meaning it is closest to the prey. In the hunting search progress, the updated position of Wolf \(\omega\) is very important, which can be calculated as follows:  
\[x_{1}^{j+1}=x_{\alpha}-a_{1}\Big{|}c_{1}x_{\alpha}-x_{r}^{j}\Big{|} \tag{28}\]  
\[x_{2}^{j+1}=x_{\beta}-a_{2}\Big{|}c_{2}x_{\beta}-x_{r}^{j}\Big{|} \tag{29}\]  
\[x_{3}^{j+1}=x_{\delta}-a_{3}\Big{|}c_{3}x_{\delta}-x_{r}^{j}\Big{|} \tag{30}\]  
\[x_{r}^{j+1}=\frac{x_{1}^{j+1}+x_{2}^{j+1}+x_{3}^{j+1}}{3}. \tag{31}\]  
Here, \(x_{r}^{j}\) is the position vector of the \(r\)th wolf in the current iteration, \(x_{r}^{j+1}\) the position vector of the \(r\)th wolf in the next iteration, \(x_{\alpha}\), \(x_{\beta}\) and \(x_{\delta}\) the current position vectors of Wolf \(\alpha\), Wolf \(\beta\) and Wolf \(\delta\), respectively, and the calculation formulas of the parameters \(a\) and \(c\) are as follows:  
\[a=2\cdot\textit{rand}1\cdot\chi-\chi \tag{32}\]  
\[c=2\cdot\textit{rand}2 \tag{33}\]  
In Equations (32) and (33), all elements in vectors \(\textit{rand}1\) and \(\textit{rand}2\) are random variables between 0 and 1, the value of the element in vector \(\chi\) gradually decreases from 2 to 0 with the increasing of iterations, and the \(i\)th-dimensional element of vector \(\chi\) can be calculated as follows:  
\[x_{i}=2-2\cdot i/\textit{Max\_iter} \tag{34}\]  
where \(i\) is the number of the current iteration and \(\textit{Max\_iter}\) the total number of iterations.  
The result obtained by substituting the position vector of the wolf into the objective function is called the fitness. Then, the steps of GWO can be described as follows:  
**Step 1:** Randomly initialize the position vectors of all wolves, including Wolf \(\alpha\), Wolf \(\beta\), Wolf \(\delta\) and all Wolves \(\omega\) within the allowable range, and obtain the corresponding fitness values.  
**Step 2:** Compare the fitness value of Wolf \(\omega\) with the fitness values of Wolf \(\alpha\), Wolf \(\beta\) and Wolf \(\delta\), respectively, and if the fitness value of Wolf \(\omega\) is superior, then use the position vector of Wolf \(\omega\) to replace the position vector of Wolf \(\alpha\), Wolf \(\beta\) or Wolf \(\delta\), accordingly.  
**Step 3:** Update the position vector of Wolf \(\omega\) in accordance with Equations (28)-(31).  
**Step 4:** Determine whether the iteration end condition is met. If the condition is satisfied, output the position vector and the fitness value of Wolf \(\alpha\), otherwise return to Step 2, and continue to perform the searching behavior.