A modularized, high-fidelity simulation of the Optimised Load Balancing (OLB) algorithm for IoT-enabled smart healthcare systems, built on the YAFS (Yet Another Fog Simulator) framework.
This project provides a complete digital twin to model, simulate, and analyze the performance of load balancing strategies in a fog computing environment.
- About The Project
- Getting Started
- Usage
- Project Structure
- Core Concepts: The OLB Algorithm
- Simulation Output
- License
This simulation implements the mathematical model of the OLB algorithm within a custom YAFS placement policy. It constructs a digital twin of a smart healthcare environment, complete with patient sensors (Tier 1) and fog computing nodes (Tier 2), to evaluate how well the OLB algorithm distributes computational workloads.
Key Features:
- YAFS Integration: Seamlessly integrated with the YAFS 1.0 simulation framework.
- Digital Twin Environment: Simulates a realistic IoT healthcare environment with geospatial awareness.
- OLB Algorithm: Implements the complete mathematical model for optimised load balancing.
- Performance Metrics: Provides comprehensive analysis of latency, energy consumption, and network usage.
- Modular Design: Clean, maintainable, and extensible code structure.
Built With:
Follow these steps to get the simulation running on your local machine.
Ensure you have Python 3.8 or higher installed. You can check your version with:
python --version- Clone the repository:
git clone https://github.com/23CSE362-edge-computing-2025-26-odd/capstone-project-10-bitmistake.git cd capstone-project-10-bitmistake - Install the YAFS framework:
pip install yafs
- Install additional dependencies:
pip install networkx numpy matplotlib
To run the complete simulation, execute the main script from the root directory:
python main.pyThe script will:
- Initialize the digital twin environment.
- Set up the YAFS topology and application.
- Apply the OLB placement algorithm to assign sensor workloads to fog nodes.
- Run the simulation for the configured duration.
- Generate and save performance reports in the
results/anddata/directories.
Configuration:
You can modify simulation parameters (e.g., number of sensors, simulation time) in the src/utils.py file within the SimulationConfig class.
.
├── main.py # Main simulation entry point
├── config/ # Configuration files for experiments and placement
├── data/ # Raw simulation results (JSON)
├── docs/ # Project documentation
├── experiments/ # Scripts for evaluation and plotting
├── plots/ # Generated plots and visualizations
├── reports/ # Formatted simulation reports
├── src/ # Source code
│ ├── __init__.py # Package initializer
│ ├── comparison_algorithms.py # Additional load balancing algorithms
│ ├── devices.py # Sensor and Fog Node models
│ ├── environment.py # Digital Twin Environment setup
│ ├── healthcare_scenarios.py # Healthcare-specific simulation scenarios
│ ├── metrics.py # Performance metrics collection
│ ├── metrics_definitions.py # Definitions for custom metrics
│ ├── olb_algorithm.py # Core OLB algorithm implementation
│ ├── utils.py # Configuration and utility functions
│ ├── visualization.py # Plotting and visualization functions
│ ├── workload_models.py # Workload generation models
│ └── yafs_integration.py # YAFS-specific integration code
└── README.md # This file
The OLB algorithm dynamically assigns sensor workloads to the most optimal fog node by calculating a total latency score. The node with the minimum score is selected.
This measures the time it takes to transmit data from a sensor to a fog node. It is calculated based on:
- Distance: Euclidean distance between the sensor and the fog node.
- Channel Gain & SNR: Signal strength and quality over the wireless channel.
- Device Capacity: The maximum data rate the fog node can handle from the sensor.
- Total Traffic Load: The cumulative traffic from all sensors assigned to the node.
This measures the time it takes for a fog node to process the received data. It is calculated based on:
- Individual Computing Load: The computational demand of a single sensor's workload.
- Total Computing Load: The cumulative computational demand from all sensors assigned to the node.
The final placement decision is made by selecting the fog node j that minimizes Total Latency = L_m(j) + L_p(j).
The OLB algorithm implements:
- Communication latency calculation
- Computing latency estimation
- Energy consumption modeling
- Load balancing optimization
This implementation uses:
- YAFS: Core simulation framework
- NetworkX: Graph-based topology modeling
- Digital Twin: IoT environment simulation
- OLB Placement Policy: Custom YAFS placement algorithm
- Geospatial Environment: Created a 2D coordinate system of 3000x2000 units
- IoT Layer Entities (Tier 1): Implemented 10 sensor devices with all required OLB parameters:
coordinates: (x, y) position tupletransmissionPower: P(x) signal strength in WattsaverageFlowRate: fl(x) data generation frequency in HzflowTrafficSize: l(x) network packet size in megabitsaverageFlowSize: ν(x) computational workload in MI
- Fog Layer Entities (Tier 2): Implemented 6 fog nodes with parameters:
coordinates: (x, y) static position tupleprocessingPower: Cj CPU capacity in MIPSbandwidth: BWj network interface capacity in MHzcarrierFrequency: operational frequency in GHznoisePower: σ² ambient noise level in Watts
- YAFS Application: Properly integrated with YAFS framework
- Application Modules: Defined three module types:
Client_Module: SOURCE type, handles sensor data ingestionProcessing_Module: MODULE type, performs data processingStorage_Module: SINK type, stores processed results
- Data Flow Topology: Implemented DAG structure in YAFS:
- Sensor → Client_Module → Processing_Module → Storage_Module
Implemented complete mathematical model within YAFS Placement policy:
- Distance Calculation: Euclidean distance between sensor and fog node
- Channel Gain:
g(x) = 10 * log10(λ²/(4πd)²)where λ = c/f - Signal-to-Noise Ratio:
SNR(x) = (P(x) * g(x))/σ² - Device Capacity:
cj(x) = BWj * (1 + SNR(x)) - Individual Traffic Load:
eaj(x) = (fl(x) * l(x))/cj(x) - Total Traffic Load:
TLj = Σ eaj(x)for all assigned modules - Communication Latency:
L_m(j) = TLj/(1 - TLj)
- Individual Computing Load:
ebj(x) = (fl(x) * ν(x))/Cj - Total Computing Load:
CLj = Σ ebj(x)for all assigned modules - Computing Latency:
L_p(j) = CLj/(1 - CLj)
- Total Latency:
L_total = L_m(j) + L_p(j) - Optimal Selection: Node with minimum L_total score
Full YAFS simulation execution with comprehensive KPI collection:
- Overall Latency (L): 4.1962 - Sum of all communication and computing latencies
- Network Usage (Nusage): 5.0760 MB/s - Total data transmission volume
- Execution Time (Te): 0.4196 ms - Average end-to-end task time
- Energy Consumption (Etotal): 21.5153 W - Total device energy consumption
- Cost of Execution (Ce): 1.1037 - Composite cost metric
- SensorDevice: Encapsulates Tier 1 IoT sensor parameters
- FogNodeDevice: Encapsulates Tier 2 fog node parameters
- OLBPlacement: Custom YAFS Placement policy implementing OLB algorithm
- DigitalTwinEnvironment: Manages the complete simulation environment
- Proper YAFS Topology: NetworkX-based topology with fog nodes, proxy, and cloud
- YAFS Application: Correctly structured modules and message flows
- YAFS Placement: Custom placement policy integrating OLB mathematical model
- YAFS Simulation: Full simulation execution with module deployment
- All formulas implemented exactly as specified
- Proper handling of edge cases (division by zero, overflow)
- Load balancing ensures no node exceeds 99% utilization
- Distance-based channel gain calculations using speed of light constant
The YAFS simulation successfully assigned 10 sensors across 6 fog nodes:
- Intelligent Load Distribution: Fog Node 5 (3 sensors), Fog Nodes 0&4 (2 sensors each), others (1 sensor each)
- Latency Optimization: Total latency 4.1962 with Communication (0.1045) + Computing (4.0917)
- Real-time Decision Making: Each sensor evaluated against all fog nodes with dynamic load consideration
The simulation generates several output files:
data/olb_simulation_results.json: A JSON file containing raw metrics and configuration details.results/reports/olb_simulation_report.txt: A human-readable report summarizing the performance and module assignments.results/plots/: Visualizations comparing algorithm performance (if generated via experiment scripts).
Distributed under the MIT License.