# Two-Stage Genetic Algorithm for Optimization Logistics Network for Groupage Delivery
## 3 Materials and Methods
### Two-Stage Genetic Alghotithm  
The primary objective was to address the logistics network optimization [32] for groupage delivery by selecting optimal warehouses and solving the VRP. To achieve this, a two-stage GA was employed (Figure 2a). The first stage focused on warehouse selection, and the second stage refined the routes between these selected warehouses to determine the most favorable locations and optimize the goods distribution. Figure 1: The difference between the TSP and VRP. The GA operates iteratively [33], orchestrating a series of generational changes while concurrently employing multiple interacting algorithms to emulate evolutionary mechanisms. The schematic representation of the GA process is depicted in Figure 2b. The complex optimization task at hand was addressed using the BaumEvA package [34], an advanced GA implemented in Python. Offering versatility, BaumEvA accommodates both binary and combinatorial data types, equipped with a comprehensive suite of optimization and search tools. It integrates various mechanisms for selection [35], crossover [36], mutation [37], and parent selection [38], ensuring robust performance across diverse optimization scenarios. Mathematically, our problem can be formulated as follows:  
\[\min\left(\underbrace{\sum_{l\in L}\sum_{i\in I\setminus\{i\}}c_{ij}x_{ijl}}_{ \text{Line~{}Haul~{}Cost}}+\underbrace{\sum_{j\in J}D_{j}}_{\text{Last~{}Mile~{}Cost}}\right) \tag{1}\]  
where  
* \(c_{ij}\) represents the cost of the line haul delivery between warehouse \(i\in I\) and customer \(j\in I\setminus\{i\}\). * \(x_{ijl}=1\) if a truck travels from warehouse \(i\in I\) to customer \(j\in I\setminus\{i\}\), and \(x_{ijl}=0\) otherwise. * \(D_{j}\) represents the cost of last-mile delivery to customer \(j\in J\). Here, \(I\subset J\) denotes the set of warehouses, and \(J\) is the set of all potential delivery points (including both customers and warehouses). Next, let us denote the creation of a warehouse at a delivery point \(i\in J\) by \(z_{i}\). Specifically, \(z_{i}=1\) if a warehouse is established at delivery point \(i\), and \(z_{i}=0\) otherwise. Therefore, we can express the set of warehouses \(I\) as  
\[I=\{i\in J:z_{i}=1\}\]  
We also define the volume of cargo \(v_{il}\) transported by truck to warehouse \(i\in I\) for product \(l\in L\). The total volume \(v_{il}\) transported to warehouse \(i\) should equal the total demand \(q_{j}\) for customers \(j\in F_{i}\), where \(F_{i}\) denotes the set of customers served by warehouse \(i\). This relationship can be written as  
Figure 2: (**a**) Two-stage GA scheme and (**b**) general scheme of the GA.  
\[\sum_{l\in L}v_{il}=\sum_{j\in F_{i}}q_{j},\quad\forall i\in I\]  
Each delivery point \(j\in J\) should be associated with a particular warehouse \(i\in I\). Let \(f_{ij}=1\) if delivery point \(j\in J\) is linked to warehouse \(i\in I\), and \(f_{ij}=0\) otherwise. Let \(F_{i}\) denote the set of delivery points associated with warehouse \(i\). In other words,  
\[F_{i}=\{j\in J\backslash I:\ f_{ij}=1,\ z_{i}=1,\ z_{j}=0\}\]  
\[\sum_{i\in I}f_{ij}=1,\ \forall j\in J\backslash I\]  
and any transported cargo volume is limited by the maximum capacity \(h\) of the trucks:  
\[\sum_{i\in I}v_{il}\leq h,\ \forall l\in L\]  
The load share of truck \(l\) can be calculated as \(\frac{\sum_{i\in I}v_{il}}{h}\). If truck \(l\) is carrying cargo to warehouse \(i\), its route must include a segment to reach this destination from some other point.