Presentation is loading. Please wait.

Presentation is loading. Please wait.

EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1.

Similar presentations


Presentation on theme: "EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1."— Presentation transcript:

1 EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1

2 CHAPTER 6 THE TRAVELING SALESMAN PROBLEM Hamilton Joins the Circuit 2

3 The Traveling Salesman Problem Outline/learning Objectives 3  To identify and model Hamilton circuit and Hamilton path problems.  To recognize complete graphs and state the number of Hamilton circuits that they have.  To identify traveling-salesman problems and the difficulties faced in solving them.  To implement brute-force, nearest-neighbor, repeated nearest-neighbor, and cheapest-link algorithms to find approximate solutions to traveling –salesman problems.  To recognize the difference between efficient and inefficient algorithms.  To recognize the difference between optimal and approximate algorithms.

4 THE TRAVELING SALESMAN PROBLEM 6.1 Hamilton Circuits and Hamilton Paths 4

5 Hamilton Circuits and Paths 5  Hamilton path A path that visits each vertex of the graph once and only once.  Hamilton circuit A circuit that visits each vertex of the graph once and only once (at the end, of course, the circuit must return to the starting vertex).

6 Hamilton Circuits and Paths 6  Dodecahedron

7 Hamilton Circuits and Paths 7  Herschel Graph  Smallest polyhedral that does not contain a Hamilton circuit.

8 Hamilton Circuits and Paths 8 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (b) shows a graph that has no Euler circuits but does have Euler paths (for example C, D, E, B, A, D), has no Hamilton circuits (sooner or later you have to go to C, and then you are stuck) but does have Hamilton paths (for example, A, B, E, D, C). Aha, a graph can have a Hamilton path but no Hamilton Circuit!

9 Hamilton Circuits and Paths 9 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (b) shows a graph that has no Euler circuits but does have Euler paths (for example C, D, E, B, A, D), has no Hamilton circuits (sooner or later you have to go to C, and then you are stuck) but does have Hamilton paths (for example, A, B, E, D, C). Aha, a graph can have a Hamilton path but no Hamilton Circuit!

10 Hamilton Circuits and Paths 10 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (c) shows a graph that has neither Euler circuits nor paths (it has four odd vertices), has Hamilton circuits (for example A, B, C, D, E, A– there are plenty more), and consequently has Hamilton paths (for example, A, B, C, D, E).

11 Hamilton Circuits and Paths 11 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (d) shows a graph that has Euler circuits (the vertices are all even), has no Hamilton circuits (no matter what, your are going to have to go through E more than once!) but has Hamilton paths (for example, A, B, E, D, C).

12 Hamilton Circuits and Paths 12 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (e) shows a graph that has no Euler circuits but has Euler paths (F and G are the two odd vertices), had neither Hamilton circuits nor Hamilton paths.

13 Hamilton Circuits and Paths 13 Hamilton Circuit (Paths vs Euler Circuit Path)  Figure (f) shows a graph that has neither Euler circuits nor Euler paths (too many odd vertices), has neither Hamilton circuits nor Hamilton paths.

14 Hamilton Circuits and Paths 14

15 Hamilton Circuits and Paths 15  The lesson in the previous Example is that the existence of an Euler path or circuit in a graph tells us nothing about the existence of a Hamilton path or circuit in that graph.  This is important because it implies that Euler ’ s circuit and path theorems from Chapter 5 are useless when it comes to Hamilton circuits and paths.

16 Hamilton Circuits and Paths 16 There are, however, nice theorems that identify special situations where a graph must have a Hamilton circuit.  This best known of these theorems is Dirac ’ s theorem : If a connected graph has N vertices (N > 2) and all of them have degree bigger or equal to N/2, then the graph has a Hamilton circuit.

17 THE TRAVELING SALESMAN PROBLEM 6.2 Complete Graphs 17

18 Complete Graphs 18 If a graph has a Hamilton circuit, then how many different Hamilton circuits does a it have? A graph with N vertices in which every pair of distinct vertices is joined by an edge is called a complete graph on N vertices and denoted by the symbol K N.

19 Complete Graphs 19  Every vertex has a degree of N-1  Therefor the sum of all the degrees are N(N-1)  Thus the number of edges is N(N-1)/2

