source: trunk/packages/optimizer/examples/app-qdot.tcl @ 1970

Last change on this file since 1970 was 1166, checked in by liveletlive, 14 years ago

Changes Made: Vanilla restart added, no modifications can be made to existing parameters in the middle of a run. Only mutation creates a new population on restart.
New configuration options added: MutationandCrossover? option. amount to be mutated made configurable. configration for (not)allowing duplicate strings added. app-qdot and simple modified to keep pace with these changes.

File size: 7.1 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE:  Rappture optimization for app-qdot
3#
4#  The purpose of this script is to use a scrpt like simple.tcl to interface with app-qdot.
5#  The plotting functions created are done away with, since the problem is not confined to a 3-d space.
6#  The inputs are configured for app-qdot.
7#  Run this as:  wish app-qdot.tcl ?-tool path/to/tool.xml?
8#
9# ======================================================================
10#  AUTHOR:  Ganesh Hegde, Purdue University
11#  Adapted from: simple.tcl
12#  Copyright (c) 2008  Purdue Research Foundation
13#
14#  See the file "license.terms" for information on usage and
15#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16# ======================================================================
17set auto_path [linsert $auto_path 0 /tmp/opt/lib]
18package require BLT
19package require Itcl
20package require Rappture
21package require RapptureGUI
22set auto_path [linsert $auto_path 0 /home/ganesh/workspace/optim_post_dir_changes/src/lib]
23package require -exact RapptureOptimizer 1.1
24set popsize 100  ;# size of each population for genetic algorithm
25
26set xml_path [lindex $argv 0]
27puts $xml_path
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
37after 2000
38puts $params(-tool)
39after 2000
40#blt::bltdebug 100
41
42# open the XML file containing the tool parameters
43if {![file exists $params(-tool)]} {
44    puts stderr "can't find tool \"$params(-tool)\""
45    exit 1
46}
47set xmlobj [Rappture::library $params(-tool)]
48
49set installdir [file dirname $params(-tool)]
50if {"." == $installdir} {
51    set installdir [pwd]
52}
53
54set tool [Rappture::Tool ::#auto $xmlobj $installdir]
55# ----------------------------------------------------------------------
56#  Create some plotting stuff so we can watch the progress of the
57#  optimization as it runs.
58# ----------------------------------------------------------------------
59#blt::graph .space
60#.space xaxis configure -title "x1" -min -2 -max 2
61#.space yaxis configure -title "x2" -min -2 -max 2
62#.space legend configure -hide no
63#pack .space -side left -expand yes -fill both
64
65#blt::graph .value
66#.value xaxis configure -title "job number" -min 0
67#.value yaxis configure -title "f(x1,x2)" -logscale yes -max 1
68#.value legend configure -hide yes
69#pack .value -side left -expand yes -fill both
70
71#button .quit -text Quit -command "optim abort yes"
72#pack .quit
73#set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black}
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 spots$pop -xdata x1vec$pop -ydata x2vec$pop \
79#        -color [lindex $colors $pop] -linewidth 0 -label "Population #$pop"
80
81#    blt::vector jobvec$pop
82#    blt::vector fvec$pop
83#    .value element create line$pop -xdata jobvec$pop -ydata fvec$pop \
84#        -color [lindex $colors $pop] -symbol none
85#}
86
87
88#set jobnumber 0
89proc display_current_values {xmlobj} {
90#    x1vec$pop append [$xmlobj get input.number(x1).current]
91#    x2vec$pop append [$xmlobj get input.number(x2).current]
92    set xl  [$xmlobj get output.number(xl).current]
93    set yl  [$xmlobj get output.number(yl).current]
94    set zl  [$xmlobj get output.number(zl).current]
95    set Ef  [$xmlobj get output.number(Ef).current]
96    set temp  [$xmlobj get output.number(temp).current]
97    set theta  [$xmlobj get output.number(theta).current]
98    set phi  [$xmlobj get output.number(phi).current]
99    set fitness [$xmlobj get output.number(f).current]
100    set max_string [$xmlobj get  output.string(maxlist).current]
101    puts "Device and Light Paramters for this evaluation: Xl = $xl nm,  Yl = $yl nm,   Zl = $zl nm,   Ef = $Ef eV,   temp = $temp K,  theta = $theta,   deg phi = $phi deg"
102    puts "The fitness in this evaluation is $fitness................."
103    puts "Maxima(s) at x equals $max_string"
104}
105
106#proc find_fitness {xmlobj} {
107#       set fitness 1000 #Arbitrarily setting fitness to a large value
108#       set opt_abs_curve output.curve(abs).component.xy
109#       puts $opt_abs_curve
110#       set index 0
111#       set xytuples [split $opt_abs_curve "\n"]
112#       set no_of_curve_points [llength $xytuples]
113#       foreach xytuple $xytuples {
114#               set tuple [split $xytuple " "]
115#               set x($index) [lindex $tuple 0]
116#               set y($index) [lindex $tuple 1]
117#               puts $x($index)
118#               puts $y($index)
119#               incr index
120#       }
121#       set size [llength xytuples]
122#       for {set index 0} {$index <= ($size-1)} {incr index} {
123#               if($index != ($size-2)){
124#                       set slope_at_x (($y($index+1)-$y($index))/($x($index+1)-$x($index)))
125#                       set slope_x_plus_one (($y($index+2)-$y($index+1))/($x($index+2)-$x($index+1)))
126#               }else{
127#                       set slope_x_plus_one (($y($index)-$y($index-1))/($x($index)-$x($index-1)))
128#                       set slope_at_x (($y($index-1)-$y($index-2))/($x($index-1)-$x($index-2)))
129#               }
130#               if(slope_at_x > 0 && slope_x_plus_one <=0){
131#                       set maxima_point $x($index)
132#                       set fitness abs($maxima_point-2)
133#                       break
134#                        ####Max required at 2 eV, so minimize the difference between the current max and required max
135#               }
136#
137#       }
138#
139#$xmlobj put output.number(f).about.label "Optimization of Absorption Plot for Qdot"
140#$xmlobj put output.number(f).about.description \
141#    "Fitness = abs(difference between first maxima in the current run and required value (Here 2 eV))"
142#$xmlobj put output.number(f).current $fitness
143#
144#}
145
146# ----------------------------------------------------------------------
147#  Create an optimization context and configure the parameters used
148#  for optimization...
149# ----------------------------------------------------------------------
150Rappture::optimizer optim -tool $tool -using pgapack
151
152optim add number input.group(tabs).group(geometry).structure.current.parameters(boxparams).number(xlen) -min 5 -max 40 -randdist uniform -strictmin yes -strictmax yes -units nm
153optim add number input.group(tabs).group(geometry).structure.current.parameters(boxparams).number(ylen)  -min 5 -max 40 -randdist uniform -strictmin yes -strictmax yes -units nm
154optim add number input.group(tabs).group(geometry).structure.current.parameters(boxparams).number(zlen)  -min 5 -max 20 -randdist uniform -strictmin yes -strictmax yes -units nm
155optim add number input.group(tabs).(light).number(Ef)  -min 0 -max 5 -randdist uniform -strictmin yes -strictmax yes -units eV
156optim add number input.group(tabs).group(light).number(temperature)  -min 0 -max 1000 -randdist gaussian -mean 300 -stddev 10 -strictmin yes -strictmax yes -units K
157optim add number input.group(tabs).group(light).number(theta)  -min 0 -max 90 -randdist uniform -stddev 0.5 -strictmin yes -strictmax yes -units deg
158optim add number input.group(tabs).group(light).number(phi)  -min 0 -max 360 -randdist uniform  -strictmin yes -strictmax yes -units deg
159
160optim configure -operation minimize -popsize 50 -maxruns 100 -mutnrate 0.1 -crossovrate 0.9 -randnumseed 9 -stpcriteria toosimilar
161
162optim get configure
163
164set status [optim perform -fitness output.number(f).current -updatecommand display_current_values]
165puts "done: $status"
Note: See TracBrowser for help on using the repository browser.