# Two-Stage Metaheuristic Algorithms for Order-Batching and Routing Problems
## 4 Proposed Algorithm
### SA Algorithm  
Because this study involved two problems, a single-solution metaheuristic is more suitable for solving the problems compared with a population-based metaheuristic. If a population-based metaheuristic is adopted, then multiple solutions are generated at the first stage, and each solution results in the generation of several solutions at the second stage, thereby reducing the efficiency of deriving solutions. In addition, the SA algorithm involves a random mechanism; hence, it was applied for solving the problems in the two stages. The SA algorithm can be applied to solve both TSPs and batching and packing problems. Therefore, we initially combined two types of SA. First, the framework of the first stage was used when solving the batches through the SA algorithm. Each time the neighboring solution was substituted, the SA algorithm applied to the picking routes was reconsidered. The distance of the picking routes must be determined to yield the neighboring solution of the batch. The following parameter values must be established first:  
1. Starting temperature (\(T_{0}\)): Temperature setting is crucial in the SA algorithm. If the value is excessively high, then the convergence is slow; however, if the value is excessively low, then the solution quality becomes unsatisfactory. 2. Maximum chain length (\(L_{max}\)): The chain length is determined to control the search frequency at each temperature. If the length is too short, then the execution time can be shortened; however, the quality of solutions cannot be enhanced. If the length is too long, then the eventual quality and effect of the solution increase. However, the additional execution time reduces the efficiency of obtaining solutions. The maximum batching and picking chain lengths are set as \(LL_{max}\) and \(L_{max}\), respectively. 3. Annealing parameter (\(\beta\)): The variable s represents the annealing frequency and \(\beta\) represents a parameter whose value is set at 1; moreover, \(T(s+1)=T/(1+\beta T(s))\). 4. Stopping criterion: To avoid falling into infinite loops, a terminal temperature and computation time are set. The SA algorithm steps are described as follows: Step 1: Set the starting temperature as \(T_{0}\), the number of maximum order items as \(item_{max}\), number of minimum order items as \(item_{min}\), the Boltzmann constant as \(K\), the number of orders as \(O\), the maximum location of an item as \(I_{max}\), the minimum location of an item as \(I_{min}\), the maximum capacity in terms of weight as \(cap_{max}\), the minimum capacity as \(cap_{min}\) the annealing parameter as \(\beta\), the maximum picking chain length as \(L_{max}\), the maximum batching chain length as \(LL_{max}\), and the starting chain length as \(L=0\) and \(LL=0\). Step 2: For each order, randomly generate the weight of the order \(OW\), and set the order item numbers as \(OI\) and the item location as \(OL\). Step 3: Assign orders to batches according to the order sequence; specifically, the order number corresponds to the batch number. Assume that the results acquired are from the initial batching solution. Moreover, assign \(OW\), \(OI\), and \(OL\) to the corresponding batches, and set the initial batching solution as the current batching solution \(B_{curr}\). Step 4: Using the \(OL\) sequence as the picking order of the initial batching solution, start from the minimum and proceed to the maximum. In addition, set the current picking order as \(P_{curr}\), calculate the picking distance of each batch \(d_{M}\), and sum all batch distances to obtain the current total distance \(D_{curr}\). Set the optimal total distance as \(D_{best}=D_{curr}\), the optimal picking order as \(P_{best}=P_{curr}\), and the optimal batch as \(B_{best}=B_{curr}\), and then, proceed to Step 6. Step 5: In \(B_{curr}\), randomly select the swap or mutation procedure to generate the neighboring batching solution \(B_{neigh}\), and then, proceed to Step 6.