Dijkstra algorithm which use priority queue thus complexity is equal O(ElogV) where E is number of edges and V is number of vertices. Used data structures are based on interfaces so you can implement your own or reused present. Simply example below. More information about algorithm you can find on the wikipedia.
Install the latest version from NuGet
Install-Package Dijkstra.NET
var graph = new Graph<int, string>();
graph.AddNode(1);
graph.AddNode(2);
graph.Connect(0, 1, 5, "some custom information in edge"); //First node has key equal 0
var dijkstra = new Dijkstra<int, string>(graph);
IShortestPathResult result = dijkstra.Process(0, 1); //result contains the shortest path
result.GetPath();Library provide parallel version of finding the shortest path in graph, it uses breadth-first search algorithm and Map-Reduce technics. Parallel version use all cores to find the shortest path thus processing cost is higher than classic way, however it can gives quicker result when dense graph with similar weights was processed. Simple example below.
var graph = new Graph<int, string>();
graph.AddNode(1);
graph.AddNode(2);
graph.Connect(0, 1, 5, "some custom information in edge"); //First node has key equal 0
var bfs = new BfsParallel<int, string>(graph);
IShortestPathResult result = bfs.Process(0, 1); //result contains the shortest path
result.GetPath();For Graph where number of vertices is 1 000 000 and number of edges is 10 000 000. Benchmark is available on the benchmark branch.
Host Process Environment Information:
BenchmarkDotNet.Core=v0.9.9.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-6820HQ CPU 2.70GHz, ProcessorCount=8
Frequency=2648439 ticks, Resolution=377.5809 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1586.0
Type=DijkstraBenchmark Mode=SingleRun LaunchCount=1
WarmupCount=1 TargetCount=1
| Method | Median | StdDev |
|---|---|---|
| GetPath | 695.5040 us | 0.0000 us |
Dijkstra.NET is licensed under the MIT license. See LICENSE file for full license information.