# bsingh88/open-pit-mining-gym architecture

> Architecture diagram of the GitHub repository bsingh88/open-pit-mining-gym, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bsingh88/open-pit-mining-gym
- Repository: https://github.com/bsingh88/open-pit-mining-gym

## Overview

Mining-Gym benchmarks truck-dispatch policies in a configurable open-pit mine simulator. Users launch training or playback with an RL policy, or run classical schedulers for comparison; both approaches use the discrete-event simulation to model haulage and produce performance metrics. The RL path adapts the simulator through a Gymnasium environment, with observations and rewards exchanged through a CSV handshake. The graph preserves documented breakdown, rendering, and KPI capabilities. Some simulator internals are grouped because they share one source file; edges reflect excerpts, the source index, or README statements.

Main entry points: [`mGym_DesEnv.py`](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py) (Discrete-event simulator), [`mGym_GymEnv.py`](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymEnv.py) (Gym environment), [`mGym_GymRun.py`](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymRun.py) (RL train and play), [`mgym_gui.py`](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mgym_gui.py) (Experiment GUI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interfaces"]
  node_gui["Experiment GUI<br/>[mgym_gui.py]"]
end

subgraph group_rl["RL workflow"]
  node_rlrun["RL train and play<br/>[mGym_GymRun.py]"]
  node_gym["Gym environment<br/>[mGym_GymEnv.py]"]
  node_ppo["PPO policy<br/>[mGym_GymRun.py]"]
end

subgraph group_simulation["Mine simulation"]
  node_des["Discrete-event simulator<br/>[mGym_DesEnv.py]"]
  node_haul["Haulage and resources<br/>[mGym_DesEnv.py]"]
  node_breakdown["Equipment breakdowns<br/>[mGym_DesEnv.py]"]
  node_kpi["KPI tracking<br/>[mGym_DesEnv.py]"]
end

subgraph group_policy["Dispatch and configuration"]
  node_classrun["Classical run<br/>[mGym_DefSchdRun.py]"]
  node_scheduler["Rule-based policies<br/>[scheduler.py]"]
  node_config["Config sampler<br/>[read_config.py]"]
  node_settings["Mine settings<br/>[config_extend.txt]"]
end

node_user(("Researcher"))

node_user -->|"operates"| node_gui
node_user -->|"runs directly"| node_rlrun
node_user -->|"runs directly"| node_classrun
node_gui -->|"starts training or play"| node_rlrun
node_gui -->|"starts scheduler"| node_classrun
node_rlrun -->|"registers environment"| node_gym
node_rlrun -->|"trains or loads"| node_ppo
node_ppo -.->|"acts in"| node_gym
node_gym -->|"starts simulator"| node_des
node_gym -->|"exchanges CSV actions and results"| node_des
node_classrun -->|"runs episodes"| node_des
node_des -->|"uses dispatch policies"| node_scheduler
node_des -->|"samples settings"| node_config
node_gym -->|"samples settings"| node_config
node_config -.->|"parses"| node_settings
node_des -->|"simulates haulage"| node_haul
node_des -->|"models failures"| node_breakdown
node_des -->|"tracks performance"| node_kpi
node_haul -.->|"supplies metrics"| node_kpi

click node_gui "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mgym_gui.py"
click node_rlrun "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymRun.py"
click node_gym "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymEnv.py"
click node_ppo "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymRun.py"
click node_classrun "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DefSchdRun.py"
click node_des "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py"
click node_haul "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py"
click node_breakdown "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py"
click node_kpi "https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py"
click node_scheduler "https://github.com/bsingh88/open-pit-mining-gym/blob/main/scheduler.py"
click node_config "https://github.com/bsingh88/open-pit-mining-gym/blob/main/read_config.py"
click node_settings "https://github.com/bsingh88/open-pit-mining-gym/blob/main/config_extend.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gui toneBlue
class node_rlrun,node_gym,node_ppo toneAmber
class node_des,node_haul,node_breakdown,node_kpi toneMint
class node_classrun,node_scheduler,node_config,node_settings toneRose
class node_user toneIndigo
```

## Components

### User interfaces

- [Experiment GUI](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mgym_gui.py): `mgym_gui.py`

### RL workflow

- [RL train and play](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymRun.py): `mGym_GymRun.py`
- [Gym environment](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymEnv.py): `mGym_GymEnv.py`
- [PPO policy](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_GymRun.py): `mGym_GymRun.py`

### Mine simulation

- [Discrete-event simulator](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py): `mGym_DesEnv.py`
- [Haulage and resources](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py): `mGym_DesEnv.py`
- [Equipment breakdowns](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py): `mGym_DesEnv.py`
- [KPI tracking](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DesEnv.py): `mGym_DesEnv.py`

### Dispatch and configuration

- [Classical run](https://github.com/bsingh88/open-pit-mining-gym/blob/main/mGym_DefSchdRun.py): `mGym_DefSchdRun.py`
- [Rule-based policies](https://github.com/bsingh88/open-pit-mining-gym/blob/main/scheduler.py): `scheduler.py`
- [Config sampler](https://github.com/bsingh88/open-pit-mining-gym/blob/main/read_config.py): `read_config.py`
- [Mine settings](https://github.com/bsingh88/open-pit-mining-gym/blob/main/config_extend.txt): `config_extend.txt`

### Other components

- **Researcher**

## Connections

- Researcher → Experiment GUI: operates (evidence: `README.md`)
- Researcher → RL train and play: runs directly (evidence: `README.md`)
- Researcher → Classical run: runs directly (evidence: `README.md`)
- Experiment GUI → RL train and play: starts training or play (evidence: `mgym_gui.py`)
- Experiment GUI → Classical run: starts scheduler (evidence: `mgym_gui.py`)
- RL train and play → Gym environment: registers environment (evidence: `mGym_GymRun.py`)
- RL train and play → PPO policy: trains or loads (evidence: `mGym_GymRun.py`)
- PPO policy → Gym environment: acts in
- Gym environment → Discrete-event simulator: starts simulator (evidence: `mGym_GymEnv.py`)
- Gym environment → Discrete-event simulator: exchanges CSV actions and results (evidence: `mGym_GymEnv.py`)
- Classical run → Discrete-event simulator: runs episodes (evidence: `mGym_DefSchdRun.py`)
- Discrete-event simulator → Rule-based policies: uses dispatch policies (evidence: `mGym_DesEnv.py`)
- Discrete-event simulator → Config sampler: samples settings (evidence: `mGym_DesEnv.py`)
- Gym environment → Config sampler: samples settings (evidence: `mGym_GymEnv.py`)
- Config sampler → Mine settings: parses
- Discrete-event simulator → Haulage and resources: simulates haulage (evidence: `README.md`)
- Discrete-event simulator → Equipment breakdowns: models failures (evidence: `README.md`)
- Discrete-event simulator → KPI tracking: tracks performance (evidence: `mGym_DesEnv.py`)
- Haulage and resources → KPI tracking: supplies metrics (evidence: `mGym_DesEnv.py`)
