1 | # ---------------------------------------------------------------------- |
---|
2 | # Visualize the output of genetic optimization |
---|
3 | # |
---|
4 | # This script reads a bunch of runXXXX.xml files and plots them |
---|
5 | # so you can see where the genetic algorithm was simulating and |
---|
6 | # what it came up with. |
---|
7 | # |
---|
8 | # Run this as: wish visualize.tcl |
---|
9 | # |
---|
10 | # ====================================================================== |
---|
11 | # AUTHOR: Michael McLennan, Purdue University |
---|
12 | # Copyright (c) 2008 Purdue Research Foundation |
---|
13 | # |
---|
14 | # See the file "license.terms" for information on usage and |
---|
15 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | # ====================================================================== |
---|
17 | package require BLT |
---|
18 | package require Rappture |
---|
19 | |
---|
20 | # ---------------------------------------------------------------------- |
---|
21 | # Load up all of the Rappture result files |
---|
22 | # ---------------------------------------------------------------------- |
---|
23 | set jobs 0 |
---|
24 | foreach file [lsort [glob run*.xml]] { |
---|
25 | set result($jobs) [Rappture::library $file] |
---|
26 | incr jobs |
---|
27 | } |
---|
28 | |
---|
29 | blt::graph .space |
---|
30 | .space xaxis configure -title "x1" -min -2 -max 2 |
---|
31 | .space yaxis configure -title "y1" -min -2 -max 2 |
---|
32 | .space legend configure -hide no |
---|
33 | pack .space -side left -expand yes -fill both |
---|
34 | |
---|
35 | blt::graph .value |
---|
36 | .value xaxis configure -title "job number" -min 0 -max $jobs |
---|
37 | .value yaxis configure -title "f(x1,x2)" -min 0 -max 2 |
---|
38 | .value legend configure -hide yes |
---|
39 | pack .value -side left -expand yes -fill both |
---|
40 | |
---|
41 | set colors {blue purple magenta green yellow orange tomato red black} |
---|
42 | for {set pop [expr [llength $colors]-1]} {$pop >= 0} {incr pop -1} { |
---|
43 | blt::vector x1vec$pop |
---|
44 | blt::vector x2vec$pop |
---|
45 | .space element create spots$pop -xdata x1vec$pop -ydata x2vec$pop \ |
---|
46 | -color [lindex $colors $pop] -linewidth 0 -label "Population #$pop" |
---|
47 | |
---|
48 | blt::vector jobvec$pop |
---|
49 | blt::vector fvec$pop |
---|
50 | .value element create line$pop -xdata jobvec$pop -ydata fvec$pop \ |
---|
51 | -color [lindex $colors $pop] -symbol none |
---|
52 | } |
---|
53 | |
---|
54 | for {set n 0} {$n < $jobs} {incr n} { |
---|
55 | set pop [expr {$n/100}] |
---|
56 | x1vec$pop append [$result($n) get input.number(x1).current] |
---|
57 | x2vec$pop append [$result($n) get input.number(x2).current] |
---|
58 | jobvec$pop append $n |
---|
59 | fvec$pop append [$result($n) get output.number(f).current] |
---|
60 | update |
---|
61 | after 100 |
---|
62 | } |
---|