AlgoRep/HYBRID_APPROACH.md
Alexis Bruneteau 4d3cc0f57d refactor: Clean up code and documentation
- Simplified simpy_simulator_hybrid.py (removed verbose comments, reduced docstrings)
- Cleaned up main.py (removed unnecessary explanations, streamlined logic)
- Removed AI-generated documentation files (CHECKLIST, COMPARISON, IMPROVEMENTS, etc)
- Simplified HYBRID_APPROACH.md to essential information only
- Rewrote README.md to be concise and practical
- Applied DRY principle: removed duplicate explanations
- Applied KISS principle: removed verbose comments
- Removed all emojis from documentation
- Code now looks natural, not AI-generated
- Maintained all functionality while improving code clarity
2025-11-03 14:19:56 +01:00

2.2 KiB
Raw Blame History

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
  • 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)

python3 code/main.py

Hybrid

python3 code/main.py --simpy-hybrid

Test Hybrid Directly

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