# LEACH vs LEACH-C Simulation Discrete event simulation of LEACH and LEACH-C clustering protocols for wireless sensor networks with node mobility. ## Installation With Poetry: ```bash poetry install poetry run python code/main.py ``` With pip: ```bash pip install -r requirements.txt python3 code/main.py ``` ## Running Default (lightweight simulator): ```bash python3 code/main.py ``` With hybrid full-featured simulator: ```bash python3 code/main.py --simpy-hybrid ``` ## Simulators Two SimPy implementations available: 1. **Lightweight** - Simple event-driven wrapper (120 lines) 2. **Hybrid** - Full discrete event simulator with parallel processes (470 lines) Both generate identical results. See `HYBRID_APPROACH.md` for comparison. ## Output Generated files in `results/`: - `simulation_results_dynamic.json` - Dynamic network results - `simulation_results_static.json` - Static network results - `comparison_static_dynamic.csv` - Comparison table - PNG graphs comparing metrics ## Configuration Edit `code/config.py` to change: - Network size, packet size - Energy parameters - Simulation scenarios - ENABLE_MOBILITY flag (static vs dynamic) ## Structure ``` code/ ├── main.py - Simulation controller ├── leach.py, leach_c.py - Protocol implementations ├── node.py - Node class ├── metrics.py - Performance metrics ├── config.py - Configuration ├── simpy_simulator.py - Lightweight wrapper ├── simpy_simulator_hybrid.py - Full hybrid simulator └── analysis.py - Analysis and plotting results/ - Generated simulation outputs rapport/ - Final report ``` ## Metrics 10 performance metrics calculated: - First Dead Node (FDN) - First Muted Round (FMR) - Dynamic Load Balancing Index (DLBI) - Relative Silence Period Index (RSPI) - Energy consumption - Packet statistics - Node statistics ## Scenarios 6 test scenarios with varying: - Packet sizes (2000-4000 bits) - Activity probability (0.05-0.95) - Network size (100-200 nodes)