$population = regenrate_population();
...
sub regenrate_population {
my $new_population = [];
for my $i ( 0 .. ( $population_size - 1 ) ) {
my $chromosome1 = get_nonrandom_chromosome();
my $chromosome2 = get_nonrandom_chromosome();
$$new_population[$i] = get_child( $chromosome1, $chromosome2 );
}
return $new_population;
}
####
my $crossover_point = int( rand($chromosome_size) );
for my $i ( 0 .. ( $chromosome_size - 1 ) ) {
if ( $i < $crossover_point ) {
push( @$new_chromosome, @$chromosome1[$i] );
}
else {
push( @$new_chromosome, @$chromosome2[$i] );
}
}
##
##
my $crossover_point = int( rand($chromosome_size) );
$new_chromosome = [
@{$chromosome1}[ 0 .. $crossover_point-1],
@{$chromosome2}[ $crossover_point .. $#{$chromosome2} ]
];