parga-0.5.0.0: A parallel implementation of genetic algorithms.

Stabilityexperimental
Maintainergeorg@schaathun.net
Safe HaskellNone

AI.GA

Description

This module provides the core definitions for a sequential execution of genetic algorithms.

Synopsis

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

cConfig :: ChromosomeConfig c g

The chromosome model defining functions for cost function, mating, and mutation). This is intended as read-only.

popSize :: Int

Population size

keep :: Int

The number of chromosomes elligible for mating

elite :: Int

The number of chromosomes not to be replaced in the subsequent generation.

numGen :: Int

Population size

cost :: c -> Double

The cost function

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

rndPop

Arguments

:: Int

number of chromosomes

-> Int

length of each chromosomes

-> ReaderT (Config c p g) m p

population

rndPop instantiates a new random population.

newPop

Arguments

:: p

old popultion

-> ReaderT (Config c p g) m p

new popultion

newPop runs the evolution for one generation and returns the new population. Note that mutation and crossover are configurable as the functions are defined in the Config object held in the Reader monad.

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

bestCost

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

getConfig :: PopulationType c p g m => ReaderT (Config c p g) m (Config c p g)

The getConfig method returns a Config object from a Reader monad. This is purely an alias for the ask method of the 'Reader'/'ReaderT' class and it is introduced for the sake of readability.

solveIO

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.

solveIOinner

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.

ioThread

Arguments

:: (Chromosome c, PopulationType' c p) 
=> Handle

File handle for the output

-> (c -> Double)

Cost function

-> Chan p

Channel to receive log data

-> IO () 

The ioThread function creates a separate thread to handle log data. The inputs include a Chan object which is used to transfer log data two the new thread, and a file Handle to which the log data will be written.

This function must be called before the solver.