Execute genetic algorithm (GA) simulations in a customizable and extensible way.

Overview

genevo

Crates.io Docs.rs Linux Build Status Windows Build Status codevoc.io MIT/Apache Join the chat

genevo provides building blocks to run simulations of optimization and search problems using genetic algorithms (GA).

The vision for genevo is to be a flexible and greatly extensible framework for implementing genetic algorithm applications.

genevo is written in Rust. The library's API utilizes lots of traits and types for modelling the domain of genetic algorithms.

Documentation

Features

This crate provides a default implementation of the genetic algorithm to be used to find solutions for a wide variety of search and optimization problems.

The implementation is split into building blocks which are all represented by traits. This crate provides most common implementation for all building blocks. So it can be used for many problems out of the box.

Anyway if one wants to use different implementations for one or the other building block it can be extended by implementing any of the traits in a more sophisticated and customized way.

The building blocks (defined as traits) are:

  • Simulation
  • Algorithm
  • Termination
  • Operator
  • Population
  • Phenotype and Genotype
  • FitnessFunction

The simulation can run an algorithm that is executed in a loop. An algorithm implements the steps to be done for each iteration of the loop. The provided implementation of the genetic algorithm implements the Algorithm trait and can therefore be executed by the Simulator which is the provided implementation of the Simulation trait.

The Simulator holds state about the simulation and tracks statistics about the execution of the algorithm, such as number of iterations and processing time.

The simulation runs until the termination criteria are met. The termination criteria can be a single one such as max number of iterations or a logical combination of multiple termination criteria, e.g. max number of iterations OR a minimum fitness value has been reached. Of coarse Termination is a trait as well and one can implement any termination criteria he/she can think of.

The algorithm can make use of operators that perform different stages of the algorithm. E.g. the basic genetic algorithm defines the stages: selection, crossover, mutation and accepting. These stages are performed by the appropriate operators: SelectionOp, CrossoverOp, MutationOp, RecombinationOp and ReinsertionOp.

This crate provides multiple implementations for each one of those operators. So one can experiment with combining the different implementations to compose the best algorithm for a specific search or optimization problem. Now you may have guessed that the defined operators are traits as well and you are free to implement any of these operators in a way that suits best for your problem and plug them into the provided implementation of the genetic algorithm.

The genetic algorithm needs a population that it evolves with each iteration. A population contains a number of individuals. Each individual represents a possible candidate solution for an optimization problem for which the best solution is searched for. This crate provides a PopulationBuilder to build population of genomes. To run the population builder it needs an implementation of the GenomeBuilder trait. A GenomeBuilder defines how to create one individual (or genome) within the population.

Last but maybe most important are the traits Phenotype, Genotype and FitnessFunction. These are the traits which define the domain of the optimization problem. They must be implemented individually for each application of the genetic algorithm.

Enough words about the building blocks. Show me some concrete examples. Have a look at the examples in the examples folder to find out how to use this crate:

Usage

Add this to your Cargo.toml:

[dependencies]
genevo = "0.5"

If you are not using Rust 2018 edition add this to your crate root:

extern crate genevo;

References

I started this project mainly to learn about genetic algorithms (GAs). During this journey I searched a lot for information about GA. Here are the links to sources of information about GA that I found most useful for me.

[JFGA]: Jeremy Fisher: Genetic Algorithms

[OBI98]: Marek Obitko: Genetic Algorithms Tutorial

[GEAT]: GEATbx: Evolutionary Algorithms

[IGAYT]: Noureddin Sadawi: A Practical Introduction to Genetic Algorithms

[CT9YT]: The Coding Train: 9: Genetic Algorithms - The Nature of Code

[BT95]: Tobias Blickle, Lothar Thiele, 1995: A Comparison of Selection Schemes used in Genetic Algorithms.

[RRCGH]: StefanoD: Rust_Random_Choice Rust library.

[TSP95]: TSPLIB95: library of sample instances for the TSP (and related problems)


Copyright © 2017-2019, Innoave.com and contributors

Comments
  • This crate can run on wasm32 with a little modification.

    This crate can run on wasm32 with a little modification.

    I wrote a traveling salesman problem in rust and build it with wasm bindgen.

    1. rayon::join doesn't work on wasm32, so I limit the population under 50.
    2. time::get_time is unimplemented!. so I stub the time crate return value with 0.

    demo https://warycat.github.io/ga_wasm/ src https://github.com/warycat/ga_wasm

    Thank you for making this awesome crate.

    opened by warycat 5
  • Disable GA parallelism

    Disable GA parallelism

    I'm currently implementing a genetic algorithm that runs a circuit simulation to evaluate a circuits fitness. To perform the simulation, I use a third party C API. This API is called from within the fitness_of() function of the FitnessFunction trait I defined.

    The third party C API I use cannot be used in a multi-threaded fashion. so I'm wondering if it's possible to disable the parallelism in the ga module; or if there is a less performant, sequential version of genevo.

    opened by keegit 3
  • Add default mutation operators for binary, value and permutation encoding

    Add default mutation operators for binary, value and permutation encoding

    Default mutation operators for basic encoding types are helpful to use the library for simulations with basic genotypes.

    With this issue mutation operators for the following 3 encoding types will be supported:

    • binary encoding
    • value encoding
    • permutation encoding
    feature 
    opened by haraldmaida 2
  • Add default crossover operators for binary, value and permutation encoding

    Add default crossover operators for binary, value and permutation encoding

    Default crossover operators for basic encoding types are helpful to use the library for simulations with basic genotypes.

    With this issue crossover operators for the following 3 encoding types will be supported:

    • binary encoding
    • value encoding
    • permutation encoding
    feature 
    opened by haraldmaida 2
  • Add default types for binary encoding, value encoding and permutation encoding

    Add default types for binary encoding, value encoding and permutation encoding

    Without knowing anything about the encoding of gene it is impossible to provide default implementations for crossover and mutation operator. Therefore it would make sense to implement the basic types of gene encodings, which are:

    • binary encoding
    • value encoding
    • permutation encoding
    • tree encoding

    the implementation will be split up into 2 parts. with this feature request only the first 3 encoding types:

    • binary encoding
    • value encoding
    • permutation encoding

    will be implemented. For tree encoding a separate issue will be created.

    feature 
    opened by haraldmaida 1
  • Future compile error on Rust beta 1.60 in `types/tests.rs`

    Future compile error on Rust beta 1.60 in `types/tests.rs`

    A crater run found that this crate's tests no longer compile with rust 1.60 beta (see https://github.com/rust-lang/rust/issues/94504) due to a newly added method causing conflicts in method resolution.

    The regression has been deemed an acceptable minor change per RFC 1105. It can be fixed by using fully qualified function call syntax to unambiguously call the extension trait that previously provided abs_diff or by switching to the new std API once 1.60 is released.

    opened by the8472 0
  • [fix] index comparison with correct collection size

    [fix] index comparison with correct collection size

    I received an index out of bounds error when using an OrderOneCrossover operator: index out of bounds: the len is 2 but the index is 2. I believe, this is due to the second index p2_index in the cyclic crossover function being compared to the wrong vector's size.

    opened by dariogoetz 0
  • [fix] index comparison with correct collection size

    [fix] index comparison with correct collection size

    I received an index out of bounds error when using an OrderOneCrossover operator: index out of bounds: the len is 2 but the index is 2. I believe, this is due to the second index p2_index in the cyclic crossover function being compared to the wrong vector's size.

    opened by dariogoetz 0
  • impl RandomValueMutator for bool type

    impl RandomValueMutator for bool type

    this PR is for the case when using Vec<bool> as the Genotype in combination with RandomValueMutator.

    As a result, we can use the built-in Vec<bool> instead of the fixedbitset crate for binary encoded individual.

    sample codes:

        let algorithm = genetic_algorithm()
            .with_evaluation(MagFitnessEvaluator)
            .with_selection(RouletteWheelSelector::new(0.7, 2))
            .with_crossover(MultiPointCrossBreeder::new(3))
            .with_mutation(RandomValueMutator::new(0.1, false, true))
            .with_reinsertion(ElitistReinserter::new(MagFitnessEvaluator, false, 0.7))
            .with_initial_population(initial_population)
            .build();
    
    opened by ybyygu 0
  • Processing time is not meassured correctly

    Processing time is not meassured correctly

    Since execution of crossover and mutation is done in parallel, the processing time is no longer correct. The processing time should be meassured in each thread separately.

    bug 
    opened by haraldmaida 0
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    innoave/genevo now has a Chat Room on Gitter

    @haraldmaida has just created a chat room. You can visit it here: https://gitter.im/innoave/genevo.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
  • GenomeBuilder -> GenotypeBuilder?

    GenomeBuilder -> GenotypeBuilder?

    I'm no biologist, but reading definitions, should structs/traits/fns with GenomeBuilder be rather called GenotypeBuilder? Also Evaluated::genome should be a genotype?

    opened by KoltesDigital 0
  • Getting the current population after calling step()?

    Getting the current population after calling step()?

    Quick question, is it possible to get the current population after calling Simulator::step()?

    It seems step() returns an EvaluatedPopulation, which you can query using EvaluatedPopulation::individuals(), but this is the population before applying selection. I want to get the population after applying selection (so after selecting the best parents and cross-breeding them). Is this possible at all?

    (Basically I'm looking for a way to access GeneticAlgorithm.population directly, which is not possible at the moment since it's private)

    opened by Bauxitedev 1
  • How to use `f32` / `f64` as fitness scores?

    How to use `f32` / `f64` as fitness scores?

    Hello,

    I am currently stuck using a janky float discretization technique because I can't use floats directly.

    Is there a better workaround? Is there some truly compelling reason we cannot implement the Fitness trait for floats internally like is done for the signed and unsigned integers?

    Thank you.

    opened by wbrickner 2
  • add genotype fixer

    add genotype fixer

    Hello! I'm working under a handler that will help us fix the genotype after mutation, if necessary. I’m very interested in your opinion about this, maybe I'm doing something wrong.

    opened by GoWebProd 0
  • Advertise features in README

    Advertise features in README

    Hi, I'm doing my first experiments in the field of GAs. After looking at all crates matching "genetic", genevo looked to me as the most promising library. Great work! For others doing the same evaluation, a list of features in the README would help a lot. And for a beginner like me, more documentation would be immensely helpful. Ideal would be an exerpt of OBI98 with included code examples. Maybe you would get the permission for copying parts of it (see FAQ)? But anyway, this issue is mostly to thank you for your work! Gruss, Pirmin

    opened by pka 1
  • Trait based impl. of OrderOneCrossover and PartiallyMappedCrossover

    Trait based impl. of OrderOneCrossover and PartiallyMappedCrossover

    Hi, I've changed OrderOneCrossover and PartiallyMappedCossover to a trait based implemenation, because I wanted to have my permutation encoding in something different than Vec<usize>. Since I'm an absolute beginner in the field of GAs, I don't know whether my approach makes sense though. Thanks for your great work! Pirmin

    opened by pka 2
