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, 3.9 and 3.10

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.2.tar.gz (14.3 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.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: GeneticAlgos-1.0.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for GeneticAlgos-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a767a45528246dac1ece591afd4bdc21bf8f9794a49722be080a192bd1f14419
MD5 38aa9dd9e06681584a4bd70ec0c16158
BLAKE2b-256 59e8d2298fc76802273a0666fddc4fbabd788036943db550ce90361f44685929

See more details on using hashes here.

File details

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

File metadata

  • Download URL: GeneticAlgos-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for GeneticAlgos-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eaab5c91bd45b710cd553f209420c58c22e540dd506970188b7f8aeae7c4227e
MD5 9badd3148691f644fb70f762333e5068
BLAKE2b-256 0a5592de161a8c871207889a4eee4c08054586854c7da7d28117d2b8f296eb5c

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