the traveling salesman problem nearest-neighbor...

30
The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture 31 Sections 6.4 Robb T. Koether Hampden-Sydney College Mon, Nov 6, 2017 Robb T. Koether (Hampden-Sydney College) The Traveling Salesman ProblemNearest-Neighbor Algorithm Mon, Nov 6, 2017 1 / 15

Upload: others

Post on 23-Jul-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Traveling Salesman ProblemNearest-Neighbor Algorithm

Lecture 31Sections 6.4

Robb T. Koether

Hampden-Sydney College

Mon, Nov 6, 2017

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 1 / 15

Page 2: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

1 Greedy and Approximate Algorithms

2 The Nearest-Neighbor Algorithm

3 The Repetitive Nearest-Neighbor Algorithm

4 Assignment

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 2 / 15

Page 3: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Outline

1 Greedy and Approximate Algorithms

2 The Nearest-Neighbor Algorithm

3 The Repetitive Nearest-Neighbor Algorithm

4 Assignment

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 3 / 15

Page 4: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Greedy Algorithms

Definition (Greedy Algorithms)A greedy algorithm is an algorithm that, like greedy people, grabs whatlooks best in the short run, whether or not it is best in the long run.

Greedy algorithms optimize locally, but not necessarily globally.The benefit of greedy algorithms is that they are simple and fast.They may or may not produce the optimal solution.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 4 / 15

Page 5: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Approximate Algorithms

Definition (Approximate Algorithm)An approximate algorithm is an algorithm that gives a good solution,but not necessarily the best solution.

The benefit of approximate algorithms is that they can produce agood solution very quickly.

They operate under the principle “Good is good enough.”Also known as “The perfect is the enemy of the good.”“Striving to be better, oft we mar what’s well.” (Shakespeare)

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 5 / 15

Page 6: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Approximate Algorithms

Definition (Approximate Algorithm)An approximate algorithm is an algorithm that gives a good solution,but not necessarily the best solution.

The benefit of approximate algorithms is that they can produce agood solution very quickly.They operate under the principle “Good is good enough.”

Also known as “The perfect is the enemy of the good.”“Striving to be better, oft we mar what’s well.” (Shakespeare)

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 5 / 15

Page 7: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Approximate Algorithms

Definition (Approximate Algorithm)An approximate algorithm is an algorithm that gives a good solution,but not necessarily the best solution.

The benefit of approximate algorithms is that they can produce agood solution very quickly.They operate under the principle “Good is good enough.”Also known as “The perfect is the enemy of the good.”

“Striving to be better, oft we mar what’s well.” (Shakespeare)

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 5 / 15

Page 8: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Approximate Algorithms

Definition (Approximate Algorithm)An approximate algorithm is an algorithm that gives a good solution,but not necessarily the best solution.

The benefit of approximate algorithms is that they can produce agood solution very quickly.They operate under the principle “Good is good enough.”Also known as “The perfect is the enemy of the good.”“Striving to be better, oft we mar what’s well.” (Shakespeare)

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 5 / 15

Page 9: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Approximate Algorithms

We will look at three greedy, approximate algorithms to handle theTraveling Salesman Problem.

The Nearest-Neighbor AlgorithmThe Repetitive Nearest-Neighbor AlgorithmThe Cheapest-Link Algorithm

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 6 / 15

Page 10: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Outline

1 Greedy and Approximate Algorithms

2 The Nearest-Neighbor Algorithm

3 The Repetitive Nearest-Neighbor Algorithm

4 Assignment

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 7 / 15

Page 11: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Nearest-Neighbor Algorithm

Definition (Nearest-Neighbor Algorithm)The Nearest-Neighbor Algorithm begins at any vertex and follows theedge of least weight from that vertex. At every subsequent vertex, itfollows the edge of least weight that leads to a city not yet visited, untilit returns to the starting point.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 8 / 15

Page 12: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

7

8

79

A

B

C

D

E

F

GH

I

J

3

6

6

14

87

9

33

2

2

4

10

1

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 13: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 14: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 15: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 16: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 17: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 18: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 19: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 20: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 21: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 22: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 23: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Example

Example (Nearest-Neighbor Algorithm)

10

11

9

10

4

78

79

A

B

C

D

E

F

GH

I

J

611

9

14

111411

1517

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 9 / 15

Page 24: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Nearest-Neighbor Algorithm

Example (Nearest-Neighbor Algorithm)We ended up with the circuit ABJCEDFGHIA.The length is 94 miles.Is it possible to do better?

Yes.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 10 / 15

Page 25: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Nearest-Neighbor Algorithm

Example (Nearest-Neighbor Algorithm)We ended up with the circuit ABJCEDFGHIA.The length is 94 miles.Is it possible to do better?Yes.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 10 / 15

Page 26: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Nearest-Neighbor Algorithm

Example (Nearest-Neighbor Algorithm)Re-do the previous example, starting at city B.Re-do the previous example, starting at city C.Did we get a better solution?

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 11 / 15

Page 27: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Outline

1 Greedy and Approximate Algorithms

2 The Nearest-Neighbor Algorithm

3 The Repetitive Nearest-Neighbor Algorithm

4 Assignment

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 12 / 15

Page 28: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

The Repetitive Nearest-Neighbor Algorithm

Definition (Repetitive Nearest-Neighbor Algorithm)The Repetitive Nearest-Neighbor Algorithm applies thenearest-neighbor algorithm repeatedly, using each of the vertices as astarting point. It selects the starting point that produced the shortestcircuit.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 13 / 15

Page 29: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Outline

1 Greedy and Approximate Algorithms

2 The Nearest-Neighbor Algorithm

3 The Repetitive Nearest-Neighbor Algorithm

4 Assignment

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 14 / 15

Page 30: The Traveling Salesman Problem Nearest-Neighbor Algorithmpeople.hsc.edu/faculty-staff/robbk/Math111/Lectures... · The Traveling Salesman Problem Nearest-Neighbor Algorithm Lecture

Assignment

AssignmentChapter 6: Exercises 35, 36, 37, 41, 45.

Robb T. Koether (Hampden-Sydney College)The Traveling Salesman ProblemNearest-Neighbor AlgorithmMon, Nov 6, 2017 15 / 15