J. J. Merelo-Guervós > Algorithm-Evolutionary-0.80 > Algorithm::Evolutionary::Op::Base



Annotate this POD


Open  0
View/Report Bugs
Module Version: 3.3   Source  


Algorithm::Evolutionary::Op::Base - Base class for Algorithm::Evolutionary operators,


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

    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


Base class for operators applied to Individuals and Populations and all the rest. An operator is any object with the "apply" method, which does things to individuals or populations. It is intendedly quite general so that any genetic or population operator can fit in.



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


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 if the object the operator is applied to is in the correct class.


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
syntax highlighting: