« blib/lib/Algorithm/Evolutionary/Op/VectorCrossover.pm
↑ Summary
blib/lib/Algorithm/Evolutionary/Op/IncMutation.pm »
| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use lib qw( ../../../../lib ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Algorithm::Evolutionary::Fitness::Royal_Road - Mitchell's Royal Road function | ||||||||||
| 9 | |||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||
| 11 | |||||||||||
| 12 | my $block_size = 4; | ||||||||||
| 13 | my $rr = Algorithm::Evolutionary::Fitness::Royal_Road->new( $block_size ); | ||||||||||
| 14 | |||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||
| 16 | |||||||||||
| 17 | Royal Road function, adds block_size to fitness only when the block is complete | ||||||||||
| 18 | |||||||||||
| 19 | =head1 METHODS | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | package Algorithm::Evolutionary::Fitness::Royal_Road; | ||||||||||
| 24 | |||||||||||
| 25 | 1 | our ($VERSION) = ( '$Revision: 3.1 $ ' =~ / (\d+\.\d+)/ ) ; | |||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | use base qw(Algorithm::Evolutionary::Fitness::String); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | =head2 new( $block_size ) | ||||||||||
| 30 | |||||||||||
| 31 | Creates a new instance of the problem, with the said block size. | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | 0 | my $class = shift; | |||||||||
| 37 | 0 | my ( $block_size ) = @_; | |||||||||
| 38 | 0 | my $self = $class->SUPER::new(); | |||||||||
| 39 | 0 | $self->{'_block_size'} = $block_size; | |||||||||
| 40 | 0 | $self->initialize(); | |||||||||
| 41 | 0 | return $self; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _really_apply { | ||||||||
|
Subroutine
_really_apply: not called CC=1 SCAR=6.9
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | return $self->royal_road( @_ ); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | =head2 royal_road( $string ) | ||||||||||
| 50 | |||||||||||
| 51 | Computes the royal road function with given block size. Results are | ||||||||||
| 52 | cached by default. | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub royal_road { | ||||||||
|
Subroutine
royal_road: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | 0 | my $string = shift; | |||||||||
| 59 | 0 | my $cache = $self->{'_cache'}; | |||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | if ( $cache->{$string} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | return $cache->{$string}; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | my $fitness = 0; | |||||||||
| 66 | 0 | my $block_size = $self->{'_block_size'}; | |||||||||
| 67 | 0 | ▶ | for ( my $i = 0; $i < length( $string ) / $block_size; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | my $block = 0; | |||||||||
| 69 | 0 | ▶ | if ( length( substr( $string, $i*$block_size, $block_size )) == $block_size ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $block=1; | |||||||||
| 71 | 0 | ▶ | for ( my $j = 0; $j < $block_size; $j++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $block &= substr( $string, $i*$block_size+$j, 1 ); | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | 0 | ▶ | ( $fitness += $block_size ) if $block; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | } | ||||||||||
| 77 | 0 | $cache->{$string} = $fitness; | |||||||||
| 78 | 0 | return $cache->{$string}; | |||||||||
| 79 | |||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | =head1 Copyright | ||||||||||
| 84 | |||||||||||
| 85 | This file is released under the GPL. See the LICENSE file included in this distribution, | ||||||||||
| 86 | or go to http://www.fsf.org/licenses/gpl.txt | ||||||||||
| 87 | |||||||||||
| 88 | CVS Info: $Date: 2009/07/28 11:30:56 $ | ||||||||||
| 89 | $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Fitness/Royal_Road.pm,v 3.1 2009/07/28 11:30:56 jmerelo Exp $ | ||||||||||
| 90 | $Author: jmerelo $ | ||||||||||
| 91 | $Revision: 3.1 $ | ||||||||||
| 92 | $Name $ | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 1 | "What???"; | |||||||||