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:
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:
- define a template individual with specific encoding
from geneticpython.models import BinaryIndividual
indv_temp = BinaryIndividual(length=100)
- 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)
- 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()
- 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)
- register fitness function which gets an individual and returns its fitness value
@engine.maximize_objective
def fitness(indv):
return fitness_of_indv
- run engine
engine.create_seed(seed)
history = engine.run(generations=1000)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file geneticpython-0.0.2.tar.gz
.
File metadata
- Download URL: geneticpython-0.0.2.tar.gz
- Upload date:
- Size: 35.1 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583ec7a119ba5041a136c0c5c904e580a269db0180712363291d3c546ba12dc3 |
|
MD5 | 5b5ae848bde6e0ebcbac15cfa2344711 |
|
BLAKE2b-256 | ec3ffd847f748fad60a683ad9dde2dadd50b2932c0f9aa8f317d1bd8f9a7c401 |
File details
Details for the file geneticpython-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: geneticpython-0.0.2-py3-none-any.whl
- Upload date:
- Size: 68.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c6ed1f240d5a97b9d3214b22794efe794f2be56d4136d7c825cff26cfb80333 |
|
MD5 | 51c349a1b565c7f28274ebe9b0937b9d |
|
BLAKE2b-256 | 9b2e03477143af7a33df2df0f75df38bfda9b04648a1acdeda95da6d865374ed |