« lib/Algorithm/Evolutionary/Op/Generation_Skeleton.pm
↑ Summary
lib/Algorithm/Evolutionary/Op/Mutation.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::Op::GenerationalTerm - Checks for termination of an algorithm. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | my $gt = new Algorithm::Evolutionary::Op::GenerationalTerm 100; #apply will return false after 100 generations | ||
| 11 | |||
| 12 | =head1 Base Class | ||
| 13 | |||
| 14 | L<Algorithm::Evolutionary::Op::Base|Algorithm::Evolutionary::Op::Base> | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | Checks for termination after a number of generations | ||
| 19 | |||
| 20 | =head1 METHODS | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | package Algorithm::Evolutionary::Op::GenerationalTerm; | ||
| 25 | |||
| 26 | our ($VERSION) = ( '$Revision: 3.0 $ ' =~ / (\d+\.\d+)/ ) ; | ||
| 27 | |||
| 28 | 1 | ▶ | use base 'Algorithm::Evolutionary::Op::Base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | |||
| 30 | =head2 new( [$number_of_generations = 100] ) | ||
| 31 | |||
| 32 | Creates a new generational terminator: | ||
| 33 | |||
| 34 | my $gt = new Algorithm::Evolutionary::Op::GenerationalTerm 100; #apply will return false after 100 generations | ||
| 35 | |||
| 36 | will make the C<apply> method return false after 100 calls | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | sub new { | ||
| 41 | my $class = shift; | ||
| 42 | my $hash = { generations => shift || 100, | ||
| 43 | counter => 0 }; | ||
| 44 | my $self = Algorithm::Evolutionary::Op::Base::new( __PACKAGE__, 1, $hash ); | ||
| 45 | return $self; | ||
| 46 | } | ||
| 47 | |||
| 48 | =head2 reset | ||
| 49 | |||
| 50 | Resets the number of generations to 0 | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | sub reset { | ||
| 55 | my $self = shift; | ||
| 56 | $self->{'counter'} =0; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | =head2 apply() | ||
| 61 | |||
| 62 | Checks if the counter has arrived to the allotted number of generations, | ||
| 63 | returns false when it does. | ||
| 64 | |||
| 65 | $gt->apply(); | ||
| 66 | |||
| 67 | will return C<false> when it has been run for the number of times it has | ||
| 68 | been initialized to | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | sub apply ($) { | ||
| 73 | my $self = shift; | ||
| 74 | $self->{_counter}++; | ||
| 75 | return $self->{_counter} <= $self->{_generations}; | ||
| 76 | |||
| 77 | } | ||
| 78 | |||
| 79 | =head1 See Also | ||
| 80 | |||
| 81 | L<Algorithm::Evolutionary::Op::FullAlgorithm> needs an object of this class to check | ||
| 82 | for the termination condition. It's normally used alongside "generation-type" | ||
| 83 | objects such as L<Algorithm::Evolutionary::Op::Easy> | ||
| 84 | |||
| 85 | There are other options for termination conditions: L<Algorithm::Evolutionary::Op::NoChangeTerm|Algorithm::Evolutionary::Op::NoChangeTerm>, L<Algorithm::Evolutionary::Op::Convergence_Terminator> and L<Algorithm::Evolutionary::Op::DeltaTerm>. | ||
| 86 | |||
| 87 | |||
| 88 | =head1 Copyright | ||
| 89 | |||
| 90 | This file is released under the GPL. See the LICENSE file included in this distribution, | ||
| 91 | or go to http://www.fsf.org/licenses/gpl.txt | ||
| 92 | |||
| 93 | CVS Info: $Date: 2009/07/24 08:46:59 $ | ||
| 94 | $Header: /media/Backup/Repos/opeal/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Op/GenerationalTerm.pm,v 3.0 2009/07/24 08:46:59 jmerelo Exp $ | ||
| 95 | $Author: jmerelo $ | ||
| 96 | $Revision: 3.0 $ | ||
| 97 | $Name $ | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | "The truth is out there"; | ||