Académique Documents
Professionnel Documents
Culture Documents
Graph theory
Route problems
In this thesis we will review some route problems which are a part of graph theory problems.
In more details it will contain the basic of graph theory, some well-known algorithms related
to route problems, and different route problems solved by these algorithms.
Contents
1. INTRODUCTION .............................................................................................................................................4
2. BASIC GRAPH THEORY ...............................................................................................................................5
2.1 DEFINITION AND GRAPH REPRESENTATION ....................................................................................................5
2.2 MORE DEFINITIONS ........................................................................................................................................6
2.3 IMPORTANT THEOREM IN THIS ARTICLE .........................................................................................................7
3. MINIMUM SPANNING TREE .......................................................................................................................8
3.1 RELATED ALGORITHMS TO MINIMUM SPANNING TREE ...................................................................................8
3.2 MINIMUM SPANNING TREE APPLICATIONS ....................................................................................................11
4. SHORTEST PATH PROBLEM.....................................................................................................................13
4.1 DIJKSTRA´S ALGORITHM ..............................................................................................................................13
4.2 EXAMPLE .....................................................................................................................................................13
5. CHINESE POSTMAN PROBLEM ...............................................................................................................16
5.1 FLEURY´S ALGORITHM .................................................................................................................................16
5.2 EXAMPLE OF CHINESE POSTMAN PROBLEM ..................................................................................................17
6. THE TRAVELLING SALESMAN PROBLEM (TSP)................................................................................20
6.1 HARDNESS OF HAMILTON CIRCUIT ..............................................................................................................20
6.2 THE CLOSEST INSERTION ALGORITHM ..........................................................................................................20
6.3 PROGRESS ON TSP METHOD.........................................................................................................................22
6.4 SWEDEN TOUR .............................................................................................................................................22
7. SUMMARY......................................................................................................................................................23
8. REFERENCES ................................................................................................................................................24
1. Introduction
People in Königsberg city (now Kaliningrad, Russia) tried to devise a route around the city
which would cross each of seven bridges just once. Since their attempts had always failed,
many of them believed that the task was impossible, but it was not until 1736 when one of the
leading mathematicians of the time, Leonhard Euler, proved it. He wrote an article in which
he not only dealt with this particular problem, but also gave a general method for other
problems of the same type. This problem allowed a foundation of graph theory. Since then, it
has developed with Euler and other mathematicians and it’s still a dynamic part of discrete
mathematic. Graph theory has a surprising number of applications: in physics, biology,
chemistry, social, commerce, and computer science. In this article I will treat the route
problems. First we take a look at some basic of graph theory, and then we will discuss
minimum spanning trees. Finally we will deal with shortest path problems and different
circuits in route problem.
2. Basic graph theory
Definition: A graph G = (V, E) means a pair (V, E) consisting of a finite non- empty set V of
vertices (called also points, nodes, or just dots), and a finite set E of edges, where some pair
of vertices is connected by one or more edges.
Example: Here we have a graph G1 with vertices V = {a, b, c, d, e, f} and the edges
E = {e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12}
e11
e8
a f e7
e1
e10 e12
b e2 e9 e5 e
e3 c d e6
e4
A graph can be represented as diagram or as matrix but in this article it will be only diagram
representation. There are three different kinds of graphs:
• An undirected graph is a graph in which any paths in the graph have no specific
direction.
Example: The following graph is undirected. Let be denoted G2.
b c
• A directed graph is a graph which any path in the graph have a specific direction.
Example: The below graph is directed and we name it G3.
b c
• A mixed graph is a graph which combines both undirected and directed properties.
Here coming an example of mixed graph G4.
a c
b d
Definition: Two vertices (v1, v2) are adjacent (neighbours) if they are joined by the same edge
e1 and the edge e1 is said to be incident with the vertices (v1, v2).
If we take graph G1 as example the vertex a in graph G1 is neighbour of four vertices
(b, c, d, f) and b is only neighbour of two vertices (a, c).
Definition: The degree of a vertex is the number of edges that are incident with this vertex.
For example vertex a in graph G1 has degree four and b has degree three.
Definition: Parallel edges are two or more different edges which join the same pair of
vertices. Example: In the Graph G1 only two pair edges are parallel: (e2, e3) and (e5, e6).
Definition: A simple graph is a graph which contains no loops and no parallel edges.
Definition: A weighted graph is a graph which every edge in the graph is represented by a
number called its weight.
Definition: A circuit (cycle or tour) is a path in which the start and end vertex is the same. In
graph G1 e1e8e7e6e4e2e1 is a circuit.
Definition: An Euler circuit is a circuit which contains every edge of the given graph once
and only once.
Definition: A Hamilton circuit is circuit which all vertices in graph occur once and only once.
Definition: A complete graph is a simple undirected graph which all different pair of its
vertices is joined by an edge.
b d
Definition: A connected graph is a graph in which any pair of vertices in the graph can be
bounded by one or more edges.
All previous example graphs are connected.
Definition: A bridge edge in graph is an edge such that if we deleted it then the graph would
not be connected anymore.
Example: all edges for any tree are bridges.
Definition: A sub-graph of a graph G = (V, E), is a graph G´= (V´, E´) where V´ and E´ are
subset of V and E respectively.
For example the following graphs are a sub-graph of G2.
a b c b
The Handshaking theorem: For any graph G = (V, E): ∑ deg (v) = 2 e where “deg” means
vertex degree.
Proof: Let v1 and v2 be adjacent vertices in graph join by an edge e1, deg (v1) = deg (v2) = 1
and deg (v1) + deg (v2) = 2 e1. This is not an exception for v1 and v2 but it works for every pair
adjacent vertices in the graph. This means that ∑ deg (v) = 2 e.
Euler theorem: A connected graph G is Euler if and only if the degree of every vertex is even.
Proof: Let G = (V, E) be a graph with only even vertices degree. Choose any start vertex v1
and trace out a path arbitrarily such that every edge in graph must be chosen once and only
once. Since even-vertex degree condition assures that each vertex arrived at can be left, the
path must be inevitable finish to v1. So it is clear that the circuit is Euler.
3. Minimum spanning tree
In this part we take a look just two famous algorithms: Kruskal´s algorithm and Prim’s
algorithm. These two algorithms help to find a minimum spanning tree. We start with
Kruskal´s algorithm. Kruskal´s algorithm builds a minimum spanning tree by adding smallest
edges by ascending of its weight.
Method:
1 Select the edges ei of G which have smallest weight among the edges of G. ei does not
form a loop and cycle.
2 Add the other edges ej by ascending of its weight. The edges ej must satisfy follow
conditions:
Prim’s algorithm builds a minimum spanning tree by add one edge at the time.
Method:
1. Choose any vertex v1 of the graph G and let v1 be the start vertex.
2. Select vertex v2 of G neighbour with v1 such that v1 and v2 join by an edge with the
smallest weight (If many vertices neighbour have edges with same weight, select just
one at random).
3. First choose vertices of G neighbour with vertices which form path solution {v1, v2},
select one vertex v3 which is close as possible to the path solution. The vertex v3 have
not already been chosen in solution. Add the other vertices with the same procedure.
4. If G has n number of vertices, stop after n-1 edges have been chosen.
Example: Find the minimum spanning tree for the following graph:
2
b d
1 3
6
a 1 4
2
c e
5
Kruskal´s algorithm Prim’s algorithm
1. Choose edges with the smallest weight and 1. Choose any start point in figure, let a be
these edges don’t form a cycle. In given the start point. Vs = {a}
figure are ab and bc = 1. So Es = {ab, bc}
2
b d
1 3
a 1 6
4
2
c e
5
2. Add other edges with smallest weight 2. We select the nearest vertex to Vs = {a}, in
which are not Es in and not form a cycle. The graph the nearest vertex is b. So {ab} become
edge ac form a cycle, we can not choose it. So our tree solution.
we select only bd = 2. {ab, bc, bd} become
new tree solution
2 2
b d
b d 1 3
1 3 6
1 6 a 1 4
a 4 2
2
c e
c e 5
5
3. Add other edges with the same procedure 3. We add a vertex with the same procedure in
in point 2. We get be = 3 so point 2. Then we have {ab, bc} like our new
Es = {ab, bc, b d, be } tree solution.
2
2
b d
1 3 b d
1 6 1 3
a 4 1 6
2 a 4
2
c e
5 c e
5
4. We stop for the number of edges is equal 4. We follow the same procedure and we get
to 5 -1 = 4 (where 5 are total number of the following tree solution {ab, bc, bd}
vertices).
So {ab, bc, bd, be} is tree solution that we
have been looking for.
2 2
b d b d
1 1 3
3 a 1 6
1 4
a 2
e c e
c 5
2
b d
1
3
a 1
c e
3.2 Minimum spanning tree applications
A chef of Communication Company wants to install his company in the Småland province.
The problem is to connect all cities in the province. They wish that the distance of cities
connection will be as short as possible, in order to decrease budget material. They need to
know also how long distance between the cities is in totally in order to buy necessary
materials. This problem will be solved by graph theory. First we draw a graph between all the
cities.
Then we apply a specific algorithm to connect all cities in the province. We choose Kruskal´s
algorithm and get the following solution.
And distance is equal to 1134 km, Problem solved.
4. Shortest path problem
Short path problems consist to determine a minimum weight path between two or more
specified vertices. For example we use short path problems to find a shortest route between
two or more specified cities. We take a look for one algorithm which relates to shortest path
problems. This famous algorithm is called Dijkstra´s algorithm.
For any positive weighted graph, Dijkstra´s algorithm allows us to find a shortest path
between two or more specified vertices. This algorithm works for undirected, directed, and
mixed graphs.
Method:
Let L be a weight of a shortest path in solution from given start vertex, M a weight of edge
between the end vertex of L to its neighbour vertices in graph, and K = L + M.
1. Start with a and K (a) = 0, other vertices in graph are undermined and we label them
∞.
2. Choose all vertices u neighbour to a and K (u) = L (a) + M (a, u) and note their
weight. Now vertex a has been visited.
3. Visit other vertices of graph with the same procedure in 2. If any vertex has 2 or more
K select K with minimum weight.
4. If n-1 vertices have been visited stop (where n is a number of vertices).
4.2 Example
Use Dijkstra´s algorithm to find the shortest path from vertex b to vertex i of the following
graph.
a
1 1
2
2 1 3
b d f i
3 2 1
1 5 2
1 2
c e g
We start with L (b) = 0, other vertices are undetermined and we label ∞.
Vertices b a c d e f g i
v
K (v ) 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞
Vertices b a c d e f g i
(v )
K (v ) 0 1 1 2 3 ∞ ∞ ∞
Now we have 2 unvisited vertices a and c with shortest path L (a) = L (c) = 1. Now we will
visit a and b:
There are 2 unvisited vertices d and f neighbor to vertex a.
K (d) = L (a) +M (a, d) = 1 + 2 = 3
K (f) = L (a) +M (a, f) = 1 + 1 = 2
2. There is only one unvisited vertex e neighbor to vertex c.
K (e) = L (c) +M (c, e) = 1 + 1 = 2 < 3, we decrease 3 to 2.
Vertices a and c have been visited.
Vertices b a c d e f g i
(v )
K (v ) 0 1 1 2 2 2 ∞ ∞
We got 3 unvisited vertices d and e with shortest path L (d) = L (e) = L (f ) = 2 and will visit
it.
We start with vertex d, there are 2 unvisited vertices e and f neighbor to vertex d.
K (e) = L (d) + M (d, e) = 2 + 2 = 4 > 2 we remain 2
K (f) = L (d) + M (d, f) = 2 + 1 = 3 > 2 we remain 2
Now we have left just one unvisited vertex g and L (g) = 4.There is only one unvisited vertex
i neighbor to vertex g.
K (i) = L (g) + M (g, i) = 4 + 2 = 6 > 5 we remain 5. Now we visited all vertices of graph and
our path solution is following:
a
1 1
2
2 1 3
b d f i
3 2 1
1 5 2
1 2
c e g
5. Chinese postman problem
In 1962 a Chinese mathematician Kuan published for any given zone a way to turn once and
only once all street from a given start place and come back to this place. It is clear that Euler
circuit is involved where the cities are vertices and the streets are the edges. If any given
graph is not Euler, there is always a possibility to duplicate vertices with odd degree in order
to get an Euler graph. The terms duplicate means to add a parallel edge with the same weight
to any given pair vertices of graph. In order to get a short Euler circuit as possible we have to
find a minimal path and duplicate it. It is clear that when we duplicate we need Dijkstra´s
algorithm in order to find a minimal path. To find an Euler circuit for any given graph we
may use a famous algorithm which is called Fleury´s algorithm. Let just take a look for this
algorithm.
a
1 1
2
2 1 3
b d f i
3 2 1
1 5 2
1 2
c e g
First we check if this graph is Euler. We see that the edges a, f, e, and g have odd degree;
according to theorem the given graph is not an Euler graph. We have to duplicate these edges
which have odd degree. With help of Dijkstra´s algorithm, we duplicate the edge (a, f) and the
(e, g) in order to find a short circuit as possible. We get the following graph:
a
1
1 2
1
2 3
b d 1 f i
1 3 2 5 2
1
1 2
c e 2 g
Now it is time to choose any start vertex. Let the vertex b be a start and end vertex. With
Fleury´s algorithm we find the following Euler circuit: bafigefgecbedfadb.
a
1
1 2
1
2 3
b d 1 f i
1 3 2 1 5 2
2
1
c e 2 g
The chefs in Småland made a decision to renovate all streets which connect Småland cities. It
is clear that they need to know from their officer how they will travel around all streets once
and back to officer. Here graph theory applies to find a short circuit as possible. We take
previous example. The following cities have odd degree: Växjö, Lessebo, Torsas, Mönsterås,
Sävsjö, Vetlanda, Hultsfred, Vimmerby, Eksjö, Nässjö, Vaggeryd, and Gnosjö. We need
Dijkstra´s algorithm for duplicate a short path as possible in order to find a shortest ciruit. I
get the following result:
Take Jönköping as start end city of our searching circuit. With help of Fleury´s algorithm we
get the following circuit solution:
The edges are labelled in the order in what they are traversed during the trip.
6. The travelling salesman problem (TSP)
TSP is based on Hamilton circuits. Given any start city the objective of TPS is to visit all
cities once and only once and then return back to the start city and the circuit has to be
minimal as possible. To find the shortest Hamilton circuit is lot more complicated than it may
appear.
Firstly there is no theorem which shows us that a given graph has a Hamilton circuit.
Secondly no algorithms guarantee that found Hamilton circuit is optimal. Finally it takes
quite a long time to find a Hamilton circuit. For example if a graph is complete with n number
of vertices, we have (n - 1)! / 2 number of different possible circuit. The following table
shows how much time the computers take to find a Hamilton circuit [3]:
One algorithm which can led us to find an almost optimal Hamilton circuit is called insertion
algorithm.
a
2 4
5 3
e 6 b
5 6
9 7
d c
4
We choose a = v1 as the start vertex.
The closest vertex to a is vertex e = v2.
The next vertex closest to circuit solution is vertex c = v3. Now we have the circuit aeca.
We have here vertex b = v4 closest to circuit aeca. Now we have the following different
circuits:
• v1v2v3v4v1 = aecba has length 2 + 7 + 6 + 4 = 19
• v1v2 v4v3v1 = aebca has length 2 + 6 + 6 + 3 = 17
• v1v4v2v3v1 = abeca has length 4 + 6 + 7 + 3 = 20
The circuit aebca is smallest and the vertex d = v5 is closest to the circuit. We have the
following different circuits:
• v1v2v3v4v5 v1 = aebcda has length 2 + 6 + 6 + 4 + 5 = 23
• v1v2v3v5v4 v1 = aebdca has length 2 + 6 + 9 + 4 + 3 = 24
• v1v2v5v3v4 v1 = aedbca has length 2 + 5 + 9 + 6 + 3 = 25
• v1v5v2v3v4 v1 = adebca has length 5 + 5 + 6 + 6 + 3 = 25
So our optimal Hamilton circuit is aebcda:
a
2
5 6
e b
6
d 4 c
The algorithm gives us the circuit solution aebcda = 23 as an optimal Hamilton circuit but it
miss for example the circuit abcdea = 21 which is smaller than the algorithm circuits solution.
6.3 Progress on TSP method
Nevertheless a great progress has been done despite TSP hardness. Research allowed some
effective method which can solve problem with several cities. These methods are following
[3]:
• Meta-heuristics that can obtain upper bounds within 0.01% of optimal even when
n = 1,000,000. This method solved 42- city problem in USA 1954 (
• Cutting-plane methods that can obtain lower bounds within
0.1% of optimal for n up to 100,000 or so. This method and the next both solved the
Sweden tour in 2004, see section 6.4 below
• Branch-and-cut methods that can solve instances with n up to 10.000 to proven
optimality.
The Sweden tour is 24.978 -cities problem which was solved in May 2004 by the following
Research Team:
This tour is approximately 72.500 km long and it took one year and two months to find the
solution. They used branch- and-cut and cutting-planes method to solve this problem. The
circuit has been broken in 100 legs. Let us see some legs of the tour [4]:
3 Uppsala to Sigtuna 41 87
In this article we have seen how many algorithm works. Some algorithms yield the same
result but their procedures to obtain the solution are different. In this case we have for
example Prim’s algorithm and Kruskal´s algorithm. The big difference is that for Prim’s
algorithm we add just one edge at the time but in Kruskal´s algorithm we can add one or more
at the time. Other difference is that in a computer Prim’s algorithm is usually faster than
Kruskal´s but by hand it is clear that the opposite holds. We took also a look to Dijkstra´s
algorithm which allow us to find not only a shortest path between two specific vertices, it also
allow us to get a shortest path from any given start vertex to any vertex in graph. It is well
remarkable that this algorithm gives same result as GPS. This algorithm may be able to be use
in GPS systems. Finally we observed two different circuits. Euler circuits are easy to
determine whether a graph has an Euler circuit is easy, as well as to find such circuit because
there is a specific theorem to Euler graph and algorithm which guarantee to find an Euler
circuit. Even if a graph has not Euler circuit there is a possible to get it by duplicate the
vertices with odd degree in graph. In opposite for Hamilton circuit there is neither theorem
nor algorithm like in Euler circuit which guarantee us that a graph has a Hamilton circuit or
that given a Hamilton circuit is optimal. Nevertheless the mathematicians keep searching and
the Sweden tour shows that there is some good progress in finding minimum Hamilton
circuits.
8. References
[1] John Clark, Derek Allan Holton. A first look at graph theory. Department of Mathematics
and Statistics University of Otago (New Zealand)
[2] Vasudev, C. Graph theory with applications. New Delhi, 2006.
[3] http://www.lancs.ac.uk/staff/letchfoa/TSP 2011-11- 21.
[4] http://www.tsp.gatech.edu 2011- 11- 21.
SE-391 82 Kalmar / SE-351 95 Växjö
Tel +46 (0)772-28 80 00
dfm@lnu.se
Lnu.se/dfm