| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Algorithm::Genetic::Diploid::Chromosome; |
|
2
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
96
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use Algorithm::Genetic::Diploid::Base; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
64
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use base 'Algorithm::Genetic::Diploid::Base'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1302
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $log = __PACKAGE__->logger; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Algorithm::Genetic::Diploid::Chromosome - one of a pair of homologous chromosomes |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=over |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=item new |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Constructor takes named arguments. Creates a default list of genes and chromosome number. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
|
|
|
|
|
|
shift->SUPER::new( |
|
24
|
100
|
|
|
100
|
1
|
2770
|
'genes' => [], |
|
25
|
|
|
|
|
|
|
'number' => 1, |
|
26
|
|
|
|
|
|
|
@_, |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item genes |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Sets and gets list of genes on the chromosome |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub genes { |
|
37
|
30102
|
|
|
30102
|
1
|
46759
|
my $self = shift; |
|
38
|
30102
|
100
|
|
|
|
68503
|
if ( @_ ) { |
|
39
|
10100
|
|
|
|
|
79101
|
$log->debug("assigning new genes: @_"); |
|
40
|
10100
|
|
|
|
|
34384
|
$self->{'genes'} = \@_; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
30102
|
|
|
|
|
57515
|
return @{ $self->{'genes'} }; |
|
|
30102
|
|
|
|
|
132179
|
|
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item number |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Sets and gets chromosome number, i.e. in humans that would be 1..22, X, Y |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub number { |
|
52
|
10000
|
|
|
10000
|
1
|
16947
|
my $self = shift; |
|
53
|
10000
|
50
|
|
|
|
32828
|
$self->{'number'} = shift if @_; |
|
54
|
10000
|
|
|
|
|
67501
|
return $self->{'number'}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item recombine |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Exchanges genes with homologous chromosome (the argument to this method). |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub recombine { |
|
64
|
5000
|
|
|
5000
|
1
|
12096
|
my ( $self, $other ) = @_; |
|
65
|
5000
|
|
|
|
|
24159
|
my @g1 = $self->genes; |
|
66
|
5000
|
|
|
|
|
18241
|
my @g2 = $other->genes; |
|
67
|
5000
|
|
|
|
|
14872
|
for my $i ( 0 .. $#g1 ) { |
|
68
|
5000
|
100
|
|
|
|
28585
|
if ( $self->experiment->crossover_rate > rand(1) ) { |
|
69
|
3035
|
|
|
|
|
22248
|
( $g1[$i], $g2[$i] ) = ( $g2[$i]->mutate, $g1[$i]->mutate ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
5000
|
|
|
|
|
23317
|
$self->genes(@g1); |
|
73
|
5000
|
|
|
|
|
28329
|
$other->genes(@g2); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |