Genetic Algorithms Library

Overview

genx

crb dcb build size downloads license

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

The vision for genx is to be a flexible and greatly extensible library for implementing genetic algorithm applications. genx is written in Rust. The library's API utilizes functional programming paradigm and exposes it's API in that manner only.

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

Documentation

Basic Example

Selection

Here's a trivial example that returns back individual selected using stochastic universal sampling

use genx::selection::stochastic_universal::stochastic_universal_selection;

let num_parents:usize = 10;
let fitness_values = vec![2.4,8.4,3.2,9.4,9.0,11.0,4.5,0.6,4.4,2.3,5.6,10.0,0.2,9.0,4.8,7.7];

let result = stochastic_universal_selection(&fitness_values, num_parents, None)
                .iter()
                .map(|&a| fitness_values[a])
                .collect::<Vec<f32>>();

stochastic_universal_selection takes in the fitness_value vector, number of parents it needs to select and a seed value which is Option<u64>. It returns back the indices of selected individuals which we map to actual fitness values.

Mutation

Mutation function takes in a single individual, distribution index and returns in the mutated individual using polynomial mutation for real valued individual.

use genx::mutation::polynomial::polynomial_mutation;
let individual = 29.11;
let result = polynomial_mutation(individual, 4.2, 4.0, None);

The returned value may or may not be equal as is mutated based on a randomly generated value, which for deterministic results can be seeded.

Building Blocks

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.

A Genetic Algorithm proceeds through following operations:

  • Encoding: Binary, Real Values, Order, Tree, etc.
  • Selection: Selecting individuals after fitness evaluation.
  • Crossover: Creating new individuals from selected pool of individuals.
  • Mutation: Making stark changes in generated individual for diversification.
  • Convergence: Test for goal accomplishment or convergence.

The building blocks currently available (defined as traits) are:

  • Selection
  • Mutation

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.

Usage

Add this to your Cargo.toml:

[dependencies]
genx = "0.3.0"

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

extern crate genx;

Why Genetic Algorithms

Genetic Algorithms are at the core of soft computing which is a branch of computing that comes to rescue when problem at hand is not feasible to be solved using hard computing. There are several advantages of genetic algorithms:

  • Algorithms are adaptive and can adjust to the change of dynamic environment​
  • The approach makes use of approximate solutions to solve problems that may be either unsolvable or too time-consuming to solve with current hardware.​
  • Imprecise but usable solutions to complex computational problems allowing researchers to approach some problems that traditional computing cannot process.​

Inspiration

I started this project mainly to learn about genetic algorithms (GAs) as part of my college curriculum where am studying severals methods for soft computing. I found myself looking for simple easy to use modular functions that I can use to learn more about each step of GA.

