• No results found

2.2 Elementary Graph Theory

2.2.2 Hamiltonian cycles and optimization

In the previous subsection we were largely concerned with the problem of moving around a graph in such a way that each edge is traversed exactly once. The present subsection is concerned with the “dual” problem, namely that of moving around a graph in such a way that each vertex is visited exactly once. Such a walk is called a Hamil- tonian path. If we return to the original vertex, the walk is called a Hamiltonian cycle. The following figure depicts a graph and a Hamiltonian cycle in the graph:

Curiously, unlike the question of the existence of Eulerian circuits, there is no definitive simple criterion for the existence of Hamiltonian cycles. Known results typically involve a lower bound on the degree of each vertex.29 See the exercises below for a few additional examples.

29For example, a 1952 theorem of Paul Dirac says that a graph withnvertices has a Hamiltonian

cycle provided that each vertex has degree ≥ n/2. /Oystein Ore generalized this result to graphs (withn≥3 vertices) such that for each pair of non-adjacent vertices the sum of their degrees is≥n.

Of more significance than just finding a Hamiltonian cycle in a simple graph is that of finding a Hamiltonian cycle of least total weight

in a weighted graph. Such is the nature of the traveling salesman problem. We start with a simple example.

Example 1. A salesman needs

to visit five cities in the American Midwest: Chicago, Gary, Joliet, Merriville, and Highland. The cost of travel between the cities is de- picted in the graph to the right.30

We display the costs in tabular form. It will be convenient to use the letters A, B, C, D, and E to represent the cities. Notice that since the matrix of entries is symmetric, there is no need to fill in all of the entries.

A = Chicago B = Gary C = Merriville D= Highland E = Joliet

Chicago * $185 $119 $152 $133

Gary * $121 $150 $200

Merriville * $174 $120

Highland * $199

Joliet *

Assuming that the salesman will begin and end his trip in Chicago, what it the optimal, i.e., cheapest route for him to take? That is, which Hamilton cycle will afford the least total weight?

In order to answer this question, a few observations are in order. First of all, a complete graph is one in which every pair of distinct vertices are joined by an edge. Thus, the above graph is a (weighted) complete graph. Next, it is obvious that in a complete graph with n

vertices, there are exactly (n−1)! Hamiltonian cycles starting from a given vertex. In the present example there are 4! = 24 Hamiltonian

30The numbers are taken from Example 2, page 201 of Excursions in Modern Mathematics, Fourth

SECTION 2.2 Elementary Graph Theory 119 cycles.

In order to find the Hamiltonian cycle of minimal weight, we shall resort to the Brute-Force Method, that is we shall form a complete list of the Hamiltonian cycles and their weights, choosing the one of minimal weight as the solution of our problem. There is one final sim- plification, namely, if the complete graph with vertices {v1, v2, . . . , vn}

is weighted, then the weight of the Hamiltonian cycle (v1, v2, . . . , vn, v1) clearly has the same weight as the “reverse cycle” (v1, vn, vn−1, . . . , v2, v1). Therefore the Brute Force Method will require us to compare the weights of 12(n−1)! Hamiltonian cycles.

We now list the weights of the Hamiltonian cycles in the above graph, highlighting the cycle of minimal weight.

cycle weight reverse cycle

ABCDEA 185 + 121 + 174 + 199 + 133 = $812 AEDCBA ABCEDA 185 + 121 + 120 + 199 + 152 = $777 ADECBA ABDCEA 185 + 150 + 174 + 120 + 133 = $762 AECDBA ABDECA 185 + 150 + 199 + 120 + 119 = $773 ACEDBA ABECDA 185 + 200 + 120 + 174 + 152 = $831 ADCEBA ABEDCA 185 + 200 + 199 + 174 + 119 = $877 ACDEBA ACBDEA 119 + 121 + 150 + 199 + 133 = $722 AEDBCA ACBEDA 119 + 121 + 200 + 199 + 152 = $791 ADEBCA ADBCEA 152 + 150 + 121 + 120 + 133 = $676 AECBDA ADBECA 152 + 150 + 200 + 120 + 119 = $741 ACEBDA AEBCDA 133 + 200 + 121 + 174 + 152 = $780 ADCBEA AEBDCA 133 + 200 + 150 + 174 + 119 = $776 ACDBEA As a result of the above computations we see that the minimal cost is for the salesman to visit the cities in the order

Chicago−→ Highland −→Gary −→Merriville −→ Joliet −→Chicago,

which results in a total cost of $676. In the next subsection we shall con- sider a few algorithms which can be used to determine “good” Hamil- tonian cycles if not the optimal Hamiltonian cycle.

often abbreviated TSP—and is one of fundamental importance in Man- agement Science. It is also related to the so-called P = NP problem (one of the Millennium problems)31 in that a general good (i.e., effi- cient) solution of TSP would in fact prove that P = NP.

Exercises

