Professional Documents
Culture Documents
Unit 4.1 Branch and Bound
Unit 4.1 Branch and Bound
1
Branch and Bound
• Branch and Bound (B&B) is a systematic method for solving
optimization problem (Basically for minimization).
• B&B is a rather general optimization technique that applies
where the greedy method and dynamic programming fail.
• However, it is much slower. Indeed, it often leads to exponential
time complexities in the worst case.
• B&B is based on the principle that the total set of feasible
solution can be partitioned into smaller subsets can then be
evaluated systematically until the best solution is found.
• 1
2 3 4
3 4 2 4 2 3
4 3 4 2 3 2
Travelling Salesman Problem
• Travelling Salesman Problem (TSP): Given a set of
cities and distance between every pair of cities, the
problem is to find the shortest possible route that visits
every city exactly once and returns to the starting
point.
1->2->4->3->1
= 10+25+30+15
= 80
1 2 3 4 5
1 ∞ 20 30 10 11
2 15 ∞ 16 4 2
3 3 5 ∞ 2 4
4 19 6 18 ∞ 3
5 16 4 7 16 ∞
-1 X -3 X X
X means ignore Total Cost == Cos t of Red_Row + Cos t of Red_Column
(10+2+2+3+4) + (1+3)
= 25 // It means all the tours in the original graph have a
length atleast 25
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 ∞ ∞ 11 2 0 X 2 ∞ ∞ 11 2 0
3 0 ∞ ∞ 0 2 X 3 0 ∞ ∞ 0 2
4 15 ∞ 12 ∞ 0 X 4 15 ∞ 12 ∞ 0
5 11 ∞ 0 12 ∞ X 5 11 ∞ 0 12 ∞
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cos t of Red_Column + value of M[1][2] in last
level optimized cost matrix
= 25 + 0 + 0 + 10
= 35
1 2 3 4 5
1
25
1 ∞ 10 17 0 1
35 2 12 ∞ 11 2 0
2 3 4 5 3 0 3 ∞ 0 2
4 15 3 12 ∞ 0
5 11 0 0 12 ∞
Consider path 1,3. Make 1st row and 3rd column ∞ and set M[3][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 12 ∞ ∞ 2 0 X 2 12 ∞ ∞ 2 0
3 ∞ 3 ∞ 0 2
X 3 ∞ 3 ∞ 0 2
X 4 15 3 ∞ ∞ 0
4 15 3 ∞ ∞ 0
5 11 0 ∞ 12 ∞ X 5 11 0 ∞ 12 ∞
11 X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[1][3] in last
level optimized cost matrix
= 25 + 0 + 11 + 17
= 53
1 2 3 4 5
1 25
1 ∞ 10 17 0 1
35 53 2 12 ∞ 11 2 0
2 3 4 5 3 0 3 ∞ 0 2
4 15 3 12 ∞ 0
5 11 0 0 12 ∞
Consider path 1,4. Make 1st row and 4th column ∞ and set M[4][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 12 ∞ 11 ∞ 0 X 2 12 ∞ 11 ∞ 0
3 0 3 ∞ ∞ 2
X 3 0 3 ∞ ∞ 2
X
4 ∞ 3 12 ∞ 0 4 ∞ 3 12 ∞ 0
5 11 0 0 ∞ ∞ X 5 11 0 0 ∞ ∞
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[1][4] in last
level optimized cost matrix
= 25 + 0 + 0 + 0
= 25
1 2 3 4 5
1 25
1 ∞ 10 17 0 1
35 53 25 2 12 ∞ 11 2 0
2 3 4 5 3 0 3 ∞ 0 2
4 15 3 12 ∞ 0
5 11 0 0 12 ∞
Consider path 1-5. Make 1st row and 5th column ∞ and set M[5][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 12 ∞ 11 2 ∞ 2 2 10 ∞ 9 0 ∞
3 0 3 ∞ 0 ∞ X 3 0 3 ∞ 0 ∞
4 15 3 12 ∞ ∞ 3 4 12 0 9 ∞ ∞
5 ∞ 0 0 12 ∞ X 5 ∞ 0 0 12 ∞
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[1][5] in last
level optimized cost matrix
= 25 + 5 + 0 + 1
= 31
1 25 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
35 53 25 31 2 12 ∞ 11 ∞ 0
2 3 4 5
E-node 3 0 3 ∞ ∞ 2
4 ∞ 3 12 ∞ 0
2 3 5
5 11 0 0 ∞ ∞
Consider path 1- 4 - 2 Make 1st , 4th row and 4th , 2nd column ∞ and
set M[4][1]= ∞, M[2][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 ∞ ∞ 11 ∞ 0 X 2 ∞ ∞ 11 ∞ 0
3 0 ∞ ∞ ∞ 2 X 3 0 ∞ ∞ ∞ 2
4 ∞ ∞ ∞ ∞ ∞ X 4 ∞ ∞ ∞ ∞ ∞
5 11 ∞ 0 ∞ ∞ X 5 11 ∞ 0 ∞ ∞
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[4][2] in last
= 25 + 0+ 0 + 3 level optimized cost matrix
= 28
1 25 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
35 53 25 31 2 12 ∞ 11 ∞ 0
2 3 4 5
E-node 3 0 3 ∞ ∞ 2
2 28 3 5
4 ∞ 3 12 ∞ 0
5 11 0 0 ∞ ∞
Consider path 1-4-3 Make 1st , 4th row and 4th , 3rd column ∞ and
set M[4][1]= ∞, M[3][1]= ∞
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞ 1 ∞ ∞ ∞ ∞ ∞
2 12 ∞ ∞ ∞ 0 X 2 12 ∞ ∞ ∞ 0 2 1 ∞ ∞ ∞ 0
3 ∞ 3 ∞ ∞ 2 2 3 ∞ 1 ∞ ∞ 0 3 ∞ 1 ∞ ∞ 0
4 ∞ ∞ ∞ ∞ ∞ X 4 ∞ ∞ ∞ ∞ ∞ 4 ∞ ∞ ∞ ∞ ∞
5 11 0 ∞ ∞ ∞ X 5 11 0 ∞ ∞ ∞ 5 0 0 ∞ ∞ ∞
11 X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[4][3] in last
= 25 + 2+ 11 + 12 level optimized cost matrix
= 50
1 25 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
35 53 25 31 2 12 ∞ 11 ∞ 0
2 3 4 5
E-node 3 0 3 ∞ ∞ 2
28 50 5 4 ∞ 3 12 ∞ 0
2 3
5 11 0 0 ∞ ∞
Consider path 1-4-5 Make 1st , 4th row and 4th , 5th column ∞ and
set M[4][1]= ∞, M[5][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 12 ∞ 11 ∞ ∞ 11 2 1 ∞ 0 ∞ ∞
3 0 3 ∞ ∞ ∞ X 3 0 3 ∞ ∞ ∞
4 ∞ 3 12 ∞ ∞
X 4 ∞ ∞ ∞ ∞ ∞
5 ∞ 0 0 ∞ ∞ X 5 ∞ 0 0 ∞ ∞
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[4][3] in last
= 25 + 11 + 0 + 12 level optimized cost matrix
= 36
1 25 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
35 53 25 31
2 3 4 5 2 ∞ ∞ 11 ∞ 0
3 0 ∞ ∞ ∞ 2
28 50 36
2 4 ∞ ∞ ∞ ∞ ∞
3 5
5 11 ∞ 0 ∞ ∞
3 5
Consider path 1-4-2-3. Make 1st , 4th, 2nd row and 2nd , 4th , 3rd column ∞ and
set M[4][1]= ∞, M[2][1]= ∞, M[3][1]= ∞
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞ 1 ∞ ∞ ∞ ∞ ∞
2 ∞ ∞ ∞ ∞ ∞ X 2 ∞ ∞ ∞ ∞ ∞ 2 ∞ ∞ ∞ ∞ ∞
3 ∞ ∞ ∞ ∞ 2 2 3 ∞ ∞ ∞ ∞ 0 3 ∞ ∞ ∞ ∞ 0
4 ∞ ∞ ∞ ∞ ∞ X 4 ∞ ∞ ∞ ∞ ∞ 4 ∞ ∞ ∞ ∞ ∞
5 11 ∞ ∞ ∞ ∞ 5 0 ∞ ∞ ∞ ∞
5 11 ∞ ∞ ∞ ∞ X
11 X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[2][3] in last
= 25 + 2 + 11 + 11 level optimized cost matrix
= 52
1 25 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
35 53 25 31
2 3 4 5 2 ∞ ∞ 11 ∞ 0
3 0 ∞ ∞ ∞ 2
2
28 50 36
5 4 ∞ ∞ ∞ ∞ ∞
52 3
5 11 ∞ 0 ∞ ∞
3 5
Consider path 1-4-2-5. Make 1st , 4th, 2nd row and 2nd , 4th , 5th column ∞ and
set M[4][1]= ∞, M[2][1]= ∞, M[5][1]= ∞
1 2 3 4 5 1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞ X 1 ∞ ∞ ∞ ∞ ∞
2 ∞ ∞ ∞ ∞ ∞ X 2 ∞ ∞ ∞ ∞ ∞
3 0 ∞ ∞ ∞ ∞ X 3 ∞ ∞ ∞ ∞ 0
4 ∞ ∞ ∞ ∞ ∞ X 4 ∞ ∞ ∞ ∞ ∞
5 11 ∞ ∞ ∞ ∞
5 ∞ ∞ 0 ∞ ∞ X
X X X X X
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[2][5] in last
= 28 + 0 + 0 + 0 level optimized cost matrix
= 28
1 25 1 2 3 4 5
35 53 25 31 1 ∞ ∞ ∞ ∞ ∞
2 3 4 5 2 ∞ ∞ ∞ ∞ ∞
28 50 36 3 ∞ ∞ ∞ ∞ 0
2 3 5
52 28 4 ∞ ∞ ∞ ∞ ∞
3 5 5 11 ∞ ∞ ∞ ∞
3
Consider path 1-4-2-5-3. Make 1st , 4th, 2nd , 3rd row and 2nd , 4th , 5th , 3rd column ∞ and
set M[4][1]= ∞, M[2][1]= ∞, M[5][1]= ∞, M[3][1]= ∞
1 2 3 4 5
1 ∞ ∞ ∞ ∞ ∞
Hence the optimum cost of the
2 ∞ ∞ ∞ ∞ ∞ tour is 28
3 ∞ ∞ ∞ ∞ ∞
4 ∞ ∞ ∞ ∞ ∞
5 ∞ ∞ ∞ ∞ ∞
Total Cost = Optimum cost + Cost of Red_Row + Cost of Red_Column + value of M[5][3] in last
= 28 + 0 + 0 + 0 level optimized cost matrix
= 28
Backtracking Approach
• Backtracking is a technique based on algorithm to solve
problem. It uses recursive calling to find the solution by
building a solution step by step increasing values with time.
• It removes the solutions that doesn't give rise to the solution
of the problem based on the constraints given to solve the
problem.
• Backtracking algorithm is applied to some specific types of
problems:-
(i) Decision problem used to find a feasible solution of
the problem.
(ii) Optimization problem used to find the best solution that
can be applied.
(iii) Enumeration problem used to find the set of all feasible
solutions of the problem.
• In backtracking approach while solving a given
problem, a tree is constructed. Such a tree with all
possible solution is called State Space Tree
• In backtracking problem, the algorithm tries to find a
sequence path to the solution which has some small
checkpoints from where the problem can backtrack if
no feasible solution is found for the problem.