Skip to main content

Simple and powerful Python library for creating genetic algorithms.

Project description

https://github.com/lkozelnicky/GeneticAlgos/workflows/Tests/badge.svg https://coveralls.io/repos/github/lkozelnicky/GeneticAlgos/badge.svg?branch=master https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/pypi/v/GeneticAlgos.svg https://img.shields.io/pypi/l/GeneticAlgos.svg https://img.shields.io/pypi/pyversions/GeneticAlgos.svg GenticAlgos logo

GeneticAlgos is a simple and powerful Python library for creating genetic algorithms to solve complex optimization problems. GeneticAlgos is built on NumPy and it is under active development.

  • Uses smart defaults for genetic algorithms parameters which are good enough for generic use cases or for testing.

  • A simple-to-use API to modify genetic algorithms parameters.

  • Lightweight and just one dependency - Numpy.

  • Excellent test coverage.

  • Tested on Python 3.7, 3.8 and 3.9

Documentation

Online documentation is available at https://geneticalgos.readthedocs.io/en/latest/.

The docs include a introduction to genetic algorithms, examples, advanced usage, and other useful information.

Usage

geneticalgos is available on PYPI.

Install with pip:

$ pip install geneticalgos

Trivial example:

We want to find a set of X=(x1, x2, x3, x4) which maximizes sum(x1, x2, x3, x4), when each element x is a float from interval (0, 10). Simple answer is: x1 = 10, x2 = 10, x3 = 10, x4 = 10. First, we define our fitness function (sum) and then gene_intervals for each x.

All other parameters (population size, crossover method, mutation probability, …) are configured with default values. However, you can change and tweak them easily - Advanced usage.

import geneticalgos as ga
import numpy as np

def custom_fitness_function(chromosome):
  return sum(chromosome)

gene_intervals = np.array([[0, 10]] * 4)

# Create genetic algorithms with default values for GA parameters
# and our fitness function and gene intervals
ga_model = ga.GeneticAlgo(
    fitness_function=custom_fitness_function,
    gene_intervals=gene_intervals,
)

# Start genetic algorithm simulation
ga_model.simulate()

# print best solution
print(ga_model.best_chromosome)

# print fitness value for best chromosome
print(ga_model.best_fitness)

When to use GeneticAlgos

The main goal of the GeneticAlgos is to be simple and powerful.

  • Simple, because it can be used with basic knowledge of python (data structures, functions, …).

  • Simple, because it can be used with basic knowledge of genetic algorithms (population, chromosome, fitness function, …).

  • Powerful, because we can tweak many genetic algorithms parameters very easily and create complex models with the minimum of configuration.

When not to use GeneticAlgos

Let’s be honest, genetic algorithms are very complex algorithms which have a lot of modifications from a standard scheme.

You should look somewhere else if you need:

  • Something other than binary or numerical encoding - like permutation, strings, …

  • Chromosome genes with different encoding within same chromosome - some genes are float numbers and some of them integers.

  • An end criterion that is different from a fixed number of generation cycles.

Issues

If you encounter any problems, please file an issue along with a detailed description. Thank you 😃

About GeneticAlgos

Created by Lukas Kozelnicky.

Distributed under the MIT license. See LICENSE.txt for more information.

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

GeneticAlgos-1.0.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

GeneticAlgos-1.0.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file GeneticAlgos-1.0.1.tar.gz.

File metadata

  • Download URL: GeneticAlgos-1.0.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for GeneticAlgos-1.0.1.tar.gz
Algorithm Hash digest
SHA256 601e2aec9ce705431662689205223f6eb4f94c20768369033deba56f13da44fe
MD5 066c07c0a813edc998274cdd121cb3a6
BLAKE2b-256 7154ea3671e6fdb7d1e2b655bd0f1513c976d4ce0fa634eb19cd8fb5165ca30b

See more details on using hashes here.

File details

Details for the file GeneticAlgos-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: GeneticAlgos-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for GeneticAlgos-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a066320a6c4208e4dc25bf8523c45c6085f99e349a7761dbad164a949820dca
MD5 653f17c54c6369727c71dad5de9854ca
BLAKE2b-256 e3713842e660b851a17e294501080af5168258533dd95ed63bc015c01a998529

See more details on using hashes here.

Supported by

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