optimization

62
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum

description

tsp

Transcript of optimization

Page 1: optimization

1

Excursions in Modern Mathematics

Sixth Edition

Peter Tannenbaum

Page 2: optimization

2

Chapter 6The Traveling Salesman Problem

Hamilton Joins the Circuit

Page 3: optimization

3

The Traveling Salesman ProblemOutline/learning Objectives

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.

Page 4: optimization

4

The Traveling Salesman ProblemOutline/learning Objectives

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.

Page 5: optimization

5

The Traveling Salesman Problem

6.1 Hamilton Circuits and Hamilton Paths

Page 6: optimization

6

The Traveling Salesman Problem

Hamilton pathHamilton path

A path that visits each vertex of the graph once and only once.

Hamilton circuitHamilton 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).

Page 7: optimization

7

The Traveling Salesman Problem

Hamilton Circuit (Paths vs Euler Circuit Path

Figure (a) shows a graph that has Euler circuits and has Hamilton circuits. One such Hamilton circuit is A, F, B, C, G, D, E, A. Note that once a graph has a Hamilton circuit, it automatically has a Hamilton path-- The Hamilton circuit can always be truncated into a Hamilton path by dropping the last vertex of the circuit.

Page 8: optimization

8

The Traveling Salesman Problem

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!

Page 9: optimization

9

The Traveling Salesman Problem

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).

Page 10: optimization

10

The Traveling Salesman Problem

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).

Page 11: optimization

11

The Traveling Salesman Problem

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.

Page 12: optimization

12

The Traveling Salesman Problem

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.

Page 13: optimization

13

The Traveling Salesman Problem

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.

Page 14: optimization

14

The Traveling Salesman Problem

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.

Page 15: optimization

15

The Traveling Salesman Problem

6.2 Complete Graphs

Page 16: optimization

16

The Traveling Salesman Problem

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 KN.

Page 17: optimization

17

The Traveling Salesman Problem

Number of Edges in Number of Edges in KKNN

KN has N(N – 1)/2 edges.

Of all graphs with N vertices and no multiple edges or loops, KN has the most edges.

Page 18: optimization

18

The Traveling Salesman Problem

Hamilton Circuits in K4

If we travel the four vertices of K4 in an arbitrary order, we get a Hamilton path. For example, C, A, D, B is a Hamilton path.

Page 19: optimization

19

The Traveling Salesman Problem

Hamilton Circuits in K4

D, C, A, B is another Hamilton Path.

Page 20: optimization

20

The Traveling Salesman Problem

Hamilton Circuits in K4

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.

Page 21: optimization

21

The Traveling Salesman Problem

Hamilton Circuits in K4

The path D, C, A, B begets the circuit D, C, A, B, D.

Page 22: optimization

22

The Traveling Salesman Problem

Hamilton Circuits in K4

It is important to remember that the same Hamilton circuit can be written in many ways.

Page 23: optimization

23

The Traveling Salesman Problem

Hamilton Circuits in K4

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.

Page 24: optimization

24

The Traveling Salesman Problem

Number of Hamilton Circuits in Number of Hamilton Circuits in KKNN

There are (N – 1)! Distinct Hamilton circuits in KN.

Page 25: optimization

25

The Traveling Salesman Problem

6.3 Traveling Salesman Problems

Page 26: optimization

26

The Traveling Salesman Problem

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.

Page 27: optimization

27

The Traveling Salesman Problem

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.

Page 28: optimization

28

The Traveling Salesman Problem

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.

Page 29: optimization

29

The Traveling Salesman Problem

6.4 Simple Strategies for Solving TSPs

Page 30: optimization

30

The Traveling Salesman Problem

– Strategy 1 (Exhaustive Strategy 1 (Exhaustive Search)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.

Page 31: optimization

31

The Traveling Salesman Problem

– Strategy 2 (Go Cheap)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.

Page 32: optimization

32

The Traveling Salesman Problem

6.5 The Brute-Force and Nearest Neighbor Algorithms

Page 33: optimization

33

The Traveling Salesman Problem

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.

Page 34: optimization

34

The Traveling Salesman Problem

Algorithm 1: The Brute-Force AlgorithmAlgorithm 1: The Brute-Force Algorithm

Step 1. Make a list of all the possible Hamilton circuits of the graph.

Page 35: optimization

35

The Traveling Salesman Problem

Algorithm 1: The Brute-Force AlgorithmAlgorithm 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).

Page 36: optimization

36

The Traveling Salesman Problem

Algorithm 1: The Brute-Force AlgorithmAlgorithm 1: The Brute-Force Algorithm

Step 3. Choose an optimal circuit (there is always more than one optimal circuit to choose from!).

Page 37: optimization

37

The Traveling Salesman Problem

Algorithm 2: The Nearest-Neighbor AlgorithmAlgorithm 2: The Nearest-Neighbor Algorithm

Start. Start at the designated starting vertex. If there is no designated starting vertex, pick any vertex.

Page 38: optimization

38

The Traveling Salesman Problem

Algorithm 2: The Nearest-Neighbor AlgorithmAlgorithm 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.

Page 39: optimization

39

The Traveling Salesman Problem

Algorithm 2: The Nearest-Neighbor AlgorithmAlgorithm 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.

Page 40: optimization

40

The Traveling Salesman Problem

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.

Page 41: optimization

41

The Traveling Salesman Problem

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.

Page 42: optimization

42

The Traveling Salesman Problem

6.6 Approximate Algorithm

Page 43: optimization

43

The Traveling Salesman Problem

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.

Page 44: optimization

44

The Traveling Salesman Problem

6.7 The Repetitive Nearest-Neighbor Algorithm

Page 45: optimization

45

The Traveling Salesman Problem

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

Page 46: optimization

46

The Traveling Salesman Problem

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

Page 47: optimization

47

The Traveling Salesman Problem

Repeat the process with each of the other vertices of the graph as the starting vertex.

Algorithm 3: The Repetitive Nearest-Neighbor Algorithm

Page 48: optimization

48

The Traveling Salesman Problem

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

Page 49: optimization

49

The Traveling Salesman Problem

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

Page 50: optimization

50

The Traveling Salesman Problem

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

Page 51: optimization

51

The Traveling Salesman Problem

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

Page 52: optimization

52

The Traveling Salesman Problem

6.8 The Cheapest-Link Algorithm

Page 53: optimization

53

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 54: optimization

54

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 55: optimization

55

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 56: optimization

56

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 57: optimization

57

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 58: optimization

58

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 59: optimization

59

The Traveling Salesman Problem

The next cheapest link available is AD ($152) and it works just fine.

Algorithm 4: The Cheapest-Link AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 60: optimization

60

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 61: optimization

61

The Traveling Salesman Problem

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 AlgorithmAlgorithm 4: The Cheapest-Link Algorithm

Page 62: optimization

62

The Traveling Salesman Problem Conclusion

How does one find an optimal How does one find an optimal Hamilton circuit in a complete Hamilton circuit in a complete weighted graph?weighted graph?

The nearest-neighbor and cheapest-The nearest-neighbor and cheapest-link algorithms are two fairly simple link algorithms are two fairly simple strategies for attacking TSPs.strategies for attacking TSPs.

The search for an optimal and efficient The search for an optimal and efficient general algorithm.general algorithm.