Algorithm-Evolutionary-Fitness

 view release on metacpan or  search on metacpan

lib/Algorithm/Evolutionary/Fitness/Rastrigin.pm  view on Meta::CPAN

use strict; # -*- cperl -*-
use warnings;

use lib qw( ../../../../lib );

=head1 NAME

Algorithm::Evolutionary::Fitness::Rastrigin - Implementation of Rastrigin's function

=head1 SYNOPSIS

    my $n_dimensions=2;  #Max. number of elements to choose
    my $rastrigin = Algorithm::Evolutionary::Fitness::Rastrigin->new( $n_dimensions ); 

=head1 DESCRIPTION

Classical Rastrigin function, used for tests of numerical optimization problems. 
Check it at L<http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/TestGO_files/Page2607.htm>

=head1 METHODS

=cut

package Algorithm::Evolutionary::Fitness::Rastrigin;

our ($VERSION) = ( '$Revision: 3.3 $ ' =~ / (\d+\.\d+)/ ) ;

use Carp qw( croak );
use base qw(Algorithm::Evolutionary::Fitness);
use constant PI2    => 8 * atan2(1, 1);
use constant RASTRIGIN_A => 10;

=head2 new

Creates a new instance of the problem, with the said number of bits and peaks

=cut 

sub new {
  my $class = shift;
  my ( $n_dimensions ) = @_;

  #Instantiate superclass
  my $self = $class->SUPER::new();

  #Assign stuff
  $self->{'n_dimensions'} = $n_dimensions;
  $self->{'_base_fitness'} = RASTRIGIN_A*$n_dimensions;
  $self->initialize();
  return $self;
}

sub _really_apply {
    my $self = shift;
    return $self->Rastrigin( @_ );
}

=head2 Rastrigin

Applies the knapsack problem to the string, using a penalty function

=cut

sub Rastrigin {



( run in 0.671 second using v1.01-cache-2.11-cpan-39bf76dae61 )