8.3 Hamiltonian Cycles and the Traveling Salesman...

40
8.3 Hamiltonian Cycles and the Traveling Salesman Problem

Transcript of 8.3 Hamiltonian Cycles and the Traveling Salesman...

Page 1: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

8.3 Hamiltonian Cycles and the TravelingSalesman Problem

Page 2: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Icosian Game

The puzzleCan you determine a route along the edges of the graph that begins atsome vertex and then returns there after having visited every othervertex exactly once?

Page 3: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Definitions

DefinitionA Hamiltonian path is a path that visits each vertex once.

DefinitionA Hamiltonian cycle (or circuit) is a closed path that visits each vertexonce.

DefinitionA graph that has a Hamiltonian cycle is called Hamiltonian.

Page 4: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Definitions

DefinitionA Hamiltonian path is a path that visits each vertex once.

DefinitionA Hamiltonian cycle (or circuit) is a closed path that visits each vertexonce.

DefinitionA graph that has a Hamiltonian cycle is called Hamiltonian.

Page 5: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Definitions

DefinitionA Hamiltonian path is a path that visits each vertex once.

DefinitionA Hamiltonian cycle (or circuit) is a closed path that visits each vertexonce.

DefinitionA graph that has a Hamiltonian cycle is called Hamiltonian.

Page 6: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Which are Hamiltonian?

Of the following, which have Hamiltonian cycles? Hamiltonianpaths?

Page 7: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Showing a Graph is Not Hamiltonian

Rules:

1 If a vertex v has degree 2, then both of its incident edges must bepart of any Hamiltonian cycle.

2 During the construction of a Hamiltonian cycle, no cycle can beformed until all of the vertices have been visited.

3 If during the construction of a Hamiltonian cycle two of theedges incident to a vertex v are required, then all other incidentedges can be deleted.

GoalTo begin a construction of a Hamiltonian cycle and show at somepoint during the construction that it is impossible to proceed anyfurther.

Page 8: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Showing a Graph is Not Hamiltonian

Rules:

1 If a vertex v has degree 2, then both of its incident edges must bepart of any Hamiltonian cycle.

2 During the construction of a Hamiltonian cycle, no cycle can beformed until all of the vertices have been visited.

3 If during the construction of a Hamiltonian cycle two of theedges incident to a vertex v are required, then all other incidentedges can be deleted.

GoalTo begin a construction of a Hamiltonian cycle and show at somepoint during the construction that it is impossible to proceed anyfurther.

Page 9: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Example

Is the given graph G Hamiltonian?

a• •b •c

v• •w •x

d• •e •f

Page 10: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Solution

First apply rule 1 to vertices v,w and x

a• •b •c

v• •w •x

d• •e •f

Page 11: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Solution (cont.)

Now apply rule 1 and 3 to vertex b

a• •b x •c

v• •w •x

d• •e •f

Page 12: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Solution (cont.)

Now apply rule 3 to vertex a

a•x

•b x •c

v• •w •x

d• •e •f

Now, there is only one edge incident to c and by rule 1 noHamiltonian cycle can exist.

Page 13: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Another Example

Is the following graph Hamiltonian?

a• b• •c

•v w•

d• e• •f

Page 14: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Sufficiency Conditions

TheoremOre’s Theorem(1960) Suppose that G is a graph with n ≥ 3 verticesand for all distinct nonadjacent vertices x and y,

deg(x) + deg(y) ≥ n

The G has a Hamiltonian circuit.

Proof Suppose that G has no Hamiltonian cycle. We will show thatfor some nonadjacent vertices x, y ∈ V(G),

degG(x) + degG(y) < n (∗)

where degG(a) means the degree of a in G.

Page 15: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Sufficiency Conditions

TheoremOre’s Theorem(1960) Suppose that G is a graph with n ≥ 3 verticesand for all distinct nonadjacent vertices x and y,

deg(x) + deg(y) ≥ n

The G has a Hamiltonian circuit.

Proof Suppose that G has no Hamiltonian cycle. We will show thatfor some nonadjacent vertices x, y ∈ V(G),

degG(x) + degG(y) < n (∗)

where degG(a) means the degree of a in G.

Page 16: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Proof of Ore’s Theorem (cont.)

If we add edges to G, we eventually obtain a complete graph, whichhas a Hamiltonian circuit. Thus, in the process of adding edges, wemust eventually hit a graph H with the property that H has noHamiltonian cycle but adding any more edges to H gives us a graphwith a Hamiltonian cycle. We will show that in H, there arenonadjacent x and y so that

