## 4 Modeling and Implementing the Three-Level Framework of Heuristics and Simulation
### The OOTPr/Tr Net Model for the Three-Level Framework  
The OOTPr/Tr net for the three-level framework of heuristics and simulation is defined as follows. \[\text{OOTPr}/\text{Tr net}=(\{O_{1},O_{2}\},\{R_{1}\})\]  
Figure 2 shows the OOTPr/Tr net model. It includes two subnets \(O_{1}\) and \(O_{2}\) and there is a communication relation (\(R_{1}\)) formed by two sets of predicates, \(\{\textit{Task}\), \(\textit{Ship}\), \(\textit{OCAP\_rule}\}\in O_{1}\) and \(\{\textit{Open\_task}\), \(\textit{Avail\_QC}\}\in O_{2}\). When these predicates contain tokens simultaneously, it enables the transition _assign_QC_. The OOTr/Pr works in this way. First, in \(O_{1}\), when _Ship_token <I,D,T1>_, _Berth_token <D,T2>_, _BAP_rule_token <R1>_, and _Task_tokens <I,K,W>_ respectively appear at the predicates _Ship_, _Berth_, _BAR_rule_, and _Task_ at the same time, it enables the transition _assign_B_. After firing the transition _assign_B_, a BAP heuristic rule (such as LWL) will be used to assign a berth number to a _ship_token <I,D,T3>_ with the number binding with the token variable D. For instance, if Berth 1 is assigned to the _ship_token <1,D,T3>_ then it results in the unified _Ship_token <1,1,T3>_. The procedure of binding a value with a token variable is called \"unification\", which leads to the generation of a unified token. This assignment, indicated as (\(i\),\(j\)) = (1,1) or \(X_{11}^{t}\) = 1, will be part of the solution to the BAP. After this, a unified token will return to the predicate _Ship_ and it will trigger the subnet \(O_{1}\) to check the  
Figure 2: The OOTPr/Tr net model for the three-level framework. existence of the following tokens: _QCAP_rule_token <LB>_, _Task_tokens <I,K,W>_ and _Avail_QC_tokens <Q,T4>_. If these tokens respectively appear at the predicates, _Ship_, _QCAP_rule_, _Task_, and _Avail_QC_, respectively, and meanwhile the logical formula _F0_ (\(D\
eq\varnothing\)) is satisfied, the transition _assign_QC_ will be enabled. After firing the transition _assign_QC_, a QCAP rule will assign an _Avail_QC_token <Q,T4>_ to a _Task_token <I,K,W>_. For instance, if the _Avail_QC_token <I,0>_ is assigned to the _Task_token <I_,1,78> it then generates a _Open_task_token <I_,1,Q,1,78,73>_ in which the token variable \(Q\) is bound with the value 1 and the token variable _T3_ will be unified with the value Max[T1,T2,T4] = max[4,0,0] = 4. This assignment, indicated as (_i,q,k_) = (1,1,1) or \(Y_{111}^{t}=1\), will be part of the solution to the QCAP. In \(O_{2}\), it will start simulating the loading and unloading of containers. When the tokens _Open_Task_tokens <I,1,1,1,78,4>_ and _Avail_QC_tokens <I,0>_ simultaneously appear at the corresponding predicate _Open_task_ and _Avail_QC_, respectively, with the logical formula _F1_ (Q = Q1) also being satisfied, it enables the transition _t1_. After firing the transition _t1_, it will generate a _begin_event_, _E(t1,I,Q,K)_, and transform the _Open_task_token <I,1,1,1,78,4>_ into a _used_QC_token <I_,1,1,1,78,T5>_ to stay at the predicate _Used_QC_. The event time _t1_ and token variable _T5_ will bind with the value Max[3,T4] = Max[4,0] = 4. After the firing of _t2_, it generates an _end_event_, denoted as _E(t2,I,Q,K)_. The _T6_ will unify with the value, _T5_+usage_time_. After this, the _used_QC_token <I_,_T6>_ will return to the predicate _Avail_QC_ as a _Avail_QC_token <I,T6>_ and meanwhile a _Closed_Task_token <I,1,1,1,78,76>_ will be generated and transited to the predicate _Close_task_. Then [T111,T211] = [4,T6] is generated as a partial schedule of _QC_ 1. While there are still other _Open_task_tokens <I,D,Q,K,W,T3>_ at the predicate _Open_task_ another simulation run will be generated; Otherwise, if all _Open_task_tokens <I,D,Q,K,W,T3>_ have been transited to the predicate _Closed_task_ then the simulation stops running.