Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Individual/Base.pm view on Meta::CPAN
use strict; #-*-cperl,hi-lock,auto-fill-*-
use warnings;
use lib qw( ../../../../lib );
=head1 NAME
Algorithm::Evolutionary::Individual::Base - Base class for chromosomes that knows how to build them, and has some helper methods.
=head1 SYNOPSIS
use Algorithm::Evolutionary::Individual::Base;
my $indi = Algorithm::Evolutionary::Individual::Base->fromParam( $param_hashref ); #From parametric description
$binIndi2->Fitness( 3.5 ); #Sets or gets fitness
print $binIndi2->Fitness();
my $emptyIndi = new Algorithm::Evolutionary::Individual::Base;
=head1 DESCRIPTION
Base class for individuals, that is, "chromosomes" in evolutionary
computation algorithms. However, chromosomes needn't be bitstrings, so
the name is a bit misleading. This is, however, an "empty" base class,
that acts as a boilerplate for deriving others.
=cut
package Algorithm::Evolutionary::Individual::Base;
use YAML qw(Dump Load LoadFile);
use Carp;
our $VERSION = '3.3';
use constant MY_OPERATORS => qw(None);
=head1 METHODS
=head2 AUTOLOAD
Creates methods for instance variables automatically
=cut
sub AUTOLOAD {
my $self = shift;
my $attr = our $AUTOLOAD;
$attr =~ s/.*:://;
return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
my $instance_variable = "_$attr";
$self->{$instance_variable} = shift if @_;
return $self->{$instance_variable};
}
=head2 new( $options )
Creates a new Base individual of the required class, with a fitness, and sets fitnes to undef.
Takes as params a hash to the options of the individual, that will be passed
on to the object of the class when it iss initialized.
=cut
( run in 0.635 second using v1.01-cache-2.11-cpan-5a3173703d6 )