## 6 The Proposed Simulation Optimization Algorithm
### Adding Discrete Event Simulation Principles to BR
If, at any stage, quantity constraints are violated and no feasible bundles remain, the process is halted, the system state is restored, and a non-feasible warning is issued. Similarly, if the construction process adheres to quantity constraints but violates quality constraints, the system state is restored and a non-feasible warning is issued. For a bundle to be considered feasible, its weight, in addition to the weight of the current solution, must not surpass a predefined threshold. Bundles from prior input operations are only considered if the respective input operation has concluded. If no feasible bundles exist in the selected rack, the rack is eliminated from the list of potential racks, and the process begins anew with another rack. Conversely, if feasible bundles are available, they are arranged by decreasing the weight and then by the difference between their quality and the required quality level. Bundles with quality levels closer to the required level are given priority. Once the bundles are sorted, one of them is selected using a new geometric distribution (note that the \(\beta\) parameter value used here may differ from the one used for rack selection). Subsequently, the solution's weight, total quality, and the count of retrieved items are updated. The system state is also updated, and the list of possible racks is reset. This process continues iteratively until a feasible solution is achieved. The pseudo-code for processing output operations is detailed in Algorithm 3. ```
input:\(nextr\), \(solution\), \(racks\), \(beta\) \(sSolution\leftarrow\mathbf{copy}(solution)\) \(\triangleright\) save the state of the solution \(sol\leftarrow\textsc{NULL}\) \(\triangleright\) solution to the current request \(pRacks\leftarrow\mathbf{copy}(racks)\) \(\triangleright\) list of racks to consider \(w\gets 0\) \(\triangleright\) total weight of retrieved bundles \(q\gets 0\) \(\triangleright\) total quality of retrieved bundles \(n\gets 0\) \(\triangleright\) number of retrieved bundles while\(w<weight Required(nextr)-acceptedError(nextr)\)and\(length(pRacks)>0\)do \(pRacks\leftarrow\mathbf{sort}(pRacks,key:craneAvailability)\) \(\triangleright\) sort racks prioritizing the busiest ones \(rack\leftarrow\mathbf{findBR}(pRacks,beta)\) \(\triangleright\) select a rack by using BR \(pBundles\leftarrow\mathbf{feasibleBundles}(rack,w,nextr)\) \(\triangleright\) feasible bundles in rack if\(length(pBundles)>0\)then \(pBundles\leftarrow\mathbf{sort}(pBundles,key:increasingWeight)\) \(\triangleright\) sort bundles by weight \(pBundles\leftarrow\mathbf{sort}(pBundles,key:deltaQuality)\) \(\triangleright\) sort bundles by quality \(bundle\leftarrow\mathbf{findBR}(pBundles,beta)\) \(\triangleright\) select a bundle by using BR \(w\gets w+weight(bundle)\) \(\triangleright\) update weight \(q\gets q+quality(bundle)\) \(\triangleright\) update quality \(n\gets n+1\) \(\triangleright\) update number of retrieved bundles \(op\leftarrow\mathbf{new}\ OutputOperation(nextr,rack,bundle)\) \(\triangleright\) instantiate a retrieve scheduleOperation(\(solution,op\)) \(\triangleright\) schedule a retrieval operation \(sol\leftarrow\mathbf{add}(sol,op)\) \(pRacks\leftarrow\mathbf{copy}(racks)\) \(\triangleright\) restore the set of possible racks else \(pRacks\leftarrow\mathbf{remove}(pRacks,rack)\) endif endwhile
```  
**Algorithm 3** Pseudo-code for output processing.