20

Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Embed Size (px)

Citation preview

Page 1: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits
Page 2: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc.

6 The Mathematics of Touring

6.1 Hamilton Paths and Hamilton Circuits

6.2 Complete Graphs?

6.3 Traveling Salesman Problems

6.4 Simple Strategies for Solving TSPs

6.5 The Brute-Force and Nearest-Neighbor Algorithms

6.6 Approximate Algorithms

6.7 The Repetitive Nearest-Neighbor Algorithm

6.8 The Cheapest-Link Algorithm

Page 3: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 3Copyright © 2010 Pearson Education, Inc.

In Example 6.4 we met Willy the traveling salesman pondering his upcoming sales trip, dollar signs running through his head. (The one-way airfares between any two cities are shown again in Fig.6-10.) Imagine now that Willy, unwilling or unable to work out the problem for himself, decides to offer a reward of $50 to anyone who can find an optimal tour. Would it be worth $50 to you to work out this problem? (Yes.) So how would you do it?

Example 6.7 A Tour of Five Cities: Part 2

Page 4: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 4Copyright © 2010 Pearson Education, Inc.

In Example 6.4 we met Willy the traveling salesman pondering his upcoming sales trip,

Example 6.7 A Tour of Five Cities: Part 2

dollar signs running through his head. The one-way airfares between any two cities are shown.

Page 5: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 5Copyright © 2010 Pearson Education, Inc.

Imagine now that Willy, unwilling or unable to work out the problem for himself, decides to

Example 6.7 A Tour of Five Cities: Part 2

offer a reward of $50 to anyone who can find an optimal tour. Would it be worth $50 to you to work out this problem? (Yes.) So how would you do it?

Page 6: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 6Copyright © 2010 Pearson Education, Inc.

We will explore two strategies for solving traveling salesman problems:

1. Exhaustive Search

2. Go Cheap

Traveling Salesman Problems

Page 7: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 7Copyright © 2010 Pearson Education, Inc.

Make a list of all possible Hamilton circuits. For each circuit in the list, calculate the weight of the circuit. From all the circuits, choose a circuit with least total weight. This is your optimal tour.

STRATEGY 1(EXHAUSTIVE SEARCH)

Page 8: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 8Copyright © 2010 Pearson Education, Inc.

The table on the next slide shows a detailed implementation of this strategy. The 24 Hamilton circuits are split into two columns consisting of circuits and their mirror images. The total costs for the circuits are shown in the middle column of the table. There are two optimal tours, with a total cost of $676 – A, D, B, C ,E, A and its mirror image A, E, C, B, D, A.

Example 6.7 A Tour of Five Cities: Part 2 - STRATEGY 1

Page 9: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 9Copyright © 2010 Pearson Education, Inc.

The first group of 12 Hamilton circuits:

Example 6.7 A Tour of Five Cities: Part 2 - STRATEGY 1

Page 10: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 10Copyright © 2010 Pearson Education, Inc.

The second group of 12 Hamilton circuits:

Example 6.7 A Tour of Five Cities: Part 2 - STRATEGY 1

Page 11: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 11Copyright © 2010 Pearson Education, Inc.

There are always going to be at least two optimal tours, since the mirror image of an optimal tour is also optimal. Either one of them can be used for a solution.

Example 6.7 A Tour of Five Cities: Part 2 - STRATEGY 1

Page 12: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 12Copyright © 2010 Pearson Education, Inc.

•Start from the home city. From there go to the city that is the cheapest to get to. From each new city go to the next new city that is cheapest to get to. When there are no more new cities to go to, go back home.

STRATEGY 2(GO CHEAP)

Page 13: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 13Copyright © 2010 Pearson Education, Inc.

In Willy’s case, this strategy works like this: Start at A. From A Willy goes to C (the cheapest place he can fly to from A). From C

Example 6.7 A Tour of Five Cities: Part 2 - Strategy 2

C to E, E to D, and from D the last new city to go to is B. From B Willy has to return home to A. The total cost of this tour is $773.

Page 14: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 14Copyright © 2010 Pearson Education, Inc.

The “go cheap” strategy takes a lot less work than the “exhaustive search” strategy, but there is a hitch – the cost of the tour we get is $773, which is $97 more than the optimal tour found under the exhaustive search strategy. Willy says this is not a solution and refuses to pay the $50. The “go cheap” strategy looks like a bust, but be patient –there is more to come.

Example 6.7 A Tour of Five Cities: Part 2 - Strategy 2

Page 15: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 15Copyright © 2010 Pearson Education, Inc.

Let’s imagine now that Willy, who has done very well with his business, has expanded his sales territory to 10 cities (let’s call them A through K). Willy wants us to help him once again find an optimal tour of his sales territory. Flush with success and generosity, he is offering a whopping $200 as a reward for a solution to this problem. Should we accept the challenge?

Example 6.8 A Tour of (Gasp!) 10 Cities

Page 16: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 16Copyright © 2010 Pearson Education, Inc.

The graph represents the 10 cities. With this many edges the graph would get pretty cluttered if we tried to show the weights

Example 6.8 A Tour of (Gasp!) 10 Cities

(one-way fares between cities) on the graph itself. It is better to put them in a table, which is on the next slide.

Page 17: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 17Copyright © 2010 Pearson Education, Inc.

The table shows the one-way fares between the pairs of cities.

Example 6.8 A Tour of (Gasp!) 10 Cities

Page 18: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 18Copyright © 2010 Pearson Education, Inc.

We now know that a foolproof method for tackling this problem is the “exhaustive search” strategy. But let’s think of what we are getting into. With 10 cities we have 9! = 362,880 Hamilton circuits. Assuming we could compute the cost of a new circuit every 30 seconds–and that’s working fast–it would take about 3000 hours to do all 362,880 possible circuits. Shortcuts? Say you cut the work in half by skipping the mirror-image circuits. That’s 1500 hours of work. If you worked nonstop, 24 hours a day, 7 days a week it would still take a couple of months!

Example 6.8 A Tour of (Gasp!) 10 Cities

Page 19: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 19Copyright © 2010 Pearson Education, Inc.

Let’s now try the “go cheap” strategy. The trip would start at A, go to C (119), to E (120), to D (199), to B (150), to J (379), to G (241), to

Example 6.8 A Tour of (Gasp!) 10 Cities

K (235), toF (222), toH (211), and back toA (277).

Page 20: Excursions in Modern Mathematics, 7e: 6.4 - 2Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits

Excursions in Modern Mathematics, 7e: 6.4 - 20Copyright © 2010 Pearson Education, Inc.

The final result is the tour A, C, E, D, B, J, G, K, F, H, A, with a total cost of $2153. So we now have a tour, but is it the optimal tour? If it isn’t–is it at least close? Willy refuses to pay the $200 unless these questions can be answered to his satisfaction. We will settle this issue later in the chapter.

Example 6.8 A Tour of (Gasp!) 10 Cities