Comments
  • Add documentation for crossover functions

    Add documentation for crossover functions

    Added documentation for the following crossovers:

    • [x] blend
    • [x] cycle
    • [x] linear
    • [x] multi_point
    • [x] order
    • [x] partially_mapped
    • [x] shuffle
    • [x] simulated_binary
    • [x] single_point
    • [x] uniform
    • [ ] uniform_partially_mapped
    opened by ArpitShukIa 2
  • Precision Error in Stochastic Universal Selection

    Precision Error in Stochastic Universal Selection

    At a larger population size (~1000), I encountered out of bound panic. So i decided to find the bug behind that.

    for _ in 0..num_parents {
        while fitness_scale[current_offset] < random_offset {
          current_offset += 1;
        }
        selected_indices.push(current_offset);
        random_offset += fitness_step;
     };
    

    I found this code suspicious behind the panic. By printing some values i found out that random_offset was facing precision issues. at ith iteration, random_offset should be equal to initial_random_value + i*fitness_step but it turns to be greater than that.

    I propose we should use f64 in our codebase.

    v1.0.0 
    opened by rivalq 1
  • Fixed bug in SUS and Added new example

    Fixed bug in SUS and Added new example

    Signed-off-by: rivalq [email protected]

    • [X] Fixed precision bug in stochastic universal selection module.
    • [X] Added General Polynomial solver
    opened by rivalq 0
  • Crossover Module Refactor

    Crossover Module Refactor

    • refactor: random selection no need for fitness values
    • fix: simplify order and partially mapped
      • partially mapped wrongly implemented with maps adds in complexity
      • order crossover wrong algo correction
    • feat: uniform crossover which accepts the probability
    • refactor: simplify map access in cycle crossover
    opened by king-11 0
  • Anti Pattern Removal

    Anti Pattern Removal

    • Unnecessary braces in use statement RS-C1002
    • Found unnecessary negation in if condition RS-C1009

    Signed-off-by: Lakshya Singh [email protected]

    hacktoberfest-accepted 
    opened by king-11 0
  • Traits and Struct v1

    Traits and Struct v1

    • operators
    • genetic identifiers
    • algorithms
    • structured operations
    • do over of modules
    • traits define everything

    Signed-off-by: Lakshya Singh [email protected]

    opened by king-11 0
  • Fix Linting issues

    Fix Linting issues

    Is your feature request related to a problem? Please describe. Genx currently has many linting issues those when fixed will allow for better readability of code and also improve its maintainability.

    Describe the solution you'd like

    rustup self update
    rustup component add clippy
    cargo clippy
    

    Run the following command currently there are over/around 51 suggestions which we can improve upon.

    Describe alternatives you've considered I haven't considered how we can make linting a part of the CI process.

    enhancement good first issue 
    opened by king-11 0
  • Zero Fitness Value

    Zero Fitness Value

    Describe the bug If the fitness value of an individual is 0 many of the selection methods will fail to run with that individual. Also, there is no proper error message as to how to debug the issue. The selection methods that will fail are:

    • rank_selection
    • roulette_wheel_selection
    • stochastic_universal_selection

    To Reproduce Pass in members with fitness value zero to any of the selection methods cited above

    Expected behaviour They should at least print out a proper error message or workout the issue by adding in a value (method 1 is preferred)

    Desktop (please complete the following information):

    • OS: Manajro Orka
    • Version" 0.3.3
    enhancement help wanted v1.0.0 
    opened by king-11 0
  • Example GA Implementation

    Example GA Implementation

    Binary Encoding

    • [x] Knapsack
    • [ ] High Utility Items Mining

    Order Encoding

    • [x] TSP
    • [ ] CPU Scheduling

    Real Encoding

    • [x] 2-degree polynomial
    • [x] 3-degree polynomial
    • [ ] Weights Neural Network

    Tree Encoding

    • [ ] Finding a function from given input and output values
    good first issue examples 
    opened by king-11 0
  • Documenation for Crossover Methods

    Documenation for Crossover Methods

    Binary Encoding

    • [ ] Single Point Crossover
    • [ ] Multi Point Crossover
    • [ ] Shuffle Crossover
    • [ ] Uniform Crossover
    • [ ] Uniform Crossover with Mask
    • [ ] Half Uniform Crossover
    • [ ] Three Parent Crossover
    • [ ] Matrix Crossover

    Order Encoding:

    • [ ] Davis' Order Crossover
    • [ ] Partially-Mapped Crossover (PMX)
    • [ ] Cycle Crossover Operator (CX)

    Value Encoding:

    • [ ] Linear Crossover
    • [ ] Blend Crossover
    • [ ] Simulated Binary Crossover

    References

    documentation good first issue v1.0.0 
    opened by king-11 1
