Discrete event simulation (DES) model of an overloaded harbor with 3 docks and 1 tugboat, implemented in pure Python without external simulation libraries.
A supertanker port operates 3 docks simultaneously with a single tugboat shared for both docking and undocking maneuvers. Tankers of three sizes (small, medium, large) arrive following an exponential inter-arrival distribution. The tugboat is the main bottleneck: it must assist every tanker both to approach a dock and to leave it, and it follows a priority-based dispatching policy.
Goal: estimate the average waiting time of tankers in the port.
overloaded_harbor/
├── src/
│ ├── generators.py # Random variable generators (inverse transform, Box-Muller)
│ ├── state.py # System state: State and Tanker classes
│ ├── events.py # Event handlers (E1–E8) and tug decision logic
│ └── simulation.py # Simulation engine, replications and confidence intervals
├── main.py # Entry point
├── README.md
├── .gitignore
└── LICENSE
| Parameter | Value |
|---|---|
| Docks | 3 |
| Tugboat | 1 |
| Inter-arrival time | Exponential (mean = 8 h) |
| Tanker sizes | Small 25%, Medium 25%, Large 50% |
| Loading time (small) | Normal N(9, 1) h |
| Loading time (medium) | Normal N(12, 2) h |
| Loading time (large) | Normal N(18, 3) h |
| Tug approach time | Exponential (mean = 2 h) |
| Tug departure time | Exponential (mean = 1 h) |
| Tug transit (empty) | Exponential (mean = 0.25 h) |
All random variables are generated from scratch using random (Python standard library only):
- Exponential — inverse transform:
X = -mean * ln(U) - Normal — Box-Muller:
Z = sqrt(-2*ln(U1)) * cos(2*pi*U2), thenX = mu + sigma*Z - Discrete empirical — inverse transform on cumulative probabilities
python main.pyRuns 30 independent replications of 500 tankers each (first 50 discarded as warm-up).
Each replication uses seed=r for full reproducibility.
| Metric | Value | 95% CI |
|---|---|---|
| Mean waiting time | 10.84 h | [10.05, 11.63] h |
| Mean time in system | 26.87 h | [26.05, 27.69] h |
Python 3.8+. No external packages required.