line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
5
|
use strict; #-*-cperl-*- |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
46
|
use lib qw( ../../.. ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Algorithm::Evolutionary::Op::Replace_Worst - Incorporate individuals into the population replacing the worst ones |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $op = new Algorithm::Evolutionary::Op::Replace_Worst; |
13
|
|
|
|
|
|
|
$op->apply( $old_population_hashref, $new_population_hashref ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 Base Class |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
L |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Attempts all possible mutations in order, until a "novelty" individual |
22
|
|
|
|
|
|
|
is found. Generated individuals are checked against the population |
23
|
|
|
|
|
|
|
hash, and discarded if they are already in the population. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Algorithm::Evolutionary::Op::Replace_Worst; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our ($VERSION) = ( '$Revision: 3.2 $ ' =~ /(\d+\.\d+)/ ); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
185
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
4
|
use base 'Algorithm::Evolutionary::Op::Base'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#Class-wide constants |
38
|
|
|
|
|
|
|
our $ARITY = 1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new() |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Does nothing, really |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
|
|
|
|
|
|
my $class = shift; |
48
|
|
|
|
|
|
|
my $self = {}; # Create a reference |
49
|
|
|
|
|
|
|
bless $self, $class; # And bless it |
50
|
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 apply( $population, $chromosome_list ) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Eliminates the worst individuals in the population, replacing them by the list of new chromosomes. The population must be evaluated, but there's no need to have it sorted in advance. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub apply ($;$){ |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my $population = shift || croak "No population here!"; |
62
|
|
|
|
|
|
|
my $chromosome_list = shift || croak "No new population here!"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#Sort |
65
|
|
|
|
|
|
|
my @sorted_population = sort { $b->Fitness() <=> $a->Fitness(); } |
66
|
|
|
|
|
|
|
@$population ; |
67
|
|
|
|
|
|
|
my $to_eliminate = scalar @$chromosome_list; |
68
|
|
|
|
|
|
|
splice ( @sorted_population, -$to_eliminate ); |
69
|
|
|
|
|
|
|
push @sorted_population, @$chromosome_list; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return \@sorted_population; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SEE ALSO |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L, where the |
79
|
|
|
|
|
|
|
replacement policy is one of the parameters |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
It can also be used in L for |
82
|
|
|
|
|
|
|
insertion of new individuals asynchronously. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 Copyright |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This file is released under the GPL. See the LICENSE file included in this distribution, |
87
|
|
|
|
|
|
|
or go to http://www.fsf.org/licenses/gpl.txt |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
CVS Info: $Date: 2010/12/20 16:56:46 $ |
90
|
|
|
|
|
|
|
$Header: /cvsroot/opeal/Algorithm-Evolutionary/lib/Algorithm/Evolutionary/Op/Replace_Worst.pm,v 3.2 2010/12/20 16:56:46 jmerelo Exp $ |
91
|
|
|
|
|
|
|
$Author: jmerelo $ |
92
|
|
|
|
|
|
|
$Revision: 3.2 $ |
93
|
|
|
|
|
|
|
$Name $ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|