# A Multi-Agent Optimization Approach for Multimodal Collaboration in Marine Terminals
## 4 Solution Methodology
### Prioritized Search
#### 4.2.1 Priority Trees  
In constructing a priority tree, we begin with a given priority list \(y\) and try to define the berth allocation \(x_{\text{\tiny{p}}}\ \forall v\in\mathcal{V}\). To define \(x\), we assume that each vessel consistently selects a berth using a greedy approach, i.e., the one that minimizes any of the associated costs, always considering local conditions such as berth occupancy caused by other vessels. Each vessel is associated with a processing cost \(p_{\text{\tiny{v}}}\), and an incurred deviation cost for companies, \(c_{\text{\tiny{v}}}\), based on the selected berth. Given that the problem has two distinct objectives to minimize, different berth allocations may optimize different criteria. To address this, the algorithm may consider multiple berth allocations. When two different berths perform better for one objective but worse for the other, a branch occurs as no solution dominates the other. In Figure 7, an example of the formation of priority trees is illustrated with three vessels and priorities V1 \(>\) V2 \(>\) V3. For vessel V1, berth B is selected since it is the greedy solution compared to the infeasible solution of berth A, which yields an infinite cost. For vessel V2, both berths yield minimum values for different costs, with berth A minimizing the total sum of \(p_{\text{\tiny{v}}}\) and berth B minimizing the total sum of \(c_{\text{\tiny{v}}}\), resulting in new branches. For vessel \(V3\), two branches and four allocations must be evaluated, and only greedy solutions must be kept. Allocation \(B-B-B\) is disregarded because, for V3, allocation \(B-B-A\) performs better in both objectives, thereby dominating solution \(B-B-B\). Allocations \(B-A-A\), \(B-A-B\), and \(B-B-A\) are part of the final output of this process, but it is noted that allocation \(B-A-A\) is dominated by allocation \(B-B-A\). This branch is dominated across all solutions, but not within solutions stemming from its root, and thus is discarded at a later stage, as indicated by Figure 7.  
We generally aim to retain non-dominated solutions originating from the same root, as they may lead to better final outcomes under the current priority constraints when examining vessels further down the priority list. However, this approach introduces significant redundancy, which can negatively affect performance as the number of vessels increases. To mitigate this, we apply a simple rule: we always keep at most the top \(k\) solutions. These are selected based on minimizing the sum of the two cost components. If,at any point, the number of branches from a root exceeds \(k\), the least favorable solutions are discarded. Algorithm 3 describes the process of creating priority-based trees, as visualized in Figure 7, for a given ordered priority \(y\). We also introduce the concept of an archive _swap_, used to store indices of vessels where the greedy decision for berth allocation results in a branch, as shown in Figure 7. Information related to costs for the Berth Allocation Agent, Truck Arrival Management Agent, and occupancy constraints for the associated berths are stored in the ROOT dictionary (Algorithm 3, Line 2) and are updated for any given priority. Proceeding iteratively for every vessel \(v\in y\), the processing time of each vessel and its impact on the vessel schedule is first computed (Algorithm 3, Line 12) using the _vessel_process_ function. All possible berth allocations are evaluated iteratively, provided they are compatible with the vessel size (Algorithm 3, Line 11). Current best berth allocation for vessel processing and incurred deviation are stored in variables \(b_{p_{\sigma}}\), \(b_{c_{\sigma}}\). Vessel processing costs are calculated for a single vessel, and conflicts with vessels of subsequent priorities are checked by updating the \"curr\" dictionary. Then, the hard deviation cost to the logistics companies caused by this vessel (\(c_{\sigma}\)) and any effect to the current arrival rates applied to logistics companies is computed by Algorithm 1 (Algorithm 3, Line 13).