Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shortest Path. What is Shortest Path In a network, there are often many possible paths from one node in a network to another. It is often desirable (for.

Similar presentations


Presentation on theme: "Shortest Path. What is Shortest Path In a network, there are often many possible paths from one node in a network to another. It is often desirable (for."— Presentation transcript:

1 Shortest Path

2 What is Shortest Path In a network, there are often many possible paths from one node in a network to another. It is often desirable (for reasons of cost, time, etc.) to find the shortest of these paths. For straightforward networks, the method of trial and error is usually the easiest way to find the shortest path. Find all possible paths/routes from the start node to the finish node Calculate the sum of the weights of each path/route

3 Trial and Error Trial and Error Example Q. What is the shortest path from A to G in the following network, where each length is measured in kms. A F C E D B G 7 3 3 2 5 2 7 1 4 4 4

4 For trial and error methods, you would build a table of all possible paths PathTotal Distance

5 For trial and error methods, you would build a table of all possible paths PathTotal Distance A – B – F – G4 + 4 + 4 = 12 A – B – D – G4 + 1 + 7 = 12 A – B – D – C – E – G4 + 1 + 3 + 5 + 2 = 15 A – B – D – E – G4 + 1 + 2 + 2 = 9 A – D – G7 + 7 = 14 A – D – E – G7 + 2 + 2 = 11 A – D – C – E – G7 + 3 + 5 + 2 = 17 A –C – D – G3 + 3 + 7 = 13 A – C – D – E – G3 + 3 + 2 + 2 = 10 A – C – E – G3 + 5 + 2 = 10 Clearly the shortest path between A and G is: A  B  D  E  G The total distance from A to G is 9 kms.

6 Dijkstra’s algorithm Trial and error can be time consuming, and unreliable for complex problems. For this unit, you need to understand and be able to use Dijkstra’s algorithm. This algorithm considers all possible routes by summing the distances as we add each edge.

7 Dijkstra’s algorithm Step 1: Represent each node with an empty circle. Label the starting point circle 0 (i.e. the distance from the start). Step 2: Find the smallest total you can get by starting with a circled number, and adding an edge from there to an empty circle. When you have found the smallest total, fill in the empty circle with that total and add a back arrow on that edge. Step 3: Continue the process, repeating Step 2 until you have written a total in the end circle. Step 4: Follow the back arrows from the end point back to the start point to determine the shortest path. The shortest path is ……… The length of the shortest path is ……..

8 What is Shortest Path Example A F C D E B G 7 3 3 2 5 2 7 1 4 4 4

9 What is Shortest Path What is the shortest path from A to F in this network? Start AB1 ACB2+1=3 AC2 ABC1+1=2 ABD1+3=4 ACBD2+1+3=6 ACD2+1=3 ABCD1+1+1=3 ABE1+2=3 ACBE2+1+2=5 ACE2+2=4 ABCE1+1+2=4 ACDF2+1+3=6 ABCDF1+1+1+3=6 ABEF1+2+3=6

10 Minimum Cost

11 Another Problem A new airline is setting up a network of flights between New Zealand towns and cities. This matrix shows the towns and cities, and the distances of possible flights. AucklandTaurangaWhakataneHamiltonRotoruaWellington Auckland150160 Tauranga7012090 Whakatane65 Hamilton80350 Rotorua400 Wellington a)At the start of the operation the airline wants to ensure all towns and cities are connected, with a minimum total distance for the flight paths. b)How would the tree be adjusted if it is essential that there are flights between Auckland and Hamilton and between Auckland and Tauranga? c)What is the shortest distance that a customer can fly to get from Auckland to Wellington? d)A flight inspector is based in Wellington. He wants to fly on all the routes to inspect the flight services. Investigate this and suggest a shortest route he might take.


Download ppt "Shortest Path. What is Shortest Path In a network, there are often many possible paths from one node in a network to another. It is often desirable (for."

Similar presentations


Ads by Google