view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Individual/Tree.pm view on Meta::CPAN
you will be able to get it back from this form. It's done just for
compatibity, reading from this format will be available. In the future.
=cut
sub asXML {
my $self = shift;
my $str = $self->SUPER::asXML();
# my $str2 = ">\n<atom><![CDATA[".$self->asString()."]]></atom> ";
my $str2 = ">\n<atom><![CDATA[dummy root node]]></atom> ";
$str =~ s/\/>/$str2/e ;
return $str.$str2."\n</indi>";
}
=head2 addAtom
Dummy sub
=cut
lib/Algorithm/Evolutionary/Individual/Vector.pm view on Meta::CPAN
=head2 asXML()
Prints it as XML. See the L<Algorithm::Evolutionary::XML|lgorithm::Evolutionary::XML> OPEAL manual for details.
=cut
sub asXML {
my $self = shift;
my $str = $self->SUPER::asXML();
my $str2 = ">" .join( "", map( "<atom>$_</atom> ", @{$self->{_array}} ));
$str =~ s/\/>/$str2/e ;
return $str."\n</indi>";
}
=head2 Chrom( [$ref_to_array]
Sets or gets the array that holds the chromosome. Not very nice, and
I would never ever do this in C++
=cut
lib/Algorithm/Evolutionary/Op/ArithCrossover.pm view on Meta::CPAN
use lib qw(../../..);
=head1 NAME
Algorithm::Evolutionary::Op::ArithCrossover - Arithmetic crossover operator; performs the average of the n parents crossed
=head1 SYNOPSIS
my $xmlStr6=<<EOC; #Create it from XML
<op name='ArithCrossover' type='binary' rate='1' />
EOC
my $ref6 = XMLin($xmlStr6);
my $op6 = Algorithm::Evolutionary::Op::Base->fromXML( $ref6 );
print $op6->asXML(), "\n";
$op6->apply( $indi4, $indi5 );
print $indi4->asString(), "\n"
my $op = new Algorithm::Evolutionary::Op::ArithCrossover; #Create from scratch
=head1 Base Class
lib/Algorithm/Evolutionary/Op/Base.pm view on Meta::CPAN
sub asXML {
my $self = shift;
my ($opName) = ( ( ref $self) =~ /::(\w+)$/ );
my $name = shift; #instance variable it corresponds to
my $str = "<op name='$opName' ";
$str .= "id ='$name' " if $name;
if ( $self->{rate} ) { # "Rated" ops, such as genetic ops
$str .= " rate='".$self->{rate}."'";
}
if (keys %$self == 1 ) {
$str .= " />" ; #Close void tag, only the "rate" param
} else {
$str .= " >";
for ( keys %$self ) {
next if !$self->{$_};
if (!/\brate\b/ ) {
my ($paramName) = /_(\w+)/;
if ( ! ref $self->{$_} ) {
$str .= "\n\t<param name='$paramName' value='$self->{$_}' />";
} elsif ( ref $self->{$_} eq 'ARRAY' ) {
for my $i ( @{$self->{$_}} ) {
$str .= $i->asXML()."\n";
}
} elsif ( ref $self->{$_} eq 'CODE' ) {
my $deparse = B::Deparse->new;
$str .="<code type='eval' language='perl'>\n<src><![CDATA[".$deparse->coderef2text($self->{$_})."]]>\n </src>\n</code>";
} elsif ( (ref $self->{$_} ) =~ 'Algorithm::Evolutionary' ) { #Composite object, I guess...
$str .= $self->{$_}->asXML( $_ );
}
lib/Algorithm/Evolutionary/Op/ChangeLengthMutation.pm view on Meta::CPAN
use strict;
use warnings;
=head1 NAME
Algorithm::Evolutionary::Op::ChangeLengthMutation - Increases/decreases by one atom the length of the string
=head1 SYNOPSIS
my $xmlStr2=<<EOC;
<op name='ChangeLengthMutation' type='unary' rate='0.5' />
EOC
my $ref2 = XMLin($xmlStr2);
my $op2 = Algorithm::Evolutionary::Op::Base->fromXML( $ref2 );
print $op2->asXML(), "\n*Arity ", $op->arity(), "\n";
my $op = new Algorithm::Evolutionary::Op::ChangeLengthMutation 1, 0.5, 0.5; #Create from scratch
=head1 Base Class
lib/Algorithm/Evolutionary/Op/Creator.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::Creator - Operator that generates groups of individuals, of the intended class
=head1 SYNOPSIS
my $op = new Algorithm::Evolutionary::Op::Creator; #Creates empty op, with rate
my $xmlStr=<<EOC;
<op name='Creator' type='nullary'>
<param name='number' value='20' />
<param name='class' value='BitString' />
<param name='options'>
<param name='length' value='320 />
</param>
</op>
EOC
my $ref = XMLin($xmlStr); #This step is not really needed; only if it's going to be manipulated by another object
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
my $op2 = new Algorithm::Evolutionary::Op::Creator( 20, 'String', { chars => [a..j], length => '10' });
lib/Algorithm/Evolutionary/Op/Creator.pm view on Meta::CPAN
Serializes the object as an XML nodeset
=cut
sub asXML {
my $self = shift;
my $str=<<EOC;
<op name='Creator'>
<param name='number' value='$self->{_number}' />
<param name='class' value='$self->{_class}' />
<param name='options'>
EOC
for ( keys %{$self->{_hash}} ){
$str.="\t\t<param name='$_' value='$self->{_hash}->{$_}' />\n";
}
$str.= "\t</param>\n</op>\n";
return $str;
}
=head2 set( $params_hash )
Sets the instance variables of the object, which, so far, should be a
bit "raw". Usually called from the base class
lib/Algorithm/Evolutionary/Op/Crossover.pm view on Meta::CPAN
Algorithm::Evolutionary::Op::Crossover - n-point crossover
operator; puts fragments of the second operand into the first operand
=head1 SYNOPSIS
#Create from XML description using EvoSpec
my $xmlStr3=<<EOC;
<op name='Crossover' type='binary' rate='1'>
<param name='numPoints' value='3' /> #Max is 2, anyways
</op>
EOC
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $xmlStr3 );
print $op3->asXML(), "\n";
#Apply to 2 Individuals of the String class
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $offspring = $op3->apply( $indi2, $indi3 ); #$indi2 == $offspring
#Initialize using OO interface
lib/Algorithm/Evolutionary/Op/Gene_Boundary_Crossover.pm view on Meta::CPAN
Algorithm::Evolutionary::Op::Gene_Boundary_Crossover - n-point crossover
operator that restricts crossing point to gene boundaries
=head1 SYNOPSIS
#Create from XML description using EvoSpec
my $xmlStr3=<<EOC;
<op name='Gene_Boundary_Crossover' type='binary' rate='1'>
<param name='numPoints' value='3' /> #Max is 2, anyways
</op>
EOC
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $xmlStr3 );
print $op3->asXML(), "\n";
#Apply to 2 Individuals of the String class
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone();
my $offspring = $op3->apply( $indi2, $indi3 ); #$indi2 == $offspring
lib/Algorithm/Evolutionary/Op/Inverover.pm view on Meta::CPAN
use lib qw(../../..);
=head1 NAME
Algorithm::Evolutionary::Op::Inverover - Michalewicz's inver-over Operator.
=head1 SYNOPSIS
my $xmlStr3=<<EOC;
<op name='Inverover' type='binary' rate='1' />
EOC
my $ref3 = XMLin($xmlStr3);
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $ref3 );
print $op3->asXML(), "\n";
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone();
$op3->apply( $indi2, $indi3 );
lib/Algorithm/Evolutionary/Op/Inverover.pm view on Meta::CPAN
L<Algorithm::Evolutionary::Op::Base>
=head1 DESCRIPTION
Inver-over operator for a GA. Created by Michalewicz et al., mainly
for the travelling salesman problem. Takes two chromosomes, which are
permutations of each other.
There is some information on this operator in this interview
with Michalewicz: L<http://www.dcs.napier.ac.uk/coil/news/feature48.html>. You can also download papers from his home page: L<http://www.cs.adelaide.edu.au/~zbyszek/Papers/>.
=head1 METHODS
=cut
package Algorithm::Evolutionary::Op::Inverover;
our ($VERSION) = ( '$Revision: 3.0 $ ' =~ /(\d+\.\d+)/ );
use Carp;
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
my $op = new Algorithm::Evolutionary::Op::Permutation ; #Create from scratch
my $bit_chromosome = new Algorithm::Evolutionary::Individual::BitString 10;
$op->apply( $bit_chromosome );
my $priority = 2;
my $max_iterations = 100; # Less than 10!, absolute maximum number
# of permutations
$op = new Algorithm::Evolutionary::Op::Permutation $priority, $max_iterations;
my $xmlStr=<<EOC;
<op name='Permutation' type='unary' rate='2' />
EOC
my $ref = XMLin($xmlStr);
my $op = Algorithm::Evolutionary::Op::->fromXML( $ref );
print $op->asXML(), "\n*Arity ->", $op->arity(), "\n";
=head1 Base Class
L<Algorithm::Evolutionary::Op::Base>
lib/Algorithm/Evolutionary/Op/QuadXOver.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::QuadXOver - N-point crossover operator that changes operands
=head1 SYNOPSIS
my $xmlStr3=<<EOC;
<op name='QuadXOver' type='binary' rate='1'>
<param name='numPoints' value='2' /> #Max is 2, anyways
</op>
EOC
my $ref3 = XMLin($xmlStr3);
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $ref3 );
print $op3->asXML(), "\n";
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone(); #Operands are modified, so better to clone them
lib/Algorithm/Evolutionary/Op/Quad_Crossover_Diff.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::Quad_Crossover_Diff - Uniform crossover, but interchanges only those atoms that are different
=head1 SYNOPSIS
my $xmlStr3=<<EOC;
<op name='Quad_Crossover_Diff' type='binary' rate='1'>
<param name='numPoints' value='2' /> #Max is 2, anyways
</op>
EOC
my $ref3 = XMLin($xmlStr3);
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $ref3 );
print $op3->asXML(), "\n";
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone(); #Operands are modified, so better to clone them
lib/Algorithm/Evolutionary/Op/StringRand.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::StringRand - randomly change chars in a string
=cut
=head1 SYNOPSIS
my $xmlStr2=<<EOC;
<op name='StringRand' type='unary' rate='0.5' />
<param name='numchars' value='1' />
</op>
EOC
my $ref2 = XMLin($xmlStr2);
my $op2 = Algorithm::Evolutionary::Op::Base->fromXML( $ref2 );
print $op2->asXML(), "\n*Arity ", $op->arity(), "\n";
my $op = new Algorithm::Evolutionary::Op::StringRand 3; #Change 3 characters
=head1 Base Class
lib/Algorithm/Evolutionary/Op/Uniform_Crossover.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::Uniform_Crossover - interchanges a set of atoms
from one parent to the other.
=head1 SYNOPSIS
#Create from XML description using EvoSpec
my $xmlStr3=<<EOC;
<op name='Uniform_Crossover' type='binary' rate='1'>
<param name='numPoints' value='3' /> #Max is 2, anyways
</op>
EOC
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $xmlStr3 );
print $op3->asXML(), "\n";
#Apply to 2 Individuals of the String class
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone();
my $offspring = $op3->apply( $indi2, $indi3 ); #$indi2 == $offspring
lib/Algorithm/Evolutionary/Op/Uniform_Crossover_Diff.pm view on Meta::CPAN
=head1 NAME
Algorithm::Evolutionary::Op::Uniform_Crossover_Diff - Uniform crossover, but interchanges only those atoms that are different
=head1 SYNOPSIS
my $xmlStr3=<<EOC;
<op name='Uniform_Crossover_Diff' type='binary' rate='1'>
<param name='numPoints' value='2' /> #Max is 2, anyways
</op>
EOC
my $ref3 = XMLin($xmlStr3);
my $op3 = Algorithm::Evolutionary::Op::Base->fromXML( $ref3 );
print $op3->asXML(), "\n";
my $indi = new Algorithm::Evolutionary::Individual::BitString 10;
my $indi2 = $indi->clone();
my $indi3 = $indi->clone(); #Operands are modified, so better to clone them
lib/Algorithm/Evolutionary/Op/VectorCrossover.pm view on Meta::CPAN
use warnings;
=head1 NAME
Algorithm::Evolutionary::Op::VectorCrossover - Crossover for L<Algorithm::Evolutionary::Individual::Vector>.
=head1 SYNOPSIS
my $xmlStr5=<<EOC; #Create using XML from base class
<op name='VectorCrossover' type='binary' rate='1'>
<param name='numPoints' value='1' />
</op>
EOC
my $ref5 = XMLin($xmlStr5);
my $op5 = Algorithm::Evolutionary::Op::Base->fromXML( $ref5 );
print $op5->asXML(), "\n";
my $indi5 = new Algorithm::Evolutionary::Individual::Vector 10;
print $indi5->asString(), "\n";
$op5->apply( $indi4, $indi5 );
print $indi4->asString(), "\n";