When I run the following code:
#!/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; print ref $genes, "\n"; my @sorted = sort { print Dumper($a,$b); sleep 1; $genes->[$a] <=> $genes->[$b] } 0..3; my $score = $sorted[1] + 2*$sorted[2] + 3*$sorted[3]; print "DEBUG: score was $score\n"; return $score; }
I get
1037% perl genetic.pl ARRAY $VAR1 = 0; $VAR2 = 1; $VAR1 = 2; $VAR2 = 3; $VAR1 = 1; $VAR2 = 2; $VAR1 = 1; $VAR2 = 3; $VAR1 = 0; $VAR2 = 3; DEBUG: score was 7 ARRAY $VAR1 = undef; $VAR2 = undef; Use of uninitialized value in array element at genetic.pl line 27. Use of uninitialized value in array element at genetic.pl line 27. $VAR1 = undef; $VAR2 = undef; Use of uninitialized value in array element at genetic.pl line 27. Use of uninitialized value in array element at genetic.pl line 27. $VAR1 = undef; $VAR2 = undef; Use of uninitialized value in array element at genetic.pl line 27. Use of uninitialized value in array element at genetic.pl line 27. $VAR1 = undef; $VAR2 = undef; Use of uninitialized value in array element at genetic.pl line 27. Use of uninitialized value in array element at genetic.pl line 27. DEBUG: score was 14 etc...
So the first sort seems to work fine, but it crashes on subsequent iterations. A mystery...

Update: It is an official bug: check out nested sort in perl-5.7.0 fails.

-Mark


In reply to Re: AI::Genetic gives me strange warnings by kvale
in thread AI::Genetic gives me strange warnings by fizbin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.