Code covered by the BSD License  

Highlights from
Dijkstra Algorithm

4.5

4.5 | 2 ratings Rate this file 116 Downloads (last 30 days) File Size: 2.57 KB File ID: #36140

Dijkstra Algorithm

by

 

Dijstra algorithm to solve shortest path problem.

| Watch this File

File Information
Description

This algorithm is to solve shortest path problem.

Usage
[cost rute] = dijkstra(graph, source, destination)

note : graph is matrix that represent the value of the edge. if node not connected with other node, value of the edge is 0.

example:
Finding shortest path form node 1 to node 7.

>> G = [0 3 9 0 0 0 0;
     0 0 0 7 1 0 0;
     0 2 0 7 0 0 0;
     0 0 0 0 0 2 8;
     0 0 4 5 0 9 0;
     0 0 0 0 0 0 4;
     0 0 0 0 0 0 0;
     ];
>> [cost rute] = dijkstra(G,1,7)

it will resulting

cost = 15
rute = [7 6 4 5 2 1]

Required Products MATLAB
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
16 Dec 2013 Gautam Marwaha

This code mostly works fine but fails for a few cases:
G = [0 1 1 1 1 0 0;
1 0 0 1 0 1 0;
1 0 0 1 0 1 1;
1 1 1 0 1 0 0;
1 0 0 1 0 0 1;
0 1 1 0 0 0 1;
0 0 1 0 1 1 0];

dijkstra(G,3,5) yields [5 3 3] or [3 3 5]. Any ideas why this happens?

09 Dec 2013 Alex George

any idea on how this works?

24 Nov 2013 taewoo

!!

25 Apr 2013 Poonam

good algo..

25 Mar 2013 Matthias

It worked for my purpose! Thanks for it. 4 of 5 because i haven't tested it in extreme situations. Very well!!!

Contact us