# Applying Simheuristics to Minimize Overall Costs of an MRP Planned Production System
## 3 Simulation Heuristic
### Initial Simheuristic Algorithm  
The initial simheuristic depicted in Algorithm 1 allows us to develop different variants, named: static range (STR), exponential range reduction (ERR), and best solution-set base range (BSBR). The initial simheuristic provides a description of the algorithmic flow, and this generic structure facilitates to subsequently integrate the aforementioned variants. The algorithm starts by selecting the best solution of all previously finished iterations. The best solution represents the minimum overall cost of all finished iterations and provides a list with the used mode, lower bound (LB), and upper bound (UB). For the STR version, a triangular distribution is used to compute new values using the LB, the UB, and the mode given by the midpoint of the range. For all three variants, the possible values for the MRP parameters (planned lead time and safety stock) lie within the LB and the UB. While in [26] the lot size is not included, in this paper, we consider its parameter sampling for optimization in the same way as for the parameters planned lead time and safety stock. The second simheuristic version, named ERR, updates LB and UB using the best solution. This makes it possible to reach a search space outside the original bounds. The solution range is defined as \(r_{0}=\text{mode}-\text{UB}\) for both MRP parameters. The new bounds for the MRP parameters and for each item are computed as \(r_{i}=(1-\alpha)*r_{i-1}\), where, \(i\) is the simulation iteration number and \(\alpha\) is the range reduction level. The goal of the ERR variant is to reduce the LB and UB when the number of iterations increase, so the possible solution range is iteratively shrinking. In the third version, named BSBR, the LB and the UB are computed using the minimum and maximum of the best \(n\) solutions. ```
1:ifInitializationthen
2:\(\alpha\gets e.g.,\ 0.025\)
3:\(topN\gets e.g.,\ 7\)
4:\(initIterations\gets e.g.,\ 50\)
5:\(initParameterRange(lb,ub,mode)\)
6:\(n\gets 0\)
7:\(endInitPhase\gets false\)
8:\(currentSolution\leftarrow\)\(TriangularDistribution(parameterRange)\)
9:\(baseSolution\gets currentSolution\)
10:endif
11:while\(n\leq maxReplications\)do
12:\(cost(currentSolution)\leftarrow\)\(Simulate_{MRP}(currentSolution)\)
13:if\(n>initIterations\)then
14:\(endInitPhase\gets true\)
15:endif
16:if\(cost(baseSolution)<cost(currentSolution)\)then
17:\(baseSolution\gets currentSolution\)
18:endif
19:\(baseSolution\gets GetBestSolution()\)
20:if\(simheuristic=STR\lor endInitPhase=false\)then
21:\(parameterRange.mode\leftarrow\)\(baseSolution\)
22:endif
23:if\(simheuristic=ERR\wedge endInitPhase=true\)then
24:\(oldRange\leftarrow(parameterRange.ub-parameterRange.lb)/2\)
25:\(newRange\leftarrow(1-\alpha)\ast oldRange\)
26:\(parameterRange.mode\leftarrow\)\(baseSolution\)
27:\(parameterRange.lb\gets parameterRange.mode-newRange\)
28:\(parameterRange.ub\gets parameterRange.mode+newRange\)
29:endif
30:if\(simheuristic=BSBR\wedge endInitPhase=true\)then
31:\(bestNSolutions\leftarrow GetBestNSolutions(topN)\)
32:\(parameterRange.mode\leftarrow\)\(baseSolution\)
33:\(parameterRange.lb\gets min(bestNSolutions)\)
34:\(parameterRange.ub\gets max(bestNSolutions)\)
35:endif
36:\(baseSolution\gets TriangularDistribution(parameterRange)\)
37:\(n\gets n+replicationsPerIteration\)
38:endwhile
```  
**Algorithm 1** Base Simheuristic Algorithm. The constant \(\alpha\) is set for the ERR range reduction and \(topN\) is required only for the BSBR version. An initialization phase can be applied for both the ERR and BSBR versions. The number of iterations is represented by the constant \(initIterations\). The variable \(endInitPhase\) is used to control the end of the initialization phase. Notice that, by design, ERR and BSBR are extensions of STR. Therefore, STR is applied during the \(initIterations\). Thus, for example, 50 iterations out of a maximum of 300 iterations can be used to find starting values for range reduction and the best \(n\) solutions.