20 Complete Graphs 20 Number of Edges in K N  K N has N(N – 1)/2 edges.  Of all graphs with N vertices and no multiple edges or loops, K N has the most edges.

21 Complete Graphs 21 Hamilton Circuits in K 4 If we travel the four vertices of K 4 in an arbitrary order, we get a Hamilton path. For example, C, A, D, B is a Hamilton path.

22 Complete Graphs 22 Hamilton Circuits in K 4 D, C, A, B is another Hamilton Path.

23 Complete Graphs 23 Hamilton Circuits in K 4 Each of these Hamilton paths can be closed into a Hamilton circuit-- the path C, A, D, B begets the circuit D, A, D, B, C.

24 Complete Graphs 24 Hamilton Circuits in K 4 The path D, C, A, B begets the circuit D, C, A, B, D.

25 Complete Graphs 25 Hamilton Circuits in K 4 It is important to remember that the same Hamilton circuit can be written in many ways.

26 Complete Graphs 26 Hamilton Circuits in K 4 For example, C, A, D, B, C is the same circuit as A, D, B, C, A– the only difference is that in the first case we used C as the reference point in the second case we used A.

27 Complete Graphs 27 Number of Hamilton Circuits in K N There are (N – 1)! Distinct Hamilton circuits in K N.

28 THE TRAVELING SALESMAN PROBLEM 6.3 Traveling Salesman Problems 28

29 The Traveling Salesman Problem 29 The “ traveling salesman ” is a convenient metaphor for many different important real-life applications, all involving Hamilton circuits in complete graphs but only occasionally involving salespeople.

30 The Traveling Salesman Problem 30 Any graph whose edges have numbers attached to them is called a weighted graph, and the numbers are called the weights of the edges. The graph is called a complete weighted graph.

31 The Traveling Salesman Problem 31 The problem we want to solve is fundamentally the same– find an optimal Hamilton circuit (a Hamilton circuit with least total weight) for the given weighted graph.

32 The Traveling Salesman Problem 32

33 The Traveling Salesman Problem 33

34 The Traveling Salesman Problem 34  15,112 Cities in Germany  Solved in 2001  Network of 110 processors  Total computer time: 22.6 years

35 The Traveling Salesman Problem 35  24,978 Cities in Sweden  Solved in 2004  Cluster of 96 dual processor Intel Xenon 2.8 Ghz workstations

36 The Traveling Salesman Problem 36 Currently the largest solved travelling salesman problem  85,900 “cities”  Solved in 2006  Bell Laboratories computer chip  It exhibits the shortest path a laser cutter can follow to sculpt the chip. http://www.math.uwaterloo.ca/tsp/optimal/

37 The Traveling Salesman Problem 37  Traveler – person going from site to site.  Sites – where the person is going.  Cost – each leg of the trip has a cost.  Tour – the path taken from beginning to end.  Optimal Tour – a tour with the least total cost.

38 The Traveling Salesman Problem 38 Other ways to look at it:  Sites – vertices of the graph  Costs – weights of the edges  Tour – Hamilton Circuit  Optimal Tour – Hamilton Circuit of the least total weight

39 The Traveling Salesman Problem 39 Other examples:  Routing School Busses  Delivering Packages  Fabricating Circuit Boards  Running Errands Around Town  Ant Colony Optimization

40 THE TRAVELING SALESMAN PROBLEM 6.4 Simple Strategies for Solving TSPs 40

41 The TSP Strategies 41  Strategy 1 (Exhaustive Search)  Make a list of all possible Hamilton circuits. For each circuit in the list, calculate the total weight of the circuit. From all the circuits, choose the circuit with smallest total weight.

42 The TSP Strategies 42 Cheapest: $676

43 The TSP Strategies 43  Strategy 2 (Go Cheap)  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 city that is cheapest to get to. When there are no more new cities to go to, go back home.

44 The TSP Strategies 44 Cheapest routes:  A to C = $119  C to E = $120  E to D = $199  D to B = $150  B to A = $185 {A, C, E, D, B, A} = $773

45 The TSP Strategies 45 A Tour of 10 Cities (start at A)

46 The TSP Strategies 46

47 The TSP Strategies 47

