Beruflich Dokumente
Kultur Dokumente
Page
Hamiltonian Graph
A Hamiltonian cycle is a cycle that passes through all the vertices of the graph. A graph is called a Hamiltonian graph if it includes at least one Hamiltonian cycle.
Manipulate this cycle by adding some edges and removing other edges so eventually a Hamiltonian cycle is formed that includes the edges that belong to the original graph
A.R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 2
HamiltonianCycle (graph G = (V, E)) Set label of all edges to 0; K = 1; H = E; // set of edges GH = G; // original graph // Phase 1 While GH contains nonadjacent vertices v with u such that degH(v) + degH(u) >= |V| then H = H U {edges(vu)} GH = (V, H) Label(edge(vu)) = k++; // Phase 2 If there exists a Hamiltonian cycle C k=max {label(edge(pq)) such that edge(pq) is in C} While (k > 0) C = a cycle due to a crossover with edge labeled by a number < k; k=max {label(edge(pq)) such that edge(pq) is in cycle C}
Page
Consider the following graph. We want to find the Hamiltonian cycle in this graph We start with phase 1 where we turn the graph into a complete graph with every vertex is connected to another vertex in the graph
a b c
d f
Page
We start with vertex a. Note that the total number of vertices in the graph is |V| = 6
The nonadjacent vertices to a are c and e
a
1 b d f
California State University San Marcos (CSUSM)
1 c
e b 2 d f
Page 5
c e
1
b 2 d f e c
Page
a 1
a 1 c 2 e b d 3 2 e f c
b
d f
Page
a
1 b d 3 2 e f
a 1
b 4 d
c 3 2 e f
Page
After adding eb, the deg(e) becomes 4 and ef is also added because deg(e) + deg(f) = 4 + 3 = 7 which is > 6
1
b 4 d c 3 2 e f b 5 4 d
1
c b 5 4 d
1 c 3 2 e
2 e f
Page
a 1 b 5 4 c 3 6 2 b 5 4
a 1 c 3 7 f 6 2
e
f
Page 10
Now the second phase starts. A cycle is created and K becomes the edge with the maximum value We order the vertices in the cycle such that the vertices attached to edge K are on the extreme ends For the following cycle, the vertices are a, c, e, f, d, b
K = ef
Thus we order the vertices of the cycle as follows: fdbace
a 1 b 5 4 d 7 f
A.R. Hadaegh Dr. Ahmad R. Hadaegh
c
3 6
Page 11
2 e
Now we find cross over edges and compare their value with the highest value of current cycle.
Two edge cross over each other if they each have a vertex that is the end point of the current cycle The first cross over edges are fb and de: fdbace This is not chosen because the weight of fb is 7 which is > 6
a 1 b 5 4 d 7 f
A.R. Hadaegh Dr. Ahmad R. Hadaegh
c
3 6
Page 12
2
e
a 1 b 5 4 c b 5 4 d 7 f
A.R. Hadaegh Dr. Ahmad R. Hadaegh
a 1 c 3 6
3
7 6
2
e f
Page 13
We start to cross over the edges again in the new cycle bdface
The first two edges are bf and de This combination is not chosen because the weight of bf is 7 which is bigger than 5, the maximum weight
a 1 b 5 4 c
3
7 f 6
Page 14
a 1 b 5 4 c
3
7 f 6
Page 15
The next two edges are bc and ae: bdface This combination is picked because the weight of ae is 2 which is less than 5, the maximum weight of the cycle Thus bc and ae are added and be and ac are removed Now the maximum weigh of the new cycle is db = 4 The new cycle is bceafd
a 1 b 5 4 d 7 f
A.R. Hadaegh Dr. Ahmad R. Hadaegh
a 1
c
3 6 2 e
b 4
c 5 3 7 f 6
Page 16
2 e
The next two edges are be and cd: bceafd This combination is not picked because the weight of be is 5 which is not less than 4 The next two edges are ba and ed: bce afd This combination is picked because both edges belong to original graph and their weight is zero Thus ba and ed are added and bd and ea are removed The new cycle is abcedf
a 1 b 4 d 7 c 5 3 6 2 e b 4 d 7 f
California State University San Marcos (CSUSM)
a 1 c 5 3 6
Page 17
2
e
f
A.R. Hadaegh Dr. Ahmad R. Hadaegh
Since the maximum weight of the new cycle is 0, it means all the edges belong to the original graph. Thus we are done.
a 1 b 4 c 5 3 7 f 6
2 e
c
e