Chapter 6 Traveling Salesman Problem
ESSENTIAL QUESTIONS:
Section 6.1: How does Hamilton’s Circuits and Paths compare to Euler’s?
Section 6.2: What is a complete graph?
Section 6.3: What do the Trav
eling Salesman Problems (TSPs) use weighted grap
hs
?
Secti
on 6.4: What are simple strategies for solving TSPs?
Section 6.5: How does the Brute

Force and Nearest
–
Neighbor Algorithms solve TSPs?
Section 6.6: What is an approximate algorithm?
Section 6.7: How does the Repetitive Nearest
–
Neighbor Algorithm improv
e your ability to solve TSPs?
Section 6.8: How does the Cheapest

Link Algorithm differ from the Nearest

Neighbor Algorithm?
WORD WALL:
Brute

Force Algorithm
Cheapest

Link Algorithm
Complete Graph
Weight
Hamilton Circuit
Hamilton Path
Inefficient Algorith
m
Nearest

Neighbor Algorithm
Repetitive Nearest

Neighbor Algorithm
Traveling Salesman Problem (TSP)
Weighted Graph
Extra Review
/ Possible Homework
:
6.1
=
pp. 221

2 # 2, 4, 6, 7, 10, 11
6.2
= p 223 # 25
–
28
6.3
=
pp. 222
–
3 # 13
–
16
6.4
/
6.5
=
pp
. 223
–
225 # 29

31, 33, 35
6.7
= p. 225 #37
–
39, 41
6.8
=
pp. 225

6 #43

45, 47
Section 6.1: Hamilton Circuits and Hamilton Paths
EULER CIRCUITS AND PATHS
HAMILTON CIRCUITS AND PATHS
•
EULER = touch
each
EDGE
of a graph
exactly one time.
•
By Definit
ion
:
must touch every vertex
“can touch
more than once depending on degree”
•
HAMILTON = Touch
each
VERTEX
exactly
one time
(enter/ leave once)
.
•
By Definition:
Doesn’t require touching every edge
HAMILTON Circuits/Paths VERSUS EULER Circuits/Paths
For ea
ch of the following graphs, use our definitions of Hamilton and Euler to determine if circuits and
paths of each type are possible.
Graph 1
Graph 2
Graph 3
Graph 4
Graph 5
Graph 6
EULER
PATH
NO
YES
NO
NO
YES
NO
EULER
CIRCUIT
YES
NO
NO
YES
NO
N
O
HAMILTON
PATH
YES
YES
YES
YES
NO
YES
HAMILTON
CIRCUIT
YES
NO
YES
NO
NO
NO
What do you notice about the relationship between a graph having an Euler Circuit or Path and having a
Hamilton Circuit of path?
There is no relationship
IN GENERAL, THERE ARE
NO THEOREMS TO DETERMINE IF A GRAPH HAS A HAMILTON PATH
OR CIRCUIT.
HELPFUL HINT:
#1: FOR HAMILTON CIRCUITS/ PATHS, VERTICES OF DEGREE 1 OR 2 ARE
VERY HELPFUL BECAUSE THEY REPRESENT REQUIRED EDGES TO REACH
THAT VERTEX.
#2:
EXAMPLE: Hamilton Circuit
=
A, B, C, D, A
SHIFT/SAME
Hamilton Circuits:
Follows the
SAME rotation order
for a circuit, but
with a different start.
DISTINCT
Hamilton Circuits:
A
different order of vertices
(Left to Right)
from
the same starting vertex.
(reverse order counts)
B, C,
D, A, B
C, D, A, B, C
D, A, B, C, D
A, D, C, B, A
(reverse order)
A, D, B, C, A
AND reverse = A, C, B, D, A
A, B, D, C, A
AND reverse =
A, C, D, B, A
A
B
C
D
EXAMPLE #1: List all possible Hamiltonian circuits in the following graph
1.
A, B, C, D, E, F, G, A
2.
A, B, E, D, C, F, G, A
3.
A, F, C, D, C, B, G, A
4.
A, F, E, D, C, B, G, A
REVER
SE EACH ONE OF THESE 4 CIRCUITS
What about the Hamiltonian circuits that start at
B
,
C, D,
etc.?
Well, since such a circuit must pass through
all
of the vertices
it doesn’t matter
which vertex we start with
.
Related to the idea of shifts of circuits.
EXAMPLE #2:
(a)
Find a Hamiltonian path that begins at A and ends at E.
(b)
Find a Hamiltonian circuit that starts at A and ends with the pair of vertices E, A.
(c)
Find a Hamiltonian path that
begins at F and ends at G.
(a)
A, F, B, C, G, D, E
(b)
A, F, B, C, G, D, E, A
(c)
F, B, C, E, A, D, G
F, A, E, B, C, D, G
Example 3:
The following graph has no Hamiltonian circuits or paths

