## 4 Two-Stage Algorithm Combining Genetic Algorithm and Quasi-Physical Approach
### Layout Task
#### 4.3.2 Algorithm for the Layout Task
* The differentiable constraint function force and torque: Generally, any differentiable constraint function (DF), as the angle of inertia constraints, can be addressed thanks to gradient-based forces and torques, expressed as \[\mathbf{F}_{i}^{DF}=-\alpha_{DF}^{F}\
abla\mathbf{h}_{DF}(\mathbf{p}_{i,j}^{c})\] (42) \[\mathbf{T}_{i}^{DF}=-\alpha_{DF}^{T}\
abla\mathbf{h}_{DF}(\mathbf{p}_{i,j}^{d})\] (43) for constraints expressed as \(\mathbf{g}(\cdot)\leq 0\) and where \(\alpha_{DF}^{F}\) and \(\alpha_{DF}^{T}\) are \"step-size\" hyperparameters of the algorithm. \(\
abla\mathbf{h}_{DF}(\mathbf{p}_{i,j}^{c})\) corresponds to the gradient of any differentiable constraint function with respect to the position of the considered component \(i\). \(\
abla\mathbf{h}_{DF}(\mathbf{p}_{a,j}^{d})\) corresponds to the gradient of any differentiable constraint function with respect to the orientation of the considered component \(i\). * The objective function forces and torques: To minimize one objective function \(f\), a gradient-based force and a gradient-based torque can be applied. The objective function force and torque are expressed as \[\mathbf{F}_{i}^{obj}=-\alpha_{obj}^{F}\
abla f_{obj}(\mathbf{p}_{i,j}^{c})\] (44) \[\mathbf{T}_{i}^{obj}=-\alpha_{obj}^{T}\
abla f_{obj}(\mathbf{p}_{a,i}^{d})\] (45) where \(\alpha_{obj}^{F}\) and \(\alpha_{obj}^{T}\) are \"step-size\" hyperparameters of the algorithm. \(\
abla f_{obj}(\mathbf{p}_{i,j}^{c})\) corresponds to the gradient of the objective function with respect to the position of the considered component \(i\), and \(\
abla f_{obj}(\mathbf{p}_{a,i}^{d})\) stands for the gradient of the objective function with respect to the orientation of the considered component. It must be noted that in the case where the orientation variables are discrete (i.e., non-cylinder components taking orientation values in a defined subset), they are handled as relaxed continuous orientations. The updated orientation is calculated as a continuous variable and a threshold is set to define the discrete orientation from the subset. For instance, in the case where the non-cylinder components take their orientation in the subset (0 deg,90 deg), if the positive updated continuous orientation is greater (respectively, lower) than 45 deg the updated discrete orientation is 90 deg (respectively, 0 deg). Figure 7: Illustration of the balancing forces. The green area corresponds to the tolerance zone where the current center of gravity must be positioned. The red cross is the current center of gravity of the components. The swap operator introduced in CSO-VF is an extended version of the previous swap operators [128; 129; 130]. The swap operator exchanges the positions of a pair of components after a given number of iterations if it is improving the objective function(s) or decreasing the violation of some selected constraint(s). Thus, the swap operator can be used to find promising configurations in terms of constraint satisfaction and objective function; therefore, it does not necessarily need the configuration to be somewhat stuck in order to be employed in CSO-VF algorithm. For instance, the swap operator can be used to exchange components such that the global center of gravity of the system quickly enters the given tolerance zone, as illustrated in Figure 8.  
Thus, the swap operator implemented in the CSO-VF algorithm has the following characteristics:  
* The swap operator can exchange all the components by pairs. * Two components are swapped if the swap leads to an improvement of the objective function or a decrease in the violation of some chosen constraint(s) while not deteriorating the other constraint(s) from a relaxation factor \(r\). * The swap operator is called straight from the first iteration. Then, it can occur throughout the optimization process. The swap operator is called at a frequency depending on the convergence status. Indeed, the swap operator induces a reconfiguration. Consequently, too frequent swaps might prevent the layout from converging.