d1 shortest path - 2July

advertisement
Decision Maths 1
Shortest path algorithm
Dijkstra’s Algorithm
A V Ali : www.2july-maths.co.uk
Dijkstra’s algorithm used to find the shortest path
through a network.
Set up 1 : Decide on a Start Node and End Node.
Set up 2 : Add a recording box to each node in the network – use the
following format to help keep track of each choice :
Box 3
Box 2
Box 1
Box 1 : Route length to this node
Box 2 : Shortest Route
Box 3 : Node order
Step 1 : For first node label Box 1, 2 and 3 all 0.
Step 2 : Each node has Box 1 labeled as the shortest distance to this
node from the start so far.
Step 3 : Go from each node labeled so far, and replace Box 1 value if a
new shortest path from the start is found.
Step 4 : Repeat 3, for all nodes in the network. Label Box 2 when you
have checked the shortest path has been found. Label Box 3 with
the node order number through the path.
Find the shortest
path from A to G
0
1
3
3
2
5
5
Step 1 : For first node
Box 1,
2 and
Steplabel
2 : Each
node
has3
all 0.1 labeled as the
Box
shortest distance to
this node from the
start so far.
3
6
8 7 6
0
6
19 18 17
0
Step 4 : Repeat 3, for
all nodes in the
Stepnetwork.
3 : Go from
each
Label
Box
node
labeled
so
2 when you havefar,
and
replace
checked
the Box 1
value
if apath
newhas
shortest
shortest
pathLabel
from
been found.
the
is the
found.
Boxstart
3 with
node
order number
through the path.
17
4
12 9
9
5
15
14
14
Shortest route
from A to G = 17
Download