- or download this
use AI::Genetic::Pro;
...
{ $ideal_score += $connections[$_] }
$all_conn_sum += $connections[$_];
}
- or download this
sub fitness
{
...
}
return $all_conn_sum - $current_score;
}
- or download this
sub terminate
{
...
my $result = $all_conn_sum - fitness($ga, $ga->getFittest);
return $result == $ideal_score ? 1 : 0;
}
- or download this
my $ga = AI::Genetic::Pro->new(
-fitness => \&fitness, # fitness function
...
-history => 1, # remember best results
-preserve => 3, # remember the bests
);
- or download this
$ga->init([0..$#costs]);
- or download this
$ga->evolve(10);
- or download this
print "SCORE: ", $ga->as_value($ga->getFittest), " for set: ", "[".joi
+n(", ", $ga->as_array($ga->getFittest))."]", ".\n";
<p>And if someone want's to see history of evolution:</p>
# $ga->chart(-filename => 'evolution.png');
- or download this
use AI::Genetic::Pro;
my @costs = map [split], <DATA>;
...
78 169 120 151 237 193 99 - 51 12
282 124 74 255 183 18 187 51 - 281
58 153 285 116 10 127 59 12 281 -
- or download this
#!perl -l
...
return 1 if $ga->getFittest->score == @aPoints;
return 0;
}