Daa Mod-5
Daa Mod-5
Let us now discuss how we can apply the branch-and-bound technique to solving
the knapsack problem: given n items of known weights wi and values vi , i = 1, 2, .
. . , n, and a knapsack of capacity W, find the most valuable subset of the items that
fit in the knapsack.
It is natural to structure the state-space tree for this problem as a binary tree
constructed as follows (see Figure 12.8 for an example). Each node on the ith
level of this tree, 0 ≤ i ≤ n, represents all the subsets of n items that include a
particular selection made from the first i ordered items. This particular selection is
uniquely determined by the path from the root to the node: a branch going to the
left indicates the inclusion of the next item, and a branch going to the right
indicates its exclusion. We record the total weight w and the total value v of this
selection in the node, along with some upper bound ub on the value of any subset
that can be obtained by adding zero or more items to this selection.
A simple way to compute the upper bound ub is to add to v, the total value of the
items already selected, the product of the remaining capacity of the knapsack W
− w and the best per unit payoff among the remaining items, which is
vi+1/wi+1:
As a specific example, let us apply the branch-and-bound algorithm to the
same instance of the knapsack problem we solved in Section 3.4 by exhaustive
search. (We reorder the items in descending order of their value-to-weight
ratios, though.)
DIAGRAMATIC REPRESENTATION
We start with the empty board and then place queen 1 in the first possible position of its row, which is
in column 1 of row 1. Then we place queen 2, after trying unsuccessfully columns 1 and 2, in the first
acceptable position for it, which is square (2, 3), the square in row 2 and column 3. This proves to be a
dead end because there is no acceptable position for queen 3. So, the algorithm backtracks and puts
queen 2 in the next possible position at (2, 4). Then queen 3 is placed at (3, 2), which proves to be
another dead end. The algorithm then backtracks all the way to queen 1 and moves it to (1, 2). Queen
2 then goes to (2, 4), queen 3 to (3, 1), and queen 4 to (4, 3), which is a solution to the problem. The
state-space tree of this search is shown in Fig below:
NOTE: If other solutions need to be found, the algorithm can simply resume its operations at the leaf
at which it stopped.
Hamiltonian Circuit Problem:
Without loss of generality, we can assume that if a Hamiltonian circuit exists, it starts at
vertex a. Accordingly, we make vertex ‘a’ the root of the state-space tree (Figure 12.3b). The
first component of our future solution, if it exists, is a first intermediate vertex of a
Hamiltonian circuit to be constructed.
Using the alphabet order to break the three-way tie among the vertices adjacent to ‘a’, we
select vertex b. From b, the algorithm proceeds to c, then to ‘d’, then to ‘e’, and finally to ‘f’,
which proves to be a dead end.
So, the algorithm backtracks from ‘f’ to ‘e’, then to ‘d’, and then to c, which provides the first
alternative for the algorithm to pursue.
Going from ‘c’ to ‘e’ eventually proves useless, and the algorithm has to backtrack from e to
c and then to b. From there, it goes to the vertices f , e, c, and d, from which it can
legitimately return to a, yielding the Hamiltonian circuit a, b, f , e, c, d, a. If we wanted to
find another Hamiltonian circuit, we could continue this process by backtracking from the
leaf of the solution found.
Branch-and-Bound
Compared to backtracking, branch-and-bound requires two additional items:
- a way to provide, for every node of a state-space tree, a bound on the
best value of the objective function1 on any solution that can be obtained by
adding further components to the partially constructed solution represented
by the node
- The value of the best solution seen so far, If this information is available,
we can compare a node’s bound value with the value of the best solution
seen so far.
- If the bound value is not better than the value of the best solution seen so
far—i.e., not smaller for a minimization problem and not larger for a
maximization problem—the node is nonpromising and can be terminated
(some people say the branch is “pruned”).
- Indeed, no solution obtained from it can yield a better solution than the
one already available. This is the principal idea of the branch-and-bound
technique.
-The value of the node’s bound is not better than the value of the best
solution seen so far.
Assignment Problem
Let us illustrate the branch-and-bound approach by applying it to the problem of assigning n
people to n jobs so that the total cost of the assignment is as small as possible. We introduced
this problem in Section 3.4, where we solved it by exhaustive search. Recall that an instance
of the assignment problem is specified by an n × n cost matrix C so that we can state the
problem as follows: select one element in each row of the matrix so that no two selected
elements are in the same column and their sum is the smallest possible.
For example, it is clear that the cost of any solution, including an optimal one, cannot be
smaller than the sum of the smallest elements in each of the matrix’s rows. For the instance
here, this sum is 2 + 3+ 1 + 4 = 10.
It is important to stress that this is not the cost of any legitimate selection (3 and 1 came from
the same column of the matrix); it is just a lower bound on the cost of any legitimate
selection. We can and will apply the same thinking to partially constructed solutions.
For example, for any legitimate selection that selects 9 from the first row, the lower bound
will be 9 + 3 + 1+ 4 = 17.