dijkstra

Version 1.0 (2.32 KB) by Jordi Palacin
Another single-function implementation of Dijkstra's Algorithm for shorter path finding in a directed matrix-graph
27 Downloads
Updated 5 Sep 2023

View License

A single-function implementation of Dijkstra's algorithm for shorter path finding in a directed matrix-graph
Didactic reference of Dijkstra's algorithm at: https://youtu.be/bZkzH5x0SKU
[route, cost, M] = dijkstra(G, initialNode, finalNode)
Interpretation of the columns of the Dijkstra matrix M
Node number | best previous node | cumulative path cost | node visited
Example: G(a,b)=z defines a directional link from (only) the node a to b, use G(b,a)=w to link from b to a
G = [;
0 1 0 0 0 0 0;
0 0 1 0 0 10 0;
2 0 0 1 0 0 0;
0 0 2 0 1 0 0;
0 0 0 2 0 1 0;
0 0 0 0 2 0 1;
0 0 0 0 0 2 0;
];
[ r, c, W] = dijkstra( G, 1, 7)
r =
1 2 3 4 5 6 7
c =
6
W =
1 0 0 1
2 1 1 1
3 2 2 1
4 3 3 1
5 4 4 1
6 5 5 1
7 6 6 1

Cite As

Jordi Palacin (2024). dijkstra (https://www.mathworks.com/matlabcentral/fileexchange/134851-dijkstra), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0