Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Individual/Vector.pm view on Meta::CPAN
my @ary = split( $sep, $str );
my $self = { _array => \@ary,
_fitness => undef };
bless $self, $class;
return $self;
}
=head2 clone()
Similar to a copy ctor: creates a new individual from another one
=cut
sub clone {
my $indi = shift || croak "Indi to clone missing ";
my $self = { _fitness => undef,
_length => $indi->{_length} };
$self->{_array} = ();
push(@{$self->{_array}}, @{$indi->{_array}});
bless $self, ref $indi;
die "Something is wrong " if scalar( @{$self->{_array}} ) > scalar( @{$indi->{_array}} );
return $self;
}
=head2 asString()
Returns a string with chromosome plus fitness. OK, this is a bit confusing
=cut
sub asString {
my $self = shift;
my $str = $self->as_string();
if ( defined $self->{_fitness} ) {
$str .=", " . $self->{_fitness};
}
return $str;
}
=head2 as_string()
Returns just the chromosome, not the fitness
=cut
sub as_string {
my $self = shift;
my $str = join( ", ", @{$self->{_array}});
return $str;
}
=head2 asXML()
Prints it as XML. See the L<Algorithm::Evolutionary::XML|lgorithm::Evolutionary::XML> OPEAL manual for details.
=cut
sub asXML {
my $self = shift;
my $str = $self->SUPER::asXML();
my $str2 = ">" .join( "", map( "<atom>$_</atom> ", @{$self->{_array}} ));
$str =~ s/\/>/$str2/e ;
return $str."\n</indi>";
}
=head2 Chrom( [$ref_to_array]
Sets or gets the array that holds the chromosome. Not very nice, and
I would never ever do this in C++
=cut
sub Chrom {
my $self = shift;
if ( defined $_[0] ) {
$self->{_array} = shift;
}
return $self->{_array}
}
=head1 Copyright
This file is released under the GPL. See the LICENSE file included in this distribution,
or go to http://www.fsf.org/licenses/gpl.txt
CVS Info: $Date: 2011/11/23 10:59:47 $
$Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Individual/Vector.pm,v 3.2 2011/11/23 10:59:47 jmerelo Exp $
$Author: jmerelo $
$Revision: 3.2 $
=cut
( run in 1.137 second using v1.01-cache-2.11-cpan-5a3173703d6 )