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

Last change on this file since 899 was 899, checked in by mmc, 16 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.

  • Property svn:executable set to *
File size: 1.2 KB
1# ----------------------------------------------------------------------
2#  EXAMPLE: Optimization of the Rosenbrock function
4#  This tool is a good example for optimization.  It implements the
5#  Rosenbrock function:
7#    f(x1,x2) = 100(x2 - x1**2)**2 + (1-x1)**2
9#  This has a minimum at (x1,x2) = (1,1).
11# ======================================================================
12#  AUTHOR:  Michael McLennan, Purdue University
13#  Copyright (c) 2004-2007  Purdue Research Foundation
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 Rappture
20# open the XML file containing the run parameters
21set driver [Rappture::library [lindex $argv 0]]
23set x1 [$driver get input.(x1).current]
24set x2 [$driver get input.(x2).current]
26set f [expr {100*($x2-$x1*$x1)*($x2-$x1*$x1) + (1-$x1)*(1-$x1)}]
28$driver put output.number(f).about.label "Rosenbrock function"
29$driver put output.number(f).about.description \
30    "f(x1,x2) = 100(x2 - x1**2)**2 + (1-x1)**2"
31$driver put output.number(f).current $f
33# save the updated XML describing the run...
34Rappture::result $driver
35exit 0
Note: See TracBrowser for help on using the repository browser.