Changeset 903 for trunk/optimizer/examples
- Timestamp:
- Feb 23, 2008, 8:16:38 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/optimizer/examples/simple.tcl
r899 r903 7 7 # to drive development and testing. 8 8 # 9 # Run this as: tclsh simple.tcl ?-tool path/to/tool.xml?9 # Run this as: wish simple.tcl ?-tool path/to/tool.xml? 10 10 # 11 11 # ====================================================================== … … 16 16 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 17 17 # ====================================================================== 18 package require BLT 18 19 package require Itcl 19 20 package require Rappture 20 21 package require RapptureGUI 21 22 package require RapptureOptimizer 23 24 set popsize 100 ;# size of each population for genetic algorithm 22 25 23 26 # ---------------------------------------------------------------------- … … 43 46 44 47 # ---------------------------------------------------------------------- 48 # Create some plotting stuff so we can watch the progress of the 49 # optimization as it runs. 50 # ---------------------------------------------------------------------- 51 blt::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 55 pack .space -side left -expand yes -fill both 56 57 blt::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 61 pack .value -side left -expand yes -fill both 62 63 set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black} 64 65 for {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 77 set jobnumber 0 78 proc 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 # ---------------------------------------------------------------------- 45 89 # Create an optimization context and configure the parameters used 46 90 # for optimization... … … 50 94 optim add number input.number(x1) -min -2 -max 2 51 95 optim add number input.number(x2) -min -2 -max 2 52 optim configure -operation minimize -popsize 100 -maxruns 20096 optim configure -operation minimize -popsize $popsize -maxruns 1000 53 97 54 98 set status [optim perform \ 55 99 -fitness output.number(f).current \ 56 -updatecommand {puts "checking"}]100 -updatecommand add_to_plot] 57 101 58 102 puts "done: $status"
Note: See TracChangeset
for help on using the changeset viewer.