15
Finite Math A Chapter 6 Notes Hamilton Circuits 1 Chapter 6: The Mathematics of Touring (Hamilton Circuits) and Hamilton Paths 6.1 Traveling Salesman Problems/ 6.2 Hamilton Paths and Circuits A traveling salesman has clients in 5 different cities. He knows the cost to travel between each pair of cities. He would like to start at his hometown, travel to each of the five cities, and return back home. What is the cheapest way to make this happen? These types of problems are similar to the type of problems we solved in chapter 5. However, we are no longer concerned with traveling EDGES; we are traveling to places (VERTICES). Euler Circuit: Covers each edge of a graph exactly once. Starts and ends at the same vertex. Euler Path: Covers each edge of a graph exactly once. Starts and ends at a different vertex. Examples: 1. Find a Hamilton Path that starts at G and ends at E. 2. Find a Hamilton Circuit for the graph at the right that starts and ends at A. 3. Is there another way to write the same set of edges using the same starting vertex? Writing a circuit “backwards” is called a _______________________________________. These are considered to be different circuits. 4. Is there another way to write the same set of edges starting at a different vertex? The vertex you start at is called the ___________________________________________. Rewriting the same order of edges starting at a different vertex is considered to be the same circuit.

Chapter 6: The Mathematics of Touring (Hamilton Circuits) and Hamilton Paths … · 2016-09-23 · 6.2 Hamilton Paths and Circuits A traveling salesman has clients in 5 different

  • Upload
    others

  • View
    92

  • Download
    0

Embed Size (px)

Citation preview

Finite Math A Chapter 6 Notes Hamilton Circuits

1

Chapter 6: The Mathematics of Touring (Hamilton Circuits) and Hamilton Paths 6.1 Traveling Salesman Problems/ 6.2 Hamilton Paths and Circuits A traveling salesman has clients in 5 different cities. He knows the cost to travel between each pair of cities. He would like to start at his hometown, travel to each of the five cities, and return back home. What is the cheapest way to make this happen? These types of problems are similar to the type of problems we solved in chapter 5. However, we are no longer concerned with traveling EDGES; we are traveling to places (VERTICES). Euler Circuit: Covers each edge of a graph exactly once. Starts and ends at the same vertex. Euler Path: Covers each edge of a graph exactly once. Starts and ends at a different vertex.

Examples: 1. Find a Hamilton Path that starts at G and ends at E. 2. Find a Hamilton Circuit for the graph at the right that starts and ends at A. 3. Is there another way to write the same set of edges using the same starting vertex? Writing a circuit “backwards” is called a _______________________________________. These are considered to be different circuits. 4. Is there another way to write the same set of edges starting at a different vertex? The vertex you start at is called the ___________________________________________. Rewriting the same order of edges starting at a different vertex is considered to be the same circuit.

Finite Math A Chapter 6 Notes Hamilton Circuits

2

Example:

Trace a “Hamilton Circuit” in the graph: Name it: Name it’s mirror image: Name it from two different reference points: For consistency, we will try to always name circuits from the same reference point. If the problem is not specific, name it alphabetically. The circuit or it’s mirror image are both considered to be correct answers.

Complete Graphs A complete graph is a graph in which every vertex is adjacent to every other vertex in the graph. We use: to represent “The complete graph with N vertices.” Draw: K3 K4 K5 K6

A, B, D, C, A & A, C, D, B, A are called mirror images—not considered equal

A, B, D,C,A All considered the same circuit, B, D, C, A, B each has a different reference point. C, A, B, D, C D, C, A, B, D

KN

A B

D C

Finite Math A Chapter 6 Notes Hamilton Circuits

3

Example: How many edges are there in 1. K19 2. K150 Example: How many vertices (what is N) if 3. KN has 5040 Hamilton Circuits? 5. KN has 120 Hamilton Circuits ?

4. KN has 990 edges ? 6. KN has 136 edges?

In a Complete Graph with N vertices: Each vertex has degree: 1N

Total number of edges: ( 1)

2

N N

Total number of Hamilton Circuits: 1 !N

(including Mirror-Images)

Example: How many Hamilton Circuits are there in: 1. K3

2. K4

3. K5

4. K6

5. K10

As the number of edges increases, the number of Hamilton Circuits GREATLY increases. If we are looking for “the best” Hamilton Circuit for our traveling salesman, we need to have a plan!

Finite Math A Chapter 6 Notes Hamilton Circuits

4

