Skip to content

270ajay/SimpleGeneticAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Simple Genetic Algorithm

Credits

This python code is written after looking at the Java code written by Lee Original Java code and explanation: http://www.theprojectspot.com/tutorial-post/creating-a-genetic-algorithm-for-beginners/3

Description

  • We provide a solution (a sequence of 0s and 1s) to the program (in gaOptimization.py).
  • Program initially creates a number of sequences randomly.
  • It then improves them until it finds a sequence that matches the solution we provided.
  • Objective: maximize count of gene match.
  • Log file in the output folder shows the process.

Prerequisites

To run this Python program, please install logging and random libraries/packages.

About the Project

  • All the code is in src folder.
  • log file is stored in output folder.
  • To run the code, please run gaOptimization.py (to run from cmd, please enter python.exe gaOptimization.py).

Sample Log File

INFO: Optimal solution to reach: 1111000000000000000000000000000000000000000000000000000000001111

INFO: Generation: 1 ObjectiveValue: 42
DEBUG: 
Population:
0 ---- 1011010101000100000111000011111100000110101000010010000111110111
1 ---- 0001111100001101101111111001010010110010101111111101010111110010
2 ---- 1110100010001001110110001010011000110011011110010011111001100111
3 ---- 0011110101010001100101011101010110110000011000001011101110111001
...
46 ---- 1101010111001101101110010010001110110101011110100101011011011011
47 ---- 0010111000010011010001100101110110000111111100010010010011100000
48 ---- 0100011110001001100000111001100001110000010101111011101100011001
49 ---- 1010111001010111010000110100001000101010100110111010111110101100
DEBUG: Fittest in this population: 1111000100100010110001101011101001101010001010010011000000001011

...

INFO: Generation: 18 ObjectiveValue: 63
DEBUG: 
Population:
0 ---- 1111000000000000000000001000000000000000000000000000000000001111
1 ---- 1111000000000000000000001000000000000000000000000000000000001111
2 ---- 1111000000001000000000101000000000000000000000000000000000101111
3 ---- 1111000000000000010000001000000000000000000000000000000000001111
...
47 ---- 1111000000000000000000101000000010000000000000000000000000001111
48 ---- 1111000000000000000000101010000000000000000000000000000000001110
49 ---- 1111000000000000000000001000000001000000000000000000000000001111
DEBUG: Fittest in this population: 1111000000000000000000001000000000000000000000000000000000001111


INFO: 
Reached optimal solution (that was provided in the beginning) in Generation: 19
DEBUG: 
Population:
0 ---- 1111000000000000000000001000000000000000000000000000000000001111
1 ---- 1111000000000000000000001000000000000000000000000000000000001111
2 ---- 1111000000000000000000001000000000000000000000000000100000001111
...
9 ---- 1111000000000000000000000000000000000000000000000000000000001111
...
47 ---- 1111000000000000000000001000000000000000000000000000000000001111
48 ---- 1111000000000000100000001000000000000000000000000000000000001111
49 ---- 1111000001000000000000001100000000000000000000000000000000001111
INFO: Fittest in this population: 1111000000000000000000000000000000000000000000000000000000001111