Algorithm-Evolutionary-Fitness

 view release on metacpan or  search on metacpan

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

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

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

=encoding utf8

=head1 NAME

Algorithm::Evolutionary::Fitness::Any - Façade for any function so that it can be used as fitness

=head1 SYNOPSIS

   use Algorithm::Evolutionary::Utils qw( string_decode )

   sub squares {
     my $chrom = shift;
     my @values = string_decode( $chrom, 10, -1, 1 );
     return $values[0] * $values[1];
   }

   my $any_eval = new Algorithm::Evolutionary::Fitness::Any \&squares;


=head1 DESCRIPTION

Turns any subroutine or closure into a fitness function. Useful mainly
if you want results cached; it's not really needed otherwise.

=head1 METHODS

=cut

package Algorithm::Evolutionary::Fitness::Any;

use Carp;

use base 'Algorithm::Evolutionary::Fitness';

our $VERSION =  '3.2';

=head2 new( $function )

Assigns default variables

=cut 

sub new {
  my $class = shift;
  my $self = { _function => shift || croak "No functiona rray" };
  bless $self, $class;
  $self->initialize();
  return $self;
}

=head2 apply( $individual )

Applies the instantiated problem to a chromosome. It is actually a
wrapper around C<_apply>.

=cut

sub apply {
    my $self = shift;
    my $individual = shift || croak "Nobody here!!!";
    $self->{'_counter'}++;



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