Skip to content

Knapsack problem solution using an implementation of a genetic algorithm and hill climbing.

Notifications You must be signed in to change notification settings

TudorBNG/KnapsackProblem-A.I.-Approach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item, or don’t pick it (0-1 property).

I solved it by implementing: Genetic Algorithm(GA) and Hill Climbing(HC)

Input file format:
The number of items
The weights of the items(vector)
The values of the items(vector)
Knapsack capacity


Output file format:
The number of selected items
Binary vector(1 if the item was selected, 0 otherwise)
Value vector(value if the item was selected, 0 otherwise)
Total value of the selected items

About

Knapsack problem solution using an implementation of a genetic algorithm and hill climbing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages