0% found this document useful (0 votes)
15 views49 pages

DAA Unit - 5

Uploaded by

sharmameghaa5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views49 pages

DAA Unit - 5

Uploaded by

sharmameghaa5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Branch and bound

What is Branch and bound?


Branch and bound is one of the techniques used for problem solving. It
is similar to the backtracking since it also uses the state space tree. It is
used for solving the optimization problems and minimization problems.
If we have given a maximization problem then we can convert it using
the Branch and bound technique by simply converting the problem into
a maximization problem.
Let's understand through an example.

Jobs = {j1, j2, j3, j4}


• P = {10, 5, 8, 3}
• d = {1, 2, 1, 2}
The above are jobs, problems and problems given. We can write the solutions in two ways
which are given below:
• Suppose we want to perform the jobs j1 and j2 then the solution can be represented in
two ways:
The first way of representing the solutions is the subsets of jobs.
S1 = {j1, j4}
The second way of representing the solution is that first job is done, second and third jobs are not
done, and fourth job is done.
S2 = {1, 0, 0, 1}
• The solution s1 is the variable-size solution while the solution s2 is the fixed-size solution.
First, we will see the subset method where we will see the variable size.
• First method:
• In this case, we first consider the first job, then second job, then third
job and finally we consider the last job.
• As we can observe in the above figure that the breadth first search is
performed but not the depth first search. Here we move breadth wise
for exploring the solutions. In backtracking, we go depth-wise whereas
in branch and bound, we go breadth wise.
Now one level is completed. Once I take
first job, then we can consider either j2,
j3 or j4. If we follow the route then it says Now we will consider the node 3. In this case, we are doing job
that we are doing jobs j1 and j4 so we will j2 so we can consider either job j3 or j4. Here, we have
not consider jobs j2 and j3. discarded the job j1.
Now we will expand the
Now we will expand node 6, and here we will consider the jobs
node 4. Since here we are
j3 and j4.
doing job j3 so we will
consider only job j4.
Now we will expand node 7 and
here we will consider job j4.

Now we will expand node 9, and here we will consider job j4.

The last node, i.e., node 12 which is left to be expanded. Here, we consider job j4.
The above is the state space tree for the solution s1 = {j1, j4}
Second method:
• We will see another way to solve the problem to achieve the solution
s1.
• First, we consider the node 1 shown as below:
• Now, we will expand the node 1. After expansion, the state space tree
would be appeared as:
• On each expansion, the node will be pushed into the stack shown as
below:

Now the expansion would be based on the node that appears


on the top of the stack. Since the node 5 appears on the top of
the stack, so we will expand the node 5. We will pop out the
node 5 from the stack. Since the node 5 is in the last job, i.e., j4
so there is no further scope of expansion.
The next node that appears on the top of the stack is node 4.
Pop out the node 4 and expand. On expansion, job j4 will be
considered and node 6 will be added into the stack shown as
below:

The next node is 6 which is to be expanded. Pop out the node 6


and expand. Since the node 6 is in the last job, i.e., j4 so there
is no further scope of expansion.

The next node to be expanded is node 3. Since the node 3


works on the job j2 so node 3 will be expanded to two nodes,
i.e., 7 and 8 working on jobs 3 and 4 respectively. The nodes 7
and 8 will be pushed into the stack shown as below:
The next node that appears on the top of the stack is node 8.
Pop out the node 8 and expand. Since the node 8 works on the
job j4 so there is no further scope for the expansion.

The next node that appears on the top of the stack is node 7. Pop out the node 7 and expand. Since the
node 7 works on the job j3 so node 7 will be further expanded to node 9 that works on the job j4 as shown
as below and the node 9 will be pushed into the stack.

The next node that appears on the top of the stack is node 9.
Since the node 9 works on the job 4 so there is no further
scope for the expansion.
The next node that appears on the top of the stack is node 2. Since the node 2 works on the job j1 so it means that the node 2
can be further expanded. It can be expanded upto three nodes named as 10, 11, 12 working on jobs j2, j3, and j4 respectively.
There newly nodes will be pushed into the stack shown as below:
Third method
• There is one more method that can be used to find the solution and
that method is Least cost branch and bound. In this technique, nodes
are explored based on the cost of the node. The cost of the node can
be defined using the problem and with the help of the given problem,
we can define the cost function. Once the cost function is defined, we
can define the cost of the node.
• Let's first consider the node 1 having cost infinity shown as below:
• Now we will expand the node 1. The node 1 will be expanded into
four nodes named as 2, 3, 4 and 5 shown as below:
Let's assume that cost of the nodes 2, 3, 4, and 5 are 25, 12, 19
and 30 respectively.
Since it is the least cost branch n bound, so we will explore the
node which is having the least cost. In the above figure, we can
observe that the node with a minimum cost is node 3. So, we
will explore the node 3 having cost 12.
• Since the node 3 works on the job j2 so it will be expanded into two
nodes named as 6 and 7 shown as below:

