« lib/Algorithm/Evolutionary/Hash_Wheel.pm
↑ Summary
blib/lib/Algorithm/Evolutionary/Op/Storing.pm »
| 1 | 1 | ▶ | use strict; #-*-cperl-*- | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | Algorithm::Evolutionary::Individual::Any - Wrapper around any Perl data structure, turns it into a I<Chromosome> | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||
| 9 | |||||||||||||
| 10 | use Algorithm::Evolutionary::Individual::Any; | ||||||||||||
| 11 | use Class::Name; # Your class here; it's required if not included anyways | ||||||||||||
| 12 | |||||||||||||
| 13 | my $indi = new Algorithm::Evolutionary::Individual::Any Class::Name $class_args ; | ||||||||||||
| 14 | |||||||||||||
| 15 | $indi->Fitness( $fitness ); | ||||||||||||
| 16 | print $indi->Fitness(); | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 Base Class | ||||||||||||
| 19 | |||||||||||||
| 20 | L<Algorithm::Evolutionary::Individual::Base> | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||
| 23 | |||||||||||||
| 24 | Bitstring Individual for a Genetic Algorithm. Used, for instance, in a | ||||||||||||
| 25 | canonical GA. That does not mean it can be used for mutation or | ||||||||||||
| 26 | crossover; normally you'll have to write your own classes | ||||||||||||
| 27 | |||||||||||||
| 28 | =cut | ||||||||||||
| 29 | |||||||||||||
| 30 | package Algorithm::Evolutionary::Individual::Any; | ||||||||||||
| 31 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | |||||||||||||
| 33 | 1 | our ($VERSION) = ( '$Revision: 3.0 $ ' =~ /(\d+\.\d+)/ ); | |||||||||||
| 34 | |||||||||||||
| 35 | 1 | ▶ | use base 'Algorithm::Evolutionary::Individual::Base'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | |||||||||||||
| 37 | =head1 METHODS | ||||||||||||
| 38 | |||||||||||||
| 39 | =head2 new( $base_class, $base_class_args ) | ||||||||||||
| 40 | |||||||||||||
| 41 | Creates a new individual by instantiating one of the given class with | ||||||||||||
| 42 | the arguments also issued here, which are forwarded to the class | ||||||||||||
| 43 | constructor. | ||||||||||||
| 44 | |||||||||||||
| 45 | =cut | ||||||||||||
| 46 | |||||||||||||
| 47 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||
| 48 | 1 | my $class = shift; | |||||||||||
| 49 | 1 | ▶ | my $base_class = shift || croak "Need a base class"; | ||||||||||
|
Condition50%1/2
shift() || croak('Need a base class')
MC/DC0%0/1
shift() || croak('Need a base class')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 50 | 1 | my $base_class_args = shift; # Arguments optional | |||||||||||
| 51 | 1 | my $self = | |||||||||||
| 52 | Algorithm::Evolutionary::Individual::Base::new( 'Algorithm::Evolutionary::Individual::Any'); | ||||||||||||
| 53 | 1 | ▶ | if ( !$INC{"$base_class\.pm"} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 1 | ▶ | eval "require $base_class" || croak "Can't find $base_class Module"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 1 | ▶ | my $inner_self = $base_class->new( $base_class_args ) || croak "Something is wrong when creating $base_class: $@\n"; | ||||||||||
|
Condition50%1/2
$base_class->new($base_class_args) || croak("Something is wrong when creating ${base_class}: $@\n")
MC/DC0%0/1
$base_class->new($base_class_args) || croak("Something is wrong when creating ${base_class}: $@\n")
$base_class->new($base_class_args)
Truth table50%1/2
A
A= $base_class->new($base_class_args)
| |||||||||||||
| 58 | 1 | $self->{'_inner'} = $inner_self; | |||||||||||
| 59 | 1 | return $self; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | |||||||||||||
| 63 | =head2 Atom([$index]) | ||||||||||||
| 64 | |||||||||||||
| 65 | No matter what kind of underlying structure is there, it will return the wrapped object. You can | ||||||||||||
| 66 | subclass and overload, however, but then you earn nothing to use this | ||||||||||||
| 67 | class; you're better off creating a new one altogether. | ||||||||||||
| 68 | |||||||||||||
| 69 | =cut | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub Atom { | ||||||||||
|
Subroutine
Atom: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||
| 73 | 0 | return $self->{'_inner'}; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | |||||||||||||
| 77 | =head2 size() | ||||||||||||
| 78 | |||||||||||||
| 79 | Returns 1. Here for compatibility | ||||||||||||
| 80 | |||||||||||||
| 81 | =cut | ||||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | sub size { | ||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 84 | 0 | 1; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | =head2 Copyright | ||||||||||||
| 90 | |||||||||||||
| 91 | This file is released under the GPL. See the LICENSE file included in this distribution, | ||||||||||||
| 92 | or go to http://www.fsf.org/licenses/gpl.txt | ||||||||||||
| 93 | |||||||||||||
| 94 | =cut | ||||||||||||