DAA Unit - 5
DAA Unit - 5
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:
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
• 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.
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
Next, select the node with the minimum cost to expand, namely B1 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.
Cost(1)
= Sum of all reduction elements
=4+5+6+2+1
= 18
Step-02:
Now,
•We reduce this matrix.
•Then, we find out the cost of node-02.
• Row Reduction-
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)
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)
• Now,
• We reduce this matrix.
• Then, we find out the cost of node-04.
• Row Reduction-
Now,
•We reduce this matrix.
•Then, we find out the cost of node-5.
• Row Reduction-
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)
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)
Column Reduction-
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