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://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.0.tar.gz (14.5 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.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: GeneticAlgos-1.0.0.tar.gz
  • Upload date:
  • Size: 14.5 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.0.tar.gz
Algorithm Hash digest
SHA256 d673037cf10a21a7aabb83d782fba23c62826460cffb4de079ccb0a797f659e1
MD5 ef0b50563a4383ddddd51e30ef7ee432
BLAKE2b-256 044d5eeafaac92fd4ec92d1a173ba8461d8388f8e4caa349a5ab2cbad9b6c047

See more details on using hashes here.

File details

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

File metadata

  • Download URL: GeneticAlgos-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 391a15c707ced602eb64ce6d981dfb442eb8d4c5d35e6dc7b440884c28635225
MD5 9d1b263153f28c826e48a1c10e4d20a5
BLAKE2b-256 4b8cd133c951645b8c33b5deaedc2aeb0cdf17a04b02bcfc1433e335b322e22e

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