Skip to content

gohny/knapsack-genetic-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Genetic algorithm for knapsack problem written in python

Version: 1.1.0

Usage

Variables

  • ITEMS - List of tuples containing item data (format: ({weight}, {value})).
  • CAP - Capacity of the knapsack.
  • POP - Population size.
  • GEN - Amount of generations (including initial generation).
  • CROSS - Probability of each pair of parents crossing their genes (scope: 0-1).
  • MUT - Probability of mutation of each gene (scope: 0-1).
  • USE_CURSES - Display using curses instead of printing (True/False).

Adjust these variables to get different results.

Output

Prints sets of each generation and fitness of each set.
Points out best sets with the highest fitness for each generation.

fitness - Value of each set (when it exceeds CAP its value is set to 0).

Example

GENERATION {generation number}
1. [{set of genes}] FITNESS={fitness of first set}
2. [{set of genes}] FITNESS={fitness of second set}
3. [{set of genes}] FITNESS={fitness of third set}
  BEST: FITNESS={best fitness of current generation}
  {No.} [{set of genes}]

Made by gohny

About

Genetic algorithm for knapsack problem written in python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages