1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#
# continuation.tk
#
proc continuation(build) name {
global Model Cont continuation
build_Title $name "Equilibrium Continuation"
build_DismissButtonbar $name dbbar "window(dismiss) continuation" \
{"State..." {window(open) contstate} }
# {"Colors..." {window(open) contcolors} }
build_Buttonbar $name bb0 \
[list "Forwards" [list continuation(forwards) $name]] \
[list "Backwards" [list continuation(backwards) $name]] \
[list "Continue" [list continuation(continue) $name]] \
[list "Search" [list continuation(search) $name]]
pack $name.bb0 -side bottom
set cmd [build_CmdFrame $name cmd]
build_LabelEntryColumns $cmd le0 \
{text {} {"Iterations:"}} {ientry {} {Cont(Iters)}}
bind_LabelEntryColumns $cmd.le0 1 <Return> continuation(update)
build_Optionslist $cmd olist \
{ "Monitor switch" Cont(Check_Switch) }
build_PopupMenu $cmd p1 "Mode:" \
Cont(Mode) "continuation(change_mode) $cmd" \
[array_to_listvalues Cont M_Names]
build_StdFrame $cmd plists
build_Listbox $cmd.plists pu1 "Aug params:" \
$Cont(Num_Req_Param,$Cont(Mode)) 4 \
[array_to_listvalues Model Param_Names]
pack $cmd.plists.pu1 -side left
continuation(retrieve_selection) $cmd.plists.pu1.lb
build_StdFrame $cmd.plists cp
pack $cmd.plists.cp -side right
set continuation(pu0_wid) [expr [longest [concat \
[array_to_listvalues Model Varb_Names] \
[array_to_listvalues Model Param_Names] ] ] + 4]
build_PopupMenuFixedWidth $cmd.plists.cp pu0 $continuation(pu0_wid) \
"Cont. param:" Cont(Param) continuation(leave) \
[concat [drop_last_element [array_to_listvalues Model Varb_Names]] \
[continuation(get_listbox_selection) $cmd.plists.pu1.lb] ]
continuation(change_aug_params) $cmd.plists.pu1.lb
# Change bindings to put aug params in postmaster when changed:
bind $cmd.plists.pu1.lb <1> { continuation(change_aug_params) %W }
bind $cmd.plists.pu1.lb <space> { continuation(change_aug_params) %W }
bind $cmd.plists.pu1.lb <Select> { continuation(change_aug_params) %W }
bindtags $cmd.plists.pu1.lb [list Listbox $cmd.plists.pu1.lb $name all]
pack $cmd.plists -side top
build_Choicefield $cmd ch0 "Parameter fix:" Cont(Vary_Switch) \
{"Vary" "Fix"}
build_Choicefield $cmd ch1 "Jacobian update:" Cont(Jac_Update) \
{"Each Step" "Initial Step"}
# build_Optionsrow $cmd opt0 "View Type:" \
# {"0" Cont(Plot_0)} {"1" Cont(Plot_1)} {"2" Cont(Plot_2)}
build_LabelEntryColumns $cmd le1 \
{text {} {"Absolute error:" "Relative error:" "Minimum step:" \
"Maximum step:" "Sugg. stepsize:" "Debug level:"}} \
{dentry {} {Cont(Abserr) Cont(Relerr) Cont(Minstp) \
Cont(Maxstp) Cont(Stpsize) Cont(Debug_Level)}}
bind_LabelEntryColumns $cmd.le1 1 <Return> continuation(update)
pack $cmd -fill both -expand 1
}
proc continuation(enter) {} {
pm_to_tcl Cont
if {[winfo exists .contstate]} {
contstate(enter)
}
}
proc continuation(leave) {} {
tcl_to_pm Cont
pm_to_tcl Cont
if {[winfo exists .contstate]} {
contstate(enter)
}
}
proc continuation(update) {} {
tcl_to_pm Cont
pm_to_tcl Cont
}
proc continuation(search) name {
tcl_to_pm Cont
pm_to_tcl Cont
pm PUT "Cont.Search" 1
continuation(go) Forwards $name
# Note: the choice of Forwards is arbitrary... cont_proc will disregard
# its value, since the search flag is set to TRUE
pm PUT "Cont.Search" 0
pm_to_tcl Memory Selected
}
proc continuation(forwards) name {
begin_wait "Continuing equilibria forwards..."
tcl_to_pm Cont
pm_to_tcl Cont
continuation(go) Forwards $name
pm_to_tcl Memory Selected
end_wait
}
proc continuation(continue) name {
begin_wait "Continuing equilibria..."
tcl_to_pm Cont
pm_to_tcl Cont
continuation(go) Continue $name
pm_to_tcl Memory Selected
end_wait
}
proc continuation(backwards) name {
begin_wait "Continuing equilibria backwards..."
tcl_to_pm Cont
pm_to_tcl Cont
continuation(go) Backwards $name
pm_to_tcl Memory Selected
end_wait
}
proc continuation(go) {dir name} {
global Cont Model Defaults
set w $name.cmd.plists.pu1.lb
continuation(change_aug_params) $w
set num_still_req [expr $Cont(Num_Req_Param,$Cont(Mode)) - [llength [$w curselection]]]
if {$num_still_req == 0} {
Cont($dir)
} else {
build_Dialog dialog "Aug Param Alert" "Too few parameters selected. \
Please select $num_still_req more before proceeding." 0 Ok
}
if {$Defaults(Auto_Refresh) == 1} {
twoD(refresh_all)
}
}
#
# proc continuation(change_aug_params)
#
# Saves the list of aug parameters to the postmaster, then calls for the
# continuation parameter menubutton to be modified to account for the
# new values of the listbox selection.
# Will be called whenever the 1 button is pressed in the aug parameter listbox
#
# Arguments:
# w - name of the listbox
#
proc continuation(change_aug_params) {w} {
global Model Cont continuation
# Save the list of aug. params to the postmaster
for {set i 0} {$i<$Model(Param_Dim)} {incr i} {
if [$w selection includes $i] {
pm PUT Cont.Active_Params $i 1
} else {
pm PUT Cont.Active_Params $i 0
}
}
pm_to_tcl Cont
# Rebuild the continuation parameter menu button
set wname [string trimright $w pu1lb.]
set selectionlength [llength [$w curselection]]
# Reduce the continuation parameter if it's beyond the scope of the list
if {$Cont(Param) >= [expr $Model(Varb_Dim) - 1 + $selectionlength]} {
set Cont(Param) [expr $Cont(Param) - 1]
tcl_to_pm Cont
}
# Now, change the label of the menubutton to reflect the current selection
# We'll invoke this selection below, once we've fixed the command values
set items [drop_last_element [array_to_listvalues Model Varb_Names]]
if {$selectionlength > 0} {
foreach thing [$w curselection] {
lappend items [lindex [array_to_listvalues Model Param_Names] $thing]
}
}
$wname.cp.pu0.mb configure -text "[lindex $items $Cont(Param)]"
# Rebuild the list of continuation parameter options
# Delete any parameters
while {[$wname.cp.pu0.mb.m index end] >= $Model(Varb_Dim)} {
$wname.cp.pu0.mb.m delete end
}
# Add the proper selected parameters with the appropriate command numbers
set i [expr $Model(Varb_Dim) - 1]
foreach item [continuation(get_listbox_selection) $w] {
$wname.cp.pu0.mb.m add command -label $item -command \
[list update_PopupMenu $wname.cp.pu0.mb $item \
continuation(leave) [list set Cont(Param) $i]]
incr i
}
# Now, save the new value of Cont(Param) in the postmaster
set curentry [lindex [$wname.cp.pu0.mb configure -text] 4]
$wname.cp.pu0.mb.m invoke $curentry
tcl_to_pm Cont
}
#
# proc continuation(change_mode)
#
# Called whenever the continuation mode is changed, so that we can update
# the number of requested parameters, reconfigure the aug parameter listbox,
# and (if necessary) change the continuation parameter list
#
# Arguments:
# cmd - the name of the command window
#
proc continuation(change_mode) cmd {
global Cont Model
tcl_to_pm Cont
set w $cmd.plists.pu1.lb
# Check that the number of parameters selected isn't too many
# If so, change the selection for the aug params
set new_num_params $Cont(Num_Req_Param,$Cont(Mode))
set cur_num_params [llength [$w curselection]]
if {$cur_num_params > $new_num_params} {
set new_params [$w curselection]
for {set i 0} {$i<[expr $cur_num_params - $new_num_params]} {incr i} {
set new_params [drop_last_element $new_params]
}
$w selection clear 0 end
foreach i $new_params {
$w selection set $i
}
}
$w configure \
-selectmode $Cont(Num_Req_Param,$Cont(Mode))
continuation(change_aug_params) $w
}
#
# continuation(retrieve_selection)
#
# Retrieves the active_params list from the postmaster and selects the
# values of the listbox which correspond to 1's in Cont(Active_Params)
#
proc continuation(retrieve_selection) {w} {
global Model
# pm_to_tcl Cont
# puts "retrieving selection"
for {set i 0} {$i<$Model(Param_Dim)} {incr i} {
if {[pm GET Cont.Active_Params $i] == 1} {
$w selection set $i
}
}
}
#
# continuation(get_listbox_selection)
#
# Gets the selection from the listbox on the continuation panel. Returns
# it as a text list of the entries
#
# Arguments:
# w - name of the listbox
#
proc continuation(get_listbox_selection) {w} {
global Model
set nums [$w curselection]
set vals ""
for {set i 0} {$i<$Model(Param_Dim)} {incr i} {
if {[lsearch $nums $i] != -1} {
lappend vals $Model(Param_Names,$i)
}
}
return $vals
}
|