Algorithm::Evolutionary::Op::Base - Base class for OPEAL operators; operators are any object with the "apply" method, which does things to individuals or populations.
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(); #print its back in XML shape
print $op->rate(); #application rate; relative number of times it must be applied print "Yes" if $op->check( 'BinaryIndi' ); #Prints Yes, it can be applied to BinaryIndi 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
Automatically define accesors for instance variables
Takes a hash with specific parameters for each subclass, creates the object, and leaves subclass-specific assignments to subclasses
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.
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' E<gt>
.
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, param
s are void tags; if you want
anything more fancy, you will have to override this method.
Gets or sets the rate of application of the operator
Check if the object the operator is applied to has the correct type
Returns the arity, ie, the number of individuals it can be applied to
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 => } );
will set $op-
{_foo}> and $op-
{_bar}> to the corresponding values
The introduction to the XML format used here, Algorithm::Evolutionary::XML.pod
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: 2002/07/26 07:14:56 $ $Header: /cvsroot/opeal/opeal/Algorithm/Evolutionary/Op/Base.pm,v 1.13 2002/07/26 07:14:56 jmerelo Exp $ $Author: jmerelo $ $Revision: 1.13 $ $Name $