Shortest paths: Dijkstra and Floyd 4: Unterschied zwischen den Versionen

Aus Operations-Research-Wiki
Wechseln zu: Navigation, Suche
[unmarkierte Version][unmarkierte Version]
(Dijkstra Algorithm)
(Dijkstra Algorithm)
Zeile 27: Zeile 27:
 
First of all, we select the starting node A as the first base node. Then, we have to calculate the path length from starting A to all neighbor nodes of base node A, that have not been base node yet. This step was considered in the column “sequence” (notice, D is not a neighbor node of A).  
 
First of all, we select the starting node A as the first base node. Then, we have to calculate the path length from starting A to all neighbor nodes of base node A, that have not been base node yet. This step was considered in the column “sequence” (notice, D is not a neighbor node of A).  
  
[[Datei:jh1.png]]
+
 
 +
[[Datei:jh1.PNG]]
 +
 
  
 
As demonstrated in the table, the shortest distance is between A and E with distance 2. Consequently, we select E as the new base node.
 
As demonstrated in the table, the shortest distance is between A and E with distance 2. Consequently, we select E as the new base node.
 +
 +
Now we have to continue with step 2. That means, we calculate the path length (distance from starting node!) from the new base node E to all its neighbor nodes which have not been base node yet. These neighbors which have not been base node yet are B, C and D. Furthermore, calculate the length of these ways. Then, compare the path length with the previous length calculated before. It is not possible to reach B and C over E shorter. Consequently, these two possibilities will no longer be considered, thus they are cancelled and we continue to store the old calculations. A path to D did not exist before, so there is no comparison.
 +
 +
 +
[[Datei:Jh2.PNG]]
 +
 +
 +
Next (step 3), we choose that node as base node again that has not been base node yet and that is closest to the starting point. A comparison of the distances indicates that node B has a distance of 3 and has not been base node before. So, B is the new base node.
 +
 +
Continue with step 2 again. That means, we calculate the path length (distance from starting node!) from the new base node B to all its neighbor nodes which have not been base node yet. These neighbors which have not been base node yet are C and D. No shorter way to C and D can be reached over B, so that these possibilities are cancelled.
 +
 +
 +
[[Datei:Jh3.PNG]]
 +
 +
 +
Next, we choose that node as base node again that has not been base node yet and that is closest to the starting point. As we can see, node D has a distance of 6 and was not base node before and is the closest to the starting point (A-C is 10!). Therefore, D is the new base node.

Version vom 1. Juli 2013, 18:46 Uhr

Dijkstra Algorithm

Theory

An important field of application in graph theory is the calculation of shortest paths in graphs. With the help of the Dijkstra algorithm it is possible to determine the shortest way (or optimal solution) from a starting node, over other nodes in between, to the target node. The algorithm was conceived from the Dutch computer scientist Edsger Dijkstra in 1956 and published in 1959. The Dijkstra algorithm consists of the following steps:

     1. Select starting node as base node
     2. Calculate the path length (distance from starting node)to all neighbor nodes of the base node which have not been base node yet. 
        If the path length is shorter than the shortest path one calculated up to now, the new path and length will be stored.
     3. Select that node as new base node that have not been base node yet (consider all, not just neighbors) and that is closest to the starting node.
        Is that node the target node (for shortest path) or the very last node (for shortest tree), stop the procedure.
        Otherwise continue with step 2.


Example

In the following example, the exact procedures of the Dijkstra algorithm are demonstrated in detail. The nodes represent different places (e.g. cities) and the edges in between illustrate the distances.

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Goal: Looking for the shortest path between A and C


First of all, we select the starting node A as the first base node. Then, we have to calculate the path length from starting A to all neighbor nodes of base node A, that have not been base node yet. This step was considered in the column “sequence” (notice, D is not a neighbor node of A).


Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden


As demonstrated in the table, the shortest distance is between A and E with distance 2. Consequently, we select E as the new base node.

Now we have to continue with step 2. That means, we calculate the path length (distance from starting node!) from the new base node E to all its neighbor nodes which have not been base node yet. These neighbors which have not been base node yet are B, C and D. Furthermore, calculate the length of these ways. Then, compare the path length with the previous length calculated before. It is not possible to reach B and C over E shorter. Consequently, these two possibilities will no longer be considered, thus they are cancelled and we continue to store the old calculations. A path to D did not exist before, so there is no comparison.


Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden


Next (step 3), we choose that node as base node again that has not been base node yet and that is closest to the starting point. A comparison of the distances indicates that node B has a distance of 3 and has not been base node before. So, B is the new base node.

Continue with step 2 again. That means, we calculate the path length (distance from starting node!) from the new base node B to all its neighbor nodes which have not been base node yet. These neighbors which have not been base node yet are C and D. No shorter way to C and D can be reached over B, so that these possibilities are cancelled.


Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden


Next, we choose that node as base node again that has not been base node yet and that is closest to the starting point. As we can see, node D has a distance of 6 and was not base node before and is the closest to the starting point (A-C is 10!). Therefore, D is the new base node.