Skip to main content

simplega

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

Install

python3 -m pip install simplega

Usage

Import the package

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

Create a fitness function that suits your 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

ga.run()
print(ga.get_fittest())

All the script - really simple:

from simplega import *

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

ga = GA(maximize)
ga.run()
print(ga.get_fittest())

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 ga.run(True)

Contributing

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

Download files

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

Source Distribution

simplega-1.0.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplega-1.0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file simplega-1.0.2.tar.gz.

File metadata

  • Download URL: simplega-1.0.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for simplega-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f7e02e93285ad838f55f5d8247348b397bc959f3b8237fdceffb7faa8b1b7866
MD5 b8a59f8228d8e5b8d41d37c2ef1edf15
BLAKE2b-256 93524d641fda56a97940286e5ad37dbe27af2e3a09f980118e4c022e9138858a

See more details on using hashes here.

File details

Details for the file simplega-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: simplega-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for simplega-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7cf9b7707cb81df68019364ddc679256d5376bac19b95cdf7489245ae2e19e8
MD5 c93d17fb373b90c56c49c040cfbe3fdc
BLAKE2b-256 69c031990907c4f86f1255c8b08dc3f45daf5455507a00fbd727cf2974d59c07

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page