GA-0.1: Genetic algorithm library



GA, a Haskell library for working with genetic algoritms

Aug. 2011, by Kenneth Hoste

version: 0.1



class (Eq a, Read a, Show a, ShowEntity a) => Entity a b c | a -> b, a -> c whereSource

Type class for entities that represent a candidate solution.

Three parameters:

  • data structure representing an entity (a)
  • data used to score an entity, e.g. a list of numbers (b)
  • some kind of pool used to generate random entities, e.g. a Hoogle database (c)


genRandom :: c -> Int -> aSource

Generate a random entity.

crossover :: c -> Float -> Int -> a -> a -> Maybe aSource

Crossover operator: combine two entities into a new entity.

mutation :: c -> Float -> Int -> a -> Maybe aSource

Mutation operator: mutate an entity into a new entity.

score :: a -> b -> DoubleSource

Score an entity (lower is better).

data GAConfig Source

Configuration for genetic algorithm.




popSize :: Int

population size

archiveSize :: Int

size of archive (best entities so far)

maxGenerations :: Int

maximum number of generations to evolve

crossoverRate :: Float

fraction of entities generated by crossover (tip: >= 0.80)

mutationRate :: Float

fraction of entities generated by mutation (tip: <= 0.20)

crossoverParam :: Float

parameter for crossover (semantics depend on actual crossover operator)

mutationParam :: Float

parameter for mutation (semantics depend on actual mutation operator)

withCheckpointing :: Bool

enable/disable built-in checkpointing mechanism

class ShowEntity a whereSource

Type class for pretty printing an entity instead of just using the default show implementation.


showEntity :: a -> StringSource

Show an entity.

evolve :: Entity a b c => StdGen -> GAConfig -> c -> b -> IO aSource

Do the evolution!