0% found this document useful (0 votes)
13 views

UNIT 3

Uploaded by

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

UNIT 3

Uploaded by

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

BRANCH AND BOUND

&
BACKTRACKING
 Backtracking is a depth first search, with some
bounding functions.
 Bounding functions or validity functions
represent the constraints of the given problem.
 First, the backtracking process defines a solution
vector as n-tuple vector (x 1 , x 2 ,…, x n ) for the
given problem.
 n is number of components of solution vector
 Each x i , where i ranges from 1 to n represents a
partial solution.
 These partial solution components x i are
generated based on the concept of constraints.
 Constraints are rules that restrict the generati on or
processing of a tuple.
 Two types of constraints: Explicit and Implicit
 Explicit constraints are rules that restrict a component of a
solution vector, say x i , from choosing a specific value from
a set S. Eg. x i > = 0.
 Implicit constraints are rules that limit the generation or
processing of a solution vector that maximizes, minimizes,
or satisfies the criterion function that is also expressed as
a vector (x 1 , x 2 ,…, x n ).
 The criterion function is called a promising function or a
bounding function or validity function.
 Eg. An 8-queen’s problem, where no two queen are in an
attacking position, implicitly means: no two queens are in
same row, column or diagonal.
 First part of the soluti on.
 Also known as soluti on space or recursion tree.

 A state-space tree is an arrangement of all possible


solutions in a tree-like fashion.
 Some of the terminologies associated with state-space
tree are:
 Answer states: These are solution states where the
path from the root to the leaf defines the solution of
the problem.
 Live node: A node that has been generated already but is
yet to generate the children, is called a live node.
 E-node: A node that is under consideration and is in the
process of being generated is called an e-node.
 Dead node: A node that is already explained and cannot be
considered for further searches is called a dead node.
Algorithm queen(i)
%%Input: Queen i
%% Output: Placement of queen i given by col(i)
Begin
if promising(i) then (promising function is a bounding function)
if(i==n) then
print col[1] .. col[n]
end if
else
for j = 1 to n do %% all columns j
col[i+1] = j

queen[i+1]
end for
end if
End
Algorithm promising(i)
%% Input: Queen i
%% Output: Status about the feasibility of the
placement of queen i as true or false
flag = true
for k = 1 to i - 1 do
if((|col[i]-col[k]|= | i-k | ) or (col[i]==col[k])) then
flag = false
End if
return flag
End
1 2 3 4

2 3 4 1 3 4 1 2 4 1 2 3

3 4 2 4 2 3 3 4 1 4 1 3 2 4 1 4 1 2 2 3 1 3 1 2

4 3 4 2 3 2 4 3 4 1 3 1 4 2 4 1 2 1 3 2 3 1 2 1
1 2 3 4

2 3 4 1 3 4 1 2 4 1 2 3

2 4 2 3 1 3 2 4 2 3 1 3

3 3 2 2
 The argument of 4-queen problem can be extended
to an 8-queen problem as well.
 It can be seen that the number of nodes that will be
generated are 1 + 4 + 4 2 + 4 3 + 4 4 = ( 4 4 + 1 – 1)/(4 –1)
=(4 5 + 1)/3
 However, the constraint that no two queens in an
attacking position reduces these constraints to
1 + 4 + 4 х 3 + 4 х 3 х 2 + 4 х 3 х 2 х 1 promising nodes.
 In general 1+(n)+n(n-1)+n(n-1)(n-2)+…+n!
promising nodes are possible.
 This number of nodes can be used as an upper bound
to access the worst case behavior of the algorithm.
Algorithm sum_of_subsets(I, weight, total, W)
%% Input: Item i, weight is the weight if items added so far and total is the total
that is still available, W is the integer weight for which one wishes to find the
subsets of items whose sum must be equal to w, S is the vector whose values
are 0 or 1 that indicate the inclusion or exclusion of the items
%% Output: Items whose sum equals W
Begin
if promising_sum_of_subsets(i)
if(weight = = w) then
print items X[1 .. i]
end if
else
(X[i+1]=1) %% Include the item
sum_of_subsets(i+1, weight+wi+1, total-wi+1, W)
(X[i+1]=0) %% Exclude the item
sum_of_subsets(i+1, weight, total-wi+1, W)
End if
End
Algorithm promising_sum_of_subsets(i)
%% Input: Item I
%% Output: Status about feasibility of including
item as part of the subset
Begin
flag=true
if((weight+total)<w) and (weight!=w) and
(weight+w i + 1 >w)) then
flag=false
end if
return flag
End
 It can be observed that the generated
state space tree is a binary tree.
 At every stage, a node generates two
children nodes.
 Therefore the number of nodes that will
be generated equals 1 + 2 + 2 2 + 2 3 + . . + 2 n =
2n + 1 - 1 .
 This leads to a time complexity of sum of
