| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 16514 | use strict; #-*-cperl-*- | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 2 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =head1 NAME | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | Algorithm::Evolutionary::Individual::Any - Wrapper around any Perl class, turns it into a I | 
| 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 | 
| 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 |  |  | 1 |  | 4 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 107 |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | our ($VERSION) =  ( '$Revision: 3.0 $ ' =~ /(\d+\.\d+)/ ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 1 |  |  | 1 |  | 4 | use base 'Algorithm::Evolutionary::Individual::Base'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 378 |  | 
| 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 |  |  |  |  |  |  | sub new { | 
| 48 | 1 |  |  | 1 | 1 | 15 | my $class = shift; | 
| 49 | 1 |  | 33 |  |  | 3 | my $base_class = shift || croak "Need a base class"; | 
| 50 | 1 |  |  |  |  | 2 | my $base_class_args = shift; # Arguments optional | 
| 51 | 1 |  |  |  |  | 5 | my $self = | 
| 52 |  |  |  |  |  |  | Algorithm::Evolutionary::Individual::Base::new( 'Algorithm::Evolutionary::Individual::Any'); | 
| 53 | 1 | 50 |  |  |  | 5 | if ( !$INC{"$base_class\.pm"} ) { | 
| 54 | 1 | 50 |  |  |  | 39 | eval "require $base_class" || croak "Can't find $base_class Module"; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 1 |  | 33 |  |  | 24512 | my $inner_self = $base_class->new( $base_class_args ) || croak "Something is wrong when creating $base_class: $@\n"; | 
| 58 | 1 |  |  |  |  | 47 | $self->{'_inner'} = $inner_self; | 
| 59 | 1 |  |  |  |  | 3 | return $self; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head2 Atom([$index]) | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | No matter what you write, it will return the object wrapped. You can | 
| 66 |  |  |  |  |  |  | subclass and overload, however, but then you win nothing to use this | 
| 67 |  |  |  |  |  |  | class; you're better off creating a new one altogether | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =cut | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub Atom { | 
| 72 | 0 |  |  | 0 | 1 |  | 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 |  |  |  |  |  |  | sub size { | 
| 84 | 0 |  |  | 0 | 1 |  | 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 |  |  |  |  |  |  | CVS Info: $Date: 2009/07/24 08:46:59 $ | 
| 95 |  |  |  |  |  |  | $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Individual/Any.pm,v 3.0 2009/07/24 08:46:59 jmerelo Exp $ | 
| 96 |  |  |  |  |  |  | $Author: jmerelo $ | 
| 97 |  |  |  |  |  |  | $Revision: 3.0 $ | 
| 98 |  |  |  |  |  |  | $Name $ | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =cut |