Skip to content

madaffrager/Bounded-Multi-Source-Shortest-Path-Algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Implementation of the BMSSP Algorithm in python

Python License Tests

A comprehensive implementation and analysis of the Bounded Multi-Source Shortest Path (BMSSP) algorithm, comparing theoretical promises with practical performance.

๐ŸŽฏ Project Overview

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

๐Ÿง  Understanding BMSSP

The Problem

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

The Innovation

BMSSP employs a recursive divide-and-conquer strategy:

  1. Fast Base Case: Use bounded Dijkstra to explore easily reachable vertices
  2. Intelligent Decomposition: Identify promising unexplored regions
  3. Recursive Solving: Solve smaller subproblems with tighter bounds
  4. Result Merging: Combine solutions back into the global answer

The Secret Sauce: Batch Operations

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.

๐Ÿ“ Repository Structure

โ”œโ”€โ”€ 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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • No external dependencies required!

Installation

git clone https://github.com/madaffrager/Bounded-Multi-Source-Shortest-Path-Algorithm
cd Bounded-Multi-Source-Shortest-Path-Algorithm

Running the Code

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.

๐Ÿ“Š Key Findings

Performance Results

Benchmark Overview:

Description Result
Total Benchmarks 71
Dijkstra Wins 4
BMSSP Wins 67
Average Dijkstra Advantage 1.50ร—
Average BMSSP Advantage 1.40ร—

Full results :

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ร—)

Key Insights

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

Why Dijkstra's Wins (For Now)

  1. Constant Factor Dominance: At practical scales (< 10K nodes), BMSSP's implementation overhead outweighs its asymptotic advantages

  2. Language Overhead: Python's recursion and object creation costs significantly impact BMSSP's complex control flow

  3. Hardware Reality: Modern CPUs excel at the simple, cache-friendly operations that characterize Dijkstra's algorithm

  4. Scale Threshold: The crossover point where BMSSP becomes advantageous likely occurs at much larger scales (millions of nodes)

๐Ÿ”ฌ Technical Deep Dive

The Specialized Priority Queue

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

Recursive Architecture

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)

๐ŸŽ“ Educational Value

This project demonstrates several important software engineering principles:

Algorithm Analysis in Practice

  • How constant factors affect real-world performance
  • The importance of implementation quality vs. theoretical complexity
  • Why benchmarking methodology matters

Engineering Trade-offs

  • Recursive vs. iterative approaches
  • Memory allocation patterns and performance
  • Language choice impact on algorithmic performance

Research Translation

  • Challenges in implementing academic algorithms
  • The gap between pseudocode and production code
  • Importance of correctness verification

๐Ÿ”ฎ Future Work

Potential Improvements

  1. C++ Implementation: Eliminate Python overhead to better isolate algorithmic differences
  2. Larger Scale Testing: Benchmark on graphs with 100K+ vertices
  3. Graph Type Analysis: Test on specialized topologies (road networks, social graphs)
  4. Memory Profiling: Analyze memory usage patterns and cache behavior

Research Questions

  • At what scale does BMSSP become advantageous?
  • How do different graph topologies affect relative performance?
  • Can hybrid approaches combine the best of both algorithms?

๐Ÿค Contributing

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

๐Ÿ“š References and Further Reading

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

๐Ÿ“œ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • 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! ๐Ÿ—บ๏ธ

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages