## 4 Two-Stage Algorithm Combining Genetic Algorithm and Quasi-Physical Approach
### Layout Task
#### 4.3.2 Algorithm for the Layout Task
\begin{cases}\frac{\mathbf{p}^{c}_{I,C}-\mathbf{p}^{c}_ {I,i}}{\|\mathbf{p}^{c}_{I,C}-\mathbf{p}^{c}_{I,i}\|+\epsilon}v_{max}- \mathbf{v}_{i},&\text{if }\Delta S_{i/C}(\mathbf{p}^{c}_{I,i},\mathbf{p}^{c}_{I,C})<S _{i},\\ \mathbf{0}&\text{otherwise}.\end{cases} \] (37) where \(\mathbf{p}^{c}_{I,C}\) corresponds to the position vector of the geometrical center of the container. \(\Delta S_{i/C}\) is the intersection area between the component \(i\) and the exclusion zone, and \(S_{i}\) is the surface of the component \(i\). The related torque is calculated as follows: \[\mathbf{T}^{container}_{i}=\mathbf{O_{i}O_{out}}\wedge\mathbf{F}^{container}_{i}\] (38) where \(O_{i}\) is the center of inertia of component \(i\) and \(O_{out}\) is the geometrical center of the area of the component \(i\) situated outside the container. * The functional constraint force and torque between two components: If a component is too close to an incompatible component \(j\), a repulsive force \(\mathbf{F}^{functional}_{i}\) is applied to the component \(i\), as illustrated in Figure 6. The functional force acts as an overlapping  
Figure 5: Illustration of the forces and torques to solve overlapping constraints between two components, between a component and an exclusion zone, and between a component and the container. force between the component \(i\) and the influence zone of the component \(j\). Then, the functional force is expressed as  
\[\mathbf{F}_{i}^{functional}=\left\{ \begin{aligned} &-\frac{\mathbf{p}_{i,j}^{c}- \mathbf{p}_{i,j}^{c}}{\|\mathbf{p}_{i,j}^{c}-\mathbf{p}_{i,i}^{c}\|+\epsilon }\mathbf{v}_{max}-\mathbf{v}_{i},&\text{if }\Delta S_{i/SZj}(\mathbf{p}_{i,i}^{c}, \mathbf{p}_{i,j}^{c})\
eq 0,\\ &\mathbf{0}&\text{otherwise}.\end{aligned} \right. \tag{39}\]  
where \(\Delta S_{i/SZj}\) is the intersection area between component \(i\) and the functional security zone surrounding component \(j\). The related torque is calculated as follows:  
\[\mathbf{T}_{i}^{functional}=\mathbf{O}_{\mathbf{i}}\mathbf{O}_{\mathbf{z}j} \wedge\mathbf{F}_{i}^{functional} \tag{40}\]  
where \(O_{i}\) is the center of inertia of component \(i\) and \(O_{zj}\) is the geometrical center of the area of component \(i\) overlapping the functional security zone surrounding component \(i\). * The balancing constraint force: In order to position the center of mass of the components in a tolerance zone centered at the geometrical center of the container, gradient-based forces are applied along the opposite of the gradient of the position of the global center of mass according to the position of the center of inertia of each component. This force is named \(\mathbf{F}_{i}^{CG}\) and is illustrated in Figure 7. The balancing force is expressed as \[\mathbf{F}_{i}^{CG}=\left\{ \begin{aligned} &-\alpha_{CG}\
abla\mathbf{h}_{CG}^{F}( \mathbf{p}_{i,j}^{c}),&\text{if }\sqrt{(x_{CG}-x_{e})^{2}+(y_{CG}-y_{e})^{2}} \leq\delta_{CG},\\ &\mathbf{0}&\text{otherwise}.\end{aligned} \right.\] (41) where \(\alpha_{CG}^{F}\) is a \"step-size\" hyperparameter of the algorithm and \(\
abla\mathbf{h}_{CG}(\mathbf{p}_{i,i}^{c})\) corresponds to the gradient of the position of the center of gravity of the components with respect to the position of the considered component \(i\). \(\{x_{CG},y_{CG}\}\) are the coordinates of the current center of gravity; \(\{x_{e},y_{e}\}\) are the coordinates of the position of reference on which the tolerance zone defined by \(\delta_{CG}\) is centered. This type of force is inspired by gradient-based descent algorithms. Figure 6: Illustration of the functional force and torque.