Algorithm-Evolutionary

 view release on metacpan or  search on metacpan

lib/Algorithm/Evolutionary/Op/VectorCrossover.pm  view on Meta::CPAN

use strict;
use warnings;

=head1 NAME

Algorithm::Evolutionary::Op::VectorCrossover - Crossover for L<Algorithm::Evolutionary::Individual::Vector>.

=head1 SYNOPSIS

  my $xmlStr5=<<EOC; #Create using XML from base class
  <op name='VectorCrossover' type='binary' rate='1'>
    <param name='numPoints' value='1' />
  </op>
  EOC
  my $ref5 = XMLin($xmlStr5);
  my $op5 = Algorithm::Evolutionary::Op::Base->fromXML( $ref5 );
  print $op5->asXML(), "\n";

  my $indi5 = new Algorithm::Evolutionary::Individual::Vector 10;
  print $indi5->asString(), "\n";
  $op5->apply( $indi4, $indi5 );
  print $indi4->asString(), "\n";

  my $op = new VectorCrossover 1; # Using ctor, with a single crossing point

=head1 Base Class

L<Algorithm::Evolutionary::Op::Base|Algorithm::Evolutionary::Op::Base>

=head1 DESCRIPTION

Crossover operator for a  individual with vector (array) representation

=cut

package Algorithm::Evolutionary::Op::VectorCrossover;

our ($VERSION) = ( '$Revision: 3.1 $ ' =~ / (\d+\.\d+)/ );

use Carp;
use Clone qw(clone);

use base 'Algorithm::Evolutionary::Op::Base';

#Class-wide constants
our $APPLIESTO =  'Algorithm::Evolutionary::Individual::Vector';
our $ARITY = 2;

=head2 new( [$number_of_crossing_points = 2], [$priority_rate = 1] )

Creates a new 1 or 2 point crossover operator. But this is just to have a non-empty chromosome
Defaults to 2 point crossover

=cut

sub new {
  my $class = shift;
  my $hash = { numPoints => shift || 2 };
  my $rate = shift || 1;
  my $self = Algorithm::Evolutionary::Op::Base::new( 'Algorithm::Evolutionary::Op::VectorCrossover', $rate, $hash );
  return $self;
}

=head2 create( [$number_of_crossing_points = 2] )

Creates a new 1 or 2 point crossover operator. But this is just to have a non-empty chromosome
Defaults to 2 point. 

=cut

sub create {
  my $class = shift;



( run in 0.707 second using v1.01-cache-2.11-cpan-df04353d9ac )