The moo package

[Tags: bsd3, library]

Moo library provides building blocks to build custom genetic algorithms in Haskell. They can be used to find solutions to optimization and search problems.

Variants supported out of the box: binary (using bit-strings) and continuous (real-coded). Potentially supported variants: permutation, tree, hybrid encodings (require customizations).

Binary GAs: binary and Gray encoding; point mutation; one-point, two-point, and uniform crossover. Continuous GAs: Gaussian mutation; BLX-α, UNDX, and SBX crossover. Selection operators: roulette, and tournament; with optional niching and scaling. Replacement strategies: generational with elitism and steady state. Constrained optimization: random constrained initialization, death penalty, constrained selection without a penalty function. Multi-objective optimization: NSGA-II and constrained NSGA-II.


[Skip to ReadMe]

Properties

Version1.0
Change logNone available
Dependenciesarray, base (==4.*), gray-code (>=0.2.1), mersenne-random-pure64, monad-mersenne-random, mtl (>=2), random (>=0.1), random-shuffle (>=0.0.2), time [details]
LicenseBSD3
AuthorSergey Astanin <s.astanin@gmail.com>
MaintainerSergey Astanin <s.astanin@gmail.com>
Stabilityexperimental
CategoryAI, Algorithms, Optimisation, Optimization
Home pagehttp://www.github.com/astanin/moo/
Source repositoryhead: git clone git://github.com/astanin/moo.git
UploadedTue May 21 16:34:03 UTC 2013 by SergeyAstanin
Downloads343 total (15 in last 30 days)
Votes
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for moo-1.0

Moo

 ------------------------------------------------
< Moo. Breeding Genetic Algorithms with Haskell. >
 ------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Features

|                       | Binary GA            | Continuous GA            |
|-----------------------+----------------------+--------------------------|
|Encoding               | binary bit-string    | sequence of real values  |
|                       | Gray bit-string      |                          |
|-----------------------+----------------------+--------------------------|
|Initialization         |            random uniform                       |
|                       |            constrained random uniform           |
|                       |            arbitrary custom                     |
|-----------------------+-------------------------------------------------|
|Objective              |            minimization and maximiation         |
|                       |            optional scaling                     |
|                       |            optional ranking                     |
|                       |            optional niching (fitness sharing)   |
|-----------------------+-------------------------------------------------|
|Selection              |            roulette                             |
|                       |            stochastic universal sampling        |
|                       |            tournament                           |
|                       |            optional elitism                     |
|                       |            optionally constrained               |
|                       |            custom non-adaptive ^                |
|-----------------------+-------------------------------------------------|
|Crossover              |            one-point                            |
|                       |            two-point                            |
|                       |            uniform                              |
|                       |            custom non-adaptive ^                |
|                       +----------------------+--------------------------|
|                       |                      | BLX-α (blend)            |
|                       |                      | SBX (simulated binary)   |
|                       |                      | UNDX (unimodal normally  |
|                       |                      | distributed)             |
|-----------------------+----------------------+--------------------------|
|Mutation               | point                | Gaussian                 |
|                       | asymmetric           |                          |
|                       | constant frequency   |                          |
|                       +----------------------+--------------------------|
|                       |            custom non-adaptive ^                |
|-----------------------+-------------------------------------------------|
|Replacement            |            generational with elitism            |
|                       |            steady state                         |
|-----------------------+-------------------------------------------------|
|Stop                   |            number of generations                |
|condition              |            values of objective function         |
|                       |            stall of objective function          |
|                       |            custom or interactive (`loopIO`)     |
|                       |            time limit (`loopIO`)                |
|                       |            compound conditions (`And`, `Or`)    |
|-----------------------+-------------------------------------------------|
|Logging                |            pure periodic (any monoid)           |
|                       |            periodic with `IO`                   |
|-----------------------+-------------------------------------------------|
|Constrainted           |            constrained initialization           |
|optimization           |            constrained selection                |
|                       |            death penalty                        |
|-----------------------+-------------------------------------------------|
|Multiobjective         |            NSGA-II                              |
|optimization           |            constrained NSGA-II                  |

^ non-adaptive: any function which doesn't depend on generation number

There are other possible encodings which are possible to represent with list-like genomes (type Genome a = [a]):

Contributing

There are many ways you can help developing the library:

An example

Minimizing Beale's function (optimal value f(3, 0.5) = 0):

import Moo.GeneticAlgorithm.Continuous


beale :: [Double] -> Double
beale [x, y] = (1.5 - x + x*y)**2 + (2.25 - x + x*y*y)**2 + (2.625 - x + x*y*y*y)**2


popsize = 101
elitesize = 1
tolerance = 1e-6


selection = tournamentSelect Minimizing 2 (popsize - elitesize)
crossover = unimodalCrossoverRP
mutation = gaussianMutate 0.25 0.1
step = nextGeneration Minimizing beale selection elitesize crossover mutation
stop = IfObjective (\values -> (minimum values) < tolerance)
initialize = getRandomGenomes popsize [(-4.5, 4.5), (-4.5, 4.5)]


main = do
  population <- runGA initialize (loop stop step)
  print (head . bestFirst Minimizing $ population)

For more examples, see examples/ folder.