Releases(v0.7.1)
Owner
Innoave
Innoave
Example of a genetic algorithm in Rust and Python

Example of a genetic algorithm in Rust and Python Monkey typewriter Finding the phrase 'To be or not to be. That is the question.' Inspired by the exa

sotrh 2 Jan 27, 2022
Genetic Algorithm library in Rust

RsGenetic Summary and Features RsGenetic is a framework for executing genetic algorithms in Rust. It is designed to have a simple but modular API. Exa

Mathieu De Coster 74 Dec 27, 2022
nsga is an opinionated implementation of the NSGA-II (Non-dominated Sorting Genetic Algorithm)

nsga nsga is an opinionated implementation of the NSGA-II (Non-dominated Sorting Genetic Algorithm), a multi-objective genetic optimization algorithm.

Max Kuznetsov 8 Oct 1, 2022
Suite for automatically testing algorithm questions from the Polish Algorithm Olympiad.

oisuite Your number #1 tool to managing your algo questions! This software only works on UNIX-based operating systems (macOS, Linux, BSD, etc.) Projec

null 3 Nov 25, 2021
A browser app that evolves vehicles using genetic algorithms, written in Rust and Bevy

Vehicle Evolver Deluxe This is a simulation that uses AI (to be specific: genetic algorithms) to try to build better and better vehicles. The vehicles

