Supermarine
The algorithm of Dijkstra is used to solve the problem of the shortest way between two tops of a related graph whose weight related to the edges is positive or null.
To illustrate the interest of this algorithm, one can take for example the highway network of an area: each top is a city and each arc is a road whose weight is mileage. The algorithm of Dijkstra then makes it possible to find the shortest way of a city to another.
The algorithm carries the name of its inventor, the Informaticien Dutch Edsger Dijkstra and was published in 1959.
Notations
The graph is noted where:- the unit is the whole of the tops of the graph ;
- the unit is the whole of the edges of such as: if is in , then there exists an edge since the node towards the node ;
- one defines the procedure definite on which returns the positive weight of the edge connecting to (and an infinite weight for the pairs of tops which is not connected by an edge).
Principles
The weight of the way between two tops is the sum of the weights of the edges which compose it. For a given pair of tops (the top of the departure) (top of arrival) pertaining to , the algorithm finds the way since towards of less weight (in other words the lightest way or shortest).The algorithm functions by building a subgraph so that the distance between a top of since either known and or a minimum in . Initially contains simply the node insulated, and with itself outdistances it is worth zero. Arcs are added to with each stage:
-
1. by identifying all the edges in such as is in and is in ;
- 2. by choosing the edge in which gives the distance minimum since to while passing all the ways created driving to this node.
The algorithm finishes either when becomes a covering tree of , or when all the nodes of interest are in .
Algorithm
Function appendices
The algorithm uses the following additional functions.Initialization of the algorithm
Initialization (G, sdeb) 1 for each point S of G 2 to make D: = infinite/* one initializes the tops other than sdeb with 0 * 3 predecessor: = 0/* because one does not know at the beginning any way between S and sdeb * 4 D: = 0/* sdeb being the point nearest to sdeb *
Seek node nearest
- One seeks the node nearest (connected by the weakest edge of the weight) to among the nodes located in a whole, made up of the nodes distant from an edge of the elements of . One uses for that the function Trouve_min () . The found node is then unobtrusive of the unit and is then turned over to the principal function like result of the function.
Update of the distances
- One updates distances between and by raising the question: is it to better pass by or not?
Principal function
Here the principal function using the preceding additional functions:Dijkstra (G, Weight, sdeb) 1 Initialization (G, sdeb) 2 P: = empty set 3 Q: = together of all the nodes 4 as long as Q is not an empty set 5 to make s1: = Trouve_min (Q) 6 P: = P union {s1} 7 for each node s2 close to s1 8 to make maj_distances (s1, s2)
The shortest way of with can be then calculated repeatedly according to the following algorithm, with the continuation representing the shortest way of with : 1 has = empty continuation 2 S: = sfin 3 = S has + has/* inserts S into the beginning of A * 4 as long as S! = sdeb 5 S = predecessor/* one continues to follow the way * 6 = S has + has
Improvements of the algorithm
It is possible to slightly improve the principal algorithm by stopping research when the equality is checked, in condition of course of seeking only the minimal distance between and .
The algorithm of Dijkstra could be implemented effectively by storing the graph in the form of lists of adjacency and by using a Tas like a File at priorities to fulfill the function Trouve_min. If the graph has arcs and nodes, by supposing that the comparisons of the weights of arcs are at constant time, then the Complexité of the algorithm is: . It will be noted that the use of Tas of Fibonacci gives a better execution time deadened: .
Example
The following example shows the successive stages in the resolution of the shortest way in a graph. The nodes symbolize cities in Germany and the edges indicate the distance between the cities. One wants to go from Frankfurt ( Frankfurt ) to Munich ( München ).
Codes
Pseudo code
function Dijkstra (nodes, wire, distance, beginning, end) For N traversing nodes n.parcouru = infinite // Can be implemented with -1 = 0 n.precedent End for debut.parcouru = 0 Empty DejaVu = list PasEncoreVu = nodes As long as PasEncoreVu! = empty list n1 = minimum (PasEncoreVu) // the node in PasEncoreVu with traversed smallest DejaVu.ajouter (n1) PasEncoreVu.enlever (n1) For N2 traversing wire (n1) // nodes connected to n1 by an arc If n2.parcouru > n1.parcouru + distance (n1, N2) // distance corresponds to the weight of the arc connecting n1 and N2 n2.parcouru = n1.parcouru + distance (n1, N2) n2.precedent = n1 // Say that to go with N2, it is necessary to pass by n1 End if End for End as long as empty chemin = list N = fine As long as N! = beginning chemin .ajouterAvant (N) N = n.precedent End as long as To turn over way Fine Dijkstra function
Caml implementation
Here the code of implementation Caml:
Applications
An application of most current of the algorithm of Dijkstra is the protocol open shortest path first which allows a very effective routing Internet of information by seeking the most effective course.The routers IS-IS also use the algorithm. The sites of road routes use it same manner and allow many adaptations by adjusting the weight of the arcs such as for example: the most economic way, fastest…
Appearance in the popular culture
The algorithm of Dijkstra is used by the investigators of the series NUMB3RS, in the episode 23 of the season 3.
Appendices
References
- “'' has shorts introduction to the art off programming ''” of Edsger W. Dijkstra, containing the original article describing the algorithm of Dijkstra (pages 67 to 73)
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: “ Introduction to algorithmic the ”, (version 2nd edition, 2001, MIT Close and McGraw-Hill, section 24.3, “ Dijkstra' S algorithm ”, pages 595-601)
Internal bonds
- Edsger Dijkstra
- Pathfinding and Problems of advance
- Algorithm of course in width
- Algorithm A*
- Articles on the Algorithm of Dantzig-Ford and the Algorithme of Ford-Bellman which make it possible to calculate shorter ways with negative weights of edge
External bonds
- detailed Explanation of the algorithm of Dijkstra and implementation supplements in C++
- Rapport on the algorithm of Dijkstra and the play of simulation OpenCity
- Applet Java showing the algorithm of Dijkstra stage by stage
- Applets Java using the algorithm.
Additional sources and indications
| Random links: | Ventured | Eastern (Congo-Kinshasa) | Canton of Dijon-8 | Birotonde bilunaire | FIFA Soccer 95 |