The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Algorithm::Evolutionary::Individual::Base - Base class for chromosomes that knows how to build them, and has some helper methods.

SYNOPSIS

  use  Algorithm::Evolutionary::Individual::Base;
  my $xmlStr="<indi type='BitString'><atom>1</atom><atom>0</atom><atom>1</atom><atom>0</atom></indi>";
  my $ref = XMLin($xmlStr);

  my $binIndi2 = Algorithm::Evolutionary::Individual::Base->fromXML( $ref ); #From XML fragment
  print $binIndi2->asXML();

  my $indi = Algorithm::Evolutionary::Individual::Base->fromParam( $ref->{initial}{section}{indi}{param} ); #From parametric description

  $binIndi2->Fitness( 3.5 ); #Sets or gets fitness
  print $binIndi2->Fitness();

  my $emptyIndi = new Algorithm::Evolutionary::Individual::Base;

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.

METHODS

AUTOLOAD

Creates methods for instance variables automatically

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.

create( $ref_to_hash )

Creates a new individual, but uses a different interface: takes a ref-to-hash, with named parameters, which gives it a common interface to all the hierarchy. The main difference with respect to new is that after creation, it is initialized with random values.

set( $ref_to_hash )

Sets values of an individual; takes a hash as input. Keys are prepended an underscore and turn into instance variables

fromXML( $xml_string )

Takes a definition in the shape <indi><atom>....</indi><fitness></fitness></indi> and turns it into a bitstring, if it knows how to do it. The definition must have been processed using XML::Simple. It forwards stuff it does not know about to the corresponding subclass, which should implement the set method. The class it refers about is required in runtime.

fromParam( $xml_fragment )

Takes an array of params that describe the individual, and builds it, with random initial values.

Params have this shape: <param name='type' value='Vector' /> <param name='length' value='2' /> <param name='range' start='0' end='1' />

The 'type' will show the class of the individuals that are going to be created, and the rest will be type-specific, and left to the particular object to interpret.

asXML()

Prints it as XML. The caller must close the tags.

as_yaml()

Prints it as YAML.

as_string()

Prints it as a string in the most meaningful representation possible

as_string_with_fitness( [$separator] )

Prints it as a string followed by fitness. Separator by default is ;

Atom( $index [, $value )

Sets or gets the value of an atom. Each individual is divided in atoms, which can be accessed sequentially. If that does not apply, Atom can simply return the whole individual

Fitness( [$value] )

Sets or gets fitness

my_operators()

Operators that can act on this data structure. Returns an array with the names of the known operators

evaluate( $fitness )

Evaluates using the $fitness thingy given. Can be a Algorithm::Evolutionary::Fitness::Base object or a ref-to-sub

Chrom()

Sets or gets the chromosome itself, that is, the data structure evolved. Since each derived class has its own data structure, and its own name, it is left to them to return it

size()

OK, OK, this is utter inconsistence, but I'll re-consistence it eventually. Returns a meaningful size; but should be reimplemented by siblings

Known subclasses

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: 2009/11/17 19:19:41 $ 
  $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Individual/Base.pm,v 3.2 2009/11/17 19:19:41 jmerelo Exp $ 
  $Author: jmerelo $ 
  $Revision: 3.2 $
  $Name $