File Coverage

lib/Algorithm/Evolutionary/Fitness/ZDT1.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1 2     2   11 use strict; # -*- cperl -*-
  2         4  
  2         79  
2 2     2   13 use warnings;
  2         5  
  2         80  
3              
4 2     2   11 use lib qw( ../../../../lib );
  2         4  
  2         12  
5              
6             =head1 NAME
7              
8             Algorithm::Evolutionary::Fitness::ZDT1 - Zitzler-Deb-Thiele #1 Multiobjective test function
9              
10             =head1 SYNOPSIS
11              
12             my $number_of_bits = 5;
13             my $z = Algorithm::Evolutionary::Fitness::ZDT1->new( $number_of_bits);
14             my $string = "10101"x30;
15             $z->zdt1( $string);
16             #Previously created binary chromosome with 5x30 bits
17             $z->apply( $chromosome );
18              
19             =head1 DESCRIPTION
20              
21             Implementation of the first ZDT test function, found at "Comparison of Multiobjective Evolutionary
22             Algorithms: Empirical Results" by Zitzler, Deb and Thiele
23              
24              
25             =head1 METHODS
26              
27             =cut
28              
29             package Algorithm::Evolutionary::Fitness::ZDT1;
30              
31             our $VERSION = sprintf "%d.%03d", q$Revision: 3.1 $ =~ /(\d+)\.(\d+)/g;
32              
33 2     2   596 use Carp qw(croak);
  2         14  
  2         132  
34              
35 2     2   11 use lib qw(../../.. ../.. ..);
  2         4  
  2         133  
36              
37 2     2   973 use base qw(Algorithm::Evolutionary::Fitness::String);
  2         3  
  2         1970  
38 2     2   1820 use Algorithm::Evolutionary::Utils qw(decode_string);
  0            
  0            
39              
40             use constant { M => 30,
41             NINE => 9 };
42              
43             =head2 new
44              
45             Creates a new instance of the problem, with the said number of bits and peaks
46              
47             =cut
48              
49             sub new {
50             my $class = shift;
51             my $number_of_bits = shift || croak "Need non-null number of bits\n";
52             my $self = { '_number_of_bits' => $number_of_bits };
53             bless $self, $class;
54             $self->initialize();
55              
56             return $self;
57             }
58              
59             =head2 _really_apply
60              
61             Applies the instantiated problem to a chromosome
62              
63             =cut
64              
65             sub _really_apply {
66             my $self = shift;
67             my $chromosome_string = shift || croak "No chromosome!!!\n";
68             return $self->zdt1( $chromosome_string );
69             }
70              
71             =head2 zdt1
72              
73             Computes ZDT1, returning an array hash with the values of f1 and f2.
74              
75             =cut
76              
77             sub zdt1 {
78             my $self = shift;
79             my $string = shift;
80             my @vector = decode_string( $string,
81             $self->{'_number_of_bits'},
82             0, 1 );
83             my $g = g( @vector );
84             my $h = 1-sqrt($vector[0]/$g);
85             return [ $vector[0], $g*$h ];
86             }
87              
88             =head2 g
89              
90             G function in ZDT
91              
92             =cut
93              
94             sub g {
95             my @x = @_;
96             my $sum =0;
97             map( $sum += $_, @x[1..$#x] );
98             return 1+NINE*$sum/(M-1);
99             }
100              
101             =head1 Copyright
102            
103             This file is released under the GPL. See the LICENSE file included in this distribution,
104             or go to http://www.fsf.org/licenses/gpl.txt
105              
106             CVS Info: $Date: 2009/07/24 10:25:49 $
107             $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Fitness/ZDT1.pm,v 3.1 2009/07/24 10:25:49 jmerelo Exp $
108             $Author: jmerelo $
109             $Revision: 3.1 $
110             $Name $
111              
112             =cut
113              
114             "What???";