NAME AI::Genetic::Pro - Efficient genetic algorithms for professional purpose. SYNOPSIS use AI::Genetic::Pro; sub fitness { my ($ga, $chromosome) = @_; return oct('0b' . $ga->as_string($chromosome)); } sub terminate { my ($ga) = @_; my $result = oct('0b' . $ga->as_string($ga->getFittest)); return $result == 4294967295 ? 1 : 0; } my $ga = AI::Genetic::Pro->new( -fitness => \&fitness, # fitness function -terminate => \&terminate, # terminate function -type => 'bitvector', # type of individuals -population => 1000, # population -crossover => 0.9, # probab. of crossover -mutation => 0.01, # probab. of mutation -parents => 2, # number of parents -selection => [ 'Roulette' ], # selection strategy -strategy => [ 'Points', 2 ], # crossover strategy -cache => 0, # cache results -history => 1, # remember best results ); # init population of 32-bit vectors $ga->init(32); # evolve 10 generations $ga->evolve(10); # best score print "SCORE: ", $ga->as_value($ga->getFittest), ".\n"; # save evolution path as a chart $ga->chart(-filename => 'evolution.png'); DESCRIPTION This module provides efficient implementation of a genetic algorithm for a professional purpose. It was designed to operate as fast as possible even on very large populations and big individuals. "AI::Genetic::Pro" was inspired by "AI::Genetic", so it is in most cases compatible (there are some changes). Additionaly "AI::Genetic::Pro" doesn't have limitations of its ancestor (ie. seriously slow down in case of big populations ( >10000 ) or vectors with size > 33 fields). Speed To increase speed XS code are used, however with portability in mind. This distribution was tested on Windows and Linux platforms (should work on any other). Memory This module was designed to use as little memory as possible. Population of size 10000 consist 92-bit vectors uses only ~24MB (in "AI::Genetic" something about ~78MB!!!). Advanced options To provide more flexibility "AI::Genetic::Pro" supports many statistic distributions, such as: "uniform", "natural", "chi_square" and others. This feature can be used in selection or/and crossover. See documentation below. METHODS Simply description of available methods. See below. new( %options ) Constructor. It accepts options in hash-value style. See options and an example below. -fitness This defines a *fitness* function. It expects a reference to a subroutine. -terminate This defines a *terminate* function. It expects a reference to a subroutine. -type This defines the type of chromosomes. Currently, "AI::Genetic::Pro" supports four types: bitvector listvector rangevector combination -population This defines the size of the population, i.e. how many individuals to simultaneously exist at each generation. -crossover This defines the crossover rate. Fairest results are achieved with crossover rate ~0.95. -mutation -parents -selection -strategy -cache -history population($population) Set/get population. type($type) Set/get type of individuals. Currently it can be set to: "bitvector", "listvector", "rangevector", "combination". parents($parents) Set/get number of parents in *Roulette* crossover. init() evolve() history() getAvgFitness() getFittest() getHistory() generation() chart(%options) Generate a chart describing changes of min, mean, max scores in Your population. To satisfy Your needs, You can pass following options: -filename File to save a chart in (obligatory). -title Title of a chart (default: *Evolution*). -x_label X label (default: *Generations*). -y_label Y label (default: *Value*). -format Format of values, like "sprintf" (default: *'%.2f'*). -legend1 Description of min line (default: *Min value*). -legend2 Description of min line (default: *Mean value*). -legend3 Description of min line (default: *Max value*). -width Width of a chart (default: *640*). -height Height of a chart (default: *480*). -font Path to font in (*.ttf format) to be used (default: none). -logo Path to logo (png/jpg image) to embed in a chart (default: none). In example: $ga->chart(-width => 480, height => 320, -filename => 'chart.png'); save($file) Save current state of the genetic algorithm to a specified file. load($file) Load a state of the genetic algorithm from a specified file. as_array($chromosome) Return an array representing specified chromosome. as_value($chromosome) Return score of specified chromosome. Value of *chromosome* is calculated by fitness function. as_string($chromosome) Return string-representation of specified chromosome. DOCUMENTATION At the moment for more information see documentation of AI::Genetic. It is compatible in most cases. SUPPORT "AI::Genetic::Pro" is still under development and it has poor documentation (for now). However it is used in many production environments. TODO More documentation. More tests. Warnings. REPORTING BUGS When reporting bugs/problems please include as much information as possible. It may be difficult for me to reproduce the problem as almost every setup is different. A small script which yields the problem will probably be of help. AUTHOR Strzelecki Łukasz SEE ALSO AI::Genetic COPYRIGHT Copyright (c) Strzelecki Łukasz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.