Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Op/CX.pm view on Meta::CPAN
use strict;
use warnings;
use lib qw( ../../../../lib ); # mainly to avoid syntax errors when saving
=head1 NAME
Algorithm::Evolutionary::Op::CX (Cycle crossover) - 2-point crossover operator; Builds offspring in such a way
that each gene comes from one of the parents. Preserves the absolute position of the elements
in the parent sequence
=head1 SYNOPSIS
my $op4 = new Algorithm::Evolutionary::Op::CX 3;
my $indi = new Algorithm::Evolutionary::Individual::Vector 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone();
$op3->apply( $indi2, $indi3 );
=head1 Base Class
L<Algorithm::Evolutionary::Op::Base|Algorithm::Evolutionary::Op::Base>
=head1 DESCRIPTION
Cycle Crossover operator for a GA. It is applied to chromosomes that are
a permutation of each other; even as the class it applies to is
L<Algorithm::Evolutionary::Individual::Vector>, it will issue lots of
"La jodimos!" messages if the parents do not fulfill this condition.
Some information on this operator can be obtained from
L<this
evolutionary computation tutorial|http://www.cs.bham.ac.uk/~rmp/slide_book/node4.html#SECTION00444300000000000000>
=head1 METHODS
=cut
package Algorithm::Evolutionary::Op::CX;
our $VERSION = '3.2';
use Carp;
use base 'Algorithm::Evolutionary::Op::Base';
#Class-wide constants
our $APPLIESTO = 'Algorithm::Evolutionary::Individual::Vector';
our $ARITY = 2;
=head2 new
Creates a new Algorithm::Evolutionary::Op::CX operator.
=cut
sub new {
my $class = shift;
my $hash = { numPoints => shift || 2 };
my $rate = shift || 1;
my $self = Algorithm::Evolutionary::Op::Base::new( __PACKAGE__, $rate, $hash );
return $self;
}
( run in 1.509 second using v1.01-cache-2.11-cpan-4991d5b9bd9 )