null 95 Dec 26, 2022
Radiate is a parallel genetic programming engine capable of evolving solutions to many problems as well as training learning algorithms.

Radiate Coming from Evolutionary Radiation. Evolutionary radiation is a rapid increase in the number of species with a common ancestor, characterized

kalivas 109 Dec 18, 2022
Genetic Algorithms Library

genx genx provides modular building blocks to run simulations of optimization and search problems using Genetic Algorithms (GA). The vision for genx i

Lakshya Singh 29 Aug 9, 2022
hubpack is an algorithm for converting Rust values to bytes and back.

hubpack is an algorithm for converting Rust values to bytes and back. It was originally designed for encoding messages sent between embedded programs. It is designed for use with serde.

Cliff L. Biffle 6 Nov 11, 2022
Library that implements different versions of PPMD algorithm (compress and decompress)

ppmd-rs Library that implements different versions of PPMD algorithm (compress and decompress) Dependencies Rust 1.58 or newer Cargo How to build Clon

Alexander Zaitsev 3 Jun 20, 2022
Online algorithm for mean and variance, with support for uneven weights

welford Online algorithm for mean and variance, with support for uneven weights. This implements the Welford's online algorithm for computing mean and

Felipe S. S. Schneider 1 Sep 8, 2022
A SIMD-accelerated Adler-32 rolling hash algorithm implementation.

simd-adler32 A SIMD-accelerated Adler-32 rolling hash algorithm implementation. Features No dependencies Support no_std (with default-features = false

Marvin Countryman 23 Dec 19, 2022
A Trig-less Line of Sight Algorithm in Two Dimensions

In many examples of 2D line-of-sight algorithms, expensive operations like trigonometry are used. Additionally, some methods have intentional inaccuracies in them for the sake of simplicity. Here, we give an algorithm which does not fudge the numbers, and uses only basic arithmetic: addition, subtraction, multiplication, and division. This is not intended to replace the existing algorithms, or even be more efficient in practice.

null 22 Dec 22, 2022
Rust implementation of AstroBWT Proof-Of-Work algorithm

AstroBWT AstroBWT is a proof-of-work (PoW) algorithm based on Burrows-Wheeler transform (BWT). Developed and used by the DERO Project for Mobile (arm)

null 6 Mar 7, 2022
An implementation of the A-Star pathfinding algorithm tailored for traversing a bespoke collection of weighted hexagons.

An implementation of the A-Star pathfinding algorithm tailored for traversing a bespoke collection of weighted hexagons. It's intended to calculate the most optimal path to a target hexagon where you are traversing from the centre of one hexagon to the next along a line orthogonal to a hexagon edge

null 19 Dec 11, 2022
The labs of Raft consensus algorithm based on MadSim.

MadRaft The labs of Raft consensus algorithm based on MadSim. Some codes are derived from MIT 6.824 and PingCAP Talent Plan: Raft Lab. Thanks for thei

MadSys Research Group 48 Dec 28, 2022
Pure Rust implementation of the Double Ratchet algorithm

Double Ratchet A pure Rust implementation of the Double Ratchet, as specified by Trevor Perrin and Moxie Marlinspike. The Double Ratchet allows two us

Sebastian 52 Nov 25, 2022
A rust implementation of Alexey Akhunov's multiproof algorithm

multiproof.rs A rust implementation of Alexey Akhunov's multiproof algorithm. At the time of creation, multiproof is still a work in progress and this

Guillaume Ballet 30 Aug 24, 2022
Maximum Relevance - Minimum redundancy feature selection algorithm

mrmr Maximum Relevance - Minimum redundancy feature selection algorithm implemented in Rust. Usage CLI app. It gets input from a csv dataset with head

Jorge 2 Jan 1, 2022