Skip to content

Implementation of the 0-1 Knapsack Problem in Python

Notifications You must be signed in to change notification settings

NateRice/0-1_Knapsack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

0-1 Knapsack Problem using branch and bound best first search method

An example of this problem concerns a thief breaking into a jewelry store carrying a knapsack. The knapsack will break if the total weight of the items stolen exceeds some maximum weight W. Each item has a value and a weight. The thief’s dilemma is to maximize the total value of the items while not making the total weight exceed W. This problem is called the 0-1 Knapsack problem ("Foundations of Algorithms"-Neapolitan).

Implementation

Implemented in Python. Optimal solution includes the maximum profit and a list of items that make the maximum profit. Returns maxprofit value with list storing the index position of the items in the best solution. The profit is maximized while staying under the weight limit. This program uses a priority queue to store the nodes ordered by best bound, the nodes are sorted as they are inserted into the priority queue. The node with the highest bound value is returned when removing from the priority queue. The best first approach arrives at an optimal solition faster than breadth first search especially with larger problem sets with a large amount of items.

About

Implementation of the 0-1 Knapsack Problem in Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages