Skip to content

Using genetic algorithm to solve the knapsack problem

License

Notifications You must be signed in to change notification settings

smadardan/Knapsack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knapsack

Knapsack solves the knapsack problem using genetic algorithm.

  • more about the knapsack problem can be found here
  • Explanation about genetic algorithm is present here

Usage

  1. clone the repository
  2. insert items in config/items.txt in the form of:
6 2
5 3
8 6
9 7
6 5
7 9
3 4

where the left int is the value of each item and the right int is the weight

  1. open the console. change directory to this repository
  2. write:
python main.py
  1. then you will need to insert 3 variables:

    • population size between 10 to 50 - how many chromosomes - possible solutions will be in each set of solutions
    • maximum weight between 10 to 20 - what is the maximum allowed weight for the knapsack (remember we want to maximize value and minimize weight)
    • number of iterations between 10 to 30 - how many iterations that creates population should execute? it is important to find the optimum of this hyperparameter
  2. in the end we will receive the best solution with the exact items in the logs\log_file.log. (an example is already present there)

License

MIT

About

Using genetic algorithm to solve the knapsack problem

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages