source: trunk/optimizer/examples/simple.tcl @ 899

Last change on this file since 899 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.0 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:  tclsh simple.tcl ?-tool path/to/tool.xml?
10#
11# ======================================================================
12#  AUTHOR:  Michael McLennan, Purdue University
13#  Copyright (c) 2008  Purdue Research Foundation
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# ======================================================================
18package require Itcl
19package require Rappture
20package require RapptureGUI
21package require RapptureOptimizer
22
23# ----------------------------------------------------------------------
24#  Create a Tool object based on the tool.xml file...
25# ----------------------------------------------------------------------
26Rappture::getopts argv params {
27    value -tool tool.xml
28}
29
30# open the XML file containing the tool parameters
31if {![file exists $params(-tool)]} {
32    puts stderr "can't find tool \"$params(-tool)\""
33    exit 1
34}
35set xmlobj [Rappture::library $params(-tool)]
36
37set installdir [file dirname $params(-tool)]
38if {"." == $installdir} {
39    set installdir [pwd]
40}
41
42set tool [Rappture::Tool ::#auto $xmlobj $installdir]
43
44# ----------------------------------------------------------------------
45#  Create an optimization context and configure the parameters used
46#  for optimization...
47# ----------------------------------------------------------------------
48Rappture::optimizer optim -tool $tool -using pgapack
49
50optim add number input.number(x1) -min -2 -max 2
51optim add number input.number(x2) -min -2 -max 2
52optim configure -operation minimize -popsize 100 -maxruns 200
53
54set status [optim perform \
55    -fitness output.number(f).current \
56    -updatecommand {puts "checking"}]
57
58puts "done: $status"
Note: See TracBrowser for help on using the repository browser.