12 DRR
12 DRR
Program-12
Aim:- Implementa on of solu on of 0-1 Knapsack problem using Branch and Bound Method.
class KnapsackBB {
double bound;
this.level = level;
this.profit = profit;
this.weight = weight;
this.bound = bound;
totalWeight += wt[j];
profitBound += val[j];
j++;
if (j < n)
return profitBound;
Arrays.sort(wt);
pq.add(u);
int maxProfit = 0;
while (!pq.isEmpty()) {
u = pq.poll();
count++;
Node v = new Node(u.level + 1, u.profit + val[u.level + 1], u.weight + wt[u.level + 1], 0);
maxProfit = v.profit;
pq.add(v);
pq.add(v);
return maxProfit;
int W = 50;
int n = val.length;
}
Name-Vikash kumar Roll-11232947 Sec on-4D3
Output:-
Maximum Profit: 220
Total nodes processed: 7
Graph:-