why not?
4 bridges exist = can’t have a circuit; No path possible b
ecause
multiple vertices of degree 1
EXAMPLE #4:
(a)
Find all Hamiltonian circuits that starts at A.
(b)
Find all Hamiltonian circuits that starts at D.
(c)
Explain why your answers in a and b must have the same
number of circuits.
(a)
A, C, F, D, E, B, A
A, D, F,
E, B, C, A
A, D, E, F, C, B, A (REVERSE ORDER as well)
(b)
Re

order answers in part a
(c)
Re

ordering concept
HOMEWORK
: pp. 221

22
2 # 2, 4, 6, 7, 10, 11
A
B
C
D
F
E
G
F
A
B
C
D
G
E
A
B
C
D
E
F
Section 6.2: Complete Graphs
EXAMPLE PUT 6 OR 8 DOTS ON WHITEBOARD AND START CONNECTING THEM AND ASK
STUD
ENTS TO DESCRIBE HOW I AM MAKING THE GRAPH:
“ONE DOT IS CONNECTED TO
EVERY OTHER DOT” TO START DEFINITION
COMPLETE GRAPH:
A
graph in which
every pair of distinct vertices
is joined by
exactly one edge
.
o
Notation
:
K
N
=
a complete graph of N vertices
EXAM
PLES OF COMPLETE GRAPHS
for 3, 4, and 5 vertices
:
Use the definition of a complete graph to answer the following questions:
1.
Does a complete graph have to be connected?
YES;
“every pair of vertices connected by an edge”
2.
Is a c
omplete graph allowed to have loops?
NO; “Distinct (Different) Vertices only”
3.
Is a complete graph allowed to have multiple edges?
NO; exactly
“
one edge
”
4.
Can different vertices have different degree?
NO; each vertex must be connected all remaining
ver
tices
What is the
DEGREE
of each
VERTEX
for N vertices?
K
3
: Degree = 2
K
4
: Degree = 3
K
5
: Degree = 4
1 Less than the # of vertices
Degree = N