1. Two of the three graphs below have a Hamiltonian cycle. Deter- mine which two and in each case find a Hamiltonian cycle.

2. Find a Hamiltonian cycle of mini- mal weight in the graph to the right.

3. Let G be a complete graph having six vertices. Suppose that we label each edge with either a 0 or a 1. Prove that in this graph there must exist either

(a) three vertices among whose edges are all labeled “0,” or (b) three vertices among whose edges are all labeled “1.”32

31See www.claymath.org/millinnium.

32This is an elementary example of “Ramsey Theory.” In general, the Ramsey number of a

complete graph withn vertices is the maximum numberk such an arbitrary labeling of the edges (with 0s and1s) of the graph will result in a subgraph withkvertices having all the edge labels 0 or

SECTION 2.2 Elementary Graph Theory 121

TSP: The nearest-neighbor algorithm

As indicated above, the brute-force method will always find the optimal solution, but the amount of computing time required may be astronom- ical (which is hardly optimal!). In this and the following sections we shall consider two very simple algorithms which don’t necessarily find the optimal solution but they are known to quickly find “good” solu- tions.

The Nearest-Neighbor algorithm starts with a vertex in the weighted graph, and then proceeds to move to the “nearest neighbor” without prematurely returning to a previous vertex.

Example. In attempting to construct the cheapest route starting from

and returning to Chicago, we proceed as follows

1. Move from Chicago to Merriville; the cost of $119 is the cheapest among all costs involving travel from Chicago.

2. Move from Merriville to Joliet $120; this is the cheapest cost (other than $119, which puts us back in Chicago).

3. Move from Joliet to Highland at a cost of $199. 4. Move from Highland to Gary at a cost of $150. 5. Return to Chicago at a cost of $185.

The total cost of the above Hamiltonian route is $773, which while not optimal was an easy route to obtain.

Exercises

1. Consider the weighted graph with vertices A, B, C, D, and E, having weights assigned as follows

all the edge labels 1. The Ramsey number of the complete graph with six vertices is 3. In fact, one way the above problem is often described is as follows:

Show that among six people there must be either three mutual friends or three mutual strangers.

A B C D E A * 20 23 19 17 B * 20 25 18 C * 24 19 D * 23 E *

Use the Nearest-Neighbor algo- rithm to find a Hamiltonian cycle starting at vertex A. What is the total weight of this Hamiltonian cy- cle?

2. Use the Nearest-Neighbor algorithm to find a Hamiltonian cycle starting at vertex A. What is the resulting total weight of this cycle? A B C D E F A * 4.7 5.1 3.6 1.1 0.8 B * 0.6 8.2 5.7 5.2 C * 8.1 5.9 5.6 D * 3.2 3.1 E * 1.5 F *

3. There is a variation of the Nearest-Neighbor Algorithm which in- creases the computation time by a factor of the number of ver- tices of the weighted graph. This might seem stiff, but this added time pales by comparison with the time required to carry out the Brute-Force method. Namely, for each vertex of the weighted graph compute the Hamiltonian cycle constructed by the Nearest- Neighbor Algorithm, and then take the Hamiltonian cycle of least total weight. This is called the Repetitive Nearest-Neighbor

algorithm. Do this for the above weighted graph consisting of travel among the given five Midwestern cities.

TSP: The cheapest-link algorithm

There is a alternative algorithm—theCheapest-Linkalgorithm which efficiently computes a relatively cheap Hamiltonian cycle in a weighted graph. This is easy to describe, as follows.

In the weighted graph start by choosing the edge of minimal weight (the “cheapest link”). Next choose the next cheapest link, and so on.

SECTION 2.2 Elementary Graph Theory 123 As with the Nearest-Neighbor algorithm, we do not select any edges which would prematurely result in a cycle. Also, we need to avoid any edges which will result in more than two edges from a given vertex.

Example. We consider this algorithm on the Midwestern Cities graph.

1. Choose the {Chicago, Merriville}link as this is the cheapest among all links.

2. Choose the {Merriville, Joliet} link; this is the second cheapest at $120.

3. The third cheapest link is the {Gary, Merriville} link at $121; however, choosing this link will result in three edges issuing from Merriville. The fourth cheapest link is the {Chicago, Joliet} link at $133. However, this is also impossible as a premature cycle is formed. We settle for the {Gary, Highland} link at $150.

4. We choose the {Chicago, Highland} link at $152.

5. The only remaining choice given the constraints is the {Gary, Joliet} link at $200.

The above algorithm produces the Hamiltonian cycle

Chicago−→ Merriville −→ Joliet−→ Gary −→ Highland −→Chicago,

at a total (non-optimal) cost of $741.

The algorithm above are what are called greedy algorithms as at each stage they seek the optimal (i.e., cheapest) choice.

Exercises

1. Apply the Cheapest-Link algorithm to the graph indicated in the table in Exercise 1 on page 121.

2. Apply the Cheapest-Link algorithm to the graph indicated in the table in Exercise 2 on page 122.