Skip to main content

A simple and friendly Python framework for genetic-based algorithms

Project description

geneticpython

A simple and friendly Python framework for genetic-based algorithms (strongly supports tree-encoding)

  • Supported algorithms: Genetic Algorithm (GAEngine), NSGA-ii (NSGAIIEngine).
  • An example on ZDT1 problem:

alt tag

Installation

This package requires python 3.6 or later.

pip install geneticpython

Getting started

We can quickly design a genetic algorithm in the following steps:

  1. define a template individual with specific encoding
from geneticpython.models import BinaryIndividual
indv_temp = BinaryIndividual(length=100)
  1. define population based on this population can uniformly initialize a population or you can define your own by passing init_population argument function
from geneticpython import Population
population = Population(indv_temp, pop_size=100)
  1. define some core operators in genetic algorithm
from geneticpython.core.operators import RouletteWheelSelection, UniformCrossover, \
                                        FlipBitMutation, RouletteWheelReplacement
selection = RouletteWheelSelection()
crossover = UniformCrossover(pc=0.8, pe=0.5)
mutation = FlipBitMutation(pm=0.1)
# this function decides which individuals will be survived
replacement = RouletteWheelReplacement()
  1. create an engine and register the defined population and operators
from geneticpython import GAEngine
engine = GAEngine(population, selection=selection,
                  selection_size=100,
                  crossover=crossover,
                  mutation=mutation,
                  replacement=replacement)
  1. register fitness function which gets an individual and returns its fitness value
@engine.maximize_objective
def fitness(indv):
    return fitness_of_indv
  1. run engine
engine.create_seed(seed)
history = engine.run(generations=1000)
  1. get results and plot history
ans = engine.get_best_indv()
print(ans)
plot_single_objective_history({'geneticpython': history})

You can find more examples here

TODO

  • [] Create extensive documentation and docs and comments in source-code
  • [] Implement other algorithms: PSO, DE, MOED/A, MOPSO, MODE,...
  • [] Implement other operators: PMX crossover, ...

Issues and Contribution

This project is in development, if you find any issues, please create an issue here.

If you are interested in contributing this project, feel free to create pull request here. We appreciate any contributions from you.

Acknowledgements

Special thanks to https://github.com/PytLab/gaft for getting me started a great API design.

This repository includes adaptions of the following repositories as baselines:

Project details


Download files

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

Source Distribution

geneticpython-0.0.1.tar.gz (35.0 kB view details)

Uploaded Source

Built Distributions

geneticpython-0.0.1-py3.9.egg (169.2 kB view details)

Uploaded Source

geneticpython-0.0.1-py3-none-any.whl (68.3 kB view details)

Uploaded Python 3

File details

Details for the file geneticpython-0.0.1.tar.gz.

File metadata

  • Download URL: geneticpython-0.0.1.tar.gz
  • Upload date:
  • Size: 35.0 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.25.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.9.2

File hashes

Hashes for geneticpython-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0ca728bb88fb91d3aaa951678c877a98346e2388f2087aaadeceec9dd646dbd6
MD5 54d3913f39d3a1102abd24abeffeffd6
BLAKE2b-256 ddcbcf98bf3accf0038f90f3a2ba152223d18af599a116e822a7ea46f55f1bba

See more details on using hashes here.

File details

Details for the file geneticpython-0.0.1-py3.9.egg.

File metadata

  • Download URL: geneticpython-0.0.1-py3.9.egg
  • Upload date:
  • Size: 169.2 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.25.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.9.2

File hashes

Hashes for geneticpython-0.0.1-py3.9.egg
Algorithm Hash digest
SHA256 67d39e35e243983d4c62fd425e2616b5240405170b60225a17dcbf269c7502f0
MD5 a81b27b92488c8ca6d47d47e6d83839b
BLAKE2b-256 8efbf03db75c933bf32fd680310094b06f180a4879a4407cd977ac8075c15a6d

See more details on using hashes here.

File details

Details for the file geneticpython-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: geneticpython-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 68.3 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.25.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.9.2

File hashes

Hashes for geneticpython-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 337fd0f6925df67fd2dfe32beff5798e76c250b02ac607749b13e8b1d64f6c11
MD5 8d54c4033a0b9625c31d778a65631c21
BLAKE2b-256 a1634fc8d2ae72d9ea4ef66aafb203d4c2e0177c80aa7242a317f3430e69ae4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page