The node 6 works on job j3 while the node 7 works on job j4.
The cost of the node 6 is 8 and the cost of the node 7 is 7. Now
we have to select the node which is having the minimum cost.
The node 7 has the minimum cost so we will explore the node
7. Since the node 7 already works on the job j4 so there is no
further scope for the expansion.
Branch And Bound Algorithm Analysis For Solving Job
Assignment Problems

• Job Assignment Problem is one of the fundamental combinatorial optimization


problems. In its most common form.
• Examples of problems have a number of people and a number of jobs. Each
person can be assigned to do any job, which has different costs depending on the
job. The goal is to do as many jobs as possible by assigning one person to each job
and one job per person, in such a way that the total cost is minimized.
Method Job Assignment Problem

• Job Assignment Problem is a problem regarding the placement of an individual


(object) in carrying out a task (job) where exactly one person corresponds to
exactly one job according to that person's ability level. Assigning tasks for each
individual results in different costs. For example, person P if doing job 1 requires a
cost (cost) of c (P, 1), person Q if doing job 2 requires a cost (cost) of c (Q, 2), and
so on. So that a job mapping is formed for each person in each job and the costs.
• Suppose there are 4 people with 4 jobs, it will produce 3! Or 6 possibilities. From
the results of the mapping, there will be the minimum cost. Therefore we need an
algorithm that can solve complex problems such as Job Assignment Problems.
Branch and Bound Algorithm
• The Branch and Bound (B&B) algorithm is a method or method of systematically searching the
solution space. In this case the solution space will be organized into a status space tree. The
formation of a status space tree in this algorithm is built with a broad search scheme or Breadth
First Search which is abbreviated as BFS. However, the difference is that the expanded node is not
based on the order of generation, but the node that has the smallest “cost” value among other
lifecycle nodes.
• Each node has a "cost" value, which is the estimated value or the estimated path of the smallest
cost from the node to the destination node (goal node), and can be expressed in general terms as
follows:

• where
• ĉ (i) = value for node i
• ƒ (i) = value reaches vertex i from root
• ĝ (i) = value reaching the destination node from the vertex.
The way the B&B algorithm works is based on the following two principles.
• 1. Recursively divide the status space into smaller spaces and minimize “costs” on
these spaces. This process is called branching.
• 2. Branching will be equivalent to brute-force enumeration. To improve
performance, bound is used to limit the space in the status that is generated,
eliminating candidate solutions that are proven to not contain optimal solutions.

As the name implies, this algorithm has a bound or limiting function. This constraint
function is useful for delimiting paths that are considered not leading to a solution
node.
Example
• The job assignment problem testing will be carried out in one example of the following cases, namely there
are 4 jobs and 4 people, each of which has a cost as in table 1.
• Solving Job Assignment Problems using Branch and Bound is done by determining the lower limit by adding
the minimum cost of each row in table 1. The result can be seen in table 2.

So that Lower Bound (LB) = 4+5+3+6 = 18


There are 4 possibilities, namely A doing Job 1, A doing Job 2, A doing Job 3 and A doing Job 4. Calculate the
LB of each of these possibilities.
• Possibility 1: Person 1 (A) does Job 1 Possibility 4: Person 1 (A) does Job 4

Then LB for probability 4 is : 10+5+3+8 = 26


Then LB for probability 1 is : 11+5+3+6 = 25
Possibility 2: Person 1 (A) does Job 2

Then LB for probability 3 is : 9+6+7+6 = 28


• Then formed a tree like figure 1

the node with the minimum value to be expanded is selected, namely A 2 with LB = 18. Then the second person (B) is
chosen to do the job or assignment. There are 3 possibilities, namely B doing job 1, Job 3 or Job 4 (Job 2 is done by A)
Possibility 1: Person 2 (B) does Job 1 Possibility 3: Person 2 (B) does Job 4

Then LB for probability 1 is 4+9+3+9 = 25


Then LB for probability 1 is 4+8+3+6 = 21
Possibility 2: Person 2 (B) does Job 3

Then LB for probability 2 is: 4+5+7+6 = 22


• Then formed a tree like figure 2

Next, select the node with the minimum cost to expand, namely B1 and do the calculations as before, for the next 2
possibilities.
Possibility 1: A does Job 2, B does Job 1, C does Job 3 and D does Job 4 with the cost is 4 + 8 + 3 + 6 = 21.
Possibility 2: A does Job 2, B does Job 1, C does Job 4 and D does Job 3 with the cost is 4 + 8 + 10 + 11 = 33.
Then the possibility of 1 is chosen with cost = 21, compared to all the remaining nodes, this cost is the minimum cost so
that it is chosen as the solution.
Travelling salesman problem.

