lib/Algorithm/Evolutionary/Fitness/ONEMAX.pm

filter: Statementstmt 62.9% 17 / 27 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 1 / 1 totaltotal 62.1% 23 / 37 CC 2 SCAR 8.6
CC
2
Cov
59%
onemax
6.0
_really_apply
2.0
BEGIN
1.0
CRAP 2.4
« blib/lib/Algorithm/Evolutionary/Op/Animated_GIF_Output.pm ↑ Summary lib/Algorithm/Evolutionary/Individual/Bit_Vector.pm »
1 9 ▶use strict; # -*- cperl -*-
Subroutine BEGIN: called CC=1 SCAR=0.0
2 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 9 ▶use lib qw( ../../../../lib );
Subroutine BEGIN: called CC=1 SCAR=0.0
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 9 our ($VERSION) = ( '$Revision: 3.0 $ ' =~ / (\d+\.\d+)/ ) ;
27  
28 9 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 9 ▶use base qw(Algorithm::Evolutionary::Fitness::String);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31  
32 0 ▶sub _really_apply {
Subroutine _really_apply: not called CC=1 SCAR=6.9
33 0 my $self = shift;
34 0 return $self->onemax( @_ );
35 }
36  
37 =head2 onemax
38  
39 Computes the number of ones, using base class cache
40  
41 =cut
42  
43 0 ▶sub onemax {
Subroutine onemax: not called CC=2 SCAR=17.9
Pod documented
44 0 my $self = shift;
45 0 my $string = shift;
46  
47 0 my $cache = $self->{'_cache'};
48 0 ▶ if ( defined $cache->{$string} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache->{$string}) 0 0 0
49 0 return $cache->{$string};
50 }
51 0 my $num_ones = ($string =~ tr/1/1/);
52 # my $num_ones = grep( $_, split(//, $string ));
53 # while ( $string ) {
54 # $num_ones += chop( $string );
55 # }
56 0 $cache->{$string} = $num_ones;
57 0 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 CVS Info: $Date: 2009/07/24 08:46:59 $
66 $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Fitness/ONEMAX.pm,v 3.0 2009/07/24 08:46:59 jmerelo Exp $
67 $Author: jmerelo $
68 $Revision: 3.0 $
69  
70 =cut
71  
72 9 "What???";
« blib/lib/Algorithm/Evolutionary/Op/Animated_GIF_Output.pm ↑ Summary lib/Algorithm/Evolutionary/Individual/Bit_Vector.pm »