## 2 Modeling the Problem  
In our problem, the journey of \(P\) ports of a ship is represented. In each port \(p=1,\ldots\), \(P-1\), where this ship docks, there is a yard with containers that must be loaded onto it. At the first port, \(p=1\), the ship arrives empty and receives the loading of the containers that were at the yard of this port, as illustrated in Figure 1.  
At ports \(p=2,\ldots,P-1\), the ship first unloads the containers destined for port \(p\), where it currently is (see Figure 2), and then receives the loading of containers destined for the following ports (see Figure 3). Finally, when the ship arrives at the last port of its journey \(P\), only the unloading is performed. Observe that the numbers on the containers identify each container, and when at the port yard, this represents the removal order, starting with the smallest number and ending with the largest number contained in each yard. This order comes from a previous solution of the stowage plan, as is the convention for the CRP. Regarding removal from the ship, a dictionary contains the destination port of each container, and it must be consulted to find out which containers should be unloaded at which ports. In Figure 2, note that the ship arrives at the second port of its route, and it has to unload the four highlighted containers (3, 6, 11, and 14), of which two of them are not at the top of their stacks. For this reason, first, the blocking container (number 9) located above containers 6 and 3 will be unloaded to a reserved area of the yard, which is not the same area of the import containers nor the export containers, which are about to be loaded. Next, it can be seen in Figure 3 that after all containers destined for this port are unloaded from the ship, the container loading operation at the second port yard with the relocated containers starts. The rules proposed follow this representation and are described in detail in the following section. The following assumptions have been made based on [24; 34] for the sake of simplicity without compromising the general application of the solutions:  
* The container ship has a rectangular format and can be represented as a matrix, called the ship's occupation matrix (\(Shp\)), with rows (\(r=1,2,\ldots,R\)), columns (\(c=1,2,\ldots,C\)), and bays (\(b=1,2,\ldots,B\)) and a maximum capacity of \(R\times C\times B\) containers. Each  
Figure 1: Loading flow at port 1. Figure 2: Unloading flow at port 2.  
space to store a container is a coordinate \((r,c,b)\), where \(r\in R\), \(c\in C\), and \(b\in B\). An irregular format may be achieved by simply adding constraints that represent imaginary containers that occupy the same spaces during the whole voyage [26]. * The yard can also be represented as a matrix called \(yard_{p}\), with rows (\(i=1,\ldots,H\)) and stacks (\(j=1,\ldots,W\)). Each space to store a container is a coordinate \((i,j)\), where \(i\in H\) and \(j\in W\). * All containers have the same size and weight and are accessible only from the top. * All containers in the port yard will be loaded onto the ship. * The container ship can always carry all the containers at each port \(p\), and its capacity will never be exceeded. * In each yard, there must be at least \(H-1\) empty positions to guarantee the accessibility of any container. Analogously, onboard the ship, there must be at least \(R-1\) empty positions to guarantee the accessibility of any container. * The unloaded containers are destined for a specific area of the port yard and are not mixed with the containers that are going to be loaded nor with the relocated containers, as illustrated in Figures 2 and 3. Note that the assumptions made about the containers' weight and size are not a limitation of the representation, since it enables a focused analysis on how ship and yard container arrangements are affected by integrated planning.