• Given
• A set of some cities
• Distance between every pair of cities
Travelling Salesman Problem states-
• A salesman has to visit every city exactly once.
• He has to come back to the city from where he starts his journey.
• What is the shortest possible route that the salesman must follow to
complete his tour?
• Example-

• The following graph shows a set of cities and distance between every
pair of cities-
If salesman starting city is A, then a TSP tour in the graph is-
A→B→D→C→A
Cost of the tour
= 10 + 25 + 30 + 15
= 80 units
PRACTICE PROBLEM BASED ON TRAVELLING SALESMAN
PROBLEM USING BRANCH AND BOUND APPROACH-

• Problem-

• Solve Travelling Salesman Problem using Branch and Bound Algorithm
in the following graph-
• Solution-
• Step-01:
• Write the initial cost matrix and reduce it-

Rules
•To reduce a matrix, perform the row reduction and
column reduction of the matrix separately.
•A row or a column is said to be reduced if it contains at
least one entry ‘0’ in it.
Row Reduction-
Consider the rows of above matrix one by one.

• If the row already contains an entry ‘0’, then-


• There is no need to reduce that row.

• If the row does not contains an entry ‘0’, then-


• Reduce that particular row.
• Select the least value element from that row.
• Subtract that element from each element of that row.
• This will create an entry ‘0’ in that row, thus reducing that row.
Following this, we have-
• Reduce the elements of row-1 by 4.
• Reduce the elements of row-2 by 5.
• Reduce the elements of row-3 by 6.
• Reduce the elements of row-4 by 2.

• Performing this, we obtain the following row-reduced matrix-


Column Reduction-
Consider the columns of above row-reduced matrix one by one.

• If the column already contains an entry ‘0’, then-


There is no need to reduce that column.

• If the column does not contains an entry ‘0’, then-


• Reduce that particular column.
• Select the least value element from that column.
• Subtract that element from each element of that column.
• This will create an entry ‘0’ in that column, thus reducing that column.
Following this, we have-
• There is no need to reduce column-1.
• There is no need to reduce column-2.
• Reduce the elements of column-3 by 1.
• There is no need to reduce column-4.

Performing this, we obtain the following column-reduced matrix-

Finally, the initial distance matrix is completely reduced.


Now, we calculate the cost of node-1 by adding all the reduction elements.

Cost(1)
= Sum of all reduction elements
=4+5+6+2+1
= 18
Step-02:

•We consider all other vertices one by one.


•We select the best vertex where we can land upon to minimize the
tour cost.

Choosing To Go To Vertex-B: Node-2 (Path A → B)

•From the reduced matrix of step-01, M[A,B] = 0


•Set row-A and column-B to ∞
•Set M[B,A] = ∞

Now, resulting cost matrix is-

Now,
•We reduce this matrix.
•Then, we find out the cost of node-02.
• Row Reduction-

• We can not reduce row-1 as all its elements are ∞.


• Reduce all the elements of row-2 by 13.
• There is no need to reduce row-3.
• There is no need to reduce row-4.

• Performing this, we obtain the following row-reduced matrix-


• Column Reduction-

• Reduce the elements of column-1 by 5.


• We can not reduce column-2 as all its elements are ∞.
• There is no need to reduce column-3.
• There is no need to reduce column-4.

• Performing this, we obtain the following column-reduced matrix-


Finally, the matrix is completely reduced.
Now, we calculate the cost of node-2.

Cost(2)
= Cost(1) + Sum of reduction elements + M[A,B]
= 18 + (13 + 5) + 0
= 36
• Choosing To Go To Vertex-C: Node-3 (Path A → C)

• From the reduced matrix of step-01, M[A,C] = 7


• Set row-A and column-C to ∞
• Set M[C,A] = ∞

• Now, resulting cost matrix is-


Now,
•We reduce this matrix.
•Then, we find out the cost of node-03.
• Row Reduction-

• We can not reduce row-1 as all its elements are ∞.


• There is no need to reduce row-2.
• There is no need to reduce row-3.
• There is no need to reduce row-4.

• Thus, the matrix is already row-reduced.


Column Reduction-

• There is no need to reduce column-1.


• There is no need to reduce column-2.
• We can not reduce column-3 as all its elements are ∞.
• There is no need to reduce column-4.

• Thus, the matrix is already column reduced.


• Finally, the matrix is completely reduced.
• Now, we calculate the cost of node-3.

