0% found this document useful (0 votes)
26 views33 pages

21CB1401 - Unit V

Uploaded by

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

21CB1401 - Unit V

Uploaded by

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

21CB1401 Design & Analysis of Algorithm Unit-4

UNIT -V P, NP CLASSES AND BRANCH AND BOUND 9


Lower - Bound Arguments - P, NP, NP- Complete and NP Hard
Problems-Branch and Bound- LIFO Search and FIFO search -
Assignment problem - Knapsack Problem – Travelling Salesman
Problem - Approximation Algorithms for NP-Hard Problems -
Travelling Salesman problem - Knapsack problem.

BRANCH-AND-BOUND
General Method
 A branch and bound is a general algorithm for finding optimal
solutions of various optimization problems.
 An optimization problem seeks to minimize or maximize an
objective function, subject to some constraints.
 To deal with optimization problem we compute the best value
of best solution achieved so far.
 A bound on the best solution that can be achieved by expanding
the node is computed and compared to best.
 For a maximization problem the bound is an upper bound
 The largest possible solution that can be achieved by
expanding the node is less or equal to the upper bound.
 If upper bound > best so far, a better solution may be found
by expanding the node and the feasible node is promising .
 For a minimization problem the bound is an lower bound
 The smallest possible solution that can be achieved by
expanding the node is less or equal to the lower bound.
 If lower bound < best so far, a better solution may be found
by expanding the node and the feasible node is promising .
 A Feasible Solution is a point in the problem’s search space that
satisfies all the problem’s constraints.
Example:
21CB1401 Design & Analysis of Algorithm Unit-4
 a Hamiltonian circuit in the traveling salesman problem
 a subset of items whose total weight does not exceed
the knapsack’s capacity

 A optimal solution is a feasible solution with the best value of


the objective function.
Example The shortest Hamiltonian circuit , the most valuable
subset items that fit the knapsack .
Compared to backtracking, branch-and-bound requires two
additional items:
 For every node of a state-space tree, a bound on the best value of
the objective function 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 .
Terminate search path at the current node for any one of the
following three reasons:
1. The value of the node’s bound is not better than the value of the best
solution seen so far.
2. The node represents no feasible solutions because the constraints of
the problem are already violated.
3. When no further choices can be made— compare the feasible
solution with that of the best solution is found so far and update the
latter with the former if the new solution is better.
Knapsack Problem
Problem Definition: Given ‘n’ items of known weights w1,w2,.
. . ,wn and values v1,v2,. . . ,vn and a knapsack of capacity W, we
have to find the most valuable subset of the items that fit in the
knapsack.
 This is a maximization problem. So, upper bound value is
21CB1401 Design & Analysis of Algorithm Unit-4
associated with each node.
 It is convenient to order the items of a given instance in
descending order by their value-to-weight ratios.

 Then the first item gives the best payoff per weight unit and the
last one gives the worst payoff per weight unit, with ties resolved
arbitrarily:
v1/ w1 ≥ v2/ w2 ≥ . . . ≥ vn/ wn
Construction of the state space tree
 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.
 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.
The upper bound ub is computed using the
formula ub = v + (W - w)(vi+1/w
i+1)
where, v  Total value of the items already selected
W-w  Product of the remaining capacity of the
knapsack vi+1/w i+1  Best per unit payoff among
remaining items, which
is:
Characteristics of knapsack while solved using Branch and Bound
Technique
21CB1401 Design & Analysis of Algorithm Unit-4
 The internal nodes of a state space tree do not define a point of
the problem’s search space, because some of the solution’s
components remain undefined.

 Every node of the tree represents a subset of the items given and
uses this fact to update the information about the best subset seen
so far after generating each new node in the tree.
Example: Computing the value to weight ratios and sorting
the items in non increasing order of these efficiency

ratios yields.
 At the root of the state-space tree (see Figure 7.4), no items have
been selected as yet. Hence, both the total weight of the items
already selected w and their total value v are equal to $0. The
value of the upper bound computed by formula
ub = 0 + (10 - 0) (10) =100
 Node 1, the left child of the root, represents the subsets that
