1 / 131

HAMILTON CIRCUITS

DISCRETE MATH UNIT 6. HAMILTON CIRCUITS. The Traveling-Salesman Problem. William Rowan Hamilton. Born August 4, 1805 in Dublin, Ireland Died September 2, 1865 in Dublin, Ireland Made many contributions to the Physics field including advancements in the study of optics and dynamics

Télécharger la présentation

HAMILTON CIRCUITS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DISCRETE MATH UNIT 6 HAMILTON CIRCUITS The Traveling-Salesman Problem

  2. William Rowan Hamilton • Born August 4, 1805 in Dublin, Ireland • Died September 2, 1865 in Dublin, Ireland • Made many contributions to the Physics field • including advancements in the study of optics • and dynamics • Introductions to the Mathematics Field • formed the study of quaternion • an extension of complex numbers that allows work in the 3rd • and 4th dimensions (symbolized by a bold H) • invented the Icosian Game (now called Hamilton’s Puzzle) • solved by using Icosian Calculus and these solutions developed into • what are now called Hamilton Paths and Hamilton Circuits

  3. Hamilton Paths • Hamilton Path: a path touching every vertex exactly once • every edge does NOT have to be used B A C E D Hamilton Path Examples       F A D E B C F G G       D A B E G F C NOT a Hamilton Path (Example)        E B A D E G F C

  4. Hamilton Circuits • Hamilton Circuit: a circuit touching every vertex exactly once • every edge does NOT have to be used C B A Hamilton Circuit Examples D       F A D B C F E A E       D A E F C B D NOT a Hamilton Circuit (Example)        E F D A B C F E

  5. Weighted Circuits & Paths Weight: a numerical value assigned to each edge of the graph Total Weight: the sum of the edges’ weights used to complete the Hamilton Circuit or Path A 3 Hamilton Path Examples 2 B 6 =20 E     A B C D E 9 8 =20     5 11 A E B C D D Hamilton Circuit Examples C 3 =22      A B C D E A =28      A E B C D A

  6. Complete Graphs • Complete Graph: a graph with N vertices with edges connecting • every pair of vertices • each vertex has a degree of (no loops) • denoted by the symbol KN • vertices can be named in any order for Hamilton Circuits Formula for the Number of Hamilton Circuits: Complete Graph Examples A B C A B A A B E G B C D D C H D C K3 2 HC’s K4 6 HC’s K5 24 HC’s E F K8 5,040 HC’s

  7. Traveling-Salesman Problem • Name originates from the classic problem of a traveling-salesman • needing to find the cheapest circuit that will allow him to visit multiple • clients by traveling to each city just 1 time. • the acronym TSP is used to identify this type of problem • TSPs are used to identify any type of problem that wants to find the • cheapest route while touching every vertex exactly 1 time. • Other Examples of TSPs: • Package Deliveries • School Bus Routes • Fabricating Circuit Boards • Scheduling Jobs on a Machine • Running Errands Around Town

  8. Algorithms for Solving TSPs • Brute-Force Algorithm • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. • Nearest-Neighbor Algorithm • Pick a Starting Vertex. • Travel to The Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex. • Repetitive Nearest-Neighbor Algorithm • Pick a Starting Vertex. • Follow the Steps for the Nearest-Neighbor Algorithm (above). • Repeat the process until EVERY vertex has become the starting/ending vertex. • Cheapest-Link Algorithm • Pick the edge with the smallest weight first. (if a tie, randomly choose one) • Pick the next smallest edge. (make sure you mark each edge used – only use once) • Repeat the process until EVERY vertex has been linked. (using each vertex once) • Once every vertex has been used, link the last vertex back to the starting vertex.

  9. Example TSP (5 Cities) Jerry is the Managing Partner of the “You’re Not Guilty” Law Firm. Part of managing one of the top law firms in the country is having to travel to all 5 of their major offices each month to meet with the partners. While Jerry lives in Dallas, he must visit Chicago, Los Angeles, Miami, and New York. Traveling obviously costs money and in order for clients not to feel like they are being overcharged, Jerry has to make sure that he travels to all 5 cities for as little as possible. We must find the most cost effective means for him to travel between these cities and end back home in Dallas. The cost of flights from each city is found on the following slides. New York Chicago Los Angeles Dallas Miami

  10. Flight Prices Between Cities

  11. Flight Prices Between Cities

  12. Flight Prices Between Cities

  13. Flight Prices Between Cities

  14. Flight Prices Between Cities

  15. Flight Prices Between Cities

  16. Flight Prices Between Cities

  17. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.

  18. Flight Path & Cost of Circuit Chicago New York $787 4 $952 1 $907 2 3 $937 5 Los Angeles $779 Brute-Force TOTAL COST: $ 4,362 Miami Dallas

  19. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362

  20. Flight Path & Cost of Circuit Chicago New York $787 4 $952 1 $1,147 5 2 $937 3 $864 Los Angeles Brute-Force TOTAL COST: $ 4,687 Miami Dallas

  21. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687

  22. Flight Path & Cost of Circuit Chicago New York $818 2 $952 1 3 $864 5 $907 4 Los Angeles $779 Brute-Force TOTAL COST: $ 4,320 Miami Dallas

  23. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320

  24. Flight Path & Cost of Circuit Chicago New York $818 2 $787 3 $952 1 $864 4 Los Angeles 5 Brute-Force TOTAL COST: $ 4,220 $799 Miami Dallas

  25. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220

  26. Flight Path & Cost of Circuit Chicago New York 2 $1,094 $952 1 $907 4 5 Los Angeles $1,147 3 $864 Brute-Force TOTAL COST: $ 4,964 Miami Dallas

  27. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964

  28. Flight Path & Cost of Circuit Chicago New York 2 $1,094 3 $952 1 $787 4 $907 Los Angeles 5 Brute-Force TOTAL COST: $ 4,539 $799 Miami Dallas

  29. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539

  30. Flight Path & Cost of Circuit Chicago New York $818 3 $787 4 2 $937 5 Los Angeles $779 1 Brute-Force TOTAL COST: $ 4,120 $799 Miami Dallas

  31. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120

  32. Flight Path & Cost of Circuit Chicago 3 New York $1,094 $787 4 2 5 $937 Los Angeles $1,147 1 Brute-Force TOTAL COST: $ 4,764 $799 Miami Dallas

  33. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764

  34. Flight Path & Cost of Circuit Chicago New York $818 3 $1,094 4 $907 2 5 Los Angeles $779 1 Brute-Force TOTAL COST: $ 4,397 $799 Miami Dallas

  35. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764 DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397

  36. Flight Path & Cost of Circuit Chicago New York $818 4 3 $1,094 5 2 $1,147 $864 Los Angeles 1 Brute-Force TOTAL COST: $ 4,722 $799 Miami Dallas

  37. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764 DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397 DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722

  38. Flight Path & Cost of Circuit Chicago New York $818 2 $1,147 1 2 $937 5 Los Angeles $779 $864 4 Brute-Force TOTAL COST: $ 4,545 Miami Dallas

  39. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764 DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397 DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722 DAL–CHI–NY–MIA–LA–DAL = $1,147 + $818 + $937 + $864 + $779 = $4,545

  40. Flight Path & Cost of Circuit Chicago New York 4 $1,094 $1,147 1 2 3 $937 5 Los Angeles $907 $779 Brute-Force TOTAL COST: $ 4,864 Miami Dallas

  41. Brute-Force Algorithm • Steps for Solving the 5 Cities Example • Make a list of ALL possible Hamilton Circuits. • Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–NY–MIA–CHI–LA–DAL = $952 + $937 + $907 + $787 + $779 = $4,362 DAL–NY–MIA–LA–CHI–DAL = $952 + $937 + $864 + $787 + $1,147 = $4,687 DAL–NY–CHI–MIA–LA–DAL = $952 + $818 + $907 + $864 + $779 = $4,320 DAL–NY–CHI–LA–MIA–DAL = $952 + $818 + $787 + $864 + $799 = $4,220 DAL–NY–LA–MIA–CHI–DAL = $952 + $1,094 + $864 + $907 + $1,147 = $4,964 DAL–NY–LA–CHI–MIA–DAL = $952 + $1,094 + $787 + $907 + $799 = $4,539 DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 DAL–MIA–NY–LA–CHI–DAL = $799 + $937 + $1,094 + $787 + $1,147 = $4,764 DAL–MIA–CHI–NY–LA–DAL = $799 + $907 + $818 + $1,094 + $779 = $4,397 DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722 DAL–CHI–NY–MIA–LA–DAL = $1,147 + $818 + $937 + $864 + $779 = $4,545 DAL–CHI–MIA–NY–LA–DAL = $1,147 + $907 + $937 + $1,094 + $779 = $4,864

  42. Cheapest Circuit Found Since each circuit can be traveled in 2 directions, we only had to look at 12 circuits to cover all 24 possibilities. Chicago New York $818 3 3 $787 2 4 This circuit can be traveled in either direction. 2 4 $937 1 5 Los Angeles $779 1 5 TOTAL COST: $ 4,120 $799 Miami Dallas

  43. Nearest-Neighbor Algorithm While the Brute-Force Algorithm will ALWAYS find the cheapest method, it is not very time friendly. The Nearest-Neighbor Algorithm is a method that allows you to find the “cheapest” circuit without having to analyze every possible circuit. • Steps for the Nearest-Neighbor Algorithm • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL • vertices are used 1 time. • Once you get to the last vertex, connect it back to the • starting vertex.

  44. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  45. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  46. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  47. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  48. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  49. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

  50. Nearest-Neighbor Algorithm • Steps for Solving the 5 Cities Example • Pick a Starting Vertex. • Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. • Once you get to the last vertex, connect it back to the starting vertex.

More Related