Upload
rosalind-watkins
View
216
Download
2
Embed Size (px)
Citation preview
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice?
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice?
If we can find a path that goes over all the edges of the graph without repeating an edge then the graph is said to be traversable.
If we can find a path that goes over all the edges of the graph without repeating an edge then the graph is said to be traversable.
If we introduce a vertex where two lines meet and make the lines edges, then we can model these problems as graphs.
If we introduce a vertex where two lines meet and make the lines edges, then we can model these problems as graphs.
Route Inspection
Whether or not a graph is traversable depends on the number of edges that meet at the vertices. The number of edges that meet at a vertex is called the degree of that vertex.
Whether or not a graph is traversable depends on the number of edges that meet at the vertices. The number of edges that meet at a vertex is called the degree of that vertex.
Degree 2Degree 2Degree 3Degree 3 Degree 2Degree 2
Degree 3Degree 3
An odd vertex is one with an odd degree.
An even vertex is one with an even degree.
An odd vertex is one with an odd degree.
An even vertex is one with an even degree.
EvenEven
OddOdd
OddOdd EvenEven
Route Inspection
A graph with only even vertices is traversable and we can start and finish at the same vertex. Such a graph is called Eulerian.
A graph with only even vertices is traversable and we can start and finish at the same vertex. Such a graph is called Eulerian.
All vertices even – Eulerian graph.
All vertices even – Eulerian graph.
Route Inspection
All vertices even – Eulerian graph.
All vertices even – Eulerian graph.
A graph with exactly 2 odd vertices is traversable as long as we start on one of the odd vertices and finish at the other one. Such a graph is called Semi-Eulerian.
A graph with exactly 2 odd vertices is traversable as long as we start on one of the odd vertices and finish at the other one. Such a graph is called Semi-Eulerian.
2 odd vertices –
Semi-Eulerian
2 odd vertices –
Semi-Eulerian
Route Inspection
All vertices even – Eulerian graph.
All vertices even – Eulerian graph.
A graph with more than two odd vertices is not traversable.A graph with more than two odd vertices is not traversable.
2 odd vertices –
Semi-Eulerian
2 odd vertices –
Semi-Eulerian
4 odd vertices –
not traversable
4 odd vertices –
not traversable
Route Inspection
All vertices even – Eulerian graph.
All vertices even – Eulerian graph.
Which type of graph is the one on the far right?Which type of graph is the one on the far right?
2 odd vertices –
Semi-Eulerian
2 odd vertices –
Semi-Eulerian
4 odd vertices –
not traversable
4 odd vertices –
not traversable
Two odd vertices
- Semi-Eulerian
Two odd vertices
- Semi-Eulerian
Route Inspection
The Chinese postman algorithm
Step 4 Find an Eulerian trail.
Step 1 Find all the odd vertices in the network.
Step 2 Consider all the routes joining pairs of odd vertices. Choose the routes with the shortest total distance.
Step 3 Add in these edges again.This will give a network with only even vertices.
Consider now a network with weights associated with the edges. The route inspection problem is to find a path through the network that includes every edge at least once and has the minimum total weight.
Consider now a network with weights associated with the edges. The route inspection problem is to find a path through the network that includes every edge at least once and has the minimum total weight.
Postman Pat has to deliver along each of the roads in the network below. What is his minimum total distance?
Postman Pat has to deliver along each of the roads in the network below. What is his minimum total distance?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 6
Route Inspection
G
B
C
E
D
F
A
All the vertices are even – the network is Eulerian – so any route that traverses the graph will suffice.
All the vertices are even – the network is Eulerian – so any route that traverses the graph will suffice.
5
7
8
34
2
6
5
7
3
4 6
An example of one such path out of the many is:
AEBCDFEDBGCFA
An example of one such path out of the many is:
AEBCDFEDBGCFA
The minimum total distance is just the sum of the edges.
7 + 6 + 6 + 3 + 8 + 3 + 2 + 5 + 4 + 7 + 4 + 5 = 60
The minimum total distance is just the sum of the edges.
7 + 6 + 6 + 3 + 8 + 3 + 2 + 5 + 4 + 7 + 4 + 5 = 60
Route Inspection
G
B
C
E
D
F
A
Another road is added to Pat’s round.Another road is added to Pat’s round.
5
7
8
34
2
6
5
7
3
4 612
There are now 2 odd nodes, A and D, so the graph is Semi-Eulerian. The graph is still traversable if we start at one of the odd nodes and finish at the other one.
There are now 2 odd nodes, A and D, so the graph is Semi-Eulerian. The graph is still traversable if we start at one of the odd nodes and finish at the other one.
Route Inspection
What if Pat needs to start and finish at the same place?What if Pat needs to start and finish at the same place?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
To start and finish at A he will need to get back from D to A at the end. What is the shortest way of doing this?
To start and finish at A he will need to get back from D to A at the end. What is the shortest way of doing this?
We could use Dijkstra’s shortest path algorithm for this but for this small example we can see it is along DEA, adding 10 to the total length.
We could use Dijkstra’s shortest path algorithm for this but for this small example we can see it is along DEA, adding 10 to the total length.
Route Inspection
G
B
C
E
D
F
A
So by repeating the edges DE and EA we can start at A, cover every street and get back to A.
The total distance = sum of all the edges + repeated edges
= 72 + (3 + 7)
= 82
So by repeating the edges DE and EA we can start at A, cover every street and get back to A.
The total distance = sum of all the edges + repeated edges
= 72 + (3 + 7)
= 82
5
7
8
34
2
6
5
7
3
4 612
One of the many alternative routes that give this total is:
AEBGCFEDBCDFGDEA
One of the many alternative routes that give this total is:
AEBGCFEDBCDFGDEA
Route Inspection
Suppose now another road is added, FG.
We now have four odd vertices A, D, F and G.
We have to consider all the ways of pairing up these four vertices.
Suppose now another road is added, FG.
We now have four odd vertices A, D, F and G.
We have to consider all the ways of pairing up these four vertices.
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
Route Inspection
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
Route Inspection
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A
G – A and D – F
Which of these pairings adds the least amount of extra distance?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F
Which of these pairings adds the least amount of extra distance?
Route Inspection
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F
Which of these pairings adds the least amount of extra distance?
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F = (6 + 6) + 5 = 17
Which of these pairings adds the least amount of extra distance?
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F = (6 + 6) + 5 = 17
Which of these pairings adds the least amount of extra distance?
Route Inspection
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F = (6 + 6) + 5 = 17
The middle pairing adds the least amount of extra distance.
To complete his rounds and finish at the place he started, he will have to repeat one of the following pairs of paths
G – F and D – A = 6 + (7 + 3) = 16
G – D and F – A = (5 + 4) + 6 = 15
G – A and D – F = (6 + 6) + 5 = 17
The middle pairing adds the least amount of extra distance.
Route Inspection
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
G – D and F – A = (5 + 4) + 6 = 15
The total distance = sum of all the edges + repeated edges
= 78 + 15
= 93
We can make it easier to find a route by drawing in extra edges on the repeated route.
G – D and F – A = (5 + 4) + 6 = 15
The total distance = sum of all the edges + repeated edges
= 78 + 15
= 93
We can make it easier to find a route by drawing in extra edges on the repeated route.
Route Inspection
G
B
C
E
D
F
A
5
7
8
34
2
6
5
7
3
4 612
6
An example route is:
AFCDFEGDEBDBGBCGFA, total length 93.
An example route is:
AFCDFEGDEBDBGBCGFA, total length 93.
Route Inspection
SummarySummary
Graph Odd vertices
Repeated edges
0 None
2 The shortest path joining the two odd vertices
4 Try all possible pairings of the odd vertices and choose the smallest combination.
Route Inspection