/[ascend]/trunk/tcltk98/TK/mps.tcl
ViewVC logotype

Contents of /trunk/tcltk98/TK/mps.tcl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download) (as text)
Sat Nov 13 16:40:11 2004 UTC (17 years ago) by aw0a
File MIME type: text/x-tcl
File size: 35210 byte(s)
try again to commit moving tcl stuff
1 # mps.tcl: contains all the Tcl code connected with makeMPS
2 # by Benjamin A. Allan and Kirk A. Abbott
3 # Created: January 1994
4 # Part of ASCEND
5 # Revision: $Revision: 1.7 $
6 # Last modified on: $Date: 1998/06/18 15:55:32 $
7 # Last modified by: $Author: mthomas $
8 # Revision control file: $RCSfile: mps.tcl,v $
9 #
10 # This file is part of the ASCEND Tcl/Tk Interface.
11 #
12 # Copyright (C) 1994-1998 Carnegie Mellon University
13 #
14 # The ASCEND Tcl/Tk Interface is free software; you can redistribute
15 # it and/or modify it under the terms of the GNU General Public
16 # License as published by the Free Software Foundation; either
17 # version 2 of the License, or (at your option) any later version.
18 #
19 # The ASCEND Tcl/Tk Interface is distributed in hope that it will be
20 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with the program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the
27 # file named COPYING. COPYING is found in ../compiler.
28
29 # This file contains all the Tcl code connected with makeMPS
30 #
31 # As a user, you may need to modify the Solv6_RunSolver and
32 # Solv6_LoadSolution files, depending on how the solvers
33 # are installed at your site.
34 #
35
36 # Module: mps.tcl
37 # Tcl version: 7.3 (Tcl/Tk/XF)
38 # Tk version: 3.6
39 # XF version: 2.3
40 #
41
42 # module contents
43 global moduleList
44 global autoLoadList
45 global ascGlobalVect
46 set moduleList(mps.tcl) {.mps}
47 set autoLoadList(mps.tcl) {1}
48
49 # ____________________________________________________________________________#
50 # Set up ShowWindow.mps #
51 # ____________________________________________________________________________#
52
53 # procedure to show window .mps
54 proc ShowWindow.mps {args} {
55 # xf ignore me 7
56
57 global ascGlobalVect
58
59 # build widget .mps
60 if {"[info procs XFEdit]" != ""} {
61 catch "XFDestroy .mps"
62 } {
63 catch "destroy .mps"
64 }
65 toplevel .mps
66
67 # Window manager configurations
68 wm positionfrom .mps user
69 wm sizefrom .mps user
70 wm maxsize .mps 1024 768
71 wm minsize .mps 0 0
72 wm title .mps {makeMPS Parameters}
73 wm geometry .mps [osgpos 381x216[setpos .solver 1 30]]
74 wm protocol .mps WM_DELETE_WINDOW {Solv6_Ok}
75
76
77 # build widget .mps.frame0
78 frame .mps.frame0 \
79 -borderwidth {3} \
80 -width {231} \
81 -height {194} \
82 -relief {ridge}
83
84 # build widget .mps.frame0.frame1
85 frame .mps.frame0.frame1 \
86 -borderwidth {1} \
87 -background $ascGlobalVect(tbg)
88
89
90 # build widget .mps.frame0.frame1.label4
91 label .mps.frame0.frame1.label4 \
92 -borderwidth {0} \
93 -text {MILP Solver:} \
94 -background $ascGlobalVect(tbg)
95
96 # build widget .mps.frame0.frame1.radiobutton5
97 radiobutton .mps.frame0.frame1.radiobutton5 \
98 -anchor {w} \
99 -borderwidth {1} \
100 -command { Solv6_QOMILP_actions } \
101 -padx {0} \
102 -pady {0} \
103 -text {QOMILP} \
104 -value {QOMILP} \
105 -variable {ascSolv6Vect(solver)} \
106 -background $ascGlobalVect(tbg)
107
108 # build widget .mps.frame0.frame1.radiobutton6
109 radiobutton .mps.frame0.frame1.radiobutton6 \
110 -anchor {w} \
111 -borderwidth {1} \
112 -command {Solv6_lpsolve_actions } \
113 -padx {0} \
114 -pady {0} \
115 -text {lpsolve} \
116 -value {lpsolve} \
117 -variable {ascSolv6Vect(solver)} \
118 -background $ascGlobalVect(tbg)
119
120
121 # pack widget .mps.frame0.frame1
122 pack append .mps.frame0.frame1 \
123 .mps.frame0.frame1.label4 {top frame center expand fill} \
124 .mps.frame0.frame1.radiobutton5 {top frame w expand fill} \
125 .mps.frame0.frame1.radiobutton6 {top frame center expand fill}
126
127 # build widget .mps.frame0.frame2
128 frame .mps.frame0.frame2 \
129 -borderwidth {1} \
130 -background $ascGlobalVect(tbg)
131
132
133 # build widget .mps.frame0.frame2.radiobutton9
134 radiobutton .mps.frame0.frame2.radiobutton9 \
135 -anchor {w} \
136 -borderwidth {1} \
137 -command {Solv6_OSL_actions} \
138 -text {OSL} \
139 -value {OSL} \
140 -variable {ascSolv6Vect(solver)} \
141 -background $ascGlobalVect(tbg)
142
143 # build widget .mps.frame0.frame2.radiobutton10
144 radiobutton .mps.frame0.frame2.radiobutton10 \
145 -anchor {w} \
146 -borderwidth {1} \
147 -command {Solv6_SCICONIC_actions} \
148 -text {SCICONIC} \
149 -value {SCICONIC} \
150 -variable {ascSolv6Vect(solver)} \
151 -background $ascGlobalVect(tbg)
152
153
154 # build widget .mps.frame0.frame2.radiobutton11
155 radiobutton .mps.frame0.frame2.radiobutton11 \
156 -anchor {w} \
157 -borderwidth {1} \
158 -command {# use OSL actions for generic here
159 Solv6_OSL_actions} \
160 -padx {0} \
161 -pady {0} \
162 -text {Generic} \
163 -value {Generic} \
164 -variable {ascSolv6Vect(solver)} \
165 -background $ascGlobalVect(tbg)
166
167 # pack widget .mps.frame0.frame2
168 pack append .mps.frame0.frame2 \
169 .mps.frame0.frame2.radiobutton9 {top frame w expand fill} \
170 .mps.frame0.frame2.radiobutton10 {top frame w expand fill} \
171 .mps.frame0.frame2.radiobutton11 {top frame w expand fill}
172
173 # pack widget .mps.frame0
174 pack append .mps.frame0 \
175 .mps.frame0.frame1 {left frame w expand fill} \
176 .mps.frame0.frame2 {left frame center expand fill}
177
178 # build widget .mps.frame12
179 frame .mps.frame12 \
180 -borderwidth {3} \
181 -relief {ridge} \
182 -background $ascGlobalVect(tbg)
183
184 # build widget .mps.frame12.frame
185 frame .mps.frame12.frame \
186 -borderwidth {1} \
187 -relief {raised} \
188 -background $ascGlobalVect(tbg)
189
190 # build widget .mps.frame12.frame.label4
191 label .mps.frame12.frame.label4 \
192 -borderwidth {0} \
193 -padx {2} \
194 -text {MPS Filename:} \
195 -background $ascGlobalVect(tbg)
196
197 # build widget .mps.frame12.frame.entry5
198 entry .mps.frame12.frame.entry5 \
199 -borderwidth {1} \
200 -relief {raised} \
201 -textvariable {ascSolv6Vect(filename)} \
202 -width {0} \
203 -background $ascGlobalVect(bg)
204
205 # pack widget .mps.frame12.frame
206 pack append .mps.frame12.frame \
207 .mps.frame12.frame.label4 {left frame center} \
208 .mps.frame12.frame.entry5 {top frame center expand fill}
209
210 # pack widget .mps.frame12
211 pack append .mps.frame12 \
212 .mps.frame12.frame {top frame center expand fill}
213
214 # build widget .mps.frame13
215 frame .mps.frame13 \
216 -borderwidth {3} \
217 -relief {ridge} \
218 -background $ascGlobalVect(tbg)
219
220 # build widget .mps.frame13.checkbutton15
221 checkbutton .mps.frame13.checkbutton15 \
222 -anchor {w} \
223 -borderwidth {1} \
224 -padx {0} \
225 -pady {0} \
226 -state {disabled} \
227 -text {Use special ordered sets} \
228 -variable {ascSolv6Vect(SOS)} \
229 -background $ascGlobalVect(tbg)
230
231 # build widget .mps.frame13.checkbutton16
232 checkbutton .mps.frame13.checkbutton16 \
233 -anchor {w} \
234 -borderwidth {1} \
235 -state {disabled} \
236 -text {Use semicontinuous variables} \
237 -variable {ascSolv6Vect(semi)} \
238 -background $ascGlobalVect(tbg)
239
240 # build widget .mps.frame13.frame
241 frame .mps.frame13.frame \
242 -relief {raised} \
243 -background $ascGlobalVect(tbg)
244
245 # build widget .mps.frame13.frame.label4
246 label .mps.frame13.frame.label4 \
247 -borderwidth {1} \
248 -padx {2} \
249 -relief {raised} \
250 -text {Valid Bound:} \
251 -background $ascGlobalVect(tbg)
252
253 # build widget .mps.frame13.frame.entry5
254 entry .mps.frame13.frame.entry5 \
255 -relief {raised} \
256 -textvariable {ascSolv6Vect(boval)} \
257 -background $ascGlobalVect(bg)
258
259 # pack widget .mps.frame13.frame
260 pack append .mps.frame13.frame \
261 .mps.frame13.frame.label4 {left frame center} \
262 .mps.frame13.frame.entry5 {top frame center expand fill}
263
264 # build widget .mps.frame13.frame4
265 frame .mps.frame13.frame4 \
266 -relief {raised} \
267 -background $ascGlobalVect(tbg)
268
269 # build widget .mps.frame13.frame4.label4
270 label .mps.frame13.frame4.label4 \
271 -borderwidth {1} \
272 -padx {2} \
273 -relief {raised} \
274 -text {Termination Tolerance:} \
275 -background $ascGlobalVect(tbg)
276
277 # build widget .mps.frame13.frame4.entry5
278 entry .mps.frame13.frame4.entry5 \
279 -relief {raised} \
280 -textvariable {ascSolv6Vect(epsval)} \
281 -background $ascGlobalVect(bg)
282
283 # pack widget .mps.frame13.frame4
284 pack append .mps.frame13.frame4 \
285 .mps.frame13.frame4.label4 {left frame center} \
286 .mps.frame13.frame4.entry5 {top frame center expand fill}
287
288 # build widget .mps.frame13.checkbutton0
289 checkbutton .mps.frame13.checkbutton0 \
290 -anchor {w} \
291 -text {Solve relaxed problem} \
292 -variable {ascSolv6Vect(relaxed)} \
293 -background $ascGlobalVect(tbg)
294
295 # pack widget .mps.frame13
296 pack append .mps.frame13 \
297 .mps.frame13.checkbutton15 {top frame center expand fill} \
298 .mps.frame13.checkbutton16 {top frame center expand fill} \
299 .mps.frame13.frame {top frame center fill} \
300 .mps.frame13.frame4 {top frame center fill} \
301 .mps.frame13.checkbutton0 {top frame center expand fill}
302
303 # build widget .mps.frame14
304 frame .mps.frame14 \
305 -borderwidth {3} \
306 -relief {ridge} \
307 -background $ascGlobalVect(tbg)
308
309 # build widget .mps.frame14.button0
310 button .mps.frame14.button0 \
311 -command { Solv6_Ok } \
312 -text {OK} \
313 -background $ascGlobalVect(bg)
314
315 # build widget .mps.frame14.button1
316 button .mps.frame14.button1 \
317 -command {#script for Make MPS file button here
318 Solv6_MakeMPS} \
319 -text {Make MPS file} \
320 -background $ascGlobalVect(bg)
321
322 # build widget .mps.frame14.button2
323 button .mps.frame14.button2 \
324 -command {#script for Run solver button here
325 Solv6_RunSolver} \
326 -state {normal} \
327 -text {Run solver} \
328 -background $ascGlobalVect(bg)
329
330 # build widget .mps.frame14.button3
331 button .mps.frame14.button3 \
332 -command {#script for Load Solution button here
333 Solv6_LoadSolution} \
334 -text {Load solution} \
335 -background $ascGlobalVect(bg)
336
337 # build widget .mps.frame14.button4
338 button .mps.frame14.button4 \
339 -command {#script for Help button here
340 Help_button solver.makemps.parameters} \
341 -text {Help} \
342 -background $ascGlobalVect(bg)
343
344 # pack widget .mps.frame14
345 pack append .mps.frame14 \
346 .mps.frame14.button0 {left frame center expand fill} \
347 .mps.frame14.button1 {left frame center expand fill} \
348 .mps.frame14.button2 {left frame center expand fill} \
349 .mps.frame14.button3 {left frame center expand fill} \
350 .mps.frame14.button4 {left frame center expand fill}
351
352 # pack widget .mps
353 pack append .mps \
354 .mps.frame0 {top frame n expand fill} \
355 .mps.frame12 {top frame center expand fill} \
356 .mps.frame13 {top frame center expand fill} \
357 .mps.frame14 {top frame center expand fill}
358
359 if {"[info procs XFEdit]" != ""} {
360 catch "XFMiscBindWidgetTree .mps"
361 after 2 "catch {XFEditSetShowWindows}"
362 }
363 }
364
365 proc DestroyWindow.mps {} {# xf ignore me 7
366 if {"[info procs XFEdit]" != ""} {
367 if {"[info commands .mps]" != ""} {
368 global xfShowWindow.mps
369 set xfShowWindow.mps 0
370 XFEditSetPath .
371 after 2 "XFSaveAsProc .mps; XFEditSetShowWindows"
372 }
373 } {
374 catch "destroy .mps"
375 update
376 }
377 }
378
379 # ____________________________________________________________________________#
380 # Button handling procedures, that dim things as necessary #
381 # ____________________________________________________________________________#
382
383 #
384 # proc Solv6_QOMILP_actions {}
385 #----------------------------------------------------------------------
386 # activate dialog items as appropriate for QOMILP solver #
387 # modified by CWS, 5/95 #
388 #----------------------------------------------------------------------
389
390 proc Solv6_QOMILP_actions {} {
391
392 global ascSolv6Vect
393
394 # disable SOS
395 .mps.frame13.checkbutton15 configure -state disabled
396 # disable semicontinuous
397 .mps.frame13.checkbutton16 configure -state disabled
398 #turn off SOS and semi
399 set ascSolv6Vect(SOS) 0
400 set ascSolv6Vect(semi) 0
401 # enable valid bounds
402 .mps.frame13.frame.label4 configure -foreground Black
403 .mps.frame13.frame.entry5 configure -state normal
404 .mps.frame13.frame.entry5 configure -foreground Black
405 # enable termination tolerance
406 .mps.frame13.frame4.label4 configure -foreground Black
407 .mps.frame13.frame4.entry5 configure -state normal
408 .mps.frame13.frame4.entry5 configure -foreground Black
409
410 }
411
412
413 #
414 # proc Solv6_lpsolve_actions {}
415 #----------------------------------------------------------------------
416 # activate dialog items as appropriate for lpsolve solver #
417 # modified by CWS, 5/95 #
418 #----------------------------------------------------------------------
419
420 proc Solv6_lpsolve_actions {} {
421
422 global ascSolv6Vect
423
424 # disable SOS
425 .mps.frame13.checkbutton15 configure -state disabled
426 # disable semicontinuous
427 .mps.frame13.checkbutton16 configure -state disabled
428 #turn off buttons
429 set ascSolv6Vect(SOS) 0
430 set ascSolv6Vect(semi) 0
431 # disable valid bounds
432 .mps.frame13.frame.label4 configure -foreground Gray70
433 .mps.frame13.frame.entry5 configure -state disabled
434 .mps.frame13.frame.entry5 configure -foreground Gray70
435 # diable termination tolerance
436 .mps.frame13.frame4.label4 configure -foreground Gray70
437 .mps.frame13.frame4.entry5 configure -state disabled
438 .mps.frame13.frame4.entry5 configure -foreground Gray70
439
440 }
441
442 #
443 # proc Solv6_OSL_actions {}
444 #----------------------------------------------------------------------
445 # activate dialog items as appropriate for OSL solver #
446 # note: this is also used for the Generic solver #
447 # modified by CWS, 5/95 #
448 #----------------------------------------------------------------------
449
450 proc Solv6_OSL_actions {} {
451
452 global ascSolv6Vect
453
454 # enable SOS
455 .mps.frame13.checkbutton15 configure -state normal
456 # disable semicontinuous
457 .mps.frame13.checkbutton16 configure -state disabled
458 #turn off semi button
459 set ascSolv6Vect(semi) 0
460 # disable valid bounds
461 .mps.frame13.frame.label4 configure -foreground Gray70
462 .mps.frame13.frame.entry5 configure -state disabled
463 .mps.frame13.frame.entry5 configure -foreground Gray70
464 # disable termination tolerance
465 .mps.frame13.frame4.label4 configure -foreground Gray70
466 .mps.frame13.frame4.entry5 configure -state disabled
467 .mps.frame13.frame4.entry5 configure -foreground Gray70
468
469 }
470
471
472 #
473 # proc Solv6_SCICONIC_actions {}
474 #----------------------------------------------------------------------
475 # activate dialog items as appropriate for SICONIC solver #
476 # modified by CWS, 5/95 #
477 #----------------------------------------------------------------------
478
479 proc Solv6_SCICONIC_actions {} {
480
481 global ascSolv6Vect
482
483 # enable SOS
484 .mps.frame13.checkbutton15 configure -state normal
485 # enable semicontinuous
486 .mps.frame13.checkbutton16 configure -state normal
487 # disable valid bounds
488 .mps.frame13.frame.label4 configure -foreground Gray70
489 .mps.frame13.frame.entry5 configure -state disabled
490 .mps.frame13.frame.entry5 configure -foreground Gray70
491 # disable termination tolerance
492 .mps.frame13.frame4.label4 configure -foreground Gray70
493 .mps.frame13.frame4.entry5 configure -state disabled
494 .mps.frame13.frame4.entry5 configure -foreground Gray70
495
496 }
497
498 # ____________________________________________________________________________#
499 # Main level control, for the five buttons #
500 # ____________________________________________________________________________#
501
502 # What to do when the user clicks on the "Ok" button
503 #
504 # proc Solv6_Ok {}
505 #-----------------------------------------------------------------------
506 # Toplevel procedure for the "Make MPS file" button #
507 # modified by CWS, 5/95 #
508 #-----------------------------------------------------------------------
509 proc Solv6_Ok {} {
510
511 # just return if input is bad
512 if {[Solv6_ErrorCheck 0 ]} {return}
513
514 #Close up everything, as normally in SolverProc.tcl
515 Solve_do_Parms close 6
516
517
518 }
519
520 # What to do when the user clicks on the "Make MPS file dialog"
521 #
522 # proc Solv6_MakeMPS {}
523 #-----------------------------------------------------------------------
524 # Toplevel procedure for the "Make MPS file" button #
525 # modified by CWS, 5/95 #
526 #-----------------------------------------------------------------------
527 proc Solv6_MakeMPS {} {
528
529 global ascSolvVect
530
531 # if the current solver isn't makeMPS, switch to it
532 if {6> [expr $ascSolvVect(numberofsolvers) -1]} {
533 puts "Error: makeMPS is not available.\n"
534 return
535 }
536 if {$ascSolvVect(available.6)} {
537 Solve_do_Select 6
538 } else {
539 puts "Error: makeMPS is not available.\n"
540 return
541 }
542
543 # just return if input is bad
544 if {[Solv6_ErrorCheck 1 ]} {return}
545
546 # Close up everything, as normally in SolverProc.tcl
547 Solve_do_Parms close 6
548
549 # call optimize function, as from menu (w/o annoying dialog)
550 Solve_Optimize
551
552 }
553
554
555 #
556 # proc Solv6_RunSolver {}
557 #-----------------------------------------------------------------------
558 # Toplevel procedure for the "Run Solver" button #
559 # modified by CWS, 5/95 #
560 #-----------------------------------------------------------------------
561 proc Solv6_RunSolver {} {
562
563 global ascSolvVect ascSolv6Vect env ascSolvStatVect
564
565 # make the MPS file
566 Solv6_MakeMPS
567
568 # run the appropriate script, depending on the solver
569 switch $ascSolv6Vect(solver) {
570 QOMILP {
571 # note: qomilp returns 1 so, can't error check
572 catch {[exec qomilp $ascSolv6Vect(mpsname) 1 10000 > \
573 $ascSolv6Vect(outname) 2> $ascSolv6Vect(errname) & ]}
574 }
575 lpsolve {
576 catch {[exec lp_solve -s -mps < $ascSolv6Vect(mpsname) > \
577 $ascSolv6Vect(outname) 2> $ascSolv6Vect(errname) & ]}
578 }
579 OSL {
580 Solve_Alert "Sorry" \
581 "OSL isn't hooked up to ASCEND yet.\n(The MPS file was created.)"
582 }
583 SCICONIC {
584 # create the sciconic.add file here
585 set f [open sciconic.add w]
586 puts $f "INFILE = '$ascSolv6Vect(mpsname)' @ Specify the input file"
587 puts $f "OUTFILE = '$ascSolv6Vect(outname)' @ Specify the output file"
588 puts $f "LINES = 100000 @ Print all one big page"
589 puts $f "CONVERT @ Read and convert the MPS file"
590
591 if { $ascSolv6Vect(SOS) == 1 } {
592 puts $f "SETUP ( MARKER ) @ Create problem internally, with SOS"
593 } else {
594 puts $f "SETUP @ Create problem internally, no SOS"
595 }
596 puts $f "CRASH @ Presolve and find initial point"
597 puts $f "PRIMAL @ Use crased soln to find an initial basis"
598 puts $f "GLOBAL @ Do Branch and Bound"
599 puts $f "@ Limit info printed in soln"
600 puts $f "SELECT"
601 puts $f "ROWS"
602 puts $f " XXXXXXXX"
603 puts $f "COLUMNS"
604 puts $f " NZ;@@@@@@@@"
605 puts $f "ENDATA"
606 puts $f "PUNCHSOLUTION @ Write solution to OUTFILE"
607 puts $f "STOP @ All done!"
608
609 close $f
610 # sciconic is really noisy, so send stdout to /dev/null
611 catch {[exec sciconic < sciconic.add > /dev/null & ]}
612 }
613 Generic {
614 Solve_Alert "Sorry" \
615 "A Generic solver isn't hooked up to ASCEND yet.\n(The MPS file was created.)"
616 }
617 }
618
619 #remove output.err if it exists and is empty
620 if { [file exists $ascSolv6Vect(errname)] &&
621 ![file size $ascSolv6Vect(errname)] } {
622 catch {[file delete $ascSolv6Vect(errname)]} }
623
624
625 }
626
627
628 # This routine takes the output from lp_solve (*.out),
629 # and a name map file from ASCEND (*.map), and uses
630 # it to set the variable values in ASCEND
631 #
632 # Variables which are no longer defined generate errors
633 #
634 # by Craig Schmidt 6/21/95
635
636 proc Solv6_LoadSolution {} {
637
638 global ascSolv6Vect
639
640 # just return if input is bad (don't confirm overwrite, since read only use)
641 if {[Solv6_ErrorCheck 0 ]} {return}
642
643 if {![file exists $ascSolv6Vect(outname)]} {
644 Solve_Alert "Error" \
645 "The file $ascSolv6Vect(outname) does not exist."
646 return
647 }
648
649 if {![file exists $ascSolv6Vect(mapname)]} {
650 Solve_Alert "Error" \
651 "The file $ascSolv6Vect(mapname) does not exist."
652 return
653 }
654
655 set outf [open $ascSolv6Vect(outname) r]
656 set mapf [open $ascSolv6Vect(mapname) r]
657
658 # Process the *.out file, creating array of non-zero values
659 switch $ascSolv6Vect(solver) {
660 QOMILP
661 {
662 # search thru file until done w/ header
663 while {[gets $outf line] >= 0} {
664 if {[regexp {^Nonzero elements:} $line]} {break}
665 }
666 if {![regexp {^Nonzero elements:} $line]} {
667 Solve_Alert "Error" \
668 "Couldn't find 'Nonzero elements:' in the \nheader of the QOMILP output file."
669 close $outf
670 close $mapf
671 return
672 }
673 while {[gets $outf line] >= 0} {
674 if {[regexp { +[0-9]+ (C[0-9]+) +([0-9eE+.-]+)} $line all save1 save2] } {
675 set nonzeros($save1) $save2
676 } else { break }
677 }
678 }
679 lpsolve
680 {
681 gets $outf line
682 if {![regexp {^Value of objective function:} $line]} {
683 Solve_Alert "Error" \
684 "Couldn't find 'Value of objective function:'\n in the header of the lp_solve output file."
685 close $outf
686 close $mapf
687 return
688 }
689 while {[gets $outf line] >= 0} {
690 regexp {(^C[0-9]+)\ +([0-9eE+.-]+)} $line all save1 save2
691 set nonzeros($save1) $save2
692 }
693 }
694 OSL
695 {
696 Solve_Alert "Sorry" \
697 "OSL isn't hooked up to ASCEND yet.\n(Nothing was changed.)"
698 close $outf
699 close $mapf
700 return
701 }
702 SCICONIC
703 {
704 # search thru file until done w/ header
705 while {[gets $outf line] >= 0} {
706 if {[regexp {^ \.NUMBER\. \.COLUMN\.} $line]} {break}
707 }
708 if {![regexp {^ \.NUMBER\. \.COLUMN\.} $line]} {
709 Solve_Alert "Error" \
710 "Couldn't find '.NUMBER. .COLUMN.' in the \nheader of the SCICONIC output file."
711 close $outf
712 close $mapf
713 return
714 }
715 while {[gets $outf line] >= 0} {
716 if {[regexp {.... +[0-9]+ (C[0-9]+) .. +([0-9eE+.-]+)} $line all save1 save2] } {
717 set nonzeros($save1) $save2
718 } else { break }
719 }
720
721 }
722 Generic
723 {
724 Solve_Alert "Sorry" \
725 "A Generic solver isn't hooked up to ASCEND yet.\n(Nothing was changed.)"
726 close $outf
727 close $mapf
728 return
729 }
730 }
731
732 #eat the first 6 lines of the name map file
733 gets $mapf line
734 gets $mapf line
735 gets $mapf line
736 gets $mapf line
737 gets $mapf line
738 gets $mapf line
739
740 # Read in the name map file, setting variable values
741 while {[gets $mapf line] >= 0} {
742 regexp {(C[0-9]+) +(.+)} $line all save1 save2
743 if {[info exists nonzeros($save1)]} {
744 if {[catch "ASSIGN $save2 $nonzeros($save1)" ]} {
745 puts "Couldn't set value for undefined variable: $save2"
746 }
747 } else { #assoc element not defined, so value 0
748 if {[catch "ASSIGN $save2 0" ]} {
749 puts "Couldn't set value for undefined variable: $save2"
750 }
751 }
752 }
753
754 close $outf
755 close $mapf
756
757 #Close up everything, as normally in SolverProc.tcl
758 Solve_do_Parms close 6
759
760 }
761 # end of Solv6_LoadSolution
762
763
764
765 # ____________________________________________________________________________#
766 # Procedures to open and close the dialog
767 # ____________________________________________________________________________#
768
769
770 #
771 # proc Solv6_ErrorCheck { confirm }
772 #-----------------------------------------------------------------------
773 # This routine verifies the user's input for correctness #
774 # It returns a 0 if everything is Ok, else a 1 #
775 # Will warn about overwriting files if confirm == 1 #
776 # modified by CWS, 5/95 #
777 #-----------------------------------------------------------------------
778 proc Solv6_ErrorCheck { confirm } {
779
780 global ascSolv6Vect
781
782 if { $ascSolv6Vect(dialogup) == 1 } {
783
784 # if solver isn't QOMILP, set epsval and boval to nothing
785 if {$ascSolv6Vect(solver) != "QOMILP"} {
786 set ascSolv6Vect(epsval) ""
787 set ascSolv6Vect(boval) ""
788 }
789
790 # first make sure that the fill in numbers are empty or vaild numbers
791 if {[string length $ascSolv6Vect(epsval)] != 0} {
792 if {[catch {expr $ascSolv6Vect(epsval)}]} {
793 # need to release the grab
794 #grab release .mps
795 Solve_Alert "Input Error" "Termination Tolerance is not a number (or empty)."
796 # turn it back on
797 #grab set .mps
798 return 1
799 }
800 }
801 if {[string length $ascSolv6Vect(boval)] != 0} {
802 if {[catch {expr $ascSolv6Vect(boval)}]} {
803 # need to release the grab
804 #grab release .mps
805 Solve_Alert "Input Error" "Valid Bound is not a number (or empty)."
806 # turn it back on
807 #grab set .mps
808 return 1
809 }
810 }
811 }
812
813 # error check the file name
814 if {![Solv6_CleanName $ascSolv6Vect(filename) $confirm ]} {return 1}
815
816 return 0
817
818 }
819
820 #
821 # proc Solve_OpenMakeMPS {}
822 #-----------------------------------------------------------------------
823 # popup the makeMPS window. #
824 # modified by CWS, 5/95 #
825 #-----------------------------------------------------------------------
826 proc Solve_OpenMakeMPS {} {
827 global ascSolvVect ascSolv6Vect
828
829 # dialogup is true when makeMPS dialog is visible
830 set ascSolv6Vect(dialogup) 1
831
832 # position dialog box on the screen over the solver window
833 set ascSolv6Vect(geometry) [osgpos 156x482[setpos .solver 229 42]]
834
835 # show the window
836 ShowWindow.mps
837
838 # now that .mps.* widgets exist, we can set stuff about them
839 switch $ascSolv6Vect(solver) {
840 QOMILP {Solv6_QOMILP_actions}
841 lpsolve {Solv6_lpsolve_actions}
842 OSL {Solv6_OSL_actions}
843 SCICONIC {Solv6_SCICONIC_actions}
844 Generic {Solv6_OSL_actions}
845 }
846
847 # reset dialog elements to blank if 0
848 if {$ascSolv6Vect(bo) == 0 } { set ascSolv6Vect(boval) {} }
849 if {$ascSolv6Vect(eps) == 0 } { set ascSolv6Vect(epsval) {} }
850
851 # note: the error alerts mess up the grab stuff
852 # don't let the user get away
853 # grab set .mps
854
855 # hang out until the window goes away
856 tkwait window .mps
857
858 }
859
860 #
861 # proc Solve_CloseMakeMPS {}
862 #----------------------------------------------------------------------------
863 # pop down the makeMPS window. #
864 #----------------------------------------------------------------------------
865 proc Solve_CloseMakeMPS {} {
866 global ascSolv6Vect
867
868 # DEBUG:
869 # puts "Starting Solve_CloseMakeMPS"
870
871 # the makeMPS dialog box fills out the values of :
872 # ascSolv6Vect(SOS)
873 # ascSolv6Vect(boval)
874 # ascSolv6Vect(epsval)
875 # ascSolv6Vect(filename)
876 # ascSolv6Vect(semi)
877 # ascSolv6Vect(solver)
878 # ascSolv6Vect(relaxed)
879 #
880 # now, depending on the solver, you need to transform that into
881 # the correct set of subparameters
882
883 switch $ascSolv6Vect(solver) {
884 QOMILP {
885 set ascSolv6Vect(nonneg) 0
886 set ascSolv6Vect(obj) 3
887 set ascSolv6Vect(binary) 0
888 set ascSolv6Vect(integer) 0
889 set ascSolv6Vect(semi) 0
890 set ascSolv6Vect(sos1) 0
891 set ascSolv6Vect(sos2) 0
892 set ascSolv6Vect(sos3) 0
893 set ascSolv6Vect(bo) 1
894 set ascSolv6Vect(eps) 1
895
896 # replace empty values with 0.0, and turn off bo or eps
897 if {([string length $ascSolv6Vect(epsval)] == 0) && \
898 ($ascSolv6Vect(solver) == "QOMILP")} {
899 set ascSolv6Vect(eps) 0
900 set ascSolv6Vect(epsval) 0.0
901 }
902 if {([string length $ascSolv6Vect(boval)] == 0) && \
903 ($ascSolv6Vect(solver) == "QOMILP")} {
904 set ascSolv6Vect(bo) 0
905 set ascSolv6Vect(boval) 0.0
906 }
907 }
908
909 lpsolve {
910 set ascSolv6Vect(nonneg) 1
911 set ascSolv6Vect(obj) 0
912 set ascSolv6Vect(binary) 0
913 set ascSolv6Vect(integer) 0
914 set ascSolv6Vect(semi) 0
915 set ascSolv6Vect(sos1) 0
916 set ascSolv6Vect(sos2) 0
917 set ascSolv6Vect(sos3) 0
918 set ascSolv6Vect(bo) 0
919 set ascSolv6Vect(eps) 0
920 set ascSolv6Vect(boval) 0
921 set ascSolv6Vect(epsval) 0
922 }
923
924 OSL {
925 set ascSolv6Vect(nonneg) 0
926 set ascSolv6Vect(obj) 0
927 set ascSolv6Vect(binary) 0
928 set ascSolv6Vect(integer) 0
929 set ascSolv6Vect(semi) 0
930 set ascSolv6Vect(sos1) $ascSolv6Vect(SOS)
931 set ascSolv6Vect(sos2) 0
932 set ascSolv6Vect(sos3) $ascSolv6Vect(SOS)
933 set ascSolv6Vect(bo) 0
934 set ascSolv6Vect(eps) 0
935 set ascSolv6Vect(boval) 0
936 set ascSolv6Vect(epsval) 0
937 }
938 SCICONIC {
939 set ascSolv6Vect(nonneg) 0
940 set ascSolv6Vect(obj) 2
941 set ascSolv6Vect(binary) 1
942 set ascSolv6Vect(integer) 1
943 # set ascSolv6Vect(semi) use current value
944 set ascSolv6Vect(sos1) $ascSolv6Vect(SOS)
945 set ascSolv6Vect(sos2) 0
946 set ascSolv6Vect(sos3) $ascSolv6Vect(SOS)
947 set ascSolv6Vect(bo) 0
948 set ascSolv6Vect(eps) 0
949 set ascSolv6Vect(boval) 0
950 set ascSolv6Vect(epsval) 0
951 }
952 Generic {
953 set ascSolv6Vect(nonneg) 0
954 set ascSolv6Vect(obj) 0
955 set ascSolv6Vect(binary) 0
956 set ascSolv6Vect(integer) 0
957 set ascSolv6Vect(semi) 0
958 set ascSolv6Vect(sos1) $ascSolv6Vect(SOS)
959 set ascSolv6Vect(sos2) 0
960 set ascSolv6Vect(sos3) $ascSolv6Vect(SOS)
961 set ascSolv6Vect(bo) 0
962 set ascSolv6Vect(eps) 0
963 set ascSolv6Vect(boval) 0
964 set ascSolv6Vect(epsval) 0
965 }
966 }
967
968 # if the window is up, delete it
969 if {$ascSolv6Vect(dialogup) == 1} {DestroyWindow.mps}
970
971 set ascSolv6Vect(dialogup) 0
972
973 }
974
975 # ____________________________________________________________________________#
976 # File name expansion and error checking
977 # ____________________________________________________________________________#
978
979 # little dialog that asks for conformation to overwrite
980 # yes =1, no = 0
981
982 proc Solv6_Overwrite {args} {
983
984 global env
985
986 # stick "and" between multiple files if any
987 set name [join $args " and "]
988 # see if it contains any ands
989 if {[string first and $name] == -1} {
990 set plural file
991 set plural2 exists
992 set plural3 it
993 } else {
994 set plural files
995 set plural2 exist
996 set plural3 them
997 }
998
999 # read in Yes/No dialog box template
1000 source "$env(ASCENDTK)/templates/Procedures/YesNoBox.t"
1001
1002 global yesNoBox
1003 set yesNoBox(font) *time*18*
1004
1005 # position the dialog with second parameter
1006 return [YesNoBox "The $plural $name $plural2. \nDo you want to overwrite $plural3?" \
1007 [osgpos 350x150[setpos .solver 15 55]]]
1008
1009 }
1010
1011
1012 # This routine checks the filename the user enters for the mps file
1013 # It does ~ expansion (although it always replaces ~anyuser with $HOME,
1014 # it doen't do ~anyuser lookup), and it checks to see if the file already
1015 # exists
1016
1017 # it returns 0 if an error occurs (name is invalid) or 1 if successful
1018 # Parameters are name, the file name to clean up, and
1019 # confirm, a boolean flag if the user should be asked if he wants to
1020 # overwrite
1021
1022 proc Solv6_CleanName { name confirm } {
1023
1024 global ascSolv6Vect env
1025
1026 # only work on copy of name
1027 set ascSolv6Vect(mpsname) $name
1028
1029 # see if HOME is defined, so we can do tilde expansion
1030 if {[info exists env(HOME)]} {
1031
1032 # see if fileascSolv6Vect(mpsname) starts with a tilde, if so do expansion
1033 if {[string index $ascSolv6Vect(mpsname) 0] == "~"} {
1034
1035 set firstslash [string first "/" $ascSolv6Vect(mpsname)]
1036 if {$firstslash == -1} {
1037 Solve_Alert "Input Error" "The MPS file name $ascSolv6Vect(mpsname), contains a ~ but no / (e.g. ~/output.mps)"
1038 return 0
1039 }
1040
1041 # now we know everthing exists, so expand ascSolv6Vect(mpsname)
1042 # the slash stuff is to get rid of the cs76 if the
1043 # user enters ~cs76/test.mps
1044
1045 set ascSolv6Vect(mpsname) $env(HOME)[string range $ascSolv6Vect(mpsname) $firstslash end]
1046 }
1047 }
1048
1049
1050 # add a .mps, if it doesn't already end with it
1051 if { [expr ![regexp {.mps$} $ascSolv6Vect(mpsname)]] } {
1052 set ascSolv6Vect(mpsname) $ascSolv6Vect(mpsname).mps
1053 }
1054
1055 # get the map name from ascSolv6Vect(mpsname) [i.e. *.map]
1056 regsub {mps$} $ascSolv6Vect(mpsname) {map} ascSolv6Vect(mapname)
1057
1058 # get the error output name from ascSolv6Vect(mpsname) [i.e. *.err]
1059 regsub {mps$} $ascSolv6Vect(mpsname) {err} ascSolv6Vect(errname)
1060
1061 # get the regular output name from ascSolv6Vect(mpsname) [i.e. *.out]
1062 regsub {mps$} $ascSolv6Vect(mpsname) {out} ascSolv6Vect(outname)
1063
1064 #now see if the .mps or .map file exists, and get confirmation to overwrite
1065 if { [file exists $ascSolv6Vect(mpsname)] || [file exists $ascSolv6Vect(mapname)]} {
1066
1067 # check to make sure mps file is not a directory
1068 if {[file isdirectory $ascSolv6Vect(mpsname) ]} {
1069 Solve_Alert "Input Error" "The MPS file name $ascSolv6Vect(mpsname), is already the name of a directory"
1070 return 0
1071 }
1072
1073 # check to make sure map file is not a directory
1074 if {[file isdirectory $ascSolv6Vect(mapname) ]} {
1075 Solve_Alert "Input Error" "The variable map file name $ascSolv6Vect(mapname), is already the name of a directory"
1076 return 0
1077 }
1078
1079 if { $confirm} {
1080
1081 # if both files exist, ask for confirmation to overwrite
1082 if {[file isfile $ascSolv6Vect(mpsname) ] && [file isfile $ascSolv6Vect(mapname) ]} {
1083 set result [Solv6_Overwrite $ascSolv6Vect(mpsname) $ascSolv6Vect(mapname)]
1084 if {!$result} {
1085 return 0
1086 } else {
1087 return 1
1088 }
1089 }
1090
1091 # if it's already a file, ask for confirmation to overwrite
1092 if {[file isfile $ascSolv6Vect(mpsname) ]} {
1093 set result [Solv6_Overwrite $ascSolv6Vect(mpsname)]
1094 if {!$result} { return 0 }
1095 }
1096
1097 # if it's already a file, ask for confirmation to overwrite
1098 if {[file isfile $ascSolv6Vect(mapname) ]} {
1099 set result [Solv6_Overwrite $ascSolv6Vect(mapname)]
1100 if {!$result} { return 0 }
1101 }
1102
1103 }
1104
1105 }
1106
1107 return 1
1108
1109 }
1110 #end of Solv6_CleanName

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22