## 3 Problem Definitions and Formulation
### A Three-Level Framework of Planning
* Calculate the current workload of ship \(i\) (\(N_{L,uL}^{i}\)) by totaling the numbers of containers to load (\(N_{L}^{i}\)) and unload (\(N_{uL}^{i}\)) for each task k in the task set \(T_{i}\) using Equation (14). \[N_{L,uL}^{i}=\left(N_{L}^{i}+N_{uL}^{i}\right)=\sum_{k=u}^{K_{i}}N_{k}^{i}\] (14)
* Calculate the average number of containers (\(AN_{L,uL}^{i}\)) as a benchmark using Equation (15). \[AN_{L,uL}^{i}=\sum_{k=u}^{K_{i}}N_{k}^{i}/l_{j}\] (15)
* Calculate the respective workload of the first task \(k\) (denoted as \(N_{k}^{i}\)) and the second task \(k+1\) (denoted as \(N_{k+1}^{i}\)) in the task set Ti by totaling the number of containers to load and unload. * Estimate the expected workload (\(W_{q}\)) of the first QC \(q\) in \(Q_{j}\) if the task \(k\) of ship \(i\) is added using Equation (16). \[W_{q}=W_{q}+N_{k}^{i}\] (16)
* If \(W_{q}\geq AN_{L,uL}^{i}\) then assign the task \(k\) of ship \(i\) to the QC \(q\) pop the task \(k\) out of the \(T_{i}\) pop the QC \(q\) out of the \(Q_{j}\) \(q=q+1\) (change to the next QC) \(l_{j}=l_{j}-1\) Else if \(W_{q}<AN_{L,uL}^{i}\) and \((W_{q}+N_{k+1}^{i})-AN_{L,uL}^{i}\geq AN_{L,uL}^{i}-W_{q}\) assign the task \(k\) of ship \(i\) to the QC \(q\) pop the task \(k\) out of the task set \(T_{i}\) pop the QC \(q\) out of the \(Q_{j}\) \(q=q+1\) (change to the next QC) \(l_{j}=l_{j}-1\) Else assign the task \(k\) of ship \(i\) to the QC \(q\) pop the task \(k\) out of the task set \(T_{i}\) End if
* If \(T_{i}\
eq\varnothing\) then \(k=k+1\) (change to the next task) \(u=u+1\) Go to Step 6 Else \(i=i+1\) (change to the next ship) Go to Step 12 End if
* End
* This level deals with the QCSP. After determining which task is handled by which QC in level 2, this level uses a discrete simulation approach to simulate container loading and unloading for each task of a ship. As a result, the beginning and ending times of each task can be determined. Finally, the starting and ending working time of a ship are fed back to level 1 as the berthing time of each ship. The following steps are used in this level. * Find the task token with least available time. * Find the QC assigned to the task token. * Determine the beginning time and the end time of the task based on the available time of the assigned QC. * Update the available time of the QC after serving this task token. * Return the assigned QC. Figure 1 also shows the data flows (dotted lines) of each level in the framework. For Level 1, the berth data, ship data, and BAP rules are inputs while Data 1 {(\(\bigcup_{i=1}^{i=m}(i,j)\): \(X_{ij}^{t}=1\))} is an output. For Level 2. Data 1 (\(\bigcup_{i=1}^{i=m}(i,j)\): \(X_{ij}^{t}=1\)), QC data, task data, and QCAP rules are inputs while Data 2 \(\{\bigcup_{i=1}^{i=m}(i,q,k):Y_{i\text{\emph{i}}ak}^{t}=1,q\in Q,k\in K_{i},\,t \in T\}\) is an output. For Level 3, the QC data, task data, and Data 2 \(\{\bigcup_{i=1}^{i=m}(i,q,k):Y_{i\text{\emph{i}}ak}^{t}=1,q\in Q,k\in K_{i},\,t \in T\}\) are inputs while Data 3 (\(\{\bigcup_{i=1}^{i=m}\left(T1_{i\text{\emph{i}}ak},T2_{i\text{\emph{i}}ak} \right):Y_{i\text{\emph{i}}ak}^{t}=1,i\in S,\,q\in Q,\,q\in Q,k\in K_{i},\,t \in T\}\)) is an output. Having explored all the combinations of BAP and QCAP rules, the best solution can be found. These data are required to run the model established in the next section.