# Two-Stage Genetic Algorithm for Optimization Logistics Network for Groupage Delivery
## 3 Materials and Methods
### First Stage--Warehouse Selection  
The primary objective of this stage was to identify the optimal warehouse locations from a list of candidate delivery cities. By employing a standard GA that operated on binary strings, any delivery city capable of optimizing transportation costs could potentially serve as a branch warehouse.  
The GA utilized in this stage solves optimization problems with genotype representations [39] in the form of binary or real strings. For problems involving real strings, an original transformation to a binary string optimization problem is performed, employing either binary representation or standard reflexive Gray code [40].  
In the initial step, the genotype of a candidate solution (individual) was represented as a binary string. Each city was denoted by a bit, set to 1 if chosen as a warehouse and 0 otherwise. However, configurations where all cities were designated as warehouses (a binary string that consisted of all ones) or none (a binary string that consisted of all zeros) were deemed impractical and were typically not considered. To mitigate the likelihood of such configurations, population initialization techniques were employed to furnish the GA with an initial set of warehouses.  
Consequently, rather than commencing the optimization with entirely random configurations, the GA initiated optimization with a pre-established list of warehouses. This list could be generated through various means, including city clustering to designate cluster centers as warehouses or selecting the top cities by delivery volume.  
Subsequently, the fitness evaluation of the initial population ensued. The fitness function at this stage was derived from the GA employed in the second stage, where the routes between warehouses were determined based on the provided warehouse configuration, and the transportation budget was computed.  
The selection of individuals from the population was then conducted using selection methods grounded in the fitness values of all individuals within the current population. Proportional selection, also known as roulette wheel selection, assigned selection probabilities to the individuals proportional to their fitness values. Each individual's probability was determined by dividing their fitness by the total fitness of all individuals, akin to spinning a roulette wheel (see Figure 3a).  
Rank-based selection works not with an array of fitness function values directly, but with an array of normalized ranks assigned to individuals based on fitness values. Ranks are assigned to the elements of the unsorted fitness values array, i.e., numbers starting from 1 in the sorted array. If there are multiple identical elements in the array, the ranks are awarded to them as the arithmetic mean of the ranks of those elements in the sorted array. If this is not done, then the probability of selecting individuals of the same fitness function will not be equal to each other, which contradicts the idea of the selection operator. Next, proportional selection is used to select individuals by working with an array of ranks (Figure 4a).  
Figure 3: (a) Mechanism of proportional selection and (b) mechanism of binary mutation.  
Tournament selection [41] consists of selecting a given value of individuals from the population. Each individual can enter the group (tournament) only once. The individual with the highest fitness value is selected from this group. An individual can participate in several tournaments (Figure 4b).  
The selected individual parents are crossed and randomly form a new individual offspring with the same genetic traits of both parents. This approach ensures the heritability of genes (genotype components of individuals) in future generations. The classical binary GA uses different types of crossover (also called recombination).