decision maths dijkstra’s algorithm. wiltshire networks maps are examples of a real life networks....

26
Decision Maths Dijkstra’s Algorithm

Upload: armani-greenslade

Post on 01-Apr-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

Decision Maths

Dijkstra’s Algorithm

Page 2: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireNetworks

Maps are examples of a real life networks. In the map below each town is a vertex (node) and

each road is an edge (arc).

Page 3: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireNetworks

In real life we often want to know what is the shortest path between two places.

In the past you used to look on a map and plan the route yourself.

These days there are websites that will do this for you.

http://www.theaa.com/travelwatch/planner_main.jsp The computer cannot decide which route is the best,

so it uses an algorithm to do so. One such Algorithm is Dijkstra`s.

Page 4: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm.

Throughout this algorithm you will be required to fill in the grid below.

It is important that you have a key in your work so that the examiner will understand your workings.

Page 5: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Consider the network below. We are going to apply an algorithm to find the shortest route from S to T.

The solution to this should be obvious but it is important to learn the algorithm so we can apply it in more complex situations.

As you work through the algorithm try to understand why it works.

Page 6: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Give the start node a permanent label of 0. The “1” indicates that this is the first node to receive a

permanent label.

Page 7: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Look at all the nodes which can be reached from the start node in one edge.

That’s A, D and F. Give them a temporary label of their distance from the start node.

Page 8: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

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

Page 9: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Node A has just received the permanent label “3”. Look at all the nodes you can reach from A without a permanent label.

Give such nodes a temporary label of 3 + their distance from A.

Page 10: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Make the lowest temporary node permanent. This is node D in this case.

Page 11: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

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

the temporary label.

Page 12: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Make the lowest temporary node permanent. F now gets a permanent label. Node G already has a temporary label which does not change.

Page 13: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

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

Page 14: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

E gets a permanent label, as it has the lowest temporary label. 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. T is given a temporary label of 11.

Page 15: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Again there are two vertices that can be assigned a permanent label. G is chosen.

No adjustments need to be made.

Page 16: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

C is assigned a permanent label. T`s temporary label can be adjusted as 4 + 3 + 2 + 1

= 10.

Page 17: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

T now gets a permanent label of 10. This tells us that the shortest route from S to T has a

length 10.

Page 18: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

The shortest path will be marked with a red line. 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.

Page 19: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

The weights on the arcs can represent different things that might lead to alternate routes.

Example – They could change to represent the time taken to travel a stretch of road rather than

distance.

Page 20: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

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

Page 21: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Why do we assign temporary labels? 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.

Page 22: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Why do we make the node with the lowest temporary label permanent?

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.

Page 23: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

What happens after this? 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.

Why does the first node get assigned permanent label zero? It is the start point , you have not travelled anywhere.

Page 24: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireDijkstra`s Algorithm

Why does the method for finding the route at the end work? 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.

Page 25: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

Wiltshire

Ex 3d q1i – Shortest route from S to T

0 1

2 22

7 6

79 7

4 4

6

10 8

1015

15

333

6 5

6

10 910

410

9

Page 26: Decision Maths Dijkstra’s Algorithm. Wiltshire Networks Maps are examples of a real life networks. In the map below each town is a vertex (node) and each

WiltshireEx 3d q1i

0 1

2 22

7 6

79 7

4 4

6

10 8

1015

15

333

6 5

6

10 910

410

9