The Best-First Search with Branch-and-Bound Pruning for the 0-1 Knapsack Problem - Psudocode include below. Report the solutions found for three different problem instances, also the number of nodes generated for each problem. Include your source code. The first of the problem instances should use the instance included below.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Implement in Java The Best-First Search with Branch-and-Bound Pruning for the 0-1 Knapsack Problem - Psudocode include below.
Report the solutions found for three different problem instances, also the number of nodes generated for each problem. Include your source code.
The first of the problem instances should use the instance included below.
  
struct node
{
int level;
int profit;
int weight;
float bound;
};
// the node's level in the tree
void knapsack3 (int n,
const int p[], const int w[],
int W.
int& marprofit)
{
priority queue.of_node PQ;
node u, v;
// Initialize PQ to be
// empty.
// Initialize v to be the
// root.
initialize (PQ);
v. level = 0; v. profit = 0; v. weight = 0;
marprofit = 0;
v. bound = bound(v);
insert (PQ, v);
while (! empty (PQ)){
remove (PQ, v);
if (v. bound > marprofit){
u. level = v. level + 1;
u. weight v.weight + w[u. level];
u. profit = v. profit + p[u. level%;
// Remove node with
// best bound.
// Check if node is still
// promising.
// Set u to the child
// that includes the
// next item.
if (u. weight <= W && u. profit > marprofit)
marprofit u.profit;
u. bound bound(u):
if (u.bound > marprofit)
insert(PQ, u);
u. weight v. weight;
u. profit v. profit;
u. bound = bound(u);
if (u.bound > marprofit)
insert(PQ, u);
// Set u to the child
// that does not include
// the next item.
}
float bound (node u)
{
index j, k;
int totweight;
float result;
if (u. weight >= W)
return 0;
else{
result u. profit;
j = u. level + 1;
totweight = u.weight;
while (j<= n && totweight + w[j] <= W){
totweight totweight + w[j];
result result + pli];
// Grab as many items
// as possible.
j++:
k = j;
if (k <=n)
result = result + (W- tot weight) p[k] / w[k];
// Use k for consistency
// with formula in text.
// Grab fraction of kth
// item.
return resuit;
Transcribed Image Text:struct node { int level; int profit; int weight; float bound; }; // the node's level in the tree void knapsack3 (int n, const int p[], const int w[], int W. int& marprofit) { priority queue.of_node PQ; node u, v; // Initialize PQ to be // empty. // Initialize v to be the // root. initialize (PQ); v. level = 0; v. profit = 0; v. weight = 0; marprofit = 0; v. bound = bound(v); insert (PQ, v); while (! empty (PQ)){ remove (PQ, v); if (v. bound > marprofit){ u. level = v. level + 1; u. weight v.weight + w[u. level]; u. profit = v. profit + p[u. level%; // Remove node with // best bound. // Check if node is still // promising. // Set u to the child // that includes the // next item. if (u. weight <= W && u. profit > marprofit) marprofit u.profit; u. bound bound(u): if (u.bound > marprofit) insert(PQ, u); u. weight v. weight; u. profit v. profit; u. bound = bound(u); if (u.bound > marprofit) insert(PQ, u); // Set u to the child // that does not include // the next item. } float bound (node u) { index j, k; int totweight; float result; if (u. weight >= W) return 0; else{ result u. profit; j = u. level + 1; totweight = u.weight; while (j<= n && totweight + w[j] <= W){ totweight totweight + w[j]; result result + pli]; // Grab as many items // as possible. j++: k = j; if (k <=n) result = result + (W- tot weight) p[k] / w[k]; // Use k for consistency // with formula in text. // Grab fraction of kth // item. return resuit;
Pi
i
pi
Wi
Wi
1
$20 2
10
$30
3
$35
4
$12 3
4
$3
1 3
W = 13
Transcribed Image Text:Pi i pi Wi Wi 1 $20 2 10 $30 3 $35 4 $12 3 4 $3 1 3 W = 13
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education