#!/usr/bin/perl use strict; use warnings; use AI::Genetic; use Data::Dumper; $|=1; my $ga = AI::Genetic->new ( -fitness => \&my_fitness, -type => 'rangevector' ); $ga->init([ [0,10], [0,10], [0,10], [0,10] ]); $ga->sortIndividuals($ga->people()); # Note that using this instead of sortPopulation does NOT # cause the same warnings: # my @populace = sort {$a->score <=> $b->score} @{$ga->people()}; sub my_fitness { my $genes = shift; my @order = (0,1,2,3); my @sorted = sort { local $SIG{__WARN__} = sub {print Dumper($a,$b); print @_; sleep 1;}; $genes->[$a] <=> $genes->[$b] } @order; my $score = $sorted[1] + 2*$sorted[2] + 3*$sorted[3]; print "DEBUG: score was $score\n"; return $score; }