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

NAME

Algorithm::Evolutionary::Op::Base - Base class for Algorithm::Evolutionary operators, that is any object with the "apply" method, which does things to individuals or populations.

SYNOPSIS

    my $op = new Algorithm::Evolutionary::Op::Base; #Creates empty op, with rate

    my $xmlStr=<<EOC;
    <op name='Mutation' type='unary' rate='2'>
      <param name='probability' value='0.5' />
    </op>
    EOC

    my $ref = XMLin($xmlStr);
    my $op = Algorithm::Evolutionary::Op::Base->fromXML( $ref ); #Takes a hash of parsed XML and turns it into an operator    

    print $op->asXML(); #prints it back in XML shape

    print $op->rate();  #application rate; relative number of times it must be applied
    print "Yes" if $op->check( 'Algorithm::Evolutionary::Individual::Bit_Vector' ); #Prints Yes, it can be applied to Bit_Vector individual
    print $op->arity(); #Prints 1, number of operands it can be applied to

DESCRIPTION

Base class for operators applied to Individuals and Populations and all the rest

METHODS

AUTOLOAD

Automatically define accesors for instance variables. You should probably not worry about this unless you are going to subclass.

new( [$priority] [,$options_hash] )

Takes a hash with specific parameters for each subclass, creates the object, and leaves subclass-specific assignments to subclasses

create( [@operator_parameters] )

Creates an operator via its default parameters. Probably obsolete

fromXML()

Takes a definition in the shape <op></op> and turns it into an object, if it knows how to do it. The definition must have been processed using XML::Simple.

It parses the common part of the operator, and leaves specific parameters for the subclass via the "set" method.

asXML( [$id] )

Prints as XML, following the EvoSpec 0.2 XML specification. Should be called from derived classes, not by itself. Provides a default implementation of XML serialization, with a void tag that includes the name of the operator and the rate (all operators have a default rate). For instance, a foo operator would be serialized as <op name='foo' rate='1' > .

If there is not anything special, this takes also care of the instance variables different from rate: they are inserted as param within the XML file. In this case, params are void tags; if you want anything more fancy, you will have to override this method. An optional ID can be used.

rate( [$rate] )

Gets or sets the rate of application of the operator

check()

Check if the object the operator is applied to is in the correct class.

arity()

Returns the arity, ie, the number of individuals it can be applied to

set( $options_hashref )

Converts the parameters passed as hash in instance variables. Default method, probably should be overriden by derived classes. If it is not, it sets the instance variables by prepending a _ to the keys of the hash. That is, $op->set( { foo => 3, bar => 6} ); will set $op->{_foo} and $op->{_bar} to the corresponding values

Known subclasses

This is quite incomplete. Should be either generated automatically or suppressed altogether

See Also

The introduction to the XML format used here, XML

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/09/14 16:36:38 $ 
  $Header: /cvsroot/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Op/Base.pm,v 3.2 2009/09/14 16:36:38 jmerelo Exp $ 
  $Author: jmerelo $ 
  $Revision: 3.2 $
  $Name $