Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Op/ChangeLengthMutation.pm view on Meta::CPAN
use strict;
use warnings;
=head1 NAME
Algorithm::Evolutionary::Op::ChangeLengthMutation - Increases/decreases by one atom the length of the string
=head1 SYNOPSIS
my $xmlStr2=<<EOC;
<op name='ChangeLengthMutation' type='unary' rate='0.5' />
EOC
my $ref2 = XMLin($xmlStr2);
my $op2 = Algorithm::Evolutionary::Op::Base->fromXML( $ref2 );
print $op2->asXML(), "\n*Arity ", $op->arity(), "\n";
my $op = new Algorithm::Evolutionary::Op::ChangeLengthMutation 1, 0.5, 0.5; #Create from scratch
=head1 Base Class
L<Algorithm::Evolutionary::Op::Base|Algorithm::Evolutionary::Op::Base>
=head1 DESCRIPTION
Increases or decreases the length of a string, by adding a random element, or
eliminating it.
=head1 METHODS
=cut
package Algorithm::Evolutionary::Op::ChangeLengthMutation;
our ($VERSION) = ( '$Revision: 3.1 $ ' =~ /(\d+\.\d+)/ );
use Carp;
use base 'Algorithm::Evolutionary::Op::Base';
#Class-wide constants
our $APPLIESTO = 'Algorithm::Evolutionary::Individual::String';
our $ARITY = 1;
=head2 new( $rate[, $increment_probability] [, $decrement_probability]
Creates a new operator. It is called with 3 arguments: the rate it's
going to be applied, and the probability of adding and substracting an
element from the string each time it's applied.
=cut
sub new {
my $class = shift;
my $rate = shift;
my $probplus = shift || 1;
my $probminus = shift || 1;
my $self = { rate => $rate,
_probplus => $probplus,
_probminus => $probminus };
bless $self, $class;
return $self;
}
=head2 create
Creates a new operator. It is called with 3 arguments: the rate it's
going to be applied, and the probability of adding and substracting an
element from the string each time it's applied. Rates default to one.
( run in 0.600 second using v1.01-cache-2.11-cpan-df04353d9ac )