## 4 Two-Stage Algorithm Combining Genetic Algorithm and Quasi-Physical Approach
### Layout Task
#### 4.3.2 Algorithm for the Layout Task  
The proposed algorithm to solve the layout of each assigned container is a Component Swarm Optimization algorithm based on a Virtual-force system (CSO-VF) [124]. This algorithm is in line with other quasi-physical algorithms based on the virtual-forces system, as discussed in [3; 56; 57; 126]. The main focus of the algorithm is to define dedicated operators for the evolution of a dynamical system of the components based on the fundamental principle of dynamics to efficiently satisfy the constraints while minimizing the objective function. In CSO-VF, each component is assumed to be a particle in a swarm. At each iteration of the algorithm, depending on the virtual forces that are applied to the particle, each component moves within the container until the objective function is minimized and all constraints are satisfied. It is important to note that this type of algorithms differs from classical Particle Swarm Optimization (PSO) algorithms. Indeed, in the CSO-VF algorithm, each particle of the swarm corresponds to a single component; thus, to a subset of the entire solution while in PSO algorithms, a particle corresponds to an entire solution, i.e., an entire layout. Virtual-Force System  
In the CSO-VF algorithm, each component \(i\) is described by its dynamic features:  
* Its translational and rotational accelerations \(\mathbf{a}_{i}\) and \(\mathbf{L}_{i}\);
* Its translational and rotational speeds \(\mathbf{v}_{i}\) and \(\mathbf{\omega}_{i}\);
* Its position \(\mathbf{p}_{l,i}^{c}\) and orientation \(\mathbf{p}_{a,i}^{d}\). \(N_{F}\) forces (\(\mathbf{F}_{i}^{k},k\in\{1,...,N_{F}\}\), for component \(i\)) with a resultant \(\mathbf{F}_{i}\) as well as \(N_{T}\) torques (\(\mathbf{T}_{i}^{k},k\in\{1,...,N_{T}\}\), for component \(i\)) with a resultant \(\mathbf{T}_{i}\) are applied to the component in order to induce a movement at each iteration, as depicted in Figure 3. It must be noted that the torques are applied to non-circular components only. At the end of an iteration, the resulting force \(\mathbf{F}_{i}\) and torque \(\mathbf{T}_{i}\) are calculated for each component using Equations (27) and (28). The Fundamental Principles of the Dynamics of rotation and translation are applied in order to update the positions and orientations of the swarm of components at step \(t+1\) (separated from step \(t\) by \(\Delta t\), which corresponds to a time unit) according to Equations (29)-(31) (detailed for component \(i\) with mass \(m_{i}\) and solid inertia \(I_{i}\)). \[\mathbf{F}_{i}=\left\{ \begin{array}{ll}\sum_{k=1}^{N_{F}} \mathbf{F}_{i}^{k}&\text{if }\left\|\sum_{k=1}^{N_{F}}\mathbf{F}_{i}^{k} \right\|\leq F_{max}\\ \frac{\sum_{k=1}^{N_{F}}\mathbf{F}_{i}^{k}}{\left\|\sum_{k=1}^{N_{F}} \mathbf{F}_{i}^{k}\right\|}F_{max}&\text{otherwise.}\end{array} \right. \tag{27}\] \[\mathbf{T}_{i}=\left\{ \begin{array}{ll}\sum_{k=1}^{N_{T}} \mathbf{T}_{i}^{k}&\text{if }\left\|\sum_{k=1}^{N_{T}}\mathbf{T}_{i}^{k} \right\|\leq T_{max}\\ \frac{\sum_{k=1}^{N_{T}}\mathbf{T}_{i}^{k}}{\left\|\sum_{k=1}^{N_{T}} \mathbf{T}_{i}^{k}\right\|}T_{max}&\text{otherwise.}\end{array} \right. \tag{28}\]  
where \(F_{max}\) and \(T_{max}\) are hyperparameters corresponding to the maximum values of the norm of the resulting force and torque vectors, respectively. \[\mathbf{a}_{i,t+1}=\frac{\mathbf{F}_{i}}{m_{i}} \tag{29}\]  
\[\mathbf{v}_{i,t+1}=\mathbf{v}_{i,t}+\mathbf{a}_{i,t+1}\Delta t \tag{30}\]  
\[\mathbf{p}_{i,t+1}^{c}=\mathbf{p}_{i,t}^{c}+\mathbf{v}_{i,t+1}\Delta t \tag{31}\]  
\[\mathbf{L}_{i,t+1}=\frac{\mathbf{T}_{i}}{I_{i}} \tag{32}\]  
\[\mathbf{\omega}_{i,t+1}=\mathbf{\omega}_{i,t}+\mathbf{L}_{i,t+1}\Delta t \tag{33}\]  
\[\mathbf{p}_{\alpha,t+1}^{d}=\mathbf{p}_{\alpha,t,t+1}^{d}+\mathbf{\omega}_{i,t+1} \Delta t \tag{34}\]  
Figure 3: Definition of a component. Each of the forces and torques of the VFS aims at solving for the constraints and optimizing the objective function(s). If the objective or constraint functions take as arguments the positions of the components, a force is applied.