include item 1. The total weight and value of the items already
included are 4 and $40, respectively; the value of the upper
bound is 40 + (10 - 4) * 6 = $76.
 Node 2 represents the subsets that do not include item 1.
Accordingly, w = 0, v = $0, and ub =0+(10 - 0) * 6 = $60.
 Since node 1 has a larger upper bound than the upper bound of
node 2, it is more promising for this maximization problem, and
21CB1401 Design & Analysis of Algorithm Unit-4
we branch from node 1 first.

 Its children—nodes 3 and 4—represent subsets with item 1 and


with and without item 2, respectively.
 Since the total weight w of every subset represented by node 3
exceeds the knapsack’s capacity, node 3 can be terminated
immediately.
 Node 4 has the same values of w and v as its parent; the upper
bound ub is equal to 40 + (10 - 4) * 5 = $70.

Figure: State-space tree of the best-first branch-and-bound algorithm for


the instance of the knapsack problem.

 Selecting node 4 over node 2 for the next branching and get
nodes 5 and 6 by respectively including and excluding item 3.
21CB1401 Design & Analysis of Algorithm Unit-4
 Calculate the total weights and values as well as the upper
bounds for these nodes are computed in the same way as for the
preceding nodes.
 Branching from node 5 yields node 7, which represents no
feasible solutions, and node 8, which represents just a single
subset {1, 3} of value $65.
 The remaining live nodes 2 and 6 have smaller upper-bound
values than the value of the solution represented by node 8.
 Hence, both can be terminated making the subset {1, 3} of node
8 the optimal solution to the problem.
Example 2
21CB1401 Design & Analysis of Algorithm Unit-4
21CB1401 Design & Analysis of Algorithm Unit-4
AD8351 Design & Analysis of Algorithm Unit-4

Traveling Salesman Problem


Problem Definition:
Given a set of cities and the distances between them, determine
the shortest path starting from a given city, passing through all
the other cities exactly once and returning to the first city.
 This is a minimization problem. So lower bound value is
associated with each node.
 Lower bound can be obtained by finding the smallest element in
the intercity distance matrix D and multiplying it by the number
of cities n. But there is a less obvious and more informative lower
bound, which does not require a lot of work to compute.
 A lower bound on the length l of any tour can be computed as
follows:
 For each city i,1≤ i ≤ n, find the sum si of the distances from
city i to the two nearest cities;
 Compute the sum s of these n numbers
 Divide the result by 2
 If all the distances are integers, round up the result to the
nearest integer: lb = ┌s/2┐

Example: Solve the following travelling salesman problem


using the branch and bound approach
AD8351 Design & Analysis of Algorithm Unit-4

 For the instance of the above graph, the formula yields


lb = ┌[1 + 3) + (3 + 6) + (1 + 2) + (3 + 4) + (2 + 3)]/2┐=14.
 Moreover, for any subset of tours that must include particular
edges of a given graph, we can modify lower bound accordingly.

Figure 7.5: State-space tree of the branch-and-bound algorithm


AD8351 Design & Analysis of Algorithm Unit-4

to find a shortest Hamiltonian circuit in this graph. The list of


vertices in a node specifies a beginning part of the Hamiltonian
circuits represented by the node.

 For example, for all the Hamiltonian circuits of the graph that
must include edge (a, d), the following lower bound by summing
up the lengths of the two shortest edges incident with each of the
vertices, with the required inclusion of edges (a, d) and (d, a):
┌[(1 + 5) + (3 + 6) + (1 + 2) + (3 + 5) + (2 + 3)]/2┐=16.
 Now apply the branch-and-bound algorithm, with the bounding
function given by lb =┌ s/2┐ to find the shortest Hamiltonian
circuit for the given graph .

 To reduce the amount of potential work, we take advantage of


two observations:
 Consider only tours that start at a
 Because our graph is undirected, generate only tours in
which b is visited before c.
 After visiting n - 1 = 4 cities, a tour has no choice but to visit the
remaining unvisited city and return to the starting one.
AD8351 Design & Analysis of Algorithm Unit-4

Example 2:
AD8351 Design & Analysis of Algorithm Unit-4
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt
AD8351 Design & Analysis of Algorithm Unit-4

Scanned By ScanIt

You might also like