Decision Maths Dijkstras Algorithm Networks Wiltshire n Maps

  • Slides: 26
Download presentation
Decision Maths Dijkstra’s Algorithm

Decision Maths Dijkstra’s Algorithm

Networks Wiltshire n Maps are examples of a real life networks. n In the

Networks Wiltshire n Maps are examples of a real life networks. n In the map below each town is a vertex (node) and each road is an edge (arc).

Networks Wiltshire n In real life we often want to know what is the

Networks Wiltshire n In real life we often want to know what is the shortest path between two places. n In the past you used to look on a map and plan the route yourself. n These days there are websites that will do this for you. n http: //www. theaa. com/travelwatch/planner_main. jsp n The computer cannot decide which route is the best, so it uses an algorithm to do so. n One such Algorithm is Dijkstra`s.

Dijkstra`s Algorithm. Wiltshire n Throughout this algorithm you will be required to fill in

Dijkstra`s Algorithm. Wiltshire n Throughout this algorithm you will be required to fill in the grid below. n It is important that you have a key in your work so that the examiner will understand your workings.

Dijkstra`s Algorithm Wiltshire n Consider the network below. We are going to apply an

Dijkstra`s Algorithm Wiltshire n Consider the network below. We are going to apply an algorithm to find the shortest route from S to T. n The solution to this should be obvious but it is important to learn the algorithm so we can apply it in more complex situations. n As you work through the algorithm try to understand why it works.

Dijkstra`s Algorithm n Give the start node a permanent label of 0. n The

Dijkstra`s Algorithm n Give the start node a permanent label of 0. n The “ 1” indicates that this is the first node to receive a permanent label. Wiltshire

Dijkstra`s Algorithm Wiltshire n Look at all the nodes which can be reached from

Dijkstra`s Algorithm Wiltshire n Look at all the nodes which can be reached from the start node in one edge. n That’s A, D and F. n Give them a temporary label of their distance from the start node.

Dijkstra`s Algorithm Wiltshire n Make the lowest temporary node permanent. n This is node

Dijkstra`s Algorithm Wiltshire n Make the lowest temporary node permanent. n This is node A in this case. n If there had been more than one, then you could choose any.

Dijkstra`s Algorithm Wiltshire n Node A has just received the permanent label “ 3”.

Dijkstra`s Algorithm Wiltshire n Node A has just received the permanent label “ 3”. Look at all the nodes you can reach from A without a permanent label. n Give such nodes a temporary label of 3 + their distance from A.

Dijkstra`s Algorithm n Make the lowest temporary node permanent. n This is node D

Dijkstra`s Algorithm n Make the lowest temporary node permanent. n This is node D in this case. Wiltshire

Dijkstra`s Algorithm Wiltshire n Repeat step 4, only this time with node D. n

Dijkstra`s Algorithm Wiltshire n Repeat step 4, only this time with node D. n Label all nodes from D with temporary label (4 + distance) from D. n If a node has a temporary label, replace it, if (4 + distance) is less than the temporary label.

Dijkstra`s Algorithm Wiltshire n Make the lowest temporary node permanent. n F now gets

Dijkstra`s Algorithm Wiltshire n Make the lowest temporary node permanent. n F now gets a permanent label. n Node G already has a temporary label which does not change.

Dijkstra`s Algorithm Wiltshire n Both B and E have the same temporary label. n

Dijkstra`s Algorithm Wiltshire n Both B and E have the same temporary label. n It makes no difference which we pick, so B is selected. n B is the 5 th permanent label. C needs a temporary label.

Dijkstra`s Algorithm Wiltshire n E gets a permanent label, as it has the lowest

Dijkstra`s Algorithm Wiltshire n E gets a permanent label, as it has the lowest temporary label. n C`s temporary label must change to 9 as you can go S, D, E, C which has length 4 + 3 + 2 = 9 as this is less than the existing label. n T is given a temporary label of 11.

Dijkstra`s Algorithm Wiltshire n Again there are two vertices that can be assigned a

Dijkstra`s Algorithm Wiltshire n Again there are two vertices that can be assigned a permanent label. G is chosen. n No adjustments need to be made.

Dijkstra`s Algorithm Wiltshire n C is assigned a permanent label. n T`s temporary label

Dijkstra`s Algorithm Wiltshire n C is assigned a permanent label. n T`s temporary label can be adjusted as 4 + 3 + 2 + 1 = 10.

Dijkstra`s Algorithm Wiltshire n T now gets a permanent label of 10. n This

Dijkstra`s Algorithm Wiltshire n T now gets a permanent label of 10. n This tells us that the shortest route from S to T has a length 10.

Dijkstra`s Algorithm Wiltshire n The shortest path will be marked with a red line.

Dijkstra`s Algorithm Wiltshire n The shortest path will be marked with a red line. n To find it you work backwards from T to S identifying whose length is the same as the difference between the permanent labels at either end.

Dijkstra`s Algorithm Wiltshire n The weights on the arcs can represent different things that

Dijkstra`s Algorithm Wiltshire n The weights on the arcs can represent different things that might lead to alternate routes. n Example – They could change to represent the time taken to travel a stretch of road rather than distance.

Dijkstra`s Algorithm Wiltshire n Can you explain how the Algorithm works? n What do

Dijkstra`s Algorithm Wiltshire n Can you explain how the Algorithm works? n What do the temporary and permanent labels mean? n They are values for the quickest route to that particular node.

Dijkstra`s Algorithm Wiltshire n Why do we assign temporary labels? n The algorithm systematically

Dijkstra`s Algorithm Wiltshire n Why do we assign temporary labels? n The algorithm systematically searches for the quickest route to every node. We assign a temporary label as that stands for the current quickest route to that node. Later in the algorithm an alternative route may be found so we replace the temporary label with a new temporary label.

Dijkstra`s Algorithm Wiltshire n Why do we make the node with the lowest temporary

Dijkstra`s Algorithm Wiltshire n Why do we make the node with the lowest temporary label permanent? n All routes up to a certain point have been covered, so the node with the lowest temporary label must be the next nearest node to the start point.

Dijkstra`s Algorithm Wiltshire n What happens after this? n You are certain that there

Dijkstra`s Algorithm Wiltshire n What happens after this? n You are certain that there is no shorter way of reaching the node you are currently at. So you can assign neighbouring nodes a temporary label. n Why does the first node get assigned permanent label zero? n It is the start point , you have not travelled anywhere.

Dijkstra`s Algorithm Wiltshire n Why does the method for finding the route at the

Dijkstra`s Algorithm Wiltshire n Why does the method for finding the route at the end work? n At the end of the algorithm each node has a permanent label that represents the shortest distance to that node. If two nodes are joined then the difference in their permanent labels will tell you the shortest distance between them. If the arc joining them matches this distance then it must be the quickest route.

Ex 3 d q 1 i – Shortest route from S to T 7

Ex 3 d q 1 i – Shortest route from S to T 7 Wiltshire 6 7 9 7 2 2 2 0 9 1 4 10 8 10 4 15 10 4 6 15 3 3 3 6 5 6 10 9 10

Ex 3 d q 1 i Wiltshire 7 6 7 9 7 2 2

Ex 3 d q 1 i Wiltshire 7 6 7 9 7 2 2 2 0 9 1 4 10 8 10 4 15 10 4 6 15 3 3 3 6 5 6 10 9 10