A comprehensive implementation and analysis of the Bounded Multi-Source Shortest Path (BMSSP) algorithm, comparing theoretical promises with practical performance.
This repository contains a complete implementation of the Bounded Multi-Source Shortest Path (BMSSP) algorithm, originally proposed as a "record-breaking" improvement over classical shortest path algorithms.
The Goal: Translate academic pseudocode into working Python code and rigorously benchmark it against established algorithms like Dijkstra's.
The Result: A fascinating exploration of why theoretically superior algorithms don't always win in practice, and valuable insights into the gap between academic theory and software engineering reality.
๐ Read the full story: Deconstructing the Shortest-Path Algorithm: A Deep Dive into Theory vs. Implementation
Find shortest paths from multiple source vertices, but only up to a maximum distance B (the "bound"). This is practically important for:
- Social network analysis (friends within N degrees)
- Route planning with fuel/time constraints
- Network topology analysis with hop limits
BMSSP employs a recursive divide-and-conquer strategy:
- Fast Base Case: Use bounded Dijkstra to explore easily reachable vertices
- Intelligent Decomposition: Identify promising unexplored regions
- Recursive Solving: Solve smaller subproblems with tighter bounds
- Result Merging: Combine solutions back into the global answer
The algorithm uses a specialized bucket-based priority queue that supports batch decrease-key operations. When thousands of shortest paths are updated simultaneously, traditional heaps require O(k log n) time for k updates. BMSSP can handle these updates in batches, theoretically reducing the amortized cost.
โโโ bmssp_algorithm.py # Core BMSSP implementation
โโโ baseline_dijkstra.py # Optimized Dijkstra's for comparison
โโโ benchmark.py # Comprehensive performance benchmarks
โโโ test_algorithms.py # Full test suite with correctness verification
โโโ requirements.txt # Python dependencies (none - pure Python!)
โโโ README.md # This file
โโโ LICENSE # Apache 2.0 License
- Python 3.8 or higher
- No external dependencies required!
git clone https://github.com/madaffrager/Bounded-Multi-Source-Shortest-Path-Algorithm
cd Bounded-Multi-Source-Shortest-Path-Algorithm
1. Run the test suite (recommended first step):
python test_algorithms.py
2. See the algorithm in action:
python bmssp_algorithm.py
3. Run comprehensive benchmarks:
python benchmark.py
This will test both algorithms on various graph types and sizes, with full correctness verification.
Description | Result |
---|---|
Total Benchmarks | 71 |
Dijkstra Wins | 4 |
BMSSP Wins | 67 |
Average Dijkstra Advantage | 1.50ร |
Average BMSSP Advantage | 1.40ร |
Graph Type | Nodes | Bound | Sources | Dijkstra Time | BMSSP Time | Winner |
---|---|---|---|---|---|---|
Small Connected | 100 | 20 | 3 | 0.000089s | 0.000161s | Dijkstra (0.56ร) |
Medium Sparse | 500 | 30 | 5 | 0.000604s | 0.000924s | Dijkstra (0.65ร) |
Large Sparse | 1000 | 40 | 5 | 0.001988s | 0.002102s | Dijkstra (0.95ร) |
2D Grid | 400 | 25 | 3 | 0.000584s | 0.000937s | Dijkstra (0.62ร) |
Dense Small | 200 | 15 | 4 | 0.002757s | 0.002136s | BMSSP (1.29ร) |
Dense Multi-Source | 300 | 20 | 5 | 0.008604s | 0.006009s | BMSSP (1.43ร) |
Dense Multi-Source | 400 | 25 | 6 | 0.019451s | 0.014139s | BMSSP (1.38ร) |
-
BMSSP dominates dense, multi-source graphs: consistent speed-ups 1.3โ1.7ร.
-
Sparse graphs favor Dijkstra: small or grid-like graphs still see Dijkstra outperform.
-
Crossover threshold: BMSSPโs advantage emerges as source count and edge density increase.
-
Constant Factor Dominance: At practical scales (< 10K nodes), BMSSP's implementation overhead outweighs its asymptotic advantages
-
Language Overhead: Python's recursion and object creation costs significantly impact BMSSP's complex control flow
-
Hardware Reality: Modern CPUs excel at the simple, cache-friendly operations that characterize Dijkstra's algorithm
-
Scale Threshold: The crossover point where BMSSP becomes advantageous likely occurs at much larger scales (millions of nodes)
The heart of BMSSP's theoretical advantage:
class SpecializedPriorityQueue:
def batch_decrease_key(self, updates):
"""Process multiple distance updates efficiently"""
self.pending_updates.extend(updates)
def extract_min(self):
"""Extract minimum element after processing batch updates"""
self._process_pending_updates()
# ... bucket-based extraction logic
BMSSP's divide-and-conquer approach:
def bmssp(self, sources, bound, current_depth=0):
# Base case: Fast Dijkstra exploration
explored = self.fast_dijkstra(sources, bound)
# Recursive case: Explore promising regions
while not frontier_queue.is_empty():
vertex, distance = frontier_queue.extract_min()
remaining_bound = bound - distance
# Recursive subproblem
sub_result = self.bmssp({vertex}, remaining_bound, current_depth + 1)
explored.update(sub_result)
This project demonstrates several important software engineering principles:
- How constant factors affect real-world performance
- The importance of implementation quality vs. theoretical complexity
- Why benchmarking methodology matters
- Recursive vs. iterative approaches
- Memory allocation patterns and performance
- Language choice impact on algorithmic performance
- Challenges in implementing academic algorithms
- The gap between pseudocode and production code
- Importance of correctness verification
- C++ Implementation: Eliminate Python overhead to better isolate algorithmic differences
- Larger Scale Testing: Benchmark on graphs with 100K+ vertices
- Graph Type Analysis: Test on specialized topologies (road networks, social graphs)
- Memory Profiling: Analyze memory usage patterns and cache behavior
- At what scale does BMSSP become advantageous?
- How do different graph topologies affect relative performance?
- Can hybrid approaches combine the best of both algorithms?
Contributions are welcome! Areas of particular interest:
- Optimization: Improve the implementation efficiency
- Testing: Add more comprehensive test cases
- Benchmarking: Test on additional graph types and scales
- Documentation: Improve code comments and explanations
Please ensure all tests pass before submitting PRs:
python test_algorithms.py
- Original BMSSP paper: [Link needed - please provide if available]
- Dijkstra, E. W. (1959). "A note on two problems in connexion with graphs"
- Cormen, T. H. et al. "Introduction to Algorithms" (Chapter 24: Single-Source Shortest Paths)
- [Highway Hierarchies and Contraction Hierarchies literature]
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- The original BMSSP paper authors for pushing the boundaries of algorithmic research
- The algorithms community for decades of shortest path research
- Everyone who believes that implementing algorithms is the best way to understand them
Remember: The fastest algorithm is not always the one with the best Big O notation. Context, implementation quality, and real-world constraints matter just as much as theoretical complexity.
Happy pathfinding! ๐บ๏ธ