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

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 38 CC 2 SCAR 11.0
CC
2
Cov
0%
onemax
6.0
_really_apply
2.0
BEGIN
2.0
CRAP 3.0
1 use strict; # -*- cperl -*-
2 use warnings;
3  
4 use lib qw( ../../../../lib );
5  
6 =head1 NAME
7  
8 Algorithm::Evolutionary::Fitness::ONEMAX - Fitness function for the ONEMAX or count-ones problem
9  
10 =head1 SYNOPSIS
11  
12 my $onemax = new Algorithm::Evolutionary::Fitness::Knapsack;
13 my $string = "1010101010101010";
14 print $onemax->apply($string);
15  
16 =head1 DESCRIPTION
17  
18 ONEMAX is the classical count-ones optimization function. Fast to implement, and good for early prototyping of new evolutionary algorithms.
19  
20 =head1 METHODS
21  
22 =cut
23  
24 package Algorithm::Evolutionary::Fitness::ONEMAX;
25  
26 our ($VERSION) = ( '$Revision: 3.0 $ ' =~ / (\d+\.\d+)/ ) ;
27  
28 use Carp qw( croak );
29 use base qw(Algorithm::Evolutionary::Fitness::String);
30  
31  
32 sub _really_apply {
33 my $self = shift;
34 return $self->onemax( @_ );
35 }
36  
37 =head2 onemax
38  
39 Computes the number of ones, using base class cache
40  
41 =cut
42  
43 sub onemax {
44 my $self = shift;
45 my $string = shift;
46  
47 my $cache = $self->{'_cache'};
48 if ( defined $cache->{$string} ) {
49 return $cache->{$string};
50 }
51 my $num_ones = ($string =~ tr/1/1/);
52 # my $num_ones = grep( $_, split(//, $string ));
53 # while ( $string ) {
54 # $num_ones += chop( $string );
55 # }
56 $cache->{$string} = $num_ones;
57 return $num_ones;
58 }
59  
60 =head1 Copyright
61
62 This file is released under the GPL. See the LICENSE file included in this distribution,
63 or go to http://www.fsf.org/licenses/gpl.txt
64  
65 =cut
66  
67 "Nothing to do here, proceed";