summaryrefslogtreecommitdiff
path: root/src/genetic/score_histogram.pl
blob: facc71a0c85e3ecdb8ee7a0dd29acc88ef18794a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl

$gen = $ARGV[0];
opendir(DIR, ".");
@files = readdir(DIR);
closedir(DIR);

$min_score = 999999999; $max_score = 0;
$total = 0;
$best = "";
for $file(@files) {
    if ($file =~ m/gen(\d+)_\d+\.log/) {
        $score = 0;
        next if $1 != $gen;
        open(FILE, $file) || die $!;
        $total++;
        while(<FILE>) {
            chop;
            if (m/ correct solutions\s+\:\s+(\d+)/) {
                $score = $1;
                last;
            }
        }
        $score = int($score);
        $scores[$score] += 1;
        $names{$score} .= "$file ";
        if ($score > $max_score) {
            $max_score = $score;
            $best = $file;
        }
        $min_score = $score if ($score < $min_score);
        close(FILE);
    }
}

for ($x = $min_score; $x <= $max_score; $x++) {
    next if $scores[$x] == 0;
    printf "%4u : ", $x;
    print "*" x int($scores[$x] / $total * 60);
    print " ($scores[$x], $names{$x})\n";
}
print "Best was $best\n";
system "tail -22 $best";