degH(x) + degH(y) < n (∗∗)

But degG(a) ≤ degH(a) for all a, so (∗∗) implies (∗).

Pick any nonadjacent vertices x and y in H. Then H plus the edge{x, y} has a Hamiltonian cycle. Since H does not, this cycle must usethe edge {x, y}. Hence, it can be written as

x, y, a1, a2, . . . , an−2, x

Page 17: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Proof of Ore’s Theorem (cont.)

If we add edges to G, we eventually obtain a complete graph, whichhas a Hamiltonian circuit. Thus, in the process of adding edges, wemust eventually hit a graph H with the property that H has noHamiltonian cycle but adding any more edges to H gives us a graphwith a Hamiltonian cycle. We will show that in H, there arenonadjacent x and y so that

degH(x) + degH(y) < n (∗∗)

But degG(a) ≤ degH(a) for all a, so (∗∗) implies (∗).

Pick any nonadjacent vertices x and y in H. Then H plus the edge{x, y} has a Hamiltonian cycle. Since H does not, this cycle must usethe edge {x, y}. Hence, it can be written as

x, y, a1, a2, . . . , an−2, x

Page 18: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Proof of Ore’s Theorem (cont.)

•y •a1 •a2 . . . •ai−1 •ai •ai+1 . . . •an−2 •x

Now, V(H) = {x, y, a1, a2, . . . , an−2}. Moreover, we note that fori > 1,

{y, ai} ∈ E(H)⇒ {x, ai−1} 6∈ E(H) (∗ ∗ ∗)For if not, then

y, ai, ai+1, . . . , an−2, x, ai−1, ai−2, . . . , a1, y

is a Hamiltonian cycle in H, which is a contradiction. So, (∗ ∗ ∗) and{x, y} 6∈ E(H) imply (∗∗).

•y •a1 •a2 . . . •ai−1 •ai •ai+1 . . . •an−2 •x

//

Page 19: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Proof of Ore’s Theorem (cont.)

•y •a1 •a2 . . . •ai−1 •ai •ai+1 . . . •an−2 •x

Now, V(H) = {x, y, a1, a2, . . . , an−2}. Moreover, we note that fori > 1,

{y, ai} ∈ E(H)⇒ {x, ai−1} 6∈ E(H) (∗ ∗ ∗)For if not, then

y, ai, ai+1, . . . , an−2, x, ai−1, ai−2, . . . , a1, y

is a Hamiltonian cycle in H, which is a contradiction. So, (∗ ∗ ∗) and{x, y} 6∈ E(H) imply (∗∗).

•y •a1 •a2 . . . •ai−1 •ai •ai+1 . . . •an−2 •x

//

Page 20: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Consequence

CorollaryDirac(1952) Suppose that G is a graph with n ≥ 3 vertices and eachvertex has degree at least n

2 . The G has a Hamiltonian cycle.

Why are we not proving this?

Page 21: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction of a Hamiltonian Cycle

We will use this graph to illustrate the construction.

y1• •y2

y5• •y6

y4• •y3

Page 22: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Construction

Step 1Start with any vertex and construct the longest path you can.

γ : y1 − y2 − y3 − y4

y1• •y2

y5• •y6

y4• •y3

Page 23: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction(cont.)

Step 2Check to see if y1 and ym are adjacent.a) If y1 and ym are not adjacent, go to (3). Else y1 and ym are adjacentand go to (b).b) If m = n, stop and the output is a Hamiltonian cycle.

γ : y1 − y2 − y3 − y4 − y1

c) Locate a vertex z not on γ and a vertex yk on γ such that z isadjacent to yk. Replace γ with a path of length m + 1 given by

z− yk − . . .− ym − y1 . . .− yk−1

and go back to (2).

Page 24: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction(cont.)

y1• •y2

y5• •z

y4• •y3

γ : z− y3 − y4 − y1 − y2

Step 3Locate a vertex yk with 1 < k < m such that y1 and yk are adjacentand yk−1 and ym are adjacent. Replace γ with the path

γ : y1 − . . .− yk−1 − ym − . . .− yk

The two ends of the path, namely y1 and yk, are adjacent, and go backto (2)(b).

Page 25: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction(cont.)

After renumbering, we now we return to (2)

y4• •y5

z• •y1

y3• •y2

z− y4 − y5 − y1 − y2 − y3

and then renumber

y2• •y3

y1• •y4

y6• •y5

Page 26: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction(cont.)