1
How many
EDGES are
in K
N
(complete graph of N vertices)?
EDGES
TOTAL DEGREE
K
3
:
EDGES =
3
6 = 3*2
K
4
:
EDGES =
6
12 = 4*3
K
5
:
EDGES = 10
20 = 5*4
K
6
:
EDGES
=
15
30 = 6*5
What is the relationship between edges and degrees?
Euler’s Sum of Degree Theorem
:
(
total # of degrees
)
= 2 * (# of edges)
N(N

1) = 2 * (# of edges)
number of edges
in K
N
Where have you seen this formula before?
Chapter 1: the number of pairwise comparisons.
DEGREE and VE
RTICES are consecutive numbers.
SUMMARY OF
COMPLETE GRAPH
INFORMATION
Complete Graph
Number of Vertices
Degree of Each Vertex
Nu
mber of Edges
K
N
N
N
–
1
Connected Graph, No Loops, No Multiple Edges
K
3
K
4
K
5
K
3
= Complete Graph of 4 Vertices
K
4
= Complete Graph of 4 Vertices
1
)
How many Hamiltonian circuits does it
have?
2
1
)
How many Hamiltonian circuits does i
t
have?
6
If we were to answer the same questions for K
5
we would find the following:
1)
How many Hamiltonian circuits does it have?
(Do you notice any possible relation in how we answered this question for K
3
and K
4
that
might help you here?)
(5

1) (5

2) ( 5

3) (5

4) = (4)(3)(2)(1) =
24
(see page 202 for exact circuits)
How many
DISTINCT HAMILTON CIRCUITS are
in K
N
?
Complete Graph
Vertices
Hamilton Circuits
K
3
:
3
2
K
4
:
4
6
K
5
:
5
24
K
6
:
6
120
(N
–
1)!
= (Degree) !
=
Di
sti
nct Hamilton Circuits in K
N
.
Calculator Command Reminder
:
[MATH]
–
[PRB]
–
[
4:
!]
I
N
DEPENDENT PRACTICE:
Apply the Properties
of
Complete Graphs
(1)
How many edges are there in K
20
?
20(19)/2 = 190 edges
(2)
How many distinct Hamilton Circuits exist in K
10
?
(10
–
1)! = 9! = 362880
(3)
How many vertices are in the K
50
graph?
N = 50
(4)
What is the degree of every vertex in K
200
?
Degree = 200

1 = 199
K
4
A
B
C
D
1
A, B, C, D, A
2
A, B, D, C, A
3
A, C, B, D, A
4
A, C, D,
B, A
5
A, D, B, C, A
6
A, D, C, B, A
K
3
A
B
C
1
A, B, C, A
2
A, C, B, A
(5)
How many distinct Hamilton Circuits exist in K
22
?
(22
–
1)! = 21! Or 5.109094217E19
(6)
How many edges are there in
K
32
?
Edges = (32)(32
–
1)/2 = 496 edges
(7)
What is the degree of every vertex in K
15
?
Degree = 15
–
1 = 14
(8)
If
K
N
has 120 distinct Hamiltonian circuits then what is
N
?
N = 6
Trial and Error:
Divide 120 by consecutive numbers starting with 2
Add one to las
t number used
= Number of vertices
(9)
If
K
N
has 55 edges then what is
N
?
N = 11
55 = (N)(N

1)/2;
HINT
:
square root trick of
DOUBLE EDGES
round up
= N and round down =
N

1
(10)
If the number of edges of
K
12
is x and the number of edges of
K
13
is y, what i
s
the
values of y

x
?
(13)(12)/2

(12)(11)/ 2 = (12/2) (13

11) = 12
(11)
For each of the following cases find the value of N.
a.
K
N
has
5040
distinct Hamilton Circuits.
5040 = 7!;
N =
7 + 1 = 8
b.
K
N
has 66 edges.
66 =
12*11/2; N = 12
c.
K
N
has 80,200 edges.
80,20
0 = 401*400/2; N = 401
(12)
If K
N
has
362,880 distinct Hamilton Circuits, then
…
362,880 = 6!; N = 7
a.
How many vertices are in the K
N
graph?
7 VERTICES
b.
What is the degree of each vertex are in the K
N
graph?
7

1 = 6
c.
How many edges are in the K
N
graph?
7*6/2 = 2
1 edges
Section 6.3: Traveling Salesman Problems
WEIGHTED GRAPH:
Any graph whose edges have
numbers associated or
assigned
to them
(NOT DRAWN TO SCALE ALWAYS)
o
Weights:
number
for
each edge
o
Examples of Weights
:
distance, time, cost…
Complete Weighted
Graph:
Complete graph that has weights associated with it
TRAVELING SALESMAN PROBLEMS:
From home, the traveling salesman must visit different destinations to sell goods and return home. This is
essentially finding a Hamilton Circuit.
GOAL:
Try to find t
he cheapest, most efficient, optimal route that is a Hamilton circuit for a given graph (find
the least total weight)
Exampl
e
–
The Simpsons:
Homer Simpson he has to run errands at the Kwik

E

Mart, the Retirement
Home and Moe`s. Assuming that he wants to
begin and end his day at home find the route that will allow
him to get back to napping as soon as possible.
The numbers will represent the
number of blocks between each
destination.
When we place values like this
on the edges of a graph we
refer to
them as the
weights
of
the edges.
What if Homer preferred going to see Grandpa first to get it out of the way?
A
–
B
–
C
–
D
–
A
A

B

D

C

A
12 + 20 + 17 + 8 = 57 BLOCKS
12+15+17+20 = 64 BLOCKS
What if Homer preferred going to the KWIK

E

MART las
t?
A

B

D

C

A
A
–
D
–
B
–
C
–
A
12+15+17+20 = 64 BLOCKS
8 +15 + 20 + 20 = 63 BLOCKS
Traveling Salesman Problem Steps:
(1)
Create graph models
(2)
A
pply
weights to these models
(3)
Find
optimal Hamilton Circuits.
(Not Always a practical statement)
REAL

LIFE EXAM
PLES:
1) Routing School Buses
2) Package Deliveries: UPS or FedEx Delivery Truck
3) Running Errands around Town
4) Planning a road trip
5) Grocery Shopping: Planning which aisles you need to go down
HOMEWORK
:
pp. 222
–
22
3 # 13
–
16
12
8
20
17
15
20
A
B
C
D
Section 6.4
and 6.5
:
Simple
Algorithms
for Solving T
raveling Salesman Problems
Strategy
#1:
BRUTE FORCE
(
Exhaustive Search
)
BRUTE

FORCE ALGORITHM
Step 1:
Make a list of
ALL
distinct Hamilton circuits of the graph
from
ONE
starting vertex
Step 2:
Calculate
its
TOTAL WEIGHT
for each circuit
.
Step 3:
Choose an
OPTIMAL
circuit. (The
re is always more than one optimal circuit because of mirror

images)
PRO:
Guarantee Optimal Hamilton Circuit
CON:
INEFFICIENT ALGORITHM
# steps needed to carry out algorithm grows disproportionately with the size of population (vertices)
ie TAKES A LOT
OF TIME the more vertices/ edges there are
STRATEGY
#2:
NEAREST
–
NEIGHBOR ALGORITHM
From the start vertex, go to the vertex that is the
shortest
to get to. From each new vertex go to the next new
city that is the
shortest
to get to. When there are
no more new vertices to go to, go to the starting vertex.
A
(12) C (9) B (16) D (15) A =
52
NEAREST

NEIGHBOR ALGORITHM
Start:
Start at the
designated starting vertex
(home)
. If there is no designated starting vertex, pick any vertex.
Step 1:
From the
starting vertex go to its
NEAREST NEIGHBOR
(vertex that is
the smallest weight
away)
Middle Steps:
From each vertex go to
its nearest neighbor
that
hasn’t already been visited
.
⡳浡汬e獴s
牥浡楮楮m 睥ig桴映灯獳楢ie⁶ 牴楣e猩
hee瀠摯楮朠瑨g猠畮s楬汬⁴桥
癥牴楣e猠桡癥 e渠癩獩瑥搮
Last Step:
From the last
neighbor (vertex)
RETURN
to the starting vertex
(home)
.
PRO:
EFFICIENT ALGORITHM
Amount of computational effort required to implement it grows in some reasonable proportion with the size of
populati
on (vertices)
ie
WORKS FAST/ LESS TIME CONSUMING TO COMPLETE METHOD
CON:
Not an optimal Algorithm; Answers won’t always be the OPTIMAL, but relatively close to being the
扥獴⁰潳獩扬e⁷=y=
=
Circuit
Mirror Image
Weight
A, B, C, D, A
A, B, D, C, A
A, C, B, D, A
A, D, C, B, A
A, C, D, B, A
A, D, B, C, A
13 + 9 + 14 + 15 = 51
13 +
16 +
14 + 12 = 55
12 + 9 +
16 + 15 = 52
13
15
9
14
16
12
A
B
C
D
A weighted Graph may also be represented as table. Vertices alon
g the first
row and column. Weights on the interior of table.
A
B
C
D
A
AB =
12
AC =
20
AD =
8
B
BA =
12
BC =
20
BD =
15
C
CA =
20
CB =
20
CD =
17
D
DA =
8
DB =
15
DC =
17
Observations:
1)
Diagonal is blank because NO LOOPS exist.
2)
Upper Right
Triangle and Lower Left Triangle are Identical Numbers
a.
Represent Same Edges, but are in different order of starting and ending vertices
Draw the following complete wei
ghted graph described by table:
FIND THE NEAREST NEIGHBOR SOLUTION
STARTING AT D
:
D (1) E (6) A (3) B (5) C (6) D = 21
A
B
C
D
E
A
3
4
5
6
B
3
5
7
9
C
4
5
6
8
D
5
7
6
1
E
6
9
8
1
12
8
20
17
15
20
A
B
C
D
The following Complete Weighted Graph can also be represented by the table:
Does
BRUT
E FORCE
seem practical here?
NO;
(7

1)!= 720
POSSIBLE HAMILTON CIRCUITS
Start at Vertex A
–
Find the NEAREST NEIGHBOR SOLUTION:
(Use table or graph)
A
–
(15)
–
F
–
(13)
–
G
–
(28)
–
C
–
(30)
–
B
–
(60)
–
D
–
(20)

E
–
(35)

A
=
201
HOMEWORK
: pp. 22
3
–
225 # 29

31, 33, 35
A
B
C
D
E
F
G
A
75
50
28
35
15
22
B
75
30
60
80
65
50
C
50
30
40
48
35
28
D
28
60
40
20
30
29
E
35
80
48
20
40
32
F
15
65
35
30
40
13
G
22
50
28
29
32
13
A
G
F
E
D
B
C
A
B
C
G
F
E
D
75
22
50
13
40
20
40
30
65
50
80
35
29
15
48
35
60
28
30
32
28
9
10
17
11
13
15
A
B
C
D
Section 6.7: Repetitive Nearest

Neighbor Algorithm
The Nearest Neighbor Algorithm is an
EFFICIENT
but
NOT
always
ACCURATE
algorithm.
Is there a way we can improve it because we like its efficiency
?
Compare from different starti
ng spots
The
REPETITIVE
Nearest

Neighbor Algorithm:
P
erform the
Nearest

Neighbor Algorithm
for
every
vertex
of the
graph
as the
starting
vertex
.
Compare circuits and
CHOOSE
the circuit
with
least weight
of all
the options
.
o
If needed, Re

order
(shift
) that Hamilton Circuit to have the
DESI
GNATED START vertex first.
o
Re

ordered (shifted) circuits
have the same weight but change
its starting vertex
EX
P
#1:
Perform the nearest neighbor algorithm
for start of A
.
A
: A, B, D, C, A = 9 + 13 + 11+ 15 = 4
8
B
: B, A, D, C, B = 9 + 10 + 11 + 17 = 47
C:
C, D, A, B, C = 11 + 10 + 9 + 17 = 47
D:
D, A, B, C, D = 10 + 9 + 17 + 11 = 47
Final Answer: A,B,C,D,A or A,D,C,B,A = 47
EXAMPLE #2:
Label the graph and complete the Repetitive nearest neighbor
algo
rithm
for a start of
C
.
EXAMPLE #3
:
Perform repetitive nearest neighbor algorithm for a start of B.
Final
:
shift
A Answer
B, D, E, A, F, G, C, B
B, C, G, F, A, E, D, B
HOMEWOR
K:
p. 225 #37
–
39, 41
A
B
C
D
E
A
$185
$119
$152
$133
B
$185
$121
$150
$200
C
$119
$121
$174
$120
D
$152
$150
$174
$199
E
$133
$200
$120
$199
A
B
C
D
E
F
G
A
75
50
28
35
15
22
B
75
30
60
80
65
50
C
50
30
40
48
35
28
D
28
60
40
20
30
29
E
35
80
48
20
40
32
F
15
65
35
30
40
13
G
22
50
28
29
32
13
START with A
: a,f,g,c,b,d,e,a
201 = 5+13+28+30+60+20+35
START with
B
: b,c,g,f,a,d,e,b
214 =30+28+13+15+28+20+80
START with
C
: c
,g,f,a,d,e,b,c
214 =28+13+15+28+20+80+30
START with
D
:
d,e,a,f,g,c,b,d
221=20+35+15+13+28+50+60
START with
E
: e,d,a,f,g,c,b,e
214= 20+28+15+13+28+30+80
START with F
: f,a,g,d,e,c,b,f
229 =15+22+29+20+48+30+65
START with G
: g,f,a,d,e,c,b,g
204=13+15
+28+20+48+30+50
A
B
C
D
E
ACEDBA = $773
BCAEDB = $722
CAEDBC = $722 (Final)
DBCAED = $722
ECADBE = $741
Section 6.8: Cheapest

Link Algorithm
GOAL:
Piece together a Hamilton circuit by individual edges or “LINKS”
of graph
trying to choose the smallest or “cheapest”
weights first.
The Cheapest

Link Algorithm for N Vertices:
Step #1:
Pick the edge with the
smallest weight first
. Mark the
edge (or otherwise note that you have chosen it).
o
Smallest weight ANYWHERE on the graph
Step #2:
Pick the next ‘cheapest’ edge
anywhere in the graph
. Mark
or note it.
Step #3, …, N

1:
Continue pic
king the ‘
cheapest’
available
edge
in
the graph
and as long as
(a)
it does not close a circuit and
(b)
it does not result in three edges coming out of a single vertex.
(DEGREE = 2)
(c)
Ties can be broken at random and don’t break the two rules
HINT: Draw out the
edge
s chosen helps
to double check what
is and is not available.
Step #N:
Connect the last two vertices to close the circuit
(you are forced to choose this edge so no need for “cheapest”)
REORDER CIRCUIT TO THE NECESSARY STARTING
VERTEX
(N Vertices = N edge
s chosen for circuit)
EXAMPLE #1:
Start at G
G
A
F
E
D
B
C
A
B
C
G
F
E
D
75
22
50
13
40
20
40
30
65
50
80
35
29
15
48
35
60
28
30
32
28
When table only, draw links to visualize circuit.
START IT AT G:
G
–
F
–
A
–
D
–
E
–
C
–
B
–
G
= 13 + 15 +
28 + 20 + 48 + 30 + 50 = 204
EXAMPLE #2:
Start at
B
HOMEWORK:
pp. 225

6 #43

45, 47
A
B
C
D
E
F
G
A
75
50
28
35
15
22
B
75
30
60
80
65
50
C
50
30
40
48
35
28
D
28
60
40
20
30
29
E
3
5
80
48
20
40
32
F
15
65
35
30
40
13
G
22
50
28
29
32
13
A
B
C
D
E
EXAMPLE #3:
Start at D
A
B
C
D
E
A
$185
$119
$152
$133
B
$185
$121
$150
$200
C
$119
$121
$174
$120
D
$152
$150
$174
$199
E
$133
$200
$120
$199
A
–
C = 119
E
–
C = 120
B
–
D = 150
A
–
D = 152
E
–
B = 200
741 = total cost
Start at D:
D, A, C, E, B, D or D, B, E, C, A, D
= 741
12
24
17
21
9
19
19
27
29
Start at B:
B, A, E, C, D, B
B, D, C, E, A, B
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment