Sunday 11 September 2011

The Travelling Salesperson Algorithm

Find a cycle that goes through each vertex using the Nearest Neighbour Algorithm.

Find the lower bound by using the Lower Bound Algorithm.

The weight of the optimum route is: Lower bound ≤ Weight of optimum route ≤ Upper bound

Upper Bound Algorithm (Nearest Neighbour Algorithm)

Choose a starting vertex unless assigned one.

Choose the nearest unused vertex.

Continue until all vertices are visited and return to starting vertex.

Start at A















Total weight = 24

Start at B















Total weight = 20

Start at C















Total weight = 23
Start at D















Total weight = 20

Start at E















Total weight = 23

Lowest upper bound = 20


Lower Bound Algorithm

Choose a vertex unless assigned one.

Find the two lowest weight edges joined to that vertex and note them.

Delete that vertex and all the edges joined to it.

Find the minimum spanning tree for the rest of the network.

Add the minimum spanning trees value to the noted edges to get the total weight.

Delete A















Delete B















Delete C















Delete D















Delete E















Highest lower bound = 18

18 ≤ Weight of Optimum Route ≤ 20

© 2011 Grant Dwyer

Monday 5 September 2011

Dijkstra's Algorithm


Give the start vertex the permanent label ‘0’.

Find all vertices directly connected to the vertex you have just given a permanent label to.

Give each of these the temporary label.

Temporary label = Permanent label of previous vertex + Weight of arc joining them

If temporary label is already occupied, replace it only if the new value is lower.

The temporary label without a permanent label which has the lowest value is the next permanent label.

Repeat until end vertex has a permanent label.

Find route from start vertex to end vertex.

Order of becoming permanent
Permanent label
Temporary Labels













ABCG is the shortest path.

©2011 Grant Dwyer

Sunday 28 August 2011

Pseudo-Codes and Flow Charts


Pseudo-Code

STEP 1: Input X = 1 and Y = 2

STEP 2: Print X

STEP 3: Let X = X + Y

STEP 4: Let Y = Y + 1

STEP 5: If Y < 11, then return to Step 2

STEP 6: Stop

X
Y
PRINT
1
2
1
3
3
3
6
4
6
10
5
10
15
6
15
21
7
21
28
8
28
36
9
36
45
10
45
55
11
55
66
12


Flow Chart

















n
b
Output
n = a
1
10
1
No
2
5
2
No
3
10/3
-
No
4
5/2
-
No
5
2
5
No
6
5/3
-
No
7
10/7
-
No
8
5/4
-
No
9
10/9
-
No
10
1
10
Yes

This shows the multiples of 10.

A specific function can be used to make the algorithm terminate.

©2011 Grant Dwyer

Monday 22 August 2011

Kruskal's Algorithm


List arcs in ascending order of weight.

Pick the arc of least weight.

If the next arc forms a cycle don’t use it, if it doesn’t use it.

Continue until all vertices are joined.












Arc
Weight
Used
DF
1
Yes
DC
1
Yes
DG
2
Yes
CF
2
No
EG
2
Yes
FG
3
No
DE
3
No
AC
3
Yes
BE
3
Yes
AB
4
No
BD
4
No
AD
5
No













Weight = 12

©2011 Grant Dwyer