After renumbering, we now we return to (2)

y4• •y5

z• •y1

y3• •y2

z− y4 − y5 − y1 − y2 − y3

and then renumber

y2• •y3

y1• •y4

y6• •y5

Page 27: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Construction(cont.)

When we return to (2), we have the m = 6, so when we add the finaledge to return to start, we have completed the cycle.

y2• •y3

y1• •y4

y6• •y5

Page 28: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Knight’s Tour Problem

The knight’s tour problem involves the knight graph, which is a graphon vertices in which each vertex represents a square in an chessboard,and each edge corresponds to a legal move by a knight. The process isthis: begin with a square on the grid and and travel around the boardusing only ‘L’ shaped moves.

KK

K

DefinitionA knight’s tour is a sequence of moves by a knight such that eachsquare of the board is visited exactly once. It is therefore aHamiltonian path on the corresponding knight graph.

Page 29: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Knight’s Tour Problem

The knight’s tour problem involves the knight graph, which is a graphon vertices in which each vertex represents a square in an chessboard,and each edge corresponds to a legal move by a knight. The process isthis: begin with a square on the grid and and travel around the boardusing only ‘L’ shaped moves.

KK

K

DefinitionA knight’s tour is a sequence of moves by a knight such that eachsquare of the board is visited exactly once. It is therefore aHamiltonian path on the corresponding knight graph.

Page 30: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

When do knight’s tours exist?

ExampleDoes a knight’s tour exist for a 3× 3 board?

Consider the following board:

K

Where do we go from here?What if we started here?

K

Page 31: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

When do knight’s tours exist?

ExampleDoes a knight’s tour exist for a 3× 3 board?

Consider the following board:

K

Where do we go from here?

What if we started here?

K

Page 32: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

When do knight’s tours exist?

ExampleDoes a knight’s tour exist for a 3× 3 board?

Consider the following board:

K

Where do we go from here?What if we started here?

K

Page 33: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Knight’s Tours and Hamiltonian Graphs

Knight’s Tour

5 8 32 67 4 1

This corresponds to the graph:

1• •2

3• •4

5• •6

7• •8

9•

We could invoke one last theorem ...

Page 34: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Knight’s Tours and Hamiltonian Graphs

Knight’s Tour

5 8 32 67 4 1

This corresponds to the graph:

1• •2

3• •4

5• •6

7• •8

9•

We could invoke one last theorem ...

Page 35: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Knight’s Tours and Hamiltonian Graphs

Knight’s Tour

5 8 32 67 4 1

This corresponds to the graph:

1• •2

3• •4

5• •6

7• •8

9•

We could invoke one last theorem ...

Page 36: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

Justification for 3× 3 board

TheoremLet G be a bipartite graph with bipartition (X,Y).

1 If |X| 6= |Y|, then G does not have a Hamiltonian cycle.2 If |X| = |Y|, then G does not have a Hamiltonian path that

begins at a vertex in X and ends at a vertex in X.3 If |X| and |Y| differ by at least 2, then G does not have a

Hamiltonian path.4 If |X| = |Y|+ 1, then G does not have a Hamiltonian path that

begins at a vertex in X and ends at a vertex of Y, and vice versa.

Page 37: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Traveling Salesman Problem

The ProblemGiven a graph G with weighted edges, find a minimal Hamiltoniancycle.

So, this is analagous to finding a Hamiltonian cycle, but we heed tofactor in the weights to minimize the ‘cost’ associated with the edgestraversed.

Page 38: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

The Traveling Salesman Problem

The ProblemGiven a graph G with weighted edges, find a minimal Hamiltoniancycle.

So, this is analagous to finding a Hamiltonian cycle, but we heed tofactor in the weights to minimize the ‘cost’ associated with the edgestraversed.

Page 39: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

TSP Example

ExampleFind the minimal Hamiltonian cycle for the given graph.

B• 6

33

D• 2

2

H•

6

A•2•C

5

5

•E

43

•F 4•G

Solution: A− B− D− H − G− E − F − C − A

Page 40: 8.3 Hamiltonian Cycles and the Traveling Salesman Problembtravers.weebly.com/uploads/6/...hamiltonian_paths... · Hamiltonian path on the corresponding knight graph. The Knight’s

TSP Example

ExampleFind the minimal Hamiltonian cycle for the given graph.

B• 6

33

D• 2

2

H•

6

A•2•C

5

5

•E

43

•F 4•G

Solution: A− B− D− H − G− E − F − C − A