| Stability | experimental |
|---|---|
| Maintainer | georg@schaathun.net |
| Safe Haskell | None |
AI.GA.Chromosome
Description
This module provides class definitions and some generic functions for chromosome representations. It also provides a simple implemetation of chromosomes as lists.
- data ChromosomeConfig c g = ChromosomeConfig {}
- class (NFData c, Show c) => Chromosome c where
- rndChrom :: RandMonad m => Int -> m c
- lenChrom :: c -> Int
- crossoverSinglePoint :: RandMonad m => c -> c -> m (c, c)
- crossoverSinglePoint' :: Int -> (c, c) -> (c, c)
- class Chromosome c => ContinuousChromosome c where
- crossoverHybrid :: RandMonad m => c -> c -> m (c, c)
- crossoverHybrid' :: Int -> Double -> (c, c) -> (c, c)
- type MutationFunction c g = c -> State g c
- type CrossoverFunction c g = c -> c -> State g (c, c)
- mutateG :: RandomGen g => ChromosomeConfig c g -> g -> c -> c
- crossG :: RandomGen g => ChromosomeConfig c g -> g -> c -> c -> (c, c)
Documentation
data ChromosomeConfig c g
A ChromosomeConfig is used to keep the configure the chromosome
model. The ChromosomeConfig object is typically stored in a Reader monad.
The ChromosomeConfig type is parameterised by the Chromosome
representation and a pseudo-random generator type.
It consists of a pair of crossover and mutation functions. Both functions are probabilistic and operate in a State monad to handle the pseudo-random number generator.
Constructors
| ChromosomeConfig | |
class (NFData c, Show c) => Chromosome c where
A Chromosome is a representation of an arbitrary chromosome,
which is essentially a list of genes. It can be implemented
using lists, boxed or unboxed vectors, etc.
We require that the chromosome type is an instance of NFData
to be able to force it into normal form. This is necessary
for the parallel implementation. We make it a Show instance
purely for convenience in debugging.
Few mutation and crossover functions can be made fully generic for arbitrary chromosomes. Presently only single-point crossover is provided.
Methods
rndChrom :: RandMonad m => Int -> m c
The rndChrom function instantiates a uniformly distributed
random chromosome of the given length.
The lenChrom function returns the length of the chromosome,
that is the number of (scalar) genes.
Arguments
| :: RandMonad m | |
| => c | First parent |
| -> c | Second parent |
| -> m (c, c) | Pair of off-spring |
One-Point crossover function.
This function has a generic default implementation which
depends on crossover'.
crossoverSinglePoint' :: Int -> (c, c) -> (c, c)
Deterministic one-point crossover function. The point where the chromosomes are split is given as an argument. This function must be defined for each instance.
Instances
class Chromosome c => ContinuousChromosome c where
Very few functions can be defined generically for any
chromosome type. The ContinuousChromosome class
cover the special case of contiuous valued (floating point)
genes.
Methods
crossoverHybrid :: RandMonad m => c -> c -> m (c, c)
Hybrid one-point crossover function.
This is similar to the one-point cross-over except that the
gene at the point is replaced by a weighted average of the
parent genes.
This function has a generic default implementation which
depends on crossoverHybrid'.
crossoverHybrid' :: Int -> Double -> (c, c) -> (c, c)
Deterministic version of the hybrid one-point crossover. This function must be defined for each instance.
type MutationFunction c g = c -> State g c
type CrossoverFunction c g = c -> c -> State g (c, c)
mutateG :: RandomGen g => ChromosomeConfig c g -> g -> c -> c
crossG :: RandomGen g => ChromosomeConfig c g -> g -> c -> c -> (c, c)