blib/lib/Algorithm/Evolutionary/Fitness/Rastrigin.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
_really_apply
2.0
Rastrigin
2.0
CRAP 2.0
1 use strict; # -*- cperl -*-
2 use warnings;
3  
4 use lib qw( ../../../../lib );
5  
6 =head1 NAME
7  
8 Algorithm::Evolutionary::Fitness::Rastrigin - Implementation of Rastrigin's function
9  
10 =head1 SYNOPSIS
11  
12 my $n_dimensions=2; #Max. number of elements to choose
13 my $rastrigin = Algorithm::Evolutionary::Fitness::Rastrigin->new( $n_dimensions );
14  
15 =head1 DESCRIPTION
16  
17 Classical Rastrigin function, used for tests of numerical optimization problems.
18 Check it at L<http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/TestGO_files/Page2607.htm>
19  
20 =head1 METHODS
21  
22 =cut
23  
24 package Algorithm::Evolutionary::Fitness::Rastrigin;
25  
26 our ($VERSION) = ( '$Revision: 3.3 $ ' =~ / (\d+\.\d+)/ ) ;
27  
28 use Carp qw( croak );
29 use base qw(Algorithm::Evolutionary::Fitness::Base);
30 use constant PI2 => 8 * atan2(1, 1);
31 use constant RASTRIGIN_A => 10;
32  
33 =head2 new
34  
35 Creates a new instance of the problem, with the said number of bits and peaks
36  
37 =cut
38  
39 sub new {
40 my $class = shift;
41 my ( $n_dimensions ) = @_;
42  
43 #Instantiate superclass
44 my $self = $class->SUPER::new();
45  
46 #Assign stuff
47 $self->{'n_dimensions'} = $n_dimensions;
48 $self->{'_base_fitness'} = RASTRIGIN_A*$n_dimensions;
49 $self->initialize();
50 return $self;
51 }
52  
53 sub _really_apply {
54 my $self = shift;
55 return $self->Rastrigin( @_ );
56 }
57  
58 =head2 Rastrigin
59  
60 Applies the knapsack problem to the string, using a penalty function
61  
62 =cut
63  
64 sub Rastrigin {
65 my $self = shift;
66 my @array = @_;
67 my $fitness = $self->{'_base_fitness'};
68 for ( my $i = 0; $i < $self->{'n_dimensions'}; $i ++ ) {
69 $fitness += $array[$i]*$array[$i]- RASTRIGIN_A *cos(PI2*$array[$i]);
70 }
71 return $fitness;
72 }
73  
74  
75 =head1 Copyright
76
77 This file is released under the GPL. See the LICENSE file included in this distribution,
78 or go to http://www.fsf.org/licenses/gpl.txt
79  
80 CVS Info: $Date: 2010/09/28 19:41:26 $
81 $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Fitness/Rastrigin.pm,v 3.3 2010/09/28 19:41:26 jmerelo Exp $
82 $Author: jmerelo $
83 $Revision: 3.3 $
84 $Name $
85  
86 =cut
87  
88 "Pi squared???";