Daa Module 2 Notes Part 2
Daa Module 2 Notes Part 2
The Branch and Bound Technique is a problem solving strategy, which is most commonly
used in optimization problems, where the goal is to minimize a certain value.
The optimized solution is obtained by means of a state space tree (A state space tree is a tree
where the solution is constructed by adding elements one by one, starting from the root. Note
that the root contains no element).
This method is best when used for combinatorial problems with exponential time complexity,
since it provides a more efficient solution to such problems.
Let this function have an initial maximum value, according to the conditions of the given
problem. Also, let U0 be the initial value of U. We also calculate a cost function C which will
give us the exact value that the particular node shall achieve.
The next question is the order in which the tree is to be searched. For this, there exist multiple
types of branch and bound, which we shall discuss in detail later. For now, let us assume that
there is a set S consisting of subsets of the given set of values in the order in which they need
to be searched
The algorithm of the branch and bound method for this problem will be as follows:
For each subset s in S, do the following:
1. Calculate the value of U(s).
2. If U(s) U0, then U0 = U(s).
In the end, the the subset s for which the current value of U0 is obtained will be the best
solution to the given problem, and the value of the cost function at that node will give us the
solution. Here, after each level, the value of U0 tells us that there shall be a node with cost
less than that value.
Types of Solutions
For a branch and bound problem, there are two ways in which the solution can be
represented:
1. Variable size solution: This solution provides the subset of the given set that gives the
optimized solution for the given problem. For example, if the we are to select a combination
of elements from {A, B, C, D, E} that optimizes the given problem, and it is found that A, B,
and E together give the best solution, then the solution will be {A, B, E}.
2. Fixed size solution: This solution is a sequence of 0s and 1s, with the digit at the ith position
denoting whether the ith element should be included or not. Hence, for the earlier example,
the solution will be given by {1, 1, 0, 0, 1}.
1
Types of Branch and Bound
There are multiple types of the Branch and Bound method, based on the order in which the
state space tree is to be searched.
Here, note that the number assigned to the node signifies the order in which the tree shall be
constructed. The element next to the set denotes the next element to be added to the subset.
Note that if an element is getting added, it is assumed here that all elements in the set
preceeding that element are not added. For example, in node 4, D is getting added. This
implies that elements A, B and C are not added.
2
Here, one can see that the main difference lies in the order in which the nodes have been
explored.
In this method, after the children of a particular node have been explored, the next node to be
explored would be that node out of the unexplored nodes which has the least cost. For
example, in the previous example, after reaching node 5, the next node to be explored would
be that which has the least cost among nodes 2, 3, 4, 5.
2. 0/1 Knapsack problem: Given a set of weights of N objects and a sack which can carry a
maximum of W units. The problem deals with finding that subset of items such that the
maximum possible weight is carried in the sack. Here, one cannot take part of an object, i.e.,
one can either take an object or not take it. This problem can also be solved using the
backtracking, brute force and the dynamic programming approach.
3. Travelling Salesman Problem: Here, we are given a set of N cities, and the cost of travelling
between all pairs of cities. The problem is to find a path such that one starts from a given
node, visits all cities exactly once, and returns back to the starting city.
3
TRAVELLING SALESMAN PROBLEM
Travelling Salesman Problem (TSP) is defined as “given n cities and distance between each
pair of cities, find out the path which visits each city exactly once and come back to starting
city, with the constraint of minimizing the travelling distance.”
TSP has many practical applications. It is used in network design, and transportation route
design. The objective is to minimize the distance. We can start tour from any random city and
visit other cities in any order. With n cities, n! different permutations are possible. Exploring
all paths using brute force attacks may not be useful in real life applications.
It works as follow :
Consider directed weighted graph G = (V, E, W), where node represents cities and
weighted directed edges represents direction and distance between two cities
2. Convert cost matrix to reduced matrix by subtracting minimum values from appropriate
rows and columns, such that each row and column contains at least one zero entry.
3. Find cost of reduced matrix. Cost is given by summation of subtracted amount from the
cost matrix to convert it in to reduce matrix.
5. Find least cost valued node A (i.e. E-node), by computing reduced cost node matrix with
every remaining node.
4
Reduction procedure is described below :
Row Reduction:
Matrix M is called reduced matrix if each of its row and column has at least one zero entry or
entire row or entire column has ∞ value. Let M represents the distance matrix of 5 cities. M
can be reduced as follow:
MRowRed = {Mij – min {Mij | 1 ≤ j ≤ n, and Mij < ∞ }}
Find the minimum element from each row and subtract it from each cell of matrix.
Row reduction cost is the summation of all the values subtracted from each rows:
Row reduction cost (M) = 10 + 2 + 2 + 3 + 4 = 21
Column reduction:
Matrix MRowRed is row reduced but not the column reduced. Matrix is called column reduced
if each of its column has at least one zero entry or all ∞ entries.
MColRed = {Mji – min {Mji | 1 ≤ j ≤ n, and Mji < ∞ }}
5
To reduced above matrix, we will find the minimum element from each column and subtract
it from each cell of matrix.
Each row and column of MColRed has at least one zero entry, so this matrix is reduced matrix.
Column reduction cost (M) = 1 + 0 + 3 + 0 + 0 = 4
State space tree for 5 city problem is depicted in Fig. Number within circle indicates the order
in which the node is generated, and number of edge indicates the city being visited.
6
Example: Find the solution of following travelling salesman problem using branch and
bound method.
Solution:
The procedure for dynamic reduction is as follow:
Draw state space tree with optimal reduction cost at root node.
Derive cost of path from node i to j by setting all entries in ith row and jth column as ∞.
Set M[j][i] = ∞
Cost of corresponding node N for path i to j is summation of optimal cost + reduction cost +
M[j][i]
After exploring all nodes at level i, set node with minimum cost as E node and repeat the
procedure until all nodes are visited.
Given matrix is not reduced. In order to find reduced matrix of it, we will first find the row
reduced matrix followed by column reduced matrix if needed. We can find row reduced
matrix by subtracting minimum element of each row from each element of corresponding
row. Procedure is described below:
Reduce above cost matrix by subtracting minimum value from each row and column.
Reduce it subtracting minimum value from corresponding column. Doing this we get,
7
Cost of M1 = C(1)
= Row reduction cost + Column reduction cost
= (10 + 2 + 2 + 3 + 4) + (1 + 3) = 25
This means all tours in graph has length at least 25. This is the optimal cost of the path.
M2 is already reduced.
Cost of node 2 :
C(2) = C(1) + Reduction cost + M1 [1] [2]
= 25 + 0 + 10 = 35
8
Cost of node 3:
C(3) = C(1) + Reduction cost + M1[1] [3]
= 25 + 11 + 17 = 53
Cost of node 5:
C(5) = C(1) + reduction cost + M1 [1] [5]
= 25 + 5 + 1 = 31
9
Node 4 has minimum cost for path 1-4. We can go to vertex 2, 3 or 5. Let’s explore all three
nodes.
Select path 1-4-2 : (Add edge 4-2)
Set M4 [1] [] = M4 [4] [] = M4 [] [2] = ∞
Set M4 [2] [1] = ∞
Cost of node 7:
C(7) = C(4) + Reduction cost + M4 [4] [3]
= 25 + 2 + 11 + 12 = 50
10
Select edge 4-5 (Path 1-4-5):
Matrix M8 is reduced.
Cost of node 8:
C(8) = C(4) + Reduction cost + M4 [4][5]
= 25 + 11 + 0 = 36
11
Cost of node 9:
C(9) = C(6) + Reduction cost + M6 [2][3]
= 28 + 11 + 2 + 11 = 52
12
Add edge 5-3 (Path 1-4-2-5-3):
13
0\1 KNAPSACK PROBLEM
In solving this problem, we shall use the Least Cost- Branch and Bound method, since this
shall help us eliminate exploring certain branches of the tree. We shall also be using the
fixed-size solution here. Another thing to be noted here is that this problem is a maximization
problem, whereas the Branch and Bound method is for minimization problems. Hence, the
values will be multiplied by -1 so that this problem gets converted into a minimization
problem.
Now, consider the 0/1 knapsack problem with n objects and total weight W. We define the
upper bound(U) to be the summation of vixi (where vi denotes the value of that objects, and
xi is a binary value, which indicates whether the object is to be included or not), such that the
total weights of the included objects is less than W. The initial value of U is calculated at the
initial position, where objects are added in order until the initial position is filled.
We define the cost function to be the summation of vifi, such that the total value is the
maximum that can be obtained which is less than or equal to W. Here fi indicates the fraction
of the object that is to be included. Although we use fractions here, it is not included in the
final solution.
If the cost function for a given node is greater than the upper bound, then the node
need not be explored further. Hence, we can kill this node. Otherwise, calculate the
upper bound for this node. If this value is less than U, then replace the value of U with
this value. Then, kill all unexplored nodes which have cost function greater than this
value.
The next node to be checked after reaching all nodes in a particular level will be the
one with the least cost function value among the unexplored nodes.
While including an object, one needs to check whether the adding the object crossed
the threshold. If it does, one has reached the terminal point in that branch, and all the
succeeding objects will not be included.
In this manner, we shall find a value of U at the end which eliminates all other possibilites.
The path to this node will determine the solution to this problem.
14
Example
15
16
17
18