source: trunk/packages/optimizer/examples/visualize.tcl @ 1970

Last change on this file since 1970 was 899, checked in by mmc, 15 years ago

Added a -fitness option to the "perform" operation. Right now, you can
specify just the name of an output quantity, and that quantity can be
minimized or maximized. In the future, there should be an expression
parser so you can enter any function of Rappture quantities.

Fixed up the example so that it runs the Rosenbrock function, which is
difficult to minimize. Added a visualize.tcl script, so you can visualize
the output from many different runXXXX.xml files.

File size: 2.2 KB
1# ----------------------------------------------------------------------
2#  Visualize the output of genetic optimization
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.
8#  Run this as:  wish visualize.tcl
10# ======================================================================
11#  AUTHOR:  Michael McLennan, Purdue University
12#  Copyright (c) 2008  Purdue Research Foundation
14#  See the file "license.terms" for information on usage and
15#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16# ======================================================================
17package require BLT
18package require Rappture
20# ----------------------------------------------------------------------
21#  Load up all of the Rappture result files
22# ----------------------------------------------------------------------
23set jobs 0
24foreach file [lsort [glob run*.xml]] {
25    set result($jobs) [Rappture::library $file]
26    incr jobs
29blt::graph .space xaxis configure -title "x1" -min -2 -max 2 yaxis configure -title "y1" -min -2 -max 2 legend configure -hide no
33pack .space -side left -expand yes -fill both
35blt::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
39pack .value -side left -expand yes -fill both
41set colors {blue purple magenta green yellow orange tomato red black}
42for {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"
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
54for {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
Note: See TracBrowser for help on using the repository browser.