source: trunk/packages/optimizer/examples/simplesingle.tcl @ 6716

Last change on this file since 6716 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 4.7 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE:  Rappture optimization
3#
4#  This script shows the core of the Rappture optimization loop.
5#  It represents a simple skeleton of the much more complicated
6#  Rappture GUI, but it drives enough of the optimization process
7#  to drive development and testing.
8#
9#  Run this as:  wish simple.tcl ?-tool path/to/tool.xml?
10#
11# ======================================================================
12#  AUTHOR:  Michael McLennan, Purdue University
13#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
14#
15#  See the file "license.terms" for information on usage and
16#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
17# ======================================================================
18set auto_path [linsert $auto_path 0 /tmp/opt/lib]
19package require BLT
20package require Itcl
21package require Rappture
22package require RapptureGUI
23set auto_path [linsert $auto_path 0 /home/ganesh/workspace/optim_post_dir_changes/src/lib]
24package require -exact RapptureOptimizer 1.1
25
26set pop 0
27set popsize 100  ;# size of each population for genetic algorithm
28
29
30# ----------------------------------------------------------------------
31#  Create a Tool object based on the tool.xml file...
32# ----------------------------------------------------------------------
33Rappture::getopts argv params {
34    value -tool tool.xml
35}
36
37# open the XML file containing the tool parameters
38if {![file exists $params(-tool)]} {
39    puts stderr "can't find tool \"$params(-tool)\""
40    exit 1
41}
42set xmlobj [Rappture::library $params(-tool)]
43
44set installdir [file dirname $params(-tool)]
45if {"." == $installdir} {
46    set installdir [pwd]
47}
48
49set tool [Rappture::Tool ::#auto $xmlobj $installdir]
50
51# ----------------------------------------------------------------------
52#  Create some plotting stuff so we can watch the progress of the
53#  optimization as it runs.
54# ----------------------------------------------------------------------
55blt::graph .space
56.space xaxis configure -title "x1" -min -2 -max 2
57.space yaxis configure -title "x2" -min -2 -max 2
58.space legend configure -hide yes
59pack .space -side left -expand yes -fill both
60
61blt::graph .value
62.value xaxis configure -title "job number" -min 0
63.value yaxis configure -title "f(x1,x2)" -logscale yes -max 1
64.value legend configure -hide yes
65pack .value -side left -expand yes -fill both
66
67button .quit -text Quit -command "optim abort yes"
68pack .quit
69button .restart -text Restart -command "optim restart yes"
70pack .restart
71
72set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black brown grey lavender wheat navy}
73
74
75#for {set pop [expr [llength $colors]-1]} {$pop >= 0} {incr pop -1} {
76#    blt::vector x1vec$pop
77#   blt::vector x2vec$pop
78#    .space element create dot -xdata x1vec$pop -ydata x2vec$pop -color black -linewidth 0 -symbol scross
79#        -color [lindex $colors $pop] -linewidth 0 -label "Population #$pop"
80    blt::vector jobvec
81    blt::vector fvec
82    .value element create line -xdata jobvec -ydata fvec -color black -symbol none
83
84#        -color [lindex $colors $pop] -symbol none
85
86
87
88set jobnumber 0
89set pop -1
90proc add_to_plot {xmlobj} {
91               
92    global jobnumber popsize pop
93    if {$jobnumber%$popsize == 0} {
94        incr pop
95        blt::vector x1vec$pop
96        blt::vector x2vec$pop
97
98        blt::graph .space$pop
99        .space$pop xaxis configure -title "x1" -min -2 -max 2
100        .space$pop yaxis configure -title "x2" -min -2 -max 2
101        .space$pop legend configure -hide yes
102        pack .space$pop -side left -expand yes -fill both
103        .space$pop element create dot -xdata x1vec$pop -ydata x2vec$pop -color black -linewidth 0 -symbol scross
104       
105    }   
106    x1vec$pop append [$xmlobj get input.number(x1).current]
107    x2vec$pop append [$xmlobj get input.number(x2).current]
108    jobvec append $jobnumber
109    fvec append [$xmlobj get output.number(f).current]
110    incr jobnumber
111#    optim samples $jobnumber
112}
113
114# ----------------------------------------------------------------------
115#  Create an optimization context and configure the parameters used
116#  for optimization...
117# ----------------------------------------------------------------------
118Rappture::optimizer optim -tool $tool -using pgapack
119
120optim add number input.number(x1) -min -2 -max 2 -randdist uniform -strictmin yes -strictmax yes
121optim add number input.number(x2) -min -2 -max 2 -randdist uniform -strictmin yes -strictmax yes
122optim configure -operation minimize -popsize 100 -maxruns 100 -mutnrate 0.1 -crossovrate 0.8 -randnumseed 20 -stpcriteria maxiter -mutnandcrossover no -allowdup yes -numReplPerPop 40 -mutnValue 0.1 -crossovtype sbx
123
124
125
126optim get configure
127
128
129
130set status [optim perform \
131    -fitness output.number(f).current \
132    -updatecommand add_to_plot]
133optim samples 10
134puts "done: $status"
Note: See TracBrowser for help on using the repository browser.