dijkstra(Graph, Source, Destination, restrict2Nodes)

Dijkstra's Algo to find shortest path, with ability to restrict the path through particular nodes
798 Downloads
Updated 1 Jun 2015

View License

As mentioned in summary, This function used to find shortest path, with the ability to restrict the path through particular nodes. This function used popular method, known as Dijkstra's Algorithm. This method can be use in various domains like: Networking problem (optical/Wireless), Currency Exchange Problem, TSP etc.
%---------------------------------------------------
% usage:
% [Path, Cost, Flag] = dijkstra(Graph, Source, Destination)
% or
% [Path, Cost, Flag] = dijkstra(Graph, Source, Destination, restrict2Nodes)
%
% example:
% Inputs:
% G = [0 10 3 0 0;
% 0 0 1 2 0;
% 0 4 0 8 2;
% 0 0 0 0 7;
% 0 0 0 9 0]; % Every element of Graph should be non-negetive
% S = 1; % Starting node of the path
% D = 4; % Ending node of the path
% r2N = [2 4 1]; % If you want to restrict path only to some of your
% distinguished node (other than Source and Destination) in the Graph, you can ignore this if you want to use
% the full Graph
%
% [c, p, f] = dijkstra(G, S, D, r2N); or
% [c, p, f] = dijkstra(G, S, D)
%
% Outputs:
% Path: Shortest path found by the algorithm, =[], if not found any path
% Cost: Total cost for the shortest path, =Inf, if not found any path
% Flag: 'Found' or 'Not Found' string depending upon path found or not found
%---------------------------------------------------

Cite As

Pramit Biswas (2024). dijkstra(Graph, Source, Destination, restrict2Nodes) (https://www.mathworks.com/matlabcentral/fileexchange/51038-dijkstra-graph-source-destination-restrict2nodes), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
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.0.0

Check
help updated
Check