Cost(3)
= Cost(1) + Sum of reduction elements + M[A,C]
= 18 + 0 + 7
= 25
• Choosing To Go To Vertex-D: Node-4 (Path A → D)

• From the reduced matrix of step-01, M[A,D] = 3


• Set row-A and column-D to ∞
• Set M[D,A] = ∞

• Now, resulting cost matrix is-

• Now,
• We reduce this matrix.
• Then, we find out the cost of node-04.
• Row Reduction-

• We can not reduce row-1 as all its elements are ∞.


• There is no need to reduce row-2.
• Reduce all the elements of row-3 by 5.
• There is no need to reduce row-4.

• Performing this, we obtain the following row-reduced matrix-


• Column Reduction-

• There is no need to reduce column-1.


• There is no need to reduce column-2.
• There is no need to reduce column-3.
• We can not reduce column-4 as all its elements are ∞.
Thus, the matrix is already column-reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-4.
Thus, we have-
•Cost(2) = 36 (for Path A → B)
Cost(4)
•Cost(3) = 25 (for Path A → C)
= Cost(1) + Sum of reduction elements + M[A,D]
•Cost(4) = 26 (for Path A → D)
= 18 + 5 + 3
= 26
We choose the node with the lowest cost.
Since cost for node-3 is lowest, so we prefer to visit node-3.
Thus, we choose node-3 i.e. path A → C.
• Step-03:
• We explore the vertices B and D from node-3.
• We now start from the cost matrix at node-3 which is-

Now,
•We reduce this matrix.
•Then, we find out the cost of node-5.
• Row Reduction-

• We can not reduce row-1 as all its elements are ∞.


• Reduce all the elements of row-2 by 13.
• We can not reduce row-3 as all its elements are ∞.
• Reduce all the elements of row-4 by 8.

• Performing this, we obtain the following row-reduced matrix-


• Column Reduction-

• There is no need to reduce column-1.
• We can not reduce column-2 as all its elements are ∞.
• We can not reduce column-3 as all its elements are ∞.
• There is no need to reduce column-4.
Thus, the matrix is already column reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-5.

Cost(5)
= cost(3) + Sum of reduction elements + M[C,B]
= 25 + (13 + 8) + ∞
=∞
• Choosing To Go To Vertex-D: Node-6 (Path A → C → D)

• From the reduced matrix of step-02, M[C,D] = ∞


• Set row-C and column-D to ∞
• Set M[D,A] = ∞

• Now, resulting cost matrix is-

Now,
•We reduce this matrix.
•Then, we find out the cost of node-6.
Row Reduction- Column Reduction-

•We can not reduce row-1 as all its •There is no need to reduce column-1.
elements are ∞. •We can not reduce column-2 as all its
•There is no need to reduce row-2. elements are ∞.
•We can not reduce row-3 as all its •We can not reduce column-3 as all its
elements are ∞. elements are ∞.
•We can not reduce row-4 as all its •We can not reduce column-4 as all its
elements are ∞. elements are ∞.

Thus, the matrix is already row reduced. Thus, the matrix is already column
Finally, the matrix is completely reduced. reduced.
Now, we calculate the cost of node-6.

Cost(6)
= cost(3) + Sum of reduction elements + M[C,D]
= 25 + 0 + 0
= 25
Thus, we have-
•Cost(5) = ∞ (for Path A → C → B)
•Cost(6) = 25 (for Path A → C → D)

We choose the node with the lowest


cost.
Since cost for node-6 is lowest, so we
prefer to visit node-6.
Thus, we choose node-6 i.e. path C → D.
• Choosing To Go To Vertex-B: Node-7 (Path A → C → D → B)

• From the reduced matrix of step-03, M[D,B] = 0


• Set row-D and column-B to ∞
• Set M[B,A] = ∞

• Now, resulting cost matrix is-


Now,
•We reduce this matrix.
•Then, we find out the cost of node-7.
Row Reduction-

•We can not reduce row-1 as all its elements are ∞.


•We can not reduce row-2 as all its elements are ∞.
•We can not reduce row-3 as all its elements are ∞.
•We can not reduce row-4 as all its elements are ∞.

Column Reduction-

•We can not reduce column-1 as all its elements are ∞.


•We can not reduce column-2 as all its elements are ∞.
•We can not reduce column-3 as all its elements are ∞.
Thus, the matrix is already column reduced. •We can not reduce column-4 as all its elements are ∞.
Finally, the matrix is completely reduced.
All the entries have become ∞.
Now, we calculate the cost of node-7.

Cost(7) Thus,
= cost(6) + Sum of reduction elements + M[D,B] •Optimal path is: A → C → D → B → A
= 25 + 0 + 0 •Cost of Optimal path = 25 units

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy