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
Line 
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# ======================================================================
17package require BLT
18package require Rappture
19
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
27}
28
29blt::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
33pack .space -side left -expand yes -fill both
34
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
40
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"
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
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
62}
Note: See TracBrowser for help on using the repository browser.