NAME

Algorithm::Evolve::Util - Some useful utility functions for use in evolutionary algorithms.

SYNOPSIS

use Algorithm::Evolve::Util qw/:str/;

SYNTAX

At the moment, this module only provides string-mangling utilities. They can all be imported with the use argument ':str'.

str_crossover( $string1, $string2 [, $n ] )

Performs a random $n-point crossover between two strings, and returns the two resulting children. $n defaults to 2. The two inputs should be the same length, although this is not enforced. $n must be also less than the length of the strings.

If you are unfamiliar with the string crossover operation, try examining sample outputs for input strings of 'a' x 20 and 'b' x 20.

str_agreement( $string1, $string2 )

Returns the number of characters in which the two strings agree. Does not enforce that the strings have the same length, even though the result is somewhat meaningless in that case.

str_mutate( $string1 [, $num [, \@alphabet ]] )

Mutates the string according to the given alphabet (defaulting to {0,1}). If $num is less than one, it performs probabilistic mutation, with each character having a $num probability of being mutated. If $num is greater than or equal to 1, it performs N-point mutation: exactly $num characters are chosen at random from the string and mutated. $num defaults to 1. Returns the modified string.

A mutation will always change the character in question, i.e., an 'a' will never be chosen to replace an existing 'a' during a mutation.

str_random( $length [, \@alphabet ] )

Returns a random string of the specified length over the specified alphabet, defaulting to {0,1}.

SEE ALSO

Algorithm::Evolve

AUTHOR

Algorithm::Evolve is written by Mike Rosulek <mike@mikero.com>. Feel free to contact me with comments, questions, patches, or whatever.

COPYRIGHT

Copyright (c) 2003 Mike Rosulek. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.