This project implements a comprehensive simulation of packet routing in wireless sensor networks modeled as random geometric graphs. The simulation explores how network connectivity (radius rc) and packet generation probability (lambda λ) affect packet forwarding patterns and network performance.
- Random Geometric Graph Generation: Creates connected networks with variable connectivity radius
- Connectivity Verification: Ensures all generated networks are connected before simulation
- Sink Node Selection: Automatically selects the most central node (highest degree) as the sink
- Packet Simulation: Simulates packet generation and multihop routing using shortest paths
- Statistical Analysis: Tracks packet forwarding activity per node
- Visualization: Generates scatter plots showing relationship between node distance and packet forwarding
├── main.py # Main execution script
├── geometric_graph.py # Random geometric graph generation
├── check_connectivity.py # Network connectivity verification
├── pick_sink.py # Sink node selection algorithm
├── simulate_packets.py # Packet routing simulation engine
├── plot_results.py # Result visualization
└── README.md # This file
- Python 3.7 or higher
- NumPy
- NetworkX
- Matplotlib
- Clone the repository:
git clone https://github.com/yourusername/geometric-graph-simulation.git
cd geometric-graph-simulation- Install dependencies:
pip install numpy networkx matplotlibRun the main simulation:
python main.pyYou can modify simulation parameters directly in main.py:
run_simulation(
n=100, # Number of nodes
num_rc=10, # Number of different rc values to test
num_lambda=10, # Number of different lambda values to test
steps=1000000 # Number of simulation time steps
)- n: Number of nodes in the network (default: 100)
- rc: Connectivity radius (values from ~0.15 to √2 ≈ 1.414)
- λ (lambda): Packet generation probability per time step (0 < λ ≤ 1)
- steps: Number of simulation time steps (default: 1,000,000)
The script creates a results/ folder containing 100 scatter plots (PNG).
- X-axis: Euclidean distance of each node from sink
- Y-axis: Number of packets forwarded by that node
- Sink node appears at distance 0 with total packets received
Creates random geometric graphs with nodes randomly positioned in a unit square and edges based on Euclidean distance threshold.
Verifies that a graph is connected using NetworkX built-in functionality.
Selects the sink node by identifying nodes with maximum degree.
Core simulation engine that:
- Computes shortest paths from all nodes to sink
- Simulates packet generation and routing
- Tracks forwarding statistics
Generates scatter plots visualizing packet forwarding vs. distance from sink.
Orchestrates the entire simulation pipeline:
- Iterates through rc and lambda values
- Creates networks and runs simulations
- Saves results and statistics
The simulation with default parameters (10 rc values × 10 lambda values × 1,000,000 steps) may take several minutes to complete depending on your system. For faster testing, reduce the steps parameter or number of rc/lambda values.
This project is provided as-is for educational purposes.
For questions or issues, please open an issue on GitHub.
- NetworkX Documentation: https://networkx.org/
- Random Geometric Graphs: IEEE Transactions on Information Theory
- Wireless Sensor Networks: Routing Algorithms and Protocols