Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Op/Inverover.pm view on Meta::CPAN
use strict;
use warnings;
use lib qw(../../..);
=head1 NAME
Algorithm::Evolutionary::Op::Inverover - Michalewicz's inver-over Operator.
=head1 SYNOPSIS
my $xmlStr3=<<EOC;
<op name='Inverover' type='binary' rate='1' />
EOC
my $ref3 = XMLin($xmlStr3);
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $ref3 );
print $op3->asXML(), "\n";
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone();
$op3->apply( $indi2, $indi3 );
=head1 Base Class
L<Algorithm::Evolutionary::Op::Base>
=head1 DESCRIPTION
Inver-over operator for a GA. Created by Michalewicz et al., mainly
for the travelling salesman problem. Takes two chromosomes, which are
permutations of each other.
There is some information on this operator in this interview
with Michalewicz: L<http://www.dcs.napier.ac.uk/coil/news/feature48.html>. You can also download papers from his home page: L<http://www.cs.adelaide.edu.au/~zbyszek/Papers/>.
=head1 METHODS
=cut
package Algorithm::Evolutionary::Op::Inverover;
our ($VERSION) = ( '$Revision: 3.0 $ ' =~ /(\d+\.\d+)/ );
use Carp;
use base 'Algorithm::Evolutionary::Op::Base';
#Class-wide constants
our $APPLIESTO = 'Algorithm::Evolutionary::Individual::Vector';
our $ARITY = 2;
=head2 new( $rate )
Creates a new Algorithm::Evolutionary::Op::Inverover operator.
=cut
sub new {
my $class = shift;
my $rate = shift || 0.5;
my $hash;
my $self = Algorithm::Evolutionary::Op::Base::new( 'Algorithm::Evolutionary::Op::Inverover', $rate, $hash );
return $self;
}
=head2 create
Creates a new Algorithm::Evolutionary::Op::Inverover operator.
=cut
sub create {
my $class = shift;
my $self;
bless $self, $class;
return $self;
}
=head2 apply( $first, $second )
Applies Algorithm::Evolutionary::Op::Inverover operator to a
"Chromosome". Can be applied to anything with the Atom method.
=cut
sub apply ($$$){
my $self = shift;
my $p1 = shift || croak "No victim here!"; #first parent
my $p2 = shift || croak "No victim here!"; #second parent
my $child=$p1->clone(); #Clone S' (child) from First parent
my $i; #Iterator
( run in 0.474 second using v1.01-cache-2.11-cpan-df04353d9ac )