## 4 Methodology
### Sequential-Placement First Heuristic (\(\mathit{SPFH}\))  
This section presents the \(\mathit{SPFH}\) algorithm for the real-time operation round of SCRP. The algorithm structure of \(\mathit{SPFH}\) includes two levels. The outer level adopts a policy iteration mechanism, i.e., the set of policies comprising all possible pickup sequences, from which the best operation solution has the least cost; the inner level is the specific process of simulating the operation solution and evaluating the cost for each pickup sequence. The outer level of \(\mathit{SPFH}\) takes two inputs: \(S_{0}\) denotes the initial configuration of the current operation round of the bay, and \(P\) denotes the target container set of the current operation round. In the outer level of \(\mathit{SPFH}\), the procedure, namely AutoRetrieval, is a conventional prioritization mechanism that checks and automatically picks up the target containers if retrievable before the start of each operation round or after each relocation. This mechanism makes the configuration irreducible while freeing up optional slots for other blocking containers. The procedure, namely GenerateSequence, generates all possible pickup orders for the target containers of the current operation round. Then, iterate these orders to obtain the best operation plan for the yard cranes with minimal operation costs. The procedure, namely Simulation-Evaluation, is the inner level of the \(\mathit{SPFH}\) algorithm. The pseudo-code of the outer level of \(\mathit{SPFH}\) is shown in Algorithm 1, and the pseudo-codes of the procedure AutoRetrieval and the procedure GenerateSequence are shown in Algorithm 2. ```
1:procedureSPFH(\(S_{0}\),\(P\))
2: Initialize \(S_{cur}\gets S_{0}\), \(\mathit{sol}_{cur}\leftarrow\varnothing\), \(\mathit{sol}_{best}\leftarrow\varnothing\), \(\mathit{F}_{best}=\infty\)
3:AutoRetrieval(\(\mathit{S}_{cur}\),\(\mathit{sol}_{cur}\),\(P\))
4:if\(P\) is empty then\(\mathit{F}_{best}\gets 0\), \(\mathit{sol}_{best}\gets\mathit{sol}_{cur}\)
5:else
6:\(Q\leftarrow\textsc{GenerateSequence}(\mathit{S}_{cur}\),\(P\))
7:while\(Q\) is not empty do
8:\(q\leftarrow\) select first item from the pickup sequence set Q
9:\(\mathit{F}_{cur}\leftarrow\textsc{Simulation-Evaluation}(q\),\(\mathit{S}_{cur}\),\(\mathit{sol}_{cur}\))
10:if\(\mathit{F}_{cur}<\mathit{F}_{best}\)then\(\mathit{F}_{best}\gets\mathit{F}_{cur}\), \(\mathit{sol}_{best}\gets\mathit{sol}_{cur}\)
11:elseif\(\mathit{F}_{cur}=\mathit{F}_{best}\)then\(\mathit{sol}_{best}\gets\mathit{sol}_{best}\cup\mathit{sol}_{cur}\)
12:\(Q\gets Q\backslash\{q\}\)
13:return\(\mathit{F}_{best}\), \(\mathit{sol}_{best}\)
```  
**Algorithm 1** Outer level: the main procedure of \(\mathit{SPFH}\) algorithm  
The objective of the inner level of SPFH is to simulate the relocation operation processes and estimate the associated operation costs concerning a given pickup sequence. This procedure involves removing the target containers of the current operation round and moving their blocking containers into the best placements with the least cost (the sum of the number of instant relocation moves and the addition of ENBC). Figure 4: Processing of heuristic rule \(\mathit{FSS}\). ```
1:procedureAutoRetrieval(\(S\),\(sol\),\(T\))
2:for all\(t\in T\)do
3:if\(t\) is topmost item in stack \(w(t)\)then
4:\(S\gets S\oplus(t,w(t),0)\), \(sol\gets sol+(t,w(t),0)\), \(T\gets T\backslash\{t\}\)
5:procedureGenerateSequence(\(P\))
6:\(W\leftarrow\)Get the set of stacks containing the target containers in \(P\). 7:\(top_{1}[W]\leftarrow\)Get the top target container in each stack of \(W\) and remove them from corresponding stack. 8:\(Q_{1}\leftarrow\)Generate the set of full permutations from each target container in \(top_{1}\). 9:\(Q_{2}\leftarrow\varnothing\)
10:\(top_{2}[W]\leftarrow\)Get the top target container in each stack of \(W\) and remove them from corresponding stack.