subsets of O(2n).
Algorithm Hamiltonian(k)
do
{
NextVertex(k)
if(x[k]==0)
return;
if(k==n)
p
rint(x[
1:n])
else
H
amilto
nian(k
Algorithm NextVertex(k)
{
do
{
x[k]=(x[k]+1)mod(n+1)
if(x[k]==0)
return
if(G(x[k-1],x[k])!=0)
{
f
or j = 1
to k - 1
do
{
i
f
(
x
[
j
]
=
=
x
[
k
 The number of nodes in the state-space
tree is given as follows:

1+(n-1)+(n-1) 2 + … +(n-1) n - 1
=((n-1) n - 1 ) / (n – 2)

Therefore, the algorithm is an exponential


algorithm with a complexity of O(nn).
 The branch and bound design
technique is suitable for solving
 It is a state-space search method that can be visualized as an
• combinatorial optimization problems.
improved form of backtracking.
 In the branch and bound technique, a set of feasible solutions are
partitioned, and the subsets that do not have optimal solutions are
deleted form further consideration. Thus, the branch and bound
approach has two major steps-branching and bounding. These steps
are repeated till the problem is solved.
 Branching is the first step of the branch and
bound, which involves division of a given
problem into two or more sub problems.
 These sub problems are exclusive and

independent problems.
 In addition, they are similar to the original
 The second step is Bounding step, which aids in limiting the growth
of the state space.
 The best solution of the sub problems is identified and used as a
lower bound of the given problem.
 A lower bound is the optimistic estimate of the best solution.
 For every node I of the state space tree, the lower bound needs to be
calculated.
 In other words, exploring further down, the node i may not yield a
better solution.
 Similarly, the upper bound needs to be computed.
 This upper bound implies the minimum amount of its work required
to compute the result.
 The upper bound implies the best feasible solution.
 FIFOBB (Using Queue)
 LIFOBB (Using Stack)
 LCBB (Least Cost Branch and Bound)
Algorithm branch_bound_FIFO(P, root, goal)
%%Input: Problem P, root, and goal nodes
%%Output: Solution node
Begin
Q=Null %%Initialize queue Q with null
enqueue(Q,root) %%Initialize with root
best=value at root
while(Q!=null) then
v = dequeue(Q)
for all
children u of
v do
if bound of u is better than best
then enqueue(Q,u)
update the best value
End if
End for
End
Algorithm branch_bound_LIFO(P, root, goal)
%%Input: Problem P, root, and goal nodes
%%Output: Solution node
Begin
S=Null %%Initialize Stack S with
null push(S,root) %%Initialize with
root best=value at root
while(S!=null) then
v=pop(S)
for all children u of v do
if bound of u is better than best
then push(S,u)
update the best value
End if
End for
End
Algorithm branch_bound_LC(P, root, goal)
%%Input: Problem P, root, and goal nodes
%%Output: Solution node
Begin
Q=Null %%Initialize
priority queue Q with
null
enqueue(Q,root) %%Initialize with root
best=value at root
while(Q!=null) then
v=Extract_min(Q) %%Remove the
best node
if bound of v is better than best
then %% If it is promising then proceed further
for all children u to v
do
if bound of u is better than best
then enqueue(Q,u)
update the best value
End if
End for
End if
End while
 Assignment Problem: Assign unique job to every worker such that the
total cost is minimized. The constraint of the problem is;
n n
or

i Xij   Xij 
1
1  1
 j 1
Xij  i, j  1,2,...,
 Objective function is to
0ifunassigned n function:
1ifassigned
minimize the following
n n

f  
j 1 Cij.Xij
i1

 Cij is the cost
Complexity: of root
The assigning
of thei state
to j. f space
gives tree
the total
has nassignment cost.none
children, since
of the jobs is assigned to any workers. Nodes in next level can have
n-1
children each, as one job is allocated to a worker. Next level nodes have
n - 2 children and so on.
 Complexity of Assignment problem using Brute-force method is n!.
 Complexity of Assignment problem using Hungarian method is
O(n3 ).
 The worst case complexity of Branch and Bound remains same as
that of the Brute Force clearly because in worst case, we may never
get a chance to prune a node. Whereas, in practice it performs very
well depending on the different instance of the Assignment. The
complexity also depends on the choice of the bounding function as
they are the ones deciding how many nodes to be pruned.

 Complexity is O(nn).
 Similar to Hamiltonian cycle problem, but in addition requires to find
the optimal cycle.
 The worst case complexity of Branch and Bound remains same as
that of the Brute Force clearly because in worst case, we may never
get a chance to prune a node. Whereas, in practice it performs very
well depending on the different instance of the TSP. The complexity
also depends on the choice of the bounding function as they are the
ones deciding how many nodes to be pruned.

 Complexity is O(nn).
 Filling a knapsack with n items. Each item I is associated with a
profit v i and weight w i .
 The objective function is to achieve the maximum profit
subjected to
the constraint of the capacity of the knapsack.
 0 / 1 Knapsack problem is one where we either include the item on
the whole or exclude the item.
 The worst case complexity of Branch and Bound remains same as
that of the Brute Force clearly because in worst case, we may never
get a chance to prune a node. Whereas, in practice it performs very
well depending on the different instance of the TSP. The complexity
also depends on the choice of the bounding function as they are the
ones deciding how many nodes to be pruned.
 Complexity of 0 / 1 knapsack problem is O(2n )

You might also like