script/canonical-ga.pl untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 use lib qw( lib ../Algorithm-Evolutionary/lib ../../lib ../lib ../../Algorithm-Evolutionary/lib );
7  
8 use POE::Component::Algorithm::Evolutionary;
9 use POE;
10  
11 use Algorithm::Evolutionary qw( Individual::BitString Op::Creator
12 Op::CanonicalGA Op::Bitflip
13 Op::Crossover Op::GenerationalTerm
14 Fitness::Royal_Road);
15  
16 my $bits = shift || 64;
17 my $block_size = shift || 4;
18 my $pop_size = shift || 256; #Population size
19 my $numGens = shift || 200; #Max number of generations
20 my $selection_rate = shift || 0.2;
21  
22  
23 #----------------------------------------------------------#
24 #Initial population
25 my $creator = new Algorithm::Evolutionary::Op::Creator( $pop_size, 'BitString', { length => $bits });
26  
27 #----------------------------------------------------------#
28 # Variation operators
29 my $m = Algorithm::Evolutionary::Op::Bitflip->new( 1 );
30 my $c = Algorithm::Evolutionary::Op::Crossover->new(2, 4);
31  
32 # Fitness function: create it and evaluate
33 my $rr = new Algorithm::Evolutionary::Fitness::Royal_Road( $block_size );
34  
35 #----------------------------------------------------------#
36 #Usamos estos operadores para definir una generación del algoritmo. Lo cual
37 # no es realmente necesario ya que este algoritmo define ambos operadores por
38 # defecto. Los parámetros son la función de fitness, la tasa de selección y los
39 # operadores de variación.
40 my $generation = Algorithm::Evolutionary::Op::CanonicalGA->new( $rr , $selection_rate , [$m, $c] ) ;
41 my $gterm = new Algorithm::Evolutionary::Op::GenerationalTerm 10;
42  
43 POE::Component::Algorithm::Evolutionary->new( Fitness => $rr,
44 Creator => $creator,
45 Single_Step => $generation,
46 Terminator => $gterm,
47 Alias => 'Canonical' );
48  
49  
50 $poe_kernel->run();