## 5 Simulated Annealing Algorithm
### Application of the SA Algorithm to the 6-DoF Redundant Planar Manipulator Robot  
The SA basic algorithm starts with an iteration number \(C\), an initial state vector \(x_{i}\) of six components (initial solution), that represents the initial inverse kinematics of the robot, and maintains a calculation of a parameter \(T\), commonly called temperature, which is initially high and then is progressively reduced to a value \(T_{f}\) close to zero during the algorithm execution [23]. The configuration of the state and temperature is typically a solution for the function to be optimized. This paper considers an initial temperature \(T=\)90, \(C=450\) iterations, and the cooling factor \(\alpha=\)0.94. The solution is perturbed in each iteration of the algorithm to produce a new neighbor solution \(x_{j}\) from its neighborhood [32]. The first heuristic perturbation of the initial state \(x_{i}\) occurs according to Equation (9). \[x_{j}=x_{i}(1+n_{1}c_{1}-n_{2}) \tag{9}\]  
where: \(n_{1}\) and \(n_{2}\) are the environment variables and \(c_{1}\) is a random number evenly distributed over the (0,1) interval. Subsequently, it is verified that the value of each component of the \(x_{j}\) vector calculated in Equation (9), which represents the joint position (current inverse kinematics), is within the mechanical limits of the redundant planar manipulator robot. Otherwise, a new calculation of the values for \(x_{j}\) is made using Equation (10). \[x_{j}=x_{i}(1+n_{3}c_{2}) \tag{10}\]  
where: \(n_{3}\) is an environment variable and \(c_{2}\) is a random scale evenly distributed. This second disturbance of \(x_{i}\), governed by Equation (10) does not stop until each value of the joint variables of \(x_{j}\) is within the allowed limits. In addition, the quality of both solutions is assessed using a \(D\) target function, which is shown in Equation (11). Then, a new state \(x_{j}\) could be eventually selected from the two solutions, as long as \(x_{j}\) is better quality than \(x_{i}\). \[D=d(x_{j})-d(x_{i}) \tag{11}\]where: \(d(x_{i})\) is the performance of the initial state, and \(d(x_{j})\) the performance of the current state, as shown in Figure 3. The calculation of each performance corresponds to the root mean square function shown in Equation (12):  
\[d(x_{k})=\frac{\parallel p(x)-p(x_{k})\parallel}{2}=\frac{d_{k}}{2};\ k=i,j \tag{12}\]  
\[x_{k}=[q_{1k},q_{2k},\ldots,q_{nk}];\ k=i,j \tag{13}\]  
where: \(d_{k}\) is a cost function, \(p(x_{i})\) is the initial position of the end effector due to the initial joint configuration \(x_{i}\), \(p(x_{j})\) is the current position of the redundant planar manipulator robot, \(x_{j}\) is the current state vector of the joints position, \(p(x)\) is the set point, and \(x\) the target vector that contains the joint variables (inverse kinematics). To assess the quality of the new solution \(x_{j}\), one acceptance criterion is assessed in each execution step of the SA algorithm. This criterion is associated with a change of energy \(\triangle E\) (in this case, \(\triangle E=D\)), where: if \(D\leq 0\), the shift is immediately accepted, while if \(D>0\), the possibility of accepting the disturbing solution depends on the temperature and the solution is finally accepted, but with a probability of [33]:  
\[K<exp\left(-\frac{D}{T}\right) \tag{14}\]  
where: \(K\) is a random value \(\in\) (0,1). Once the shift is approved, the initial state vector \(x_{i}\) is updated to \(x_{j}\) (\(x_{i}=x_{j}\)) and the algorithm described iterates 449 times (as a maximum) based on Equation (9) until finding a better \(x_{j}\). Once iterations end, the starting temperature \(T\) is reduced following Equation (15), and the procedure is repeated to search for a better \(x_{j}\) until the temperature \(T\) is lower than the minimum temperature established, \(T_{f}\) (\(T<T_{f}\)) [34]. The latter is the stop criterion of the SA algorithm. \[T=\alpha T \tag{15}\]  
where: \(\alpha\) is a cooling factor, which determines the speed at which the system cools down [35].