# Sequential Memetic Algorithm Optimization for Allocation Planning in Hostelry Establishments
## 3 Sequential Optimization
### Table Distribution Optimization  
The first stage of the algorithm consists of the MA optimization for optimally allocating a certain number of tables over the introduced scenario. The algorithm's basic structure is described in the Algorithm 1. Once loaded, the base scenario \(\pi\), with the boundariesand obstacles, the population is generated according to the proposed codification, depicted in Figure 3.  
Each individual contains the Cartesian coordinates of each table over the given scenario. These values are coded in binary, which is a key design factor for future genetic operators of the MA. A binary to decimal scaled conversion is proposed for optimally surveying the given scenario, avoiding the location of tables outside the scenario boundaries in irregular establishments as proposed in [15]. Moreover, each table carries an ID tag for its identification during the LS and for the CLP optimization. The conversion and scale of each table location to the scenario of application and the obstacle collision detection are performed within the fitness function, evaluating each individual according to the achieved distance distribution and the fulfillment of certain restrictions. The main structure of this algorithm is described in Algorithm 2. ```
1 forIndividualinPopulationdo
2\(T\leftarrow\) Decodification of Population for Scenario \(\pi\);
3\(d\leftarrow\) Distance distribution \((T,d_{CLE})\);
4\(N_{obs}\leftarrow\) Number of collisions between tables \(T\) and obstacles in \(\pi\);
5\(N_{d_{s}},\delta_{d_{s}}\leftarrow\) Number of distances under \(d_{s}\) and severity of the \(d_{s}\) breach;
6 if\(\max(N_{d_{s}},N_{obs})>0\)then
7\(f(Individual)\leftarrow\) Negative fitness evaluation \((N_{d_{s}},N_{obs},\delta_{d_{s}},d)\);
8 end if
9 elseif\(\max(N_{d_{s}},N_{obs})==0\)then
10\(f(Individual)\leftarrow\) Positive fitness evaluation \((d)\);
11 end if
12
13 end for
```  
**Algorithm 2** Fitness function for the TLP MA (\(d_{CLE},Population,\pi\))  
The fitness evaluation of each individual starts by obtaining the Cartesian coordinates of each table location, \(T\). From these locations, the interpersonal distance distribution between tables \(d\) is computed, which is measured as the Euclidean distance between the CLE regions of each table, as shown in Figure 1.  
Therefore, the distance calculation requires the obtention of the distance from each table center to the intersection of each CLE region for the intersection angle. However, this distance, \(d_{CLE}\), is only dependent on the angle of intersection \(\alpha\) between tables and the table geometry. Figure 3: Codification and decodification scheme of the population for the TLP LS MA. Consequently, in the proposed algorithm, a \(d_{CLE}\) polar distribution is computed at the start of the TLP optimization for multiple intersection angles, saving these values for the table-to-table distance calculation, reducing the complexity of the fitness evaluation algorithm [16]. Moreover, the algorithm evaluates the number of collisions with obstacles and the number of distances that do not reach the \(d_{s}\) minimum interpersonal distance. The severity of the infringement \(\delta_{d_{s}}\) is also measured for the unsuitable distance, where \(\delta_{d_{s}}=d_{s}-d_{ij}\). Based on this restriction analysis, two different evaluation methodologies are proposed. Table distributions that exhibit any penalization (i.e., obstacle collision or distance unfraction) are penalized according to the expressions exhibited in Equations (5) and (6), resulting in a negative fitness value. On the other hand, table distributions that do not result in any obstacle collision or any distance infraction result in a positive fitness function, guiding the optimization into adhering to these imposed restrictions. Once evaluated, the individuals are preserved, arranged, crossed, and mutated through the respective genetic operators.