Algorithm-Evolutionary
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Individual/Bit_Vector.pm view on Meta::CPAN
use strict; #-*-cperl-*-
use warnings;
use lib qw(../../../../lib);
=head1 NAME
Algorithm::Evolutionary::Individual::Bit_Vector - Classic bitstring individual for evolutionary computation;
usually called chromosome, and using a different implementation from Algorithm::Evolutionary::Individual::BitString
=head1 SYNOPSIS
use Algorithm::Evolutionary::Individual::BitVector;
my $indi = new Algorithm::Evolutionary::Individual::Bit_Vector 10 ; # Build random bitstring with length 10
# Each element in the range 0 .. 1
my $indi3 = new Algorithm::Evolutionary::Individual::Bit_Vector;
$indi3->set( { length => 20 } ); #Sets values, but does not build the string
$indi3->randomize(); #Creates a random bitstring with length as above
print $indi3->Atom( 7 ); #Returns the value of the 7th character
$indi3->Atom( 3 ) = 1; #Sets the value
$indi3->addAtom( 1 ); #Adds a new character to the bitstring at the end
my $indi4 = Algorithm::Evolutionary::Individual::Bit_Vector->fromString( '10110101'); #Creates an individual from that string
my $indi5 = $indi4->clone(); #Creates a copy of the individual
my @array = qw( 0 1 0 1 0 0 1 ); #Create a tied array
tie my @vector, 'Algorithm::Evolutionary::Individual::Bit_Vector', @array;
print tied( @vector )->asXML();
print $indi3->asString(); #Prints the individual
print $indi3->asXML() #Prints it as XML. See L<Algorithm::Evolutionary::XML>
print $indi3->as_yaml() #Change of convention, I know...
=head1 Base Class
L<Algorithm::Evolutionary::Individual::String|Algorithm::Evolutionary::Individual::String>
=head1 DESCRIPTION
Bitstring Individual for a Genetic Algorithm. Used, for instance, in a canonical GA
=cut
package Algorithm::Evolutionary::Individual::Bit_Vector;
use Carp;
use Bit::Vector;
use String::Random; # For initial string generation
our ($VERSION) = ( '$Revision: 3.1 $ ' =~ / (\d+\.\d+)/ );
use base 'Algorithm::Evolutionary::Individual::Base';
use constant MY_OPERATORS => ( qw(Algorithm::Evolutionary::Op::BitFlip Algorithm::Evolutionary::Op::Mutation ));
=head1 METHODS
( run in 0.541 second using v1.01-cache-2.11-cpan-99c4e6809bf )