moo-1.2: Genetic algorithm library

Safe HaskellNone
LanguageHaskell98

Moo.GeneticAlgorithm.Types

Contents

Synopsis

Data structures

type Genome a = [a] Source #

A genetic representation of an individual solution.

type Objective = Double Source #

A measure of the observed performance. It may be called cost for minimization problems, or fitness for maximization problems.

type Phenotype a = (Genome a, Objective) Source #

A genome associated with its observed Objective value.

type Population a = [Phenotype a] Source #

An entire population of observed Phenotypes.

class GenomeState gt a where Source #

takeGenome extracts a raw genome from any type which embeds it.

Methods

takeGenome :: gt -> Genome a Source #

Instances
a1 ~ a2 => GenomeState (Phenotype a1) a2 Source # 
Instance details

Defined in Moo.GeneticAlgorithm.Types

Methods

takeGenome :: Phenotype a1 -> Genome a2 Source #

a1 ~ a2 => GenomeState (Genome a1) a2 Source # 
Instance details

Defined in Moo.GeneticAlgorithm.Types

Methods

takeGenome :: Genome a1 -> Genome a2 Source #

a1 ~ a2 => GenomeState (MultiPhenotype a1) a2 Source # 
Instance details

Defined in Moo.GeneticAlgorithm.Multiobjective.Types

GA operators

data ProblemType Source #

A type of optimization problem: whether the objective function has to be miminized, or maximized.

Constructors

Minimizing 
Maximizing 

class ObjectiveFunction f a where Source #

A function to evaluate a genome should be an instance of ObjectiveFunction class. It may be called a cost function for minimization problems, or a fitness function for maximization problems.

Some genetic algorithm operators, like rouletteSelect, require the Objective to be non-negative.

Methods

evalObjective :: f -> [Genome a] -> Population a Source #

Instances
a1 ~ a2 => ObjectiveFunction ([Genome a1] -> [(Genome a1, Objective)]) a2 Source #

Evaluate fitness (cost) of all genomes, possibly changing their order.

Instance details

Defined in Moo.GeneticAlgorithm.Types

Methods

evalObjective :: ([Genome a1] -> [(Genome a1, Objective)]) -> [Genome a2] -> Population a2 Source #

a1 ~ a2 => ObjectiveFunction ([Genome a1] -> [Objective]) a2 Source #

Evaluate all fitness (cost) values at once.

Instance details

Defined in Moo.GeneticAlgorithm.Types

Methods

evalObjective :: ([Genome a1] -> [Objective]) -> [Genome a2] -> Population a2 Source #

a1 ~ a2 => ObjectiveFunction (Genome a1 -> Objective) a2 Source #

Evaluate fitness (cost) values genome per genome in parallel.

Instance details

Defined in Moo.GeneticAlgorithm.Types

Methods

evalObjective :: (Genome a1 -> Objective) -> [Genome a2] -> Population a2 Source #

type SelectionOp a = Population a -> Rand (Population a) Source #

A selection operator selects a subset (probably with repetition) of genomes for reproduction via crossover and mutation.

type CrossoverOp a = [Genome a] -> Rand ([Genome a], [Genome a]) Source #

A crossover operator takes some parent genomes and returns some children along with the remaining parents. Many crossover operators use only two parents, but some require three (like UNDX) or more. Crossover operator should consume as many parents as necessary and stop when the list of parents is empty.

type MutationOp a = Genome a -> Rand (Genome a) Source #

A mutation operator takes a genome and returns an altered copy of it.

Dummy operators

noMutation :: MutationOp a Source #

Don't mutate.

noCrossover :: CrossoverOp a Source #

Don't crossover.

Life cycle

type StepGA m a Source #

Arguments

 = Cond a

stop condition

-> PopulationState a

population of the current generation

-> m (StepResult (Population a))

population of the next generation

A single step of the genetic algorithm. See also nextGeneration.

data Cond a Source #

Iterations stop when the condition evaluates as True.

Constructors

Generations Int

stop after n generations

IfObjective ([Objective] -> Bool)

stop when objective values satisfy the predicate

Eq b => GensNoChange

terminate when evolution stalls

Fields

Or (Cond a) (Cond a)

stop when at least one of two conditions holds

And (Cond a) (Cond a)

stop when both conditions hold

type PopulationState a = Either [Genome a] [Phenotype a] Source #

On life cycle of the genetic algorithm:

  [ start ]
      |
      v
  (genomes) --> [calculate objective] --> (evaluated genomes) --> [ stop ]
      ^  ^                                       |
      |  |                                       |
      |  `-----------.                           |
      |               \                          v
  [ mutate ]        (elite) <-------------- [ select ]
      ^                                          |
      |                                          |
      |                                          |
      |                                          v
  (genomes) <----- [ crossover ] <-------- (evaluted genomes)

PopulationState can represent either genomes or evaluated genomed.

data StepResult a Source #

A data type to distinguish the last and intermediate steps results.

Constructors

StopGA a 
ContinueGA a 
Instances
Show a => Show (StepResult a) Source # 
Instance details

Defined in Moo.GeneticAlgorithm.Types