Algorithm-Evolve
view release on metacpan or search on metacpan
lib/Algorithm/Evolve/Util.pm view on Meta::CPAN
(substr($s1, $x, $y-$x+1), substr($s2, $x, $y-$x+1)) =
(substr($s2, $x, $y-$x+1), substr($s1, $x, $y-$x+1));
}
return ($s1, $s2);
}
sub str_agreement {
my ($s1, $s2) = @_;
## substr is safe for unicode; xor'ing characters is not. But
## xor is about 30 times faster on longish strings...
if ($UNICODE_STRINGS) {
my $tally = 0;
for (0 .. length($s1)-1) {
$tally++ if substr($s1, $_, 1) eq substr($s2, $_, 1);
}
return $tally;
}
lib/Algorithm/Evolve/Util.pm view on Meta::CPAN
(the two "cuts" here were after the 1st and 3rd positions).
=item C<str_agreement( $string1, $string2 )>
=item C<arr_agreement( \@array1, \@array2 )>
Returns the number of positions in which the two genes agree. Does not enforce
that they have the same size, even though the result is somewhat meaningless
in that case.
String gene comparison is done in a non-unicode-friendly way. To override this
and use a (slower) unicode-friendly string comparison, set
C<$Algorithm::Evolve::Util::UNICODE_STRINGS> to a true value.
In array genes, the comparison of individual elements is done with C<eq>.
Note that this is the Hamming metric, and not the edit distance metric. Edit
distance may be an interesting fitness to use as well. There are at least two
modules (L<Text::Levenshtein|Text::Levenshtein> and
L<Text::LevenshteinXS|Text::LevenshteinXS>) that I know of which calculate the
edit distance of two strings.
( run in 0.247 second using v1.01-cache-2.11-cpan-88abd93f124 )