Traveling Salesman Problems Shown is a graph of five cities (A, B, C, D, E) that our salesman, Willy Loman must travel. Notice that this is a complete graph with 5 vertices. The weight of an edge is the cost to travel that edge. What is the weight of edge AB = __________ EB = __________ Find a Hamilton Path that starts at A and ends at D and give its weight: ________________________________________ Find a Hamilton Circuit that starts with edge CD and give its weight: _________________________________________ Find a Hamilton Circuit that ends with edge EA and give its weight _________________________________________

REAL EXAMPLES OF TRAVELING SALESMAN PROBLEMS

Read: pg178-179 School buses. Circuit boards. Errands around town. Bees.

Read: pg 183 Table 6-2, 6-3 SUPERHERO

Example: Find a Hamilton Circuit and give its weight.

Finite Math A Chapter 6 Notes Hamilton Circuits

5

6.3: Optimal Hamilton Circuits –the Brute Force Method

The only way to find an OPTIMAL Hamilton circuit is to actually find ALL POSSIBLE circuits

Check the cost one by one.

This is called the Brute Force Method. It is very time consuming and is considered to be “optimal” but “inefficient”.

Willy’s graph has 5 vertices. How many circuits would he have to check?

Which Hamilton Circuit gives the OPTIMAL tour through the graph? _________________________ ________________________ Weight: _________

Finite Math A Chapter 6 Notes Hamilton Circuits

6

Example 1: Find the OPTIMAL Hamilton Circuit for the following graph. Use the Brute Force Method. Write your answer using A as your reference point. Example 2: Find the optimal Hamilton Circuit and its weight Example 3: Find the optimal Hamilton Circuit and its weight. IND RSW LAX MSP

IND *** 253 278 339

RSW 253 *** 222 264

LAX 278 222 *** 248

MSP 339 264 248 ***

A B

D C

10

14

7

12

8

10

C

D

A

B

4 10

6 2

5

3

Finite Math A Chapter 6 Notes Hamilton Circuits

7

6.4: The Nearest-Neighbor Algorithm and Repetitive Nearest Neighbor Algorithm Brute Force Algorithm takes too long for N>4. We need a faster way to come up with a good answer.

Use the nearest neighbor algorithm, starting at vertex A, to find a Hamilton Circuit and its weight. Notice that our answer is NOT an optimal answer, but the process to find it is relatively quick. Willy Loman has to decide if the time he saved not doing Brute Force is worth the money he loses from the difference. We say that the nearest-neighbor method is _______________________ and _____________________. What if Willy Loman’s territory gets expanded to 10 cities? How many Hamilton Circuits are in this graph? How many edges are in this graph?

The Nearest Neighbor Algorithm 1. START: Start at the designated starting vertex. If there is no designated starting vertex, pick any vertex. 2. First Step: From the starting vertex, go to its nearest neighbor (the vertex for which the corresponding edge has the smallest weight). 3. Middle Steps:From each vertex, go to its nearest neighbor among the vertices that haven’t been visited yet. Keep doing this until all the vertices have been visited. 4. Last Step: From the last vertex, return to the starting vertex. The tour we get is called the nearest-neighbor tour.

Finite Math A Chapter 6 Notes Hamilton Circuits

8

A much more practical approach is to organize the data in a table.

Use the nearest neighbor algorithm to find the Hamilton Circuit starting at vertex A.

Example: a) Use the nearest neighbor method to find the Hamilton Circuit starting with vertex A. b) Use the nearest neighbor method to find the Hamilton Circuit starting with vertex B.

Example: The chart below represents the price of a bus ticket between the following cities. You would like to start and end at your hometown of Z. Find a Hamilton Circuit and its weight.

V W X Y Z

V ** $35 $10 $20 $45

W $35 ** $42 $37 $60

X $10 $42 ** $30 $50

Y $20 $37 $30 ** $77

Z $45 $60 $50 $77 **

A B

D C

1

7

4

3

6

2

Finite Math A Chapter 6 Notes Hamilton Circuits

9

Example: Use the nearest neighbor algorithm to find a Hamilton Circuit from vertex D. Write your final answer starting at the reference point A. Example: A band is planning a concert tour through 10 cities including their hometown “A”. The distances are given in the chart (yes, I know I used this example earlier for TSPs… hang on, I’m making a point)

It is logical that the MORE Hamilton Circuits that we check, the better the chance of finding a circuit that is closer to the optimal answer. The Nearest Neighbor Method is dependent on the vertex you start at. If you start at a different vertex, you will most likely get a different answer. (See table above) Remember you can rewrite any circuit so that it starts with a different reference point. With 10 vertices, there are _______________ possible circuits including mirror images. The table shows the nearest-neighbor tour found from each vertex. So we are only looking at ______ tours…. And really we only found ______ distinct values. We could rewrite any of these circuits starting at a different reference point “A”!

Finite Math A Chapter 6 Notes Hamilton Circuits

10

Example: Use the Repetitive Nearest Neighbor Method to find the Hamilton Circuit for Willy Loman’s sales district.

The Repetitive Nearest Neighbor Algorithm 1. Let X be any vertex. Find the nearest-neighbor tour with X as the starting vertex and calculate the cost of this tour. 2. Repeat the process with each of the other vertices of the graph as the starting vertex. 3. Choose the tour with the least cost. If necessary, rewrite the tour so that it starts at the designated starting vertex. The tour we get is called the repetitive nearest-neighbor tour.

Finite Math A Chapter 6 Notes Hamilton Circuits

11

Examples: Use the Repetitive Nearest Neighbor Method to find a Hamilton Circuit and its weight. 1. Home City A

2. Home city B 3. Home City Z

V W X Y Z

V ** $35 $10 $20 $45

W $35 ** $42 $37 $60

X $10 $42 ** $30 $50

Y $20 $37 $30 ** $77

Z $45 $60 $50 $77 **

A B

D C

1

7

4

3

6

2

Finite Math A Chapter 6 Notes Hamilton Circuits

12

6.5 Cheapest Link Method So far we’ve been considering the creation of a Hamilton Circuit in order from a specific starting point. What if we ignored that? Let’s look at the graph as a set of potential LINKS between cities. As long as we are very careful they are all connected at the end, it doesn’t matter if at some point in the process they are disconnected. BE CAREFUL:

Don’t close your circuit until the very end!

You only need to go IN and OUT of each vertex, so you never need three edges from any one vertex.

If you have N vertices, you will have N edges in your final circuit.

Example: Use the cheapest link algorithm to find a Hamilton Circuit.

The Cheapest Link Algorithm 1. Step 1: Pick the cheapest link available. (If there is more than one, randomly pick on among the cheapest links) Highlight the link in red (or any other color). 2. Step 2: Pick the next cheapest link and highlight it. 3. Steps 3 to N-1: Continue picking and highlighting the cheapest link available that (a) DOES NOT close a partial circuit (b) DOES NOT create three edges meeting at the same vertex. 4. Step N: Connect the two vertices that close the highlighted circuit. Once you have the Hamilton circuit, write it from the designated starting vertex. Either clockwise or counter-clockwise travel give you a tour we call the cheapest-link tour.

Finite Math A Chapter 6 Notes Hamilton Circuits

13

Examples: Use the Cheapest Link Method to find a Hamilton Circuit. 1. Home City A

2. Home city D 3. Home City Z

V W X Y Z

V ** $35 $10 $20 $45

W $35 ** $42 $37 $60

X $10 $42 ** $30 $50

Y $20 $37 $30 ** $77

Z $45 $60 $50 $77 **

A B

D C

1

7

4

3

6

2

Finite Math A Chapter 6 Notes Hamilton Circuits

14

Relative Error The Brute Force Method is _________________________ but ______________________________. The Nearest Neighbor, Repetitive Nearest Neighbor, and Cheapest Link Methods are __________________________ but only ___________________________. So far, no one has been able to produce an optimal, efficient algorithm for solving TSP’s. Also, no one has proved that an optimal, efficient algorithm is impossible. We can determine how accurate our answers are using something called “relative error”.

What were the values from Willy Loman’s Hamilton Circuits using: Brute Force: ____________ (optimal) Nearest Neighbor: ___________ Relative Error = Repetitive Nearest Neighbor ____________ Relative Error = Cheapest Link ____________ Relative Error =

Finite Math A Chapter 6 Notes Hamilton Circuits

15

Putting it all together: 1. In order to find an optimal Hamilton Circuit for the graph at the right you would need to check how many Hamilton Circuits to use the BRUTE FORCE METHOD? 2. Find a Hamilton Circuit and its weight starting at “C” using the NEAREST-NEIGHBOR METHOD. 3. Find a Hamilton Circuit and its weight starting at “C” using the REPETITIVE NEAREST-NEIGHBOR METHOD. 4. Use the CHEAPEST LINK ALGORITHM to find a Hamilton Circuit and its weight that starts at “C”. (Picture repeated for your highlighting convenience)