Help for this page

Select Code to Download


  1. or download this
    use AI::Genetic::Pro;
    
    ...
            { $ideal_score += $connections[$_] }
        $all_conn_sum += $connections[$_];
    }
    
  2. or download this
    sub fitness
    {
    ...
        }
        return $all_conn_sum - $current_score;
    }
    
  3. or download this
    sub terminate
    {
    ...
        my $result = $all_conn_sum - fitness($ga, $ga->getFittest);
        return $result == $ideal_score ? 1 : 0;
    }
    
  4. or download this
    my $ga = AI::Genetic::Pro->new(
        -fitness         => \&fitness,        # fitness function
    ...
        -history         => 1,                # remember best results
        -preserve        => 3,                # remember the bests
    );
    
  5. or download this
    $ga->init([0..$#costs]);
    
  6. or download this
    $ga->evolve(10);
    
  7. 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');
    
  8. 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 -
    
  9. or download this
    #!perl -l
    
    ...
        return 1 if $ga->getFittest->score == @aPoints;
        return 0;
    }