| Crates.io | bmssp |
| lib.rs | bmssp |
| version | 0.1.0 |
| created_at | 2025-08-12 13:21:12.401415+00 |
| updated_at | 2025-08-12 18:10:02.53288+00 |
| description | The BMSSP algorithm |
| homepage | |
| repository | https://github.com/lucas-montes/bmssp |
| max_upload_size | |
| id | 1791982 |
| size | 64,368 |
A Rust implementation of the groundbreaking BMSSP (Bounded Multi-Source Shortest Path) algorithm from the paper "Breaking the Sorting Barrier for Directed Single-Source Shortest Paths" by R. Duan, J. Mao, X. Mao, X. Shu, and L. Yin.
This library implements the first algorithm to achieve a sub-quadratic time complexity for the single-source shortest path problem on directed graphs, breaking the long-standing "sorting barrier" that has limited performance since Dijkstra's algorithm.
The BMSSP algorithm uses a recursive divide-and-conquer approach with three main components:
Instead of maintaining a single global priority queue like Dijkstra's algorithm, BMSSP:
Add this to your Cargo.toml:
cargo add bmssp
use bmssp::{ShortestPath, Graph, Edge};
// Create a graph
let mut graph = vec![Vec::new(); 4];
graph[0].push(Edge::new(1, 1.0));
graph[0].push(Edge::new(2, 4.0));
graph[1].push(Edge::new(2, 2.0));
graph[1].push(Edge::new(3, 5.0));
graph[2].push(Edge::new(3, 1.0));
// Initialize the shortest path solver
let mut sp = ShortestPath::new(graph);
// Compute shortest paths from vertex 0
let distances = sp.get(0);
// distances[i] now contains the shortest distance from vertex 0 to vertex i
println!("Distance to vertex 1: {}", distances[1]); // Output: 1.0
println!("Distance to vertex 2: {}", distances[2]); // Output: 3.0
println!("Distance to vertex 3: {}", distances[3]); // Output: 4.0
The algorithm's performance depends on graph structure:
Where:
You can check the example:
cargo run --example simple
Run the test suite:
cargo test
The implementation is verified against the AOJ GRL_1_A test cases to ensure correctness.
Run benchmarks with different type of graphs
cargo bench --bench bench_bmssp
If you want to profile the functions you can use
cargo bench --bench bench_bmssp -- --profile-time=30
| Algorithm | Time Complexity | Space | Notes |
|---|---|---|---|
| Dijkstra | O(m + n log n) | O(n) | Classical approach |
| BMSSP | O(m + n log² n / log log n) | O(n) | This implementation |
git clone https://github.com/your-username/bmssp
cd bmssp
cargo build --release
This project includes a Nix flake for reproducible builds:
nix develop # Enter development shell
cargo build
The algorithm addresses fundamental limitations in shortest path computation:
BlockHeap uses a simplified implementation (BTreeSet) rather than the specialized data structure from Lemma 3.3Contributions are welcome! Areas for improvement:
The library is organized into several key modules:
models.rs: Core data types (Vertex, Length, Edge, Graph)heaps.rs: Priority queue implementations (Heap, BlockHeap)shortest_path.rs: Main BMSSP algorithm implementation (ShortestPath)ShortestPath::get method sets up parameters and calls the main algorithmShortestPath::bmssp recursively breaks down the problemShortestPath::find_pivots identifies key vertices for partitioningShortestPath::base_case handles small subproblems with a modified Dijkstra approachLicensed under the Apache License, Version 2.0. See LICENSE for details.