| Stability | experimental |
|---|---|
| Maintainer | georg@schaathun.net |
| Safe Haskell | None |
AI.GA
Description
This module provides the core definitions for a sequential execution of genetic algorithms.
- data Config c p g = Config {}
- class (Chromosome c, SplittableRandMonad g m, PopulationType' c p) => PopulationType c p g m | p -> c where
- class Chromosome c => PopulationType' c p | p -> c where
- bestCost :: (c -> Double) -> p -> c
- populationSize :: p -> Int
- getConfig :: PopulationType c p g m => ReaderT (Config c p g) m (Config c p g)
- solveIO :: (MonadIO m, SplittableRandMonad g m, Chromosome c, PopulationType c p g m) => Chan p -> Config c p g -> Int -> Int -> Int -> m c
- solveIOinner :: (MonadIO m, SplittableRandMonad g m, Chromosome c, PopulationType c p g m) => Chan p -> Int -> Int -> Int -> ReaderT (Config c p g) m c
- ioThread :: (Chromosome c, PopulationType' c p) => Handle -> (c -> Double) -> Chan p -> IO ()
Documentation
data Config c p g
The Config type contains all the configuration parameters
need to run a genetic algorithm. It can conveniently be stored
in a Reader monad so that different functions can access it.
Constructors
| Config | |
Fields
| |
class (Chromosome c, SplittableRandMonad g m, PopulationType' c p) => PopulationType c p g m | p -> c where
This class represents a population within a monad for execution.
In addition to the chromosome and population types, it is
parameterised on a SplittableRandMond type which consists of
both a generator type (g) and a monad type (m).
Methods
Arguments
| :: Int | number of chromosomes |
| -> Int | length of each chromosomes |
| -> ReaderT (Config c p g) m p | population |
rndPop instantiates a new random population.
Instances
| (Chromosome c, SplittableRandMonad g m) => PopulationType c (ListPop c) g m | |
| (Chromosome c, SplittableRandMonad g m) => PopulationType c (ParPop c g) g m |
class Chromosome c => PopulationType' c p | p -> c where
This class represents a population of a given type of chromosomes. It is parameterised on both the chromosome type and the population type.
Methods
Arguments
| :: (c -> Double) | cost function |
| -> p | population |
| -> c | best chromosome |
bestCost returns the chromosome with the best cost
(fitness) from a population.
populationSize :: p -> Int
populationSize returns the size of a population
Instances
| Chromosome c => PopulationType' c (ListPop c) | |
| (NFRandomGen g, Chromosome c) => PopulationType' c (ParPop c g) |
getConfig :: PopulationType c p g m => ReaderT (Config c p g) m (Config c p g)
Arguments
| :: (MonadIO m, SplittableRandMonad g m, Chromosome c, PopulationType c p g m) | |
| => Chan p | Channel for logging |
| -> Config c p g | Configuration of the GA |
| -> Int | Chromosome length |
| -> Int | Population size |
| -> Int | Number of generations |
| -> m c | Best chromosome |
The solveIO takes the configuration as an input parameter
and solves the GA to return the best chromosome.
This is simply a wrapper around the solveIOinner function.
Arguments
| :: (MonadIO m, SplittableRandMonad g m, Chromosome c, PopulationType c p g m) | |
| => Chan p | Channel for logging |
| -> Int | Chromosome length |
| -> Int | Population size |
| -> Int | Number of generations |
| -> ReaderT (Config c p g) m c | Best chromosome |
The solveIOinner function solves the IO within a Reader monad
which provides the configuration.
Arguments
| :: (Chromosome c, PopulationType' c p) | |
| => Handle | File handle for the output |
| -> (c -> Double) | Cost function |
| -> Chan p | Channel to receive log data |
| -> IO () |