Inventory Simulation-Optimization

SimPy for simulation and a genetic algorithm for optimization

🔍 View Full Screen

Inventory Simulation ⇄ Optimization

Balance holding, shortage, and ordering costs under stochastic demand & lead times. Find robust reorder points.

1) Why It Matters — The Cost of Poor Replenishment

Fixed rules that ignore variability cause both overstock and stockouts. In continuous-review systems these show up as unnecessary holding costs, lost sales/backorders, and too many small rush orders.

  • Overstock → capital tied up & storage cost.
  • Stockouts → lost sales or service degradation.
  • Unstable ordering → higher setup & expediting cost.
Goal: choose reorder points \(r_i\) (with given policies) to minimize average cost per period while maintaining strong service.
Multi-product (up to 5) Continuous-review (r,Q) & (s,S) Stochastic

2) System Model — What We Simulate

Core assumptions

  • Demand: Poisson arrivals × discrete demand size per customer.
  • Lead time: exponential per order.
  • Policy: per-product (r,Q) or (s,S) with fixed Q or S.
  • Shortage handling: backorders or lost sales (fixed per product).
  • Costs: holding, shortage, and ordering (setup + per unit).

What you control

  • Decision variables: reorder points \(r_i\) for selected products.
  • Evaluation settings: horizon (periods) and number of replicates.
  • Everything else (prices, demand/lead distributions, Q/S) is static and reasonable by design.

We review every period (e.g., daily); deliveries arrive at sampled lead times; demand hits stock; costs accrue each step.

3) Simulation Mechanics — One Loop

Inventory position: \(IP_t = \text{on hand}_t + \text{outstanding}_t\).
Reorder rule: if \(IP_t \le r_i\), place order of size \(Q_i\) (r,Q) or up to \(S_i\) (s,S).
Average cost: \(\;\bar C = \frac{1}{H}\sum_{t=1}^{H}(C^{hold}_t + C^{short}_t + C^{ord}_t)\).
  • Per period: receive due orders → draw demand → update stock & costs → possibly reorder.
  • Run for horizon \(H\); repeat over replicates and average to reduce Monte-Carlo noise.

4) Optimization — Genetic Algorithm (GA)

Chromosome: \(x = (r_1,\dots,r_m)\) over selected products. Objective: minimize summed average cost across products.

GA steps

  • Initialization within smart bounds per product.
  • Tournament selection, uniform crossover, per-gene mutation.
  • Elitism + random immigrants; optional adaptive mutation.

Stopping & robustness

  • Time limit ~20s or ε-convergence (patience window).
  • Each fitness = average over replicates for stability.
  • No fixed RNG seed by default → genuine stochastic variability.

5) What You See — Inputs & Outputs

Inputs

  • Products to include (subset of five).
  • Replicates (1–20) and Horizon (10–1000).
  • GA sliders: Population size, Mutation rate, Crossover rate.

Outputs

  • Best reorder points \(r_i^*\) with per-product cost breakdown & fill rate.
  • History per generation: best/mean cost for charting.
  • Counts: evaluations, simulation runs (evals × replicates), stop reason.

After optimization, you can run a simulation with the best solution to inspect detailed per-product outcomes.

6) References

Try it & Learn More

Explore the Result:

Open live sample
Built with SimPy for simulation and a genetic algorithm for optimization.

Inventory Simulation–Optimization Results

GA over reorder points • Best cost, stop reason, per-product metrics

Open Live Demo