Ignore:
Timestamp:
Feb 23, 2008 8:16:38 PM (15 years ago)
Author:
mmc
Message:

Final tweaks on the optimization package. The demo now works properly.
Just run "wish simple.tcl" to see it work.

Fixed the Tool class to work better with the optimizer. The "run"
method now returns the result directly as a Rappture::Library object,
and the Analyzer merely loads the object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/optimizer/examples/simple.tcl

    r899 r903  
    77#  to drive development and testing.
    88#
    9 #  Run this as:  tclsh simple.tcl ?-tool path/to/tool.xml?
     9#  Run this as:  wish simple.tcl ?-tool path/to/tool.xml?
    1010#
    1111# ======================================================================
     
    1616#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1717# ======================================================================
     18package require BLT
    1819package require Itcl
    1920package require Rappture
    2021package require RapptureGUI
    2122package require RapptureOptimizer
     23
     24set popsize 100  ;# size of each population for genetic algorithm
    2225
    2326# ----------------------------------------------------------------------
     
    4346
    4447# ----------------------------------------------------------------------
     48#  Create some plotting stuff so we can watch the progress of the
     49#  optimization as it runs.
     50# ----------------------------------------------------------------------
     51blt::graph .space
     52.space xaxis configure -title "x1" -min -2 -max 2
     53.space yaxis configure -title "x2" -min -2 -max 2
     54.space legend configure -hide no
     55pack .space -side left -expand yes -fill both
     56
     57blt::graph .value
     58.value xaxis configure -title "job number" -min 0
     59.value yaxis configure -title "f(x1,x2)" -logscale yes -max 1
     60.value legend configure -hide yes
     61pack .value -side left -expand yes -fill both
     62
     63set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black}
     64
     65for {set pop [expr [llength $colors]-1]} {$pop >= 0} {incr pop -1} {
     66    blt::vector x1vec$pop
     67    blt::vector x2vec$pop
     68    .space element create spots$pop -xdata x1vec$pop -ydata x2vec$pop \
     69        -color [lindex $colors $pop] -linewidth 0 -label "Population #$pop"
     70
     71    blt::vector jobvec$pop
     72    blt::vector fvec$pop
     73    .value element create line$pop -xdata jobvec$pop -ydata fvec$pop \
     74        -color [lindex $colors $pop] -symbol none
     75}
     76
     77set jobnumber 0
     78proc add_to_plot {xmlobj} {
     79    global jobnumber popsize
     80    set pop [expr {$jobnumber/$popsize}]
     81    x1vec$pop append [$xmlobj get input.number(x1).current]
     82    x2vec$pop append [$xmlobj get input.number(x2).current]
     83    jobvec$pop append $jobnumber
     84    fvec$pop append [$xmlobj get output.number(f).current]
     85    incr jobnumber
     86}
     87
     88# ----------------------------------------------------------------------
    4589#  Create an optimization context and configure the parameters used
    4690#  for optimization...
     
    5094optim add number input.number(x1) -min -2 -max 2
    5195optim add number input.number(x2) -min -2 -max 2
    52 optim configure -operation minimize -popsize 100 -maxruns 200
     96optim configure -operation minimize -popsize $popsize -maxruns 1000
    5397
    5498set status [optim perform \
    5599    -fitness output.number(f).current \
    56     -updatecommand {puts "checking"}]
     100    -updatecommand add_to_plot]
    57101
    58102puts "done: $status"
Note: See TracChangeset for help on using the changeset viewer.