48 THE TRAVELING SALESMAN PROBLEM 6.5 The Brute-Force and Nearest Neighbor Algorithms 48

49 Brute-Force and Nearest-Neighbor 49  The Exhaustive Search strategy can be formalized into an algorithm generally known as the brute- force algorithm; the Go Cheap strategy can be formalized into an algorithm known as the nearest-neighbor algorithm.  In both cases, the objective of the algorithm is to find an optimal (cheapest, shortest, fastest) Hamilton circuit in a complete weighted graph.

50 Brute-Force and Nearest-Neighbor 50 Algorithm 1: The Brute-Force Algorithm  Step 1. Make a list of all the possible Hamilton circuits of the graph. Exhaustive Search

51 Brute-Force and Nearest-Neighbor 51 Algorithm 1: The Brute-Force Algorithm  Step 2. For each Hamilton circuit calculate its total weight (add the weights of all the edges in the circuit). Exhaustive Search

52 Brute-Force and Nearest-Neighbor 52 Algorithm 1: The Brute-Force Algorithm  Step 3. Choose an optimal circuit (there is always more than one optimal circuit to choose from!). Exhaustive Search

53 Brute-Force and Nearest-Neighbor  Find the length of the total trip starting at A using the Brute-Force method. 53

54 Brute-Force and Nearest-Neighbor 54 Algorithm 2: The Nearest-Neighbor Algorithm  Start. Start at the designated starting vertex. If there is no designated starting vertex, pick any vertex. Go Cheap

