Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Traveling-Salesman Problem. Born August 4, 1805 in Dublin, Ireland Died September 2, 1865 in Dublin, Ireland Made many contributions to the Physics.

Similar presentations


Presentation on theme: "The Traveling-Salesman Problem. Born August 4, 1805 in Dublin, Ireland Died September 2, 1865 in Dublin, Ireland Made many contributions to the Physics."— Presentation transcript:

1 The Traveling-Salesman Problem

2 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 3 rd and 4 th 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 Path: a path touching every vertex exactly once  every edge does NOT have to be used F B A C D ADEBCF Hamilton Path Examples DABEGF EBADEG G C F NOT a Hamilton Path (Example) C E G

4 Hamilton Circuit: a circuit touching every vertex exactly once  every edge does NOT have to be used F D B A C E ADBCFE Hamilton Circuit Examples DAEFCB EFDABC A D F NOT a Hamilton Circuit (Example) E

5 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 Hamilton Circuit Examples A E B C D 2 3 511 3 8 6 9 ABCDEA AEBCDA Hamilton Path Examples ABCDE AEBCD

6 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 K N  vertices can be named in any order for Hamilton Circuits Formula for the Number of Hamilton Circuits: Complete Graph Examples A CB AB CD A E B CD A G C D B F H E K 3 2 HC’s K 4 6 HC’s K 5 24 HC’s K 8 5,040 HC’s

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

9 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. Los Angeles Dallas Chicago Miami New York

10 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a DALLASn/a LOS ANGELES n/a MIAMIn/a NEW YORK n/a

11 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLASn/a LOS ANGELES n/a MIAMIn/a NEW YORK n/a

12 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES n/a MIAMIn/a NEW YORK n/a

13 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMIn/a NEW YORK n/a

14 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK n/a

15 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

16 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

17 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One.

18 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,362 1 2 3 4 5 $952 $937 $907 $787 $779 Brute-Force

19 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,687 1 2 3 4 5 $952 $937 $1,147 $787 $864 Brute-Force

21 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,320 1 2 3 4 5 $952 $818 $907 $864 $779 Brute-Force

23 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,220 1 2 5 3 4 $952 $818 $799 $787 $864 Brute-Force

25 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,964 1 2 4 5 3 $952 $1,094 $907 $1,147 $864 Brute-Force

27 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,539 1 2 4 5 3 $952 $1,094 $907 $799 $787 Brute-Force

29 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) 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 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 1 2 3 4 5 $799 $937 $818 $787 $779 Brute-Force

31 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. DAL–MIA–NY–CHI–LA–DAL = $799 + $937 + $818 + $787 + $779 = $4,120 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

32 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,764 1 2 3 4 5 $799 $937 $1,094 $787 $1,147 Brute-Force

33 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. 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–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

34 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,397 1 3 2 4 5 $799 $818 $907 $1,094 $779 Brute-Force

35 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. 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–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

36 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,722 1 5 2 4 3 $799 $1,147 $864 $818 $1,094 Brute-Force

37 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. 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–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–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722

38 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,545 1 2 2 4 5 $1,147 $937 $818 $864 $779 Brute-Force

39 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. 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–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–CHI–NY–MIA–LA–DAL = $1,147 + $818 + $937 + $864 + $779 = $4,545 DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722

40 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,864 1 3 2 4 5 $1,147 $937 $907 $1,094 $779 Brute-Force

41 Steps for Solving the 5 Cities Example a) Make a list of ALL possible Hamilton Circuits. b) Calculate the Total Weight of EVERY Hamilton Circuit & Find the Cheapest One. 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–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–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 DAL–MIA–LA–NY–CHI–DAL = $799 + $864 + $1,094 + $818 + $1,147 = $4,722

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

43 Steps for the Nearest-Neighbor Algorithm a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. a) Once you get to the last vertex, connect it back to the starting vertex. 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.

44 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

45 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

46 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

47 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

48 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147 $ 779 $ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

49 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787$ 779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

50 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

51 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 $ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

52 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

53 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

54 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907 $ 818 DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