Releases(v0.4.0)
  • v0.4.0(Nov 5, 2021)

    What's Changed

    • Simple Examples by @king-11 in https://github.com/king-11/genx/pull/17
    • Fixed bug in SUS and Added new example by @rivalq in https://github.com/king-11/genx/pull/19

    New Contributors

    • @rivalq made their first contribution in https://github.com/king-11/genx/pull/19

    Full Changelog: https://github.com/king-11/genx/compare/v0.3.3...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.3(Oct 29, 2021)

    What's Changed

    • Create CODE_OF_CONDUCT.md by @king-11 in https://github.com/king-11/genx/pull/7
    • Update issue templates by @king-11 in https://github.com/king-11/genx/pull/8
    • Anti Pattern Removal by @king-11 in https://github.com/king-11/genx/pull/10
    • Save Memory by @king-11 in https://github.com/king-11/genx/pull/9
    • Crossover Module by @king-11 in https://github.com/king-11/genx/pull/11
    • Permutation Encoding Crossover by @king-11 in https://github.com/king-11/genx/pull/12
    • Crossover Module Refactor by @king-11 in https://github.com/king-11/genx/pull/15

    Full Changelog: https://github.com/king-11/genx/compare/v0.3.0...v0.3.3

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Sep 3, 2021)

    Documentation

    • documentation added at module and sub-module level #3
    • individual function documentation with examples added #1

    Issues Fixed

    • fix issues with stochastic universal selection

    Refactor

    • polynomial mutation implementation was wrong is now corrected to use user-defined maximum perturbation
    • typo in the name of scramble_mutation function
    • Better experience for library users by fixing #2 added in re-exports
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Sep 2, 2021)

    Mutations

    Added in mutation functions for both binary encoded ( boolean vec ) and real values.

    Binary Encoded Mutation

    • Flipping/Toin Coss
    • Inversion
    • Swap
    • Scramble

    Real Encoded Mutation

    • Random Linear
    • Polynomial

    Fix possible panic in tournament selection 5947944f9ed9a1e0f9cb7ff5aa19e4021aba2ed6

    Source code(tar.gz)
    Source code(zip)
  • first(Aug 31, 2021)

    Selection Algorithms

    A variety of selection algorithms added 🥇 covering all general purpose and specialized needs.

    • Steady State
    • Stochastic Universal Sampling
    • Roulette Wheel
    • Rank proportionate
    • Tournament Selection
    • Random Selection

    Test Coverage at 100% 🚀

    Source code(tar.gz)
    Source code(zip)
Owner
Lakshya Singh
My Reactive Vue Flutters. LFX'21 @cncf GSOC'21 @chapel-lang
Lakshya Singh
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
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
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
Execute genetic algorithm (GA) simulations in a customizable and extensible way.

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

Innoave 110 Dec 21, 2022
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
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
A library that can be used as a building block for high-performant graph algorithms.

graph A library that can be used as a building block for high-performant graph algorithms. Graph provides implementations for directed and undirected

Martin Junghanns 222 Jan 1, 2023
This library provides implementations of many algorithms and data structures that are useful for bioinformatics.

This library provides implementations of many algorithms and data structures that are useful for bioinformatics. All provided implementations are rigorously tested via continuous integration.

Rust-Bio 1.2k Dec 26, 2022
darwin-rs, evolutionary algorithms with rust

darwin-rs This library allows you to write evolutionary algorithms (EA) using the Rust programming language. Written by Willi Kappler, License: MIT -

Willi Kappler 95 Jan 1, 2023
Compare binary files using alignment algorithms

biodiff Compare binary files using alignment algorithms. What is this This is a tool for binary diffing. The tool is able to show two binary files sid

null 483 Dec 22, 2022
A tool used to evaluate the output of retrieval algorithms. Written in Rust.

Rusteval A tool used to evaluate the output of retrieval algorithms. Written in Rust. Building Install Rust with curl -sSf https://static.rust-lang.or

Giorgos Sfikas 17 Mar 22, 2022
This crate implements fast route planning algorithms in Rust.

This crate implements fast route planning algorithms in Rust. Algorithms Currently implemented: Contraction Hierarchies: The implementat

Payas Rajan 4 Aug 15, 2021
DSP algorithms for embedded. Often integer math.

This crate contains some tuned DSP algorithms for general and especially embedded use.

QUARTIQ 12 Nov 3, 2022
ECFFT algorithms on the BN254 base field

ECFFT algorithms on the BN254 base field This crate implements structs and traits for the ECFFT algorithms from the paper Elliptic Curve Fast Fourier

null 36 Nov 28, 2022
"Algorithms for approximate string matching" in Rust, with Python bindings.

ukkonen Implementation of a bounded Levenshtein distance by Esko Ukkonen in "Algorithms for approximate string matching" in Rust, with Python bindings

Ethan Smith 1 Dec 1, 2021
Common data structures and algorithms for competitive programming in Rust

algorithm-rs algorithm-rs is common data structures and algorithms for competitive programming in Rust. Contents TBA How To Contribute Contributions a

Chris Ohk 16 Dec 21, 2022
zine/book about bitmap drawing algorithms and math with code examples in Rust

A Bitmapper's Companion - zine/book about bitmap drawing algorithms and math with code examples in Rust A small zine/book written in LaTeX. In progres

Manos Pitsidianakis 42 Nov 8, 2022
Algorithms implemented in Rust, explained.

Rusty Algorithms & Data Structures for Learners This repository presents Rust implementations of common algorithms and data structures, many of which

Tianyi Shi 327 Dec 19, 2022