# Hybrid SimPy Implementation

## Overview

Two SimPy integration approaches available in the codebase:

1. **Lightweight** (`simpy_simulator.py`) - Simple wrapper
2. **Hybrid** (`simpy_simulator_hybrid.py`) - Full refactor with event-driven architecture

Both approaches generate identical results. Choose based on your preference.

---

## Comparison

### Lightweight Wrapper
- 120 lines
- Wraps existing LEACH/LEACHC
- Simple, non-breaking change
- Fast execution (~30 seconds)

Pros:
- Minimal code changes
- Backward compatible
- Easy to understand

Cons:
- Less aggressive SimPy adoption
- Wrapper abstraction layer

### Hybrid Full-Featured
- 470 lines
- Complete simulator refactor
- Proper event-driven model
- Parallel processes
- DRY/KISS principles

Pros:
- True event-driven architecture
- Parallel mobility processes
- Professional code quality
- Full SimPy compliance

Cons:
- Larger codebase
- More complex

---

## Usage

### Default (Lightweight)
```bash
python3 code/main.py
```

### Hybrid
```bash
python3 code/main.py --simpy-hybrid
```

### Test Hybrid Directly
```bash
python3 code/simpy_simulator_hybrid.py
```

---

## Architecture

Both simulators support:
- Static and dynamic networks via `ENABLE_MOBILITY` flag
- 6 test scenarios with different packet sizes and activity levels
- 10 performance metrics (FDN, FMR, DLBI, RSPI, etc.)
- Comprehensive analysis and comparison
- CSV and PNG output

---

## Code Quality

Hybrid simulator demonstrates:
- DRY principles (reusable helper methods)
- KISS architecture (simple, focused methods)
- Proper event-driven model (SimPy processes)
- Event logging and state management
- Clean separation of concerns

---

## Performance

- Dynamic+Static simulation: ~30-45 seconds
- 6 scenarios × 2 protocols each
- Results identical between both approaches

---

## Metrics

Both simulators compute:
1. First Dead Node (FDN)
2. First Muted Round (FMR)
3. Dynamic Load Balancing Index (DLBI)
4. Relative Silence Period Index (RSPI)
5. Alive nodes count
6. Residual energy
7. Packet statistics

---

## Files

- `code/simpy_simulator.py` - Lightweight wrapper
- `code/simpy_simulator_hybrid.py` - Hybrid full-featured
- `code/main.py` - Simulation controller
- `code/analysis_static_dynamic.py` - Comparative analysis