55 Brute-Force and Nearest-Neighbor 55 Algorithm 2: The Nearest-Neighbor Algorithm  First step. From the starting vertex go to its nearest neighbor (the vertex for which the corresponding edge has the smallest weight. Go Cheap

56 Brute-Force and Nearest-Neighbor 56 Algorithm 2: The Nearest-Neighbor Algorithm  Middle steps. From each vertex go to its nearest neighbor, choosing only among the vertices that haven ’ t been yet visited. (If there is more than one, choose at random). Keep doing this until all the vertices have been visited. Go Cheap

57  Find the nearest-neighbor tour starting at Louisville. Brute-Force and Nearest-Neighbor 57

58 Brute-Force and Nearest-Neighbor 58  The brute-force algorithm is a classic example of what is formally known as an inefficient algorithm – an algorithm for which the number of steps needed to carry it out grows disproportionately with the size of the problem.

59 Brute-Force and Nearest-Neighbor 59  The nearest-neighbor algorithm is an efficient algorithm. Roughly speaking, an efficient algorithm is an algorithm for which the amount of computational effort required to implement the algorithm grows in some reasonable proportion with the size of the input to the problem.

60 Brute-Force and Nearest-Neighbor 60 Computing the Relative Error ε  Describes how far “off” a tour is from the optimal tour. ε = (cost of tour – cost of optimal tour) cost of optimal tour

61 Brute-Force and Nearest-Neighbor 61  Brute Force = $676  Nearest Neighbor = $773 ε = ($733 - $676) / $676 ≈ 14.35% An optimal tour would be 0%.

62 THE TRAVELING SALESMAN PROBLEM 6.6 Approximate Algorithm 62

63 Approximate Algorithm 63 A really good algorithm for solving TSP ’ s in general would have to be both efficient (like the nearest-neighbor) and optimal (like the brute-force). Unfortunately, nobody knows of such an algorithm. We will use the term approximate algorithm to describe any algorithm that produces solutions that are, most of the time, reasonably close to the optimal solution.

64 Approximate Algorithm 64  Nearest-Neighbor cost: $2153  Brute-Force cost: $1914 (computer program)  Off by the relative error of about 12.49% ε = (2153 – 1914) / 1914 ≈ 12.49%

65 THE TRAVELING SALESMAN PROBLEM 6.7 The Repetitive Nearest-Neighbor Algorithm 65

66 The Repetitive Nearest-Neighbor Algorithm 66  Let X be any vertex. Find the nearest-neighbor circuit using X as the starting vertex and calculate the total cost of the circuit. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

67 The Repetitive Nearest-Neighbor Algorithm 67  We compute the nearest- neighbor circuit with A as the starting vertex, and we got A, C, E, D, B, A with a total cost of $773. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

68 The Repetitive Nearest-Neighbor Algorithm 68  Repeat the process with each of the other vertices of the graph as the starting vertex. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

69 The Repetitive Nearest-Neighbor Algorithm 69  If we use B as the starting vertex, the nearest- neighbor circuit takes us from B to C, then to A, E, D, and back to B, with a total cost of $722. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

70 The Repetitive Nearest-Neighbor Algorithm 70  Remember we must start and end the trip at A– this very same circuit would take the form A, E, D, B, C, A. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

71 The Repetitive Nearest-Neighbor Algorithm 71  The process is once again repeated using C, D, and E as the starting vertices with respective costs of $722, $722, and $741. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

72 The Repetitive Nearest-Neighbor Algorithm 72  Of the nearest-neighbor circuits obtained, keep the best one. If there is a designated starting vertex, rewrite the circuit using that vertex as the reference point. Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

73 The Repetitive Nearest-Neighbor Algorithm 73

74 The Repetitive Nearest-Neighbor Algorithm 74  Brute Force = $676 {A, D, B, C, E, A}  Nearest Neighbor = $773 {A, C, E, D, B, A}  Repetitive Nearest-Neighbor = $722 {B, C, A, E, D, B}

75 The Repetitive Nearest-Neighbor Algorithm 75

76 THE TRAVELING SALESMAN PROBLEM 6.8 The Cheapest-Link Algorithm 76

77 The Cheapest-Link Algorithm 77  Step 1. Pick the cheapest link (edge with smallest weight) available. Among all the edges of the graph, the “cheapest link” is edge AC, with a cost of $119. Algorithm 4: The Cheapest-Link Algorithm

78 The Cheapest-Link Algorithm 78  Step 2. Pick the next cheapest link available and mark it. In this case edge CE with a cost of $120. Algorithm 4: The Cheapest-Link Algorithm

79 The Cheapest-Link Algorithm 79  Step 3, 4, …, N -1 Continue picking and marking the cheapest unmarked link available that does not (a) close a circuit, or (b) create three edges coming out of a single vertex. Algorithm 4: The Cheapest-Link Algorithm

80 The Cheapest-Link Algorithm 80  The next cheapest link available is edge BC ($121), but we should not choose BC– we would have three edges coming out of vertex C. Algorithm 4: The Cheapest-Link Algorithm

81 The Cheapest-Link Algorithm 81  The next cheapest link available is AE ($133), but we can’t take AE either-- the vertices A, C, and E would form a small circuit. Algorithm 4: The Cheapest-Link Algorithm

82 The Cheapest-Link Algorithm 82  The next cheapest link available is BD ($150). Choosing BD would not violate either of the two rules, so we can add it to our budding circuit. Algorithm 4: The Cheapest-Link Algorithm

83 The Cheapest-Link Algorithm 83  The next cheapest link available is AD ($152) and it works just fine. Algorithm 4: The Cheapest-Link Algorithm

84 The Cheapest-Link Algorithm 84  Step N. Connect the last two vertices to close the red circuit. At this point, we have only one way to close up the Hamilton circuit, edge BE. Algorithm 4: The Cheapest-Link Algorithm

85 The Cheapest-Link Algorithm 85  The Hamilton circuit can now be described using any vertex as the reference point. For A, we describe it as A, C, E, B, D, A with a total cost of $741. Algorithm 4: The Cheapest-Link Algorithm

86 The Cheapest-Link Algorithm 86  Brute Force = $676 {A, D, B, C, E, A}  Nearest Neighbor = $773 {A, C, E, D, B, A}  Repetitive Nearest-Neighbor = $722 {B, C, A, E, D, B}  Cheapest-Link Algorithm = $741 {A, C, E, B, D, A}

87  Find the length of the shortest trip using the Cheapest-Link. The Cheapest-Link Algorithm 87

88 The Cheapest-Link Algorithm 88

89 The Cheapest-Link Algorithm 89

90 The Cheapest-Link Algorithm 90

91 The Traveling Salesman Problem Conclusion 91  How does one find an optimal Hamilton circuit in a complete weighted graph?  The nearest-neighbor and cheapest-link algorithms are two fairly simple strategies for attacking TSPs.  The search for an optimal and efficient general algorithm.


Download ppt "EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1."

Similar presentations


Ads by Google