Skip to content

iskandr/genepool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GenePool is a framework for writing evolutionary optimization algorithms in OCaml. This library is not a complete solution but rather is a generic skeleton which takes care of the plumbing and nuisances of optimization. You provide GenePool with functions that give meaning to fitness and reproduction and after a specified number of generation, GenePool returns an array of the best "genomes" it evolved.

The interface to GenePool is extremely simple. It consists of a single function evolve whose type is:

    ('genome, 'fitness) ga_spec -> ga_params -> 'genome array * 'fitness

As you can tell from the signature, GenePool is polymorphic over both the representation of the genome and the type of fitness values. Typically your genome will be an array and fitness will be expressed as either an int or float. However, nothing stops you from using different types if your problem requires them. The first parameter is a record (of type ga_spec) which encodes how evolution will proceed for your specific problem.

(*
	GA Specification
	-----------------------------------------------------------------------
		evaluate  - assign a fitness to a genome
		mutatate  - given a genome, create an altered copy
		crossover - given two genomes, combine them
		genRandom - produce a random genome from scratch
		seed      - optional initial seed population
		report    - optional function to output information 
		            about the best genome of each generation 
		stop      - optional stopping predicate
*)

type ('genome, 'fitness) ga_spec = {
  evaluate : 'genome -> 'fitness;
  mutate : 'genome -> 'genome;
  crossover : 'genome * 'genome -> 'genome;
  genRandom: unit -> 'genome;
  seed: 'genome array option;
  report: (int -> 'genome -> 'fitness -> unit) option;
  stop: (int > 'genome -> 'fitness -> bool) option
}

Some parameters (ie, the maximum number of generations, the number of genomes which survive each generations, etc...) are universal across all optimization algorithms. These are provided in another record, whose type is ga_params.

(*
	GA Parameters
	--------------------------------------------------------------------
	nRandom - how many random genomes should we generate at the beginning
	nSurvivors - how many genomes survive of each generation 
	nMutations - # genomes generated by asexual reproduction each generation
	nCrossovers - # genomes by sexual reproduction each generation 
	timeLimit - seconds until algorithm termination 
	maxGen - maximum number of generations until algorithm termination 
*)

type ga_params = {
  nRandom: int;
  nSurvivors: int;
  nMutations: int;
  nCrossovers: int;
  timeLimit:float;
  maxGen: int
}

About

Framework for writing evolutionary optimization algorithms in OCaml

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages