Baisc Attributes - danielwilczak101/EasyGA GitHub Wiki

There are 2 basic variables that control the size of the GA. Keep in mind these are only basic attributes. To get a full list please see the advanced setup attributes.

ga.chromosome_length   = 10           # Number of genes per chromosome
ga.population_size     = 10           # Number of chromosomes in the population

Termination Variables

Termination variables are used to tell EasyGA when to stop evolving the algorithm.

ga.generation_goal     = 100    # Number of generations the GA will run to before terminating

Full Example

From time to time, we like to show full examples. This allows you to copy and paste the full example and use it on your own system.

import EasyGA

# Create the genetic algorithm
ga = EasyGA.GA()

# Chnage the ga attributes
ga.chromosome_length   = 10
ga.population_size     = 5
ga.generation_goal     = 20

# Evolve the genetic algorithm
ga.evolve()

# Print the current generation and population
ga.print_generation()
ga.print_population()

Output

Current Generation 	: 20
Chromosome - 0 [5][3][2][4][5][10][5][1][5][6] / Fitness = 4
Chromosome - 1 [5][3][9][4][5][10][5][1][5][6] / Fitness = 4
Chromosome - 2 [5][5][4][3][2][4][4][7][5][6] / Fitness = 3
Chromosome - 3 [5][3][2][4][5][10][4][1][5][6] / Fitness = 3
Chromosome - 4 [5][3][4][3][2][4][5][7][5][6] / Fitness = 3

See how to setup the gene and chromosomes in your genetic algorithm.