Title: CS 312: Algorithm Analysis
1CS 312 Algorithm Analysis
- Lecture 33 Solving the Traveling Salesperson
Problem with Branch and Bound
2Announcements
- Homework 22 due today
- Project 6 Solving the TSP using Branch and
Bound - Project Guidelines and scaffolding code available
on the schedule (as of Friday) - Helpful notes available on the schedule (actually
required reading for today) - Due date Monday 4/16
- No Improvement
- This project report is worth 10 of final grade
- Give this project your best effort!
- Help Session
- Tuesday (tomorrow)
- 5-6pm
- 164 TNRB
3Objectives
- Lecture 33 Solving the TSP with Branch and
Bound - Review the TSP
- Learn a sophisticated bounding function for the
TSP - Reason about Tight Bounds
- Review general BB algorithm
- Lecture 32 Branch and Bound
- Understand the difference between backtracking
and branch and bound - Understand bounding functions
- Implement branch and bound algorithm for Job
Assignment Problem (high level) - Contrast Iterative DFS, BFS, and BB in
Pseudo-code
4Traveling Salesperson Problem
- Rudrata or Hamiltonian Cycle
- Cycle in the graph that passes through each
vertex exactly once - Least Cost or shortest
5Bound on TSP Tour
1
9
8
2
10
6
5
3
12
7
4
Every tour must leave every vertex and and arrive
at every vertex.
6Bound on TSP Tour
1
9
8
2
10
6
5
3
12
7
4
Whats the cheapest way to leave each vertex?
7Bound on TSP Tour
bound86321
1
9
8
2
10
6
5
3
12
7
4
Save the sum of those costs in the bound (as a
rough draft). Can we find a tighter lower bound?
8Bound on TSP Tour
bound20
1
9-81
8-80
2
10
6
4
3
12
7
4
For a given vertex, subtract the least cost
departure from each edge leaving that vertex.
9Bound on TSP Tour
bound20
0
1
0
0
9
0
2
0
6
1
1
Repeat for the other vertices.
10Bound on TSP Tour
bound20
0
1
0
0
9
0
2
0
6
1
1
Does that set of edges now having 0 residual cost
arrive at every vertex? In this case, the edges
never arrive at vertex 3.
11Bound on TSP Tour
bound21
0
1
0
0
9
0
1
0
6
0
1
We have to take an edge to vertex 3 from
somewhere. Assume we take the cheapest.
Subtract its cost from other edges entering
vertex 3 and add the cost to the bound. We have
just tightened the bound.
12The Bound
- It will cost at least this much to visit all the
vertices in the graph. - theres no cheaper way to get in and out of each
vertex. - the edges are now labeled with the extra cost of
choosing another edge.
13Bound on TSP Tour
Algorithms do this using a cost matrix.
14Bound on TSP Tour
Reduce all rows.
15Bound on TSP Tour
Then reduce column 3. Now we have a tight bound.
16Pause
- Lets start the search
- Arbitrarily start at vertex 1
- Ignore the BSSF for now
- Focus on the bound function and on the reduced
cost matrix
17Using this bound for TSP in BB
bound 21
1to2
1to3
1to4
1to5
bound 211
18Focus going from 1 to 2
bound 21
1to2
0
1
0
1
0
0
0
9
9
0
1
0
1
6
6
0
0
bound 211
1
1
Add extra cost from 1 to 2, exclude edges from 1
or into 2.
19Focus going from 1 to 2
bound 21
1to2
0
1
0
1
0
0
0
9
9
0
1
0
1
6
6
0
0
bound 2111
1
1
No edges into vertex 4 w/ 0 reduced cost.
20Focus going from 1 to 2
bound 21
1to2
0
1
0
8
1
6
0
bound 2111
0
Add cost of reducing edge into vertex 4.
21Bounds for other choices.
bound 21
1to2(23),1to4(21)
1to2
1to3
1to4
1to5
bound 23
bound 999
bound 21
bound 999
22Leaves us with Two Possibilities on Priority Queue
0
1
0
0
0
0
9
0
1
1
0
6
6
0
0
1
bound 23
bound 21
23Leaving Vertex 4
0
0
4to2(22), 4to3(21) 4to5(28),1to2(23),
bound 21
0
0
1
0
6
0
4to2
4to3
4to5
bound 22
bound 21
bound 28
24Leaving Vertex 3
0
bound 21
0
4to2(22), 3to2(21) 1to2(23),
0
0
6
0
3to5
3to2
bound 21
bound 999
25Search Tree for This Problem
b21
b23
b999
b21
b999
b22
b21
b28
b21
b999
26Review Elements of BB Algorithm
- Generating child states from parent state
- Determines the structure of the search tree
- Managing the priority queue and the best solution
so far - Deciding when to terminate the algorithm
27Review Branch and Bound
function BandB(state) BSSF ? quick-solution(state
) // BSSF.c holds cost Q ? empty-priority-queue
state.c ? cost(state) Q.enqueue(state,
c) while !Q.empty() and time remains do s ?
Q.first() Q.dequeue() if s.c lt BSSF.c
then children generate_children(s) for
each child in children do child.c ?
cost(child) if (criterion(child) and (child.c
lt BSSF.c)) then BSSF ? child else if
(partial_criterion(child) and (child.c lt BSSF.c))
then Q.enqueue(child, child.c) else
break return BSSF
28Review Branch and Bound
function BandB(state) BSSF ? quick-solution(state
) // BSSF.c holds cost Q ? empty-priority-queue
state.c ? cost(state) Q.enqueue(state,
c) while !Q.empty() and time remains do s ?
Q.first() Q.dequeue() children
generate_children(s) for each child in children
do child.c ? cost(child) if
(criterion(child) and (child.c lt BSSF.c))
then BSSF ? child Q.trim(BSSF) else if
(partial_criterion(child) and (child.c lt BSSF.c))
then Q.enqueue(child, child.c) return BSSF
29Assignment