Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2: Business Efficiency Hamiltonian Circuit Visiting Vertices –In some graph theory problems, it is only necessary to visit specific locations (using.

Similar presentations


Presentation on theme: "Chapter 2: Business Efficiency Hamiltonian Circuit Visiting Vertices –In some graph theory problems, it is only necessary to visit specific locations (using."— Presentation transcript:

1 Chapter 2: Business Efficiency Hamiltonian Circuit Visiting Vertices –In some graph theory problems, it is only necessary to visit specific locations (using the travel routes, or streets available). –Problem: Find an efficient route along distinct edges of a graph that visits each vertex only once in a simple circuit. 1

2 Chapter 2: Business Efficiency Hamiltonian Circuit 2 Applications: Salesman visiting particular cities Delivering mail to drop-off boxes Route taken by a snowplow Pharmaceutical representative visiting doctors

3 Hamiltonian Circuit Suppose we change the “Bridges of Konigsberg” problem so that we visit each land mass exactly once. Does this make the problem easier to do? 3 L R K O YES!!

4 Chapter 2: Hamilton Circuits Outline/Learning Objectives To identify and model Hamilton circuit problems. To use the following algorithms to determine the optimal route for a Traveling Salesman Problem. –Nearest Neighbor and Sorted Edges Algorithms –Minimum-Cost Spanning Trees Kruskal’s Algorithm

5 (1805 – 1865) He was a renowned Irish mathematician and astronomer. He was a child prodigy. He could read English, Hebrew, Greek, and Latin by the time he was 4 yrs old. He became Professor of Astronomy at Trinity College in Dublin, Ireland when he was 23 yrs old. 5 Sir William Rowan Hamilton

6 Starting at vertex A, the tour can be written as ABDGIHFECA, or starting at E, it would be EFHIGDBACE. Hamiltonian Circuit: A path that starts and ends at the same vertex. Visits each vertex only once. A different circuit visiting each vertex once and only once would be CDBIGFEHAC (starting at vertex C).

7 -Circuits can start at any location. - Notice that we don’t care that we don’t use all the edges. -Use wiggly edges to show the circuit. -Unfortunately, there are no theorems that tell us whether or not a graph has a Hamilton Circuit. 7 Starting at vertex A, the tour can be written as ABDGIHFECA, or starting at E, it would be EFHIGDBACE. Hamiltonian Circuit: A different circuit visiting each vertex once and only once would be CDBIGFEHAC (starting at vertex C).

8 8 Hamiltonian Circuit vs. Euler Circuits Hamiltonian circuit – A path (shown by wiggly edges) that starts at a vertex of a graph and visits each vertex once and only once, returning to where it started. Euler circuit – A circuit that traverses each edge of a graph exactly once and starts and stops at the same vertex.

9 Similarities –Both forbid re-use. Hamiltonian didn’t reuse vertices. Euler didn’t reuse edges. Differences –Hamiltonian is a circuit of vertices. –Euler is a circuit of edges. –Euler graphs are easy to spot (connectedness and even valence). –Hamiltonian circuits are NOT as easy to determine upon inspection. 9 Hamiltonian Circuit vs. Euler Circuits

10 10 Hamiltonian Circuit vs. Euler Circuits Find both an Euler and Hamilton Circuit A B D G F E C Hamilton: one possible solution: AGFECDBA Euler: B and D have odd valences. Therefore, there is NO Euler Circuit.

11 What are the possible Hamilton Circuits for this graph? 11 A B D C One possible route: ABCDA or ADCBA Others: ABDCA or ACDBA ACBDA or ADBCA only 3 Notice that there are “mirror images” so then there are really only 3 different Hamilton circuits.

12 What are the possible Hamilton Circuits for this graph if we start at A? 12 A B D C ABCDA or ADCBA ABDCA or ACDBA ACBDA or ADBCA When we start at A how many ways can we travel: If we choose B, how many ways can we travel: If we choose D, how many ways can we travel: This means that we can have 3 x 2 x 1 possible different combinations. This can be written as 3! How does 3 relate to the number of vertices? 3! = 6, but half were mirror images so 3!/2 = 3 would be the correct amount of unique Hamilton circuits. 3 (B, D, C) 2 (D, C) 1 (C) One less than

13 Unique Hamilton Circuits 13 Principle of Counting for Hamiltonian Circuits –For a complete graph of n vertices, there are (n - 1)! possible routes. –Half of these routes are repeats, the result is: Possible unique Hamiltonian circuits are (n - 1)! / 2 Complete graph – A graph in which every pair of vertices is joined by an edge. Fundamental Principle of Counting If there are a ways of choosing one thing, b ways of choosing a second after the first is chosen, c ways of choosing a third after the second is chosen…, and so on…, and z ways of choosing the last item after the earlier choices, then the total number of choice patterns is a × b × c × … × z. Example: Jack has 9 shirts and 4 pairs of pants. He can wear 9 × 4 = 36 shirt-pant outfits.

14 How many unique Hamilton circuits are there and name one. 14 D A E C B 5 vertices so there are 4! Hamilton circuits. 4! = 24 circuits 24/2 = 12 unique circuits (Be happy. I will only ask you to find one!) Example: ABCDEA

15 Weighted Graphs Vacation–Planning Problem  What would be the best route to take if you want to visit all 4 cities?  Hamiltonian circuit concept is used to find the best route (optimal route) that minimizes the total distance traveled to visit friends in different cities. (assume less mileage  less gas  minimizes costs) Road mileage between four cities 15 Hamiltonian circuit with weighted edges  Edges of the graph are given weights, or in this case mileage or distance between cities.  As you travel from vertex to vertex, add the numbers (mileage in this case).  Each Hamiltonian circuit will produce a particular sum.

16 WWeighted graph – has numbers assigned to an edge that can be thought of as cost, distance, or time. OOptimal solution – when a problem has various solutions and you pick the best solution for you. AAlgorithm – A step-by-step description of how to solve a problem. Heuristic Algorithm – A “fast” method that doesn’t guarantee an optimal answer. Definitions

17 17 Weighted Graphs where the number of vertices in a complete graph are very large. Difficult to solve Hamiltonian circuits. This problem originated from a salesman determining his trip that minimizes costs (less mileage) as he visits the cities in a sales territory, starting and ending the trip in the same city. Many applications today: bus schedules mail drop-offs to post offices Candy machine coin pick-up routes UPS Running phone lines or cable Water lines Traveling Salesman Problem (TSP)

18 18 How can the TSP be solved? Computer program can find optimal route (not always practical). Exhaustive search called Brute Force Algorithm (Trees can be used) Heuristic methods can be used to find a “fast” answer, but does not guarantee that it is always the optimal answer. – Nearest Neighbor Algorithm (NNA) – Sorted Edges Algorithm (also known as “Cheapest Link”) –Kruskal’s Algorithm (Minimum Spanning Trees) Traveling Salesman Problem (TSP)

19 19 1)Brute Force Algorithm – optimal algorithm that always works but inefficient. Creates a Hamilton Circuit. 2) Nearest-Neighbor Algorithm (NNA) – not optimal but efficient. Creates a Hamilton Circuit. 3) Sorted-Edges Algorithm - not optimal but efficient. Creates a Hamilton Circuit. 4) Kruskal’s Algorithm and Minimum Cost Spanning Trees - not optimal but efficient. Does NOT create a Hamilton Circuit. TSP Strategies for complete graphs

20 TSP Strategy Brute Force Algorithm Algorithm (step-by-step process) for solving this airplane route problem 20 1.Generate all possible Hamiltonian tours (paths) using a table. 2.Add up the distances on the edges of each tour. 3.Choose the tour of minimum distance. CL C M S

21 TSP Strategy Brute Force Algorithm Use the Brute Force Algorithm to determine the optimal Hamilton Circuit. 21 Hamilton CircuitWeightsTotal Weight C,S,M,CL,C (or C,CL,M,S,C) C,M,CL,S,C (or C,S,CL,M,C) C,M,S,CL,C (or C,CL,S,M,C) 300 + 562 + 774 + 349 425 + 774 + 541 + 300 425 + 562 + 541 + 349 1,985 2,040 1,877

22 TSP Strategy Brute Force Algorithm The optimal Hamilton Circuit is: C,M,S,CL,C Chicago, Minn., St. Louis, Cleveland, and back to Chicago. 22

23 TSP Strategy Brute Force Algorithm and Trees 23 This method begins by selecting a starting vertex, say Chicago, and making a tree- diagram showing the next possible locations. In this example, the method of trees generated six different paths, all starting and ending with Chicago. However, only three are unique circuits. At the end of each path put total weight. Instead of creating a table, you create a tree.

24 TSP Strategy Brute Force Algorithm and Trees 425 349 562 774 541 774 300 562 187719852040198520401877 Definition: Tree – connected graph with NO circuits.

25 Use the Brute Force Algorithm to determine the optimal Hamilton Circuit. 25 D A E B C 500 205 360 340 305 320 302 165 185 200 How many Hamilton Circuits are there? How many are unique Hamilton Circuits? (5-1)! = 4! = 24 24/2 = 12

26 Use the Brute Force Algorithm to determine the optimal Hamilton Circuit. 26 Hamilton Circuit Weights Total weight Hamilton Circuit Weights Total weight ABCDEA ACEBDA ACEDBA ACDEBA ACDBEA ACBEDA ACBDEA ABECDA ABEDCA ABDECA ABDCEA ABCEDA ADBCEA ADECBA ADEBCA ADCBEA ADCEBA ADBECA AEBCDA AEDCBA AEDBCA AECDBA AECBDA AEBDCA 320+305+500 +205+302 1632 1527 1457 1355 1220 1457 1510 1250 1332 1250 1425 1550 1527 1220 1372 1510 1550 1425 1662 1632 1355 1372 1662 1332

27 Use the Tree method to determine the optimal Hamilton Circuit. A BCDE BCEBCD CDEBDE D C B D BC CE B E BCD E B E B DE C E CDD E D E C DCE DE B DB ECEBCBCDDBCB A A A A AAAAA A AAAAAAAAAAAA AA

28 TSP Strategy Nearest Neighbor Algorithm (NNA) 28 NNA starting at vertex A Hamiltonian Circuit: A-B-C-E-D-A 1)Pick a “home” city (or vertex). 2)Travel from vertex to vertex by always choosing the next vertex that can be reached quickest (least miles), that has not already been visited. 3)When all vertices have been visited, the tour returns home. NNA starting at vertex B Hamiltonian Circuit: B-C-A-D-E-B

29 Use the NNA to determine the optimal Hamilton Circuit. 29 D A E B C 500 205 360 340 305 320 302 165 185 200 Starting vertex Nearest Neighbor Nearest Neighbor Nearest Neighbor Nearest Neighbor Back to start Total AA DCEB 1250 360340165200185

30 TSP Strategy Sorted Edges Algorithm 1)Start by sorting, or arranging, the edges in order of increasing weight (smallest to largest mileage between cities). 2)Choose an edge with lowest weight a)That will NOT result in three edges meeting at a vertex b)That will NOT close up a path that doesn’t include all vertices 3)Repeat #2 until all vertices are used. 4)From last vertex, return to start 30 D A E B C 500 205 360 340 305 320 302 165 185 200

31 TSP Strategy Sorted Edges Algorithm 31 D A E B C 500 205 360 340 305 320 302 165 185 200 1)Arrange edges in order low to high: BE 165 AD 185 BD 200 ED 205 AE 302 BC 305 AB 320 EC 340 AC 360 DC 500

32 D A E B C BE 165 AD 185 BD 200 ED 205 AE 302 BC 305 AB 320 EC 340 AC 360 DC 500 Total: circuit 3 edges Not needed 1250 Hamilton circuit: ADBECA or ACEBDA Step 2) Choose an edge with lowest weight That will NOT result in three edges meeting at a vertex That will NOT close up a path that doesn’t include all vertices Step 3) Repeat #2 until all vertices are used. Step 4) From last vertex, return to start

33 Recall the Tree method to determine the optimal Hamilton Circuit. A BCDE BCEBCD CDEBDE D C B D BC CE B E BCD E B E B DE C E CDD E D E C DCE DE B DB ECEBCBCDDBCB A A A A AAAAA A AAAAAAAAAAAA AA

34 Definition: Spanning Tree – is a subgraph that connects all vertices and has NO circuits. Therefore, you don’t go back to A at the end. Each branch of a tree is a “spanning tree”

35 TSP Strategy - Spanning Trees 35 D A E B C Spanning trees look more like this: B C E D A Spanning trees don’t really look like this though.

36 TSP Strategy - Spanning Trees 36 D A E B C D A E B C Original:Example 1) D A E B C Example 2)

37 Minimum-Cost Spanning Trees and Kruskal's Algorithm 37 Goal of minimum-cost spanning tree: Create a tree that links all the vertices together and achieves the lowest cost to create. The cost of the tree is the sum of the weights on the edges.

38 Minimum-Cost Spanning Trees and Kruskal's Algorithm 38 Kruskal’s Algorithm — Developed by Joseph Kruskal (AT&T research). –Add links in order of cheapest cost according to the rules: No circuit is created (no loops). –If a circuit (or loop) is created by adding the next largest link, eliminate this largest (most expensive link)—it is not needed. Every vertex must be included in the final tree.

39 TSP Strategy Minimum-Cost Spanning Trees 39 D A E B C 500 205 360 340 305 320 165 185 200 Kruskal's Algorithm 1) On every step mark the cheapest unmarked edge. - See that the marked edges do not form circuits (loops). 2) Repeat while possible until all vertices are connected. 302 Total distance: 855 miles

40 Minimum-Cost Spanning Trees and Kruskal's Algorithm 40 The diagram shows the cost to build the connection from each vertex to all other vertices (connected graph). Costs (in millions of dollars) of installing Pictaphone service among five cities The cost of redirecting the signal may be small compared to adding another link. Example: What is the cost to construct a Pictaphone service (telephone service with video image of the callers) among five cities? Total cost: $2.55 million


Download ppt "Chapter 2: Business Efficiency Hamiltonian Circuit Visiting Vertices –In some graph theory problems, it is only necessary to visit specific locations (using."

Similar presentations


Ads by Google