File Exchange

## dijkstra(Graph, Source, Destination, restrict2Nodes)

version 1.0.0.0 (4.58 KB) by Pramit Biswas

### Pramit Biswas (view profile)

Dijkstra's Algo to find shortest path, with ability to restrict the path through particular nodes

Updated 01 Jun 2015

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
%---------------------------------------------------

### Cite As

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

rahul kumar

### rahul kumar (view profile)

Very efficient and nice programming