In the two-stage algorithm, the first stage involves predicting the distribution positions of the target slots. Given the known locations of these target slots, various algorithms are then applied in the second stage to determine container grouping and consolidation sequences.
4.2.1. Estimation of Target Slots (First Stage)
- (1)
Container pre-grouping
Container pre-grouping aims to ensure spatial compactness within each group, thereby guaranteeing a relatively reasonable estimation of target slot positions and minimizing the consolidation time. The final grouping results, however, still depend on subsequent algorithmic optimization.
Based on the total container count and the maximum stacking height per slot , the required number of target slots is calculated as . This value represents the minimum number of independent slots needed to accommodate all containers without exceeding the stacking height limit.
All containers are first sorted in ascending order based on their bay positions. Within the same bay, containers are further sorted in ascending order of row number, and finally, within the same bay and row, they are sorted in descending order of tier number. Based on this sorted sequence, containers are grouped sequentially according to a maximum group capacity of
containers per sequence.
Table 2 presents the basic grouping results for 10 containers dispersed across the container yard. For each group, the maximum intra-group bay span
is calculated, as well as the total bay span across all groups, denoted by
. This approach enables rapid initialization of container grouping and ensures a relatively high spatial density within each group, thus providing a structural basis for subsequent consolidation scheduling. However, due to possible spatial dispersion among containers within a group, further adjustment and optimization may still be required.
When the total capacity of all groups exceeds the number of containers to be consolidated, this indicates that the last group still has available space for additional containers.
is first calculated. Then, the last container from the preceding group is moved into the final group, and the new
is recalculated. If
is reduced, the new grouping is retained; otherwise, the algorithm continues to search backward for the next non-full group and repeats the procedure. This process is iterated until all non-full groups have been evaluated.
Figure 8 illustrates the optimization process applied to the container groups listed in
Table 2.
The pseudocode for Grouping is presented in
Figure 9.
- (2)
Compute the Group Centers
The center of each group serves as an approximate representation of the spatial center of the containers within that group. Determining the group center as a candidate target slot ensures the rationality of target slot selection.
By counting the number of containers in each slot within a group, if any slot contains a number of containers greater than or equal to half the stack height, it implies that at most only half of the containers in that group require consolidation. This significantly reduces the yard crane’s consolidation time. Therefore, the location of that slot is directly designated as the group center.
If no slot in the group satisfies the threshold, the weighted geometric center
is computed. Let the number of containers in slot
of group
be
; let the number of containers in all groups be
, with coordinates
representing the bay and row positions, respectively. Let
denote the weight of slot
. The weighted geometric center is calculated as follows:
where
.
After computing the center coordinates, the bay position is rounded up to the nearest odd number equal to or greater than the calculated value, and the row position is rounded to the nearest integer, ensuring both lie within valid operational bounds.
For example, let us consider the groupings Group 1: [C2, C5, C1], Group 2: [C8, C10, C3, C7], and Group 3: [C4, C6, C9]. None of the groups have a slot exceeding half the stacking height. For Group 1, Slot 1 (3, 1) has a weight , and Slot 2 (7, 2) has a weight . The weighted geometric center is calculated as follows:
. After adjusting to valid coordinates, the center is set as (7, 2). Similarly, the centers for Group 2 and Group 3 are calculated as (19, 3) and (39, 5), respectively.
The pseudocode for Computing Group Center is presented in
Figure 10.
- (3)
Estimation of Candidate Target Slot Solutions
Evaluating the cost of designating each slot and the group center as a potential target slot within each group ensures a more rational prediction of the final target slot configuration.
An ideal target slot location should minimize the total yard crane operation time. As consolidation involves the crane moving from its current position to a container’s location, picking it up, and then moving it to the target slot, the cost estimation procedure is as follows:
- ♦
Determine the number of containers to be consolidated.
- ♦
Compute the handling cost as: Number of containers × (picking time + placing time).
- ♦
Compute the distance cost by calculating the total travel time required for moving all containers in the group to the candidate target slot.
- ♦
Total cost = handling cost + distance cost.
After computing the cost of each candidate slot and the center within each group, the selection probability for each candidate is determined based on the principle that higher cost corresponds to lower selection probability. Subsequently, for each group, one candidate is probabilistically selected, and a total of distinct combinations of target slots are generated as potential target slot solutions.
The pseudocode for Estimating Target Slot Solutions is presented in
Figure 11.
4.2.2. Determining the Consolidation Solution (Second Stage)
- (1)
Greedy Algorithm
The Greedy Algorithm is a heuristic method that, at each decision step, selects the locally optimal option, with the expectation that a sequence of such local optima will collectively lead to a globally optimal solution. When applied to the consolidation problem, the GA can rapidly generate a reasonable and feasible solution, which can then serve as the initial upper bound for the BNB algorithm, thereby significantly reducing computational overhead.
In this approach, the candidate target slot solutions are first determined based on
Figure 9,
Figure 10 and
Figure 11. The GA is then employed to compute the final consolidation plan. During the consolidation process, the yard crane always moves from its current position to the nearest container, retrieves it, and consolidates it into the nearest non-full target slot.
For example, if the crane initially starts at position (1, 1) and the target slots are (1, 2), (3, 5), and (11, 3), the greedy algorithm will first move the crane to the closest container, say C4. After retrieving C4, it will be consolidated into the nearest non-full target slot, in this case (1, 2). The crane then updates its position to (1, 2). From there, it proceeds to the next closest container, say C5, and assigns it to the nearest feasible target slot, which may now be (3, 5). This process continues iteratively until all containers have been successfully consolidated into their respect target slots. The consolidation sequence is illustrated in
Figure 12.
The pseudocode for the Greedy Algorithm is presented in
Figure 13.
- (2)
Branch and Bound Algorithm
- ♦
Upper and Lower Bound Estimation
The upper bound () is estimated using the GA, which rapidly computes a feasible solution. This solution serves as the initial upper bound for the BNB procedure.
For the lower bound (), since the container consolidation process requires relocating all target containers to designated slots, each consolidation stage includes the time taken for the yard crane to move from its current location to the container’s position and perform the pickup operation, as well as the time required to transport the container to its nearest non-full target slot and complete the placement operation.
Figure 14.
The pseudocode for the Lower Bound estimation.
Figure 14.
The pseudocode for the Lower Bound estimation.
- ♦
Branch and Prune
When using the BNB algorithm to solve the consolidation problem, branch generation is primarily based on identifying which target slots the containers to be consolidated can be moved into. Specifically, the algorithm iterates through all unassigned containers and attempts to assign each of them to all feasible target slots. Given that the container consolidation problem is inherently many-to-many mapping, the number of target slots increases with the number of containers, and the possible allocation combinations between containers and target slots grow exponentially. To reduce computational complexity, based on the number of target slots, the allocation of containers in their current state is restricted to only the nearest non-full target slots (where is less than or equal to the actual number of target slots). For example, let us consider three target slots initially identified as (1, 4), (3, 5), and (7, 2), and four containers to be moved: C2, C3, C9, and C10; if containers are limited to be consolidated only into their two nearest non-full target slots, then at the initial node branching, container C2 can only be assigned to (1, 4) and (3, 5), but not (7, 2). This restriction reduces the number of branches with high time costs and accelerates the algorithm’s computation.
During pruning in BNB, the
and
of the initial solution node are first calculated, with the initial Current best set to the initial
. After branching from the initial solution node, new
and
values are computed for each child branch. If a child branch has
equal to
, it indicates that a local optimum has been found and branching is stopped. At this point, the sum of
and
(time used) is compared with
(Current best). If
, the local optimum is worse than the Current best, and the branch is pruned; if
, the local optimum is better, and Current best is updated to
. When
is less than
, the relationship between
and Current best is checked: if
, the branch is pruned; if
, branching continues. The specific branch-and-bound pruning process is illustrated in
Figure 15.
Figure 15 shows an example of BNB algorithm branching and pruning.
The pseudocode for the Branching is presented in
Figure 16.
The pseudocode for the Pruning is presented in
Figure 17.
- ♦
Branch-and-Bound Algorithm Procedure
Figure 18 illustrates the complete process of the BNB algorithm. After the algorithm is initiated, it first performs initialization by setting the positions and number of containers as well as the initial location of the yard crane, and determines the target slots using
Figure 9,
Figure 10 and
Figure 11. Since containers already located in their target slots do not require relocation, it is necessary to identify those that are not yet positioned correctly. If the number of containers to be relocated is zero, indicating that all containers are already in their designated target slots, no consolidation operation is required, and the algorithm terminates immediately with the current solution returned. If the number of containers to be relocated is greater than zero, the consolidation procedure begins for those containers.
During the consolidation process, the initial
and
are first computed. Then, using
Figure 16, the current node is branched to generate a set of child nodes denoted as set
. Processed sub-branches are removed from the set, and new
and
estimates are computed for the remaining branches in
. Subsequently,
Figure 17 is applied to perform pruning operations across the branch set, during which the current best solution is dynamically updated.
After pruning, it is necessary to check whether the current branch set is empty. If is not empty, the algorithm proceeds by selecting the first unprocessed branch in the set to continue the next iteration; if is empty, this indicates that all branches have either been explored or pruned, and the algorithm must backtrack to the previous level in the branch hierarchy.
During backtracking, the algorithm first checks whether there are unprocessed branches remaining in the upper-level branch set. If such branches exist, the first one is selected to proceed with the next round of iterations; if not, the algorithm continues backtracking to higher-level branch sets. If backtracking eventually reaches the root node and no branches are left for further exploration, this indicates that the entire feasible solution space has been traversed. The algorithm then terminates and returns the best solution obtained thus far.
- (3)
Beam Search Algorithm
As a heuristic search strategy, the Beam Search Algorithm has been widely applied in the field of combinatorial optimization, demonstrating unique advantages in solving complex problems such as scheduling and logistics. In the context of container consolidation, when faced with containers to be consolidated into target slots, the traditional BNB approach may encounter exponential complexity with up to branches in the worst case. While this method can efficiently obtain optimal solutions for small-scale problems, its computational efficiency deteriorates rapidly as the problem scale increases, making it unsuitable for real-time applications.
To address this challenge, this study innovatively introduces the BS Algorithm for solving the container consolidation problem. The core of the algorithm lies in designing a directional evaluation function to guide the search trajectory and applying a fixed beam width to restrict the number of branches retained at each level, thereby effectively controlling the size of the search space.
- ♦
Branching and Pruning Strategy
In terms of branching strategy, BS adopts the same branch generation mechanism as the BNB method (
Figure 10), but fundamentally differs in how branches are managed. Instead of treating branches generated by individual nodes independently, BS treats all branches generated at a given level as a unified set. This global perspective allows the algorithm to retain only the most promising branches based on comparative evaluation.
The design of the directional evaluation function is crucial to the algorithm’s success. Considering that the primary objective of consolidation operations is to minimize total crane operating time, this study proposes the evaluation function , where represents the time used, and UB is the estimated remaining operation time obtained via the GA. This design accurately reflects the potential total operation time of each branch, ensuring that branches with lower overall costs are prioritized. For instance, if the beam width is set to 2, the algorithm retains the two branches with the lowest evaluation values at each level while pruning all others. This strategy ensures computational efficiency while obtaining high-quality approximate solutions, thereby achieving a balance between solution quality and computational effort.
Through this systematic branching and pruning strategy, the BS algorithm is capable of effectively handling large-scale container consolidation problems.
- ♦
Beam Search Algorithm Procedure
Figure 19 illustrates the complete procedure of the BS algorithm. Upon initialization, the algorithm first processes the container locations, total container count, and crane position, and determines the target slots using
Figure 9. Since containers already located in the target slots do not require relocation, only those not yet in target positions—referred to as movable containers—are considered. If there are no movable containers, the consolidation task is unnecessary, and the algorithm terminates immediately and returns. If movable containers exist, the consolidation process begins.
During the consolidation process, the current node is branched using
Figure 10 to generate a set of child branches B, which are added to the global branch set. The algorithm then checks whether all parent nodes have completed the branching operation. If some parent nodes have not yet been branched, one is randomly selected to proceed. This continues until all parent nodes have generated branches. Once this is complete, the directional evaluation function
is applied to retain only
branches that conform to the predefined beam width. These selected branches form the next generation of parent nodes and proceed to the next iteration. The algorithm continues until either all branches at a given level are pruned or all consolidation operations are completed, at which point the algorithm terminates.