Skip to main content

A simple implementation of Genetic Algorithm

Project description


simplega is a simple python implementation of genetic algorithm and it is available through PyPI.


python3 -m pip install simplega


Import the package

from simplega import Chromosome, Population, GA, GAHelper
# or
from simplega import *

Create a fitness function that suits toyr problem

def maximize(chromosome):
    return sum( [ ord(gene) for gene in chromosome.dna ] )

Create a new instance of GA specifying the fitness function to be used

ga = GA(maximize)

Perform the steps of the genetic algorithm and retrieve the fittest chromosome

All the script - really simple:

from simplega import *

def maximize(chromosome):
    return sum( [ ord(gene) for gene in chromosome.dna ] )

ga = GA(maximize)

Advanced usage

You can customize your instance of GA, replacing any or all of its default values

ga = GA(fitness_function, 
  genes =  [ chr(n) for n in range(65,91) ], 
  chromosome_size =  10, 
  population_size =  100, 
  generations =  100, 
  crossover_points =  1, 
  elitism_rate =  0.05, 
  crossover_rate =  0.85, 
  mutation_rate =  0.01, 

You can print the fittest chromosome of each generation with


Please submit bugfixes, enhancements, unit tests, usecases and examples with a pull request.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simplega, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size simplega-1.0.1-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size simplega-1.0.1.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page