55 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

56 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 937

57 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 937

58 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 937 (4)

59 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI $799 NEW YORK $ 937 (4)

60 Steps for Solving the 5 Cities Example a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 907$ 818 (3) DALLAS$ 1,147$ 779 (1)$ 799$ 952 LOS ANGELES $ 787 (2)$ 864$ 1,094 MIAMI$799 (5) NEW YORK $ 937 (4)

61 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 5 4 3 2 1 $799 $937 $818 $787 $779 Nearest-Neighbor

62 Steps for the Repetitive Nearest-Neighbor Algorithm a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. d) Repeat the process until EVERY vertex has become the starting/ending vertex. If Jerry applied the Nearest-Neighbor Algorithm to his flight plans, he would have been able to find the cheapest route without as much work. The question that follows is, “Why ever use the Brute-Force Method if the Nearest-Neighbor Algorithm works?” Lets look at the same 5 City Example, but this time find out if the Nearest-Neighbor Algorithm works no matter what city Jerry lives in.

63 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

64 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

65 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

66 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

67 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 $ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

68 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

69 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $779$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

70 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $779 $ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

71 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

72 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

73 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS $ 799 $ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

74 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

75 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

76 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI $ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

77 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 937 (4) NEW YORK $ 818$952$ 1,094$ 937n/a

78 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 937 (4) NEW YORK $ 818

79 Steps for Solving the 5 Cities Example – Home: Chicago a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (1)$ 907$ 818 DALLAS$ 799 (3)$ 952 LOS ANGELES $779 (2)$ 864$ 1,094 MIAMI$ 937 (4) NEW YORK $ 818 (5)

80 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 3 4 5 1 2 $799 $937 $818 $787 $779 Nearest-Neighbor

81 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

82 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787 $779 $ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

83 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147 $ 799 $ 952 LOS ANGELES $ 787$779 (1)$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

84 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 799 (2)$ 952 LOS ANGELES $ 787$779 (1)$ 864$ 1,094 MIAMI $ 907 $ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

85 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO $ 818 DALLAS$ 1,147$ 799 (2)$ 952 LOS ANGELES $ 787$779 (1)$ 864$ 1,094 MIAMI$ 907 (3)$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

86 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 818 (4) DALLAS$ 1,147$ 799 (2)$ 952 LOS ANGELES $ 787$779 (1)$ 864$ 1,094 MIAMI$ 907 (3)$ 937 NEW YORK $ 1,094

87 Steps for Solving the 5 Cities Example – Home: Los Angeles a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 818 (4) DALLAS$ 1,147$ 799 (2)$ 952 LOS ANGELES $ 787$779 (1)$ 864$ 1,094 MIAMI$ 907 (3)$ 937 NEW YORK $ 1,094 (5)

88 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,397 2 3 4 5 1 $799 $907 $818 $1,094 $779 Nearest-Neighbor

89 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

90 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907 $799 $ 864$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

91 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147 $ 779 $ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799 (1)$ 864$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

92 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779 (2)$ 952 LOS ANGELES $ 787 $ 1,094 MIAMI$ 907$799 (1)$ 864$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

93 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO $ 818 DALLAS$ 1,147$ 779 (2)$ 952 LOS ANGELES $ 787 (3)$ 1,094 MIAMI$ 907$799 (1)$ 864$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

94 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 818 (4) DALLAS$ 1,147$ 779 (2)$ 952 LOS ANGELES $ 787 (3)$ 1,094 MIAMI$ 907$799 (1)$ 864$ 937 NEW YORK $ 937

95 Steps for Solving the 5 Cities Example – Home: Miami a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 818 (4) DALLAS$ 1,147$ 779 (2)$ 952 LOS ANGELES $ 787 (3)$ 1,094 MIAMI$ 907$799 (1)$ 864$ 937 NEW YORK $ 937 (5)

96 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 1 5 4 3 2 $799 $937 $818 $787 $779 Nearest-Neighbor

97 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a

98 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818 $952$ 1,094$ 937

99 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 $ 907 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818 (1)$952$ 1,094$ 937

100 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (2)$ 907 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $779 $ 864 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818 (1)$952$ 1,094$ 937

101 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (2)$ 907 DALLAS $ 799 LOS ANGELES $779 (3)$ 864 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818 (1)$952$ 1,094$ 937

102 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (2)$ 907 DALLAS$ 799 (4) LOS ANGELES $779 (3)$ 864 MIAMI $ 937 NEW YORK $ 818 (1)$952$ 1,094$ 937

103 Steps for Solving the 5 Cities Example – Home: New York a) Pick a Starting Vertex. b) Travel to the Closest (Cheapest) Vertex. Repeat until ALL vertices are used 1 time. c) Once you get to the last vertex, connect it back to the starting vertex. CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787 (2)$ 907 DALLAS$ 799 (4) LOS ANGELES $779 (3)$ 864 MIAMI$ 937 (5) NEW YORK $ 818 (1)$952$ 1,094$ 937

104 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 4 5 1 2 3 $799 $937 $818 $787 $779 Nearest-Neighbor

105 Conclusion for the 5 Cities Example HOME CITYCOST OF CIRCUIT Chicago$ 4,120 Dallas$ 4,120 Los Angeles$ 4,397 Miami$ 4,120 New York$ 4,120 This shows us that if Jerry lived in Los Angeles, it would not have been beneficial for him to trust the Nearest-Neighbor Algorithm. This does not mean he should not live in Los Angeles. It just shows that if using the Nearest-Neighbor Algorithm, you must check it from all the possible vertices to guarantee your answer is the cheapest.

106 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGOn/a$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147n/a$ 779$ 799$ 952 LOS ANGELES $ 787$779n/a$ 864$ 1,094 MIAMI$ 907$799$ 864n/a$ 937 NEW YORK $ 818$952$ 1,094$ 937n/a Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

107 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787$ 907$ 818 DALLAS$ 1,147$ 779$ 799$ 952 LOS ANGELES $ 787$779$ 864$ 1,094 MIAMI$ 907$799$ 864$ 937 NEW YORK $ 818$952$ 1,094$ 937 Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

108 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787$ 907$ 818 DALLAS$ 779$ 799$ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

109 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787$ 907$ 818 DALLAS $ 779 $ 799$ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

110 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link

111 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147$ 787$ 907$ 818 DALLAS $ 779 (1) $ 799$ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

112 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 $ 907$ 818 DALLAS $ 779 (1) $ 799$ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

113 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link $787

114 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907$ 818 DALLAS $ 779 (1) $ 799$ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

115 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907$ 818 DALLAS $ 779 (1) $ 799 $ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

116 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link $787 $799

117 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907$ 818 DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

118 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

119 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link $787 $799 $818

120 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 864$ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

121 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 864 $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

122 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link $787 $799 $818 $864

123 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 864 $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

124 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

125 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

126 Los Angeles Dallas Chicago Miami New York TOTAL COST: $779 Cheapest-Link $787 $799 $818 $907

127 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2) $ 907 $ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

128 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2)$ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 1,094 MIAMI$ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

129 CITIESCHICAGODALLAS LOS ANGELES MIAMI NEW YORK CHICAGO$ 1,147 $ 787 (2)$ 818 (4) DALLAS $ 779 (1)$ 799 (3) $ 952 LOS ANGELES $ 1,094 MIAMI $ 937 NEW YORK Steps for Solving the 5 Cities Example a) Pick the edge with the smallest weight first. (if a tie, randomly choose one) b) Pick the next smallest edge. (make sure you mark each edge used – only use once) c) Repeat the process until EVERY vertex has been linked. (using each vertex once) d) Once every vertex has been used, link the last vertex back to the starting vertex.

130 Los Angeles Dallas Chicago Miami New York TOTAL COST: $ 4,120 $779 Cheapest-Link $787 $799 $818 $937

131 You Now Know All About


Download ppt "The Traveling-Salesman Problem. Born August 4, 1805 in Dublin, Ireland Died September 2, 1865 in Dublin, Ireland Made many contributions to the Physics."

Similar presentations


Ads by Google