/[ascend]/trunk/tcltk98/generic/interface/SolverProc.h
ViewVC logotype

Contents of /trunk/tcltk98/generic/interface/SolverProc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (show annotations) (download) (as text)
Thu Dec 15 03:59:55 2005 UTC (16 years, 5 months ago) by ben.allan
File MIME type: text/x-chdr
File size: 20280 byte(s)
added slv_[un]trapint tcl callbacks which can be used to turn off
ctrl-c trapping of the commandline. in theory this will help gdb.
Note: traps are handled on a stack, so to guarantee the sigint
stack is empty, use slv_untrapint untill you get an error message:
        ascSignal.c:437: Asc_Signal (2) stack pop mismatch.


1 /*
2 * SolverProc.h
3 * by Kirk Abbott and Ben Allan
4 * Created: 1/94
5 * Version: $Revision: 1.20 $
6 * Version control file: $RCSfile: SolverProc.h,v $
7 * Date last modified: $Date: 2003/08/23 18:43:08 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the ASCEND Tcl/Tk interface
11 *
12 * Copyright 1997, 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 License as
16 * published by the Free Software Foundation; either version 2 of the
17 * 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 of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * 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 Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27 * COPYING. COPYING is found in ../compiler.
28 */
29
30 /** @file
31 * Solver procedures.
32 * <pre>
33 * Requires: #include "tcl.h"
34 * #include "utilities/ascConfig.h"
35 * </pre>
36 */
37
38 #ifndef ASCTK_SOLVERPROC_H
39 #define ASCTK_SOLVERPROC_H
40
41 /*
42 * The following global definitions (which should be going away)
43 * have moved to SolverGlobals.h:
44 *
45 * extern int g_solvinst_ndx, g_solvinst_limit;
46 * extern slv_system_t g_browsys_cur, g_solvsys_cur;
47 * extern struct Instance *g_solvinst_root; // solver root instance
48 * extern struct Instance *g_solvinst_cur; // solver current instance
49 */
50
51 /** Marker for code to be removed */
52 #define DELETEME 0
53
54 extern void Asc_SolvMemoryCleanup(void);
55 /**< Invoke system_free_reused_mem to clean up all memory solvers hide. */
56
57 extern int Asc_SolvTrapINT(ClientData cdata, Tcl_Interp *interp,
58 int argc, CONST84 char *argv[]);
59 /**< Activate floating point traps for slv/script callbacks /slv_trapint/ */
60
61 extern int Asc_SolvTrapFP(ClientData cdata, Tcl_Interp *interp,
62 int argc, CONST84 char *argv[]);
63 /**< Activate floating point traps for slv callbacks /slv_trapfp/ */
64
65 extern int Asc_SolvUnTrapINT(ClientData cdata, Tcl_Interp *interp,
66 int argc, CONST84 char *argv[]);
67 /**< Deactivate floating point traps for slv callbacks /slv_untrapfp/ */
68
69 extern int Asc_SolvUnTrapFP(ClientData cdata, Tcl_Interp *interp,
70 int argc, CONST84 char *argv[]);
71 /**< Deactivate floating point traps for slv callbacks /slv_untrapfp/ */
72
73 #if DELETEME /* going away */
74 extern int Asc_Sims2Solve(ClientData cdata, Tcl_Interp *interp,
75 int argc, CONST84 char *argv[]);
76 /**<
77 * Sends named simulation to solver context.
78 * Do this before calling solver window update. Flushes current sys.
79 * if exported instance and type are valid.
80 * Somebody elses job to update the solver window context list.
81 * Faster than Solv_ImportQlfdid.
82 * Does a presolve using slv0.
83 */
84
85 extern int Asc_Brow2Solve(ClientData cdata, Tcl_Interp *interp,
86 int argc, CONST84 char *argv[]);
87 /**<
88 * Sends browser focused simulation(or subpart) to solver context.
89 * Do this before calling solver window update. Flushes current sys.
90 * If exported instance and type are valid.
91 * Somebody elses job to update the solver window context list.
92 * Faster than Solv_ImportQlfdid.
93 * Does a presolve using slv0.
94 */
95
96 extern int Asc_SolvSimInst(ClientData cdata, Tcl_Interp *interp,
97 int argc, CONST84 char *argv[]);
98 /**<
99 * Solves top level simulation named with solver specified.
100 * This is for commandline use only.
101 * Just a wrapper of slv_interface.c Solve().
102 */
103 #endif /* DELETEME */
104
105 extern int Asc_SolvCurInst(ClientData cdata, Tcl_Interp *interp,
106 int argc, CONST84 char *argv[]);
107 /**<
108 * Solves g_curinst with solver specified.
109 * This is for commandline use only.
110 * Just a wrapper of slv_interface.c Solve() for now.
111 * this function is Extremely buggy.
112 */
113
114 extern int Asc_SolvGetModKids(ClientData cdata, Tcl_Interp *interp,
115 int argc, CONST84 char *argv[]);
116 /**<
117 * Returns a tcl list of the MODEL_INST children of the qlfdid passed
118 * in. Note this routine probably ought to be generalized to all INST
119 * types. Uses Asc_BrowQlfdidSearchCmd().
120 */
121
122 extern int Asc_SolvIncompleteSim(ClientData cdata, Tcl_Interp *interp,
123 int argc, CONST84 char *argv[]);
124 /**< Checks whether named simulation is complete. */
125
126 extern int Asc_SolvCheckSys (ClientData cdata, Tcl_Interp *interp,
127 int argc, CONST84 char *argv[]);
128 /**< Checks whether g_solvsys_cur is non-NULL. */
129
130 extern int Asc_SolvGetObjList(ClientData cdata, Tcl_Interp *interp,
131 int argc, CONST84 char *argv[]);
132 /**<
133 * Output will be a list of indexes of the included objectives
134 * This list will be enclosed in {} so the output of the function is
135 * always a 1 item list whose first item is the list of indices.
136 * The list may come back empty if appropriate.
137 * Operates on g_solvsys_cur.<br><br>
138 *
139 * Registered as: slv_get_obj_list <dest> 0= stdout 1 = stderr 2= list
140 */
141
142 extern int Asc_SolvSetObjByNum(ClientData cdata, Tcl_Interp *interp,
143 int argc, CONST84 char *argv[]);
144 /**<
145 * Sets the solvers objective to list[num] where
146 * list is the solvers list of objective relations.
147 * If num is -1 the ojective is set to NULL. <br><br>
148 *
149 * Registered as: slv_set_obj_by_num
150 */
151
152 STDHLF_H(Asc_SolvGetObjNumCmd);
153 extern int Asc_SolvGetObjNumCmd(ClientData cdata, Tcl_Interp *interp,
154 int argc, CONST84 char *argv[]);
155 /** Registered as */
156 #define Asc_SolvGetObjNumCmdHN "slv_get_obj_num"
157 /** Usage */
158 #define Asc_SolvGetObjNumCmdHU \
159 Asc_SolvGetObjNumCmdHN " takes no arguments"
160 /** Short help text */
161 #define Asc_SolvGetObjNumCmdHS \
162 "gets the solver list index for the current objective"
163 /** Long help text */
164 #define Asc_SolvGetObjNumCmdHL "\
165 * slv_get_obj_num gets the solver list index for the current \n\
166 * objective. If the objective is NULL, -1 is returned.\n\
167 "
168
169 extern int Asc_SolvGetSlvParms(ClientData cdata, Tcl_Interp *interp,
170 int argc, CONST84 char *argv[]);
171 /**<
172 * Loads up interp->result with strings from the C data. If solver not
173 * linked, returns slv0 parameters instead.
174 * g_solvsys_cur is used. specializes on slvI, I=solver number.
175 * This code should be updated if slv_parameters_structure
176 * slv_tolerance_data, or slv_output_data in slv.h are changed.
177 * If a specified solver is not linked, then slv0 parameters will be
178 * returned instead.<br><br>
179 *
180 * Returns:
181 * - number of solver parameters were retrieved from.
182 * - time_limit
183 * - iteration_limit
184 * - tolerance.termination
185 * - tolerance.feasible
186 * - tolerance.pivot
187 * - tolerance.singular
188 * - tolerance.stationary
189 * - rho
190 * - partition
191 * - ignore_bounds
192 * - on(1)/off(0) of output file more_important
193 * - on(1)/off(0) of output file less_important
194 * - factor_option (should be a sp)
195 *
196 * Additional returns, if solver I has subparameters:
197 * This is one of those places where the interface and the solver have
198 * to make a deal. In particular, the TCL writer has to look at
199 * the slvI.h files to know the meaning of what is
200 * returned. Here we will return the parameters in the order they are
201 * stored in the arrays and the arrays will be printed in order:
202 * iap,rap,cap. The vap array will not be returned to TCL. vap is for
203 * use only in C.<br><br>
204 *
205 * Registered as: slv_get_parms <solver number>
206 */
207
208 extern int Asc_SolvSetSlvParms(ClientData cdata, Tcl_Interp *interp,
209 int argc, CONST84 char *argv[]);
210 /**<
211 * Loads up slv parameters struct from argv.
212 * This code should be updated if slv_parameters_structure
213 * slv_tolerance_data, or slv_output_data in slv.h are changed.
214 * If a specified solver is not linked, parameters will not be set.<br><br>
215 *
216 * Input:
217 * - solver number
218 * - time_limit (seconds)
219 * - iteration_limit (integer)
220 * - tolerance.termination
221 * - tolerance.feasible
222 * - tolerance.pivot
223 * - tolerance.singular
224 * - tolerance.stationary
225 * - rho
226 * - partition on(1)/off(0)
227 * - ignore_bounds 1->ignore, 0 ->not ignore
228 * - on(1)/off(0) of output file more_important
229 * - on(1)/off(0) of output file less_important
230 *
231 * The exact number of values required to fill the subparameter arrays
232 * iap, rap must also be given and in the proper order.
233 * (set them just as you would be getting them.)
234 * String pointer and void pointer subparameters are set in a different
235 * call. Since no one has made use of string or void pointer parameters
236 * yet, their set call remains to be defined.<br><br>
237 *
238 * Notes: Tcl_ExprBoolean is used on the binaries.<br><br>
239 *
240 * Registered as: set_slv_parms <items>
241 */
242
243 extern int Asc_SolvGetSlvParmsNew(ClientData cdata, Tcl_Interp *interp,
244 int argc, CONST84 char *argv[]);
245 extern int Asc_SolvSetSlvParmsNew(ClientData cdata, Tcl_Interp *interp,
246 int argc, CONST84 char *argv[]);
247 /**<
248 * extern int Asc_SolvGetSlvBoolParms(ClientData cdata, Tcl_Interp *interp,
249 * int argc, CONST84 char *argv[]);
250 * extern int Asc_SolvGetSlvRealParms(ClientData cdata, Tcl_Interp *interp,
251 * int argc, CONST84 char *argv[]);
252 */
253
254 extern int Asc_SolvGetInstType(ClientData cdata, Tcl_Interp *interp,
255 int argc, CONST84 char *argv[]);
256 /**<
257 * Returns a string ptr needed for the IS_A field.
258 * DO _ NOT _ FREE this pointer as compiler owns it.
259 */
260
261 extern int Asc_SolvGetSlvStatPage(ClientData cdata, Tcl_Interp *interp,
262 int argc, CONST84 char *argv[]);
263 /**<
264 * Loads up interp->result with strings from the slv status struct.
265 * g_solvsys_cur is used.
266 * This code should be updated if slv__status_structure or
267 * slv__block_status_structure in slv.h change.<br><br>
268 *
269 * Returns:
270 * - ok (boole)
271 * - over_defined (boole)
272 * - under_defined (boole)
273 * - struct_singular (boole)
274 * - ready_to_solve (boole)
275 * - converged (boole)
276 * - diverged (boole)
277 * - inconsistent (boole)
278 * - calc_ok (boole)
279 * - iteration_limit_exceeded (boole)
280 * - time_limit_exceeded (boole)
281 * - iteration (integer)
282 * - cpu_elapsed
283 * - (block) number_of
284 * - current_block
285 * - current_size
286 * - previous_total_size
287 * - iteration
288 * - cpu_elapsed
289 * - residual
290 *
291 * Registered as: slv_get_stat_page
292 */
293
294 extern int Asc_SolvGetSlvCostPage(ClientData cdata, Tcl_Interp *interp,
295 int argc, CONST84 char *argv[]);
296 /**<
297 * Loads up interp->result with strings from the slv status struct
298 * cost list. It is likely that this data is only valid after the
299 * solver has converged or otherwise finished.
300 * Returns a list (in block order) of block costs from the current
301 * solver. Some solvers may not have one. <br><br>
302 *
303 * Each list element is:
304 * - block size
305 * - iterations in block
306 * - function calls
307 * - jacobian calls
308 * - cpu time
309 * - residual
310 * - function time
311 * - jacobian time
312 *
313 * Registered as: slv_get_cost_page
314 */
315
316 extern int Asc_SolvGetObjectiveVal(ClientData cdata, Tcl_Interp *interp,
317 int argc, CONST84 char *argv[]);
318 /**<
319 * Evaluates and returns the objective function, or "none" if there
320 * isn't one.
321 */
322
323 extern int Asc_SolvGetInstName(ClientData cdata, Tcl_Interp *interp,
324 int argc, CONST84 char *argv[]);
325 /**<
326 * Returns the name from solvinstroot to solvinstcur.
327 * Returns \none\ if either inst is null.
328 */
329
330 extern int Asc_SolvGetPathName(ClientData cdata, Tcl_Interp *interp,
331 int argc, CONST84 char *argv[]);
332 /**<
333 * Returns the name from solvinstroot to solvinstcur including sim.
334 * Returns \none\ if either inst is null.
335 */
336
337 extern int Asc_SolvGetVRCounts(ClientData cdata, Tcl_Interp *interp,
338 int argc, CONST84 char *argv[]);
339 /**<
340 * Returns the counts of variables and relations from g_solvsys_cur.
341 * Call presolve before calling this.
342 * Return order is:
343 * - total relations,
344 * - active relations,
345 * - included relations,
346 * - total vars,
347 * - active vars,
348 * - free vars,
349 * - equalities,
350 * - included equalities
351 * - inequalities,
352 * - inactive included equalities,
353 * - inactive included inequalities,
354 * - unincluded relations,
355 * - fixed vars,
356 * - inactive free vars,
357 * - inactive fixed vars,
358 * - active unattached vars
359 *
360 * Modified for including the notion of active variable and active
361 * relation. VRR
362 */
363
364 /* Hereunder we do some lowlevel operations. */
365
366 extern int Asc_SolvSlvDumpInt(ClientData cdata, Tcl_Interp *interp,
367 int argc, CONST84 char *argv[]);
368 /**< Calls slv_dump_internals on g_solvsys_cur. */
369
370 extern int Asc_SolvSlvPresolve(ClientData cdata, Tcl_Interp *interp,
371 int argc, CONST84 char *argv[]);
372 /**< Presolves the g_solvsys_cur, or tries to. */
373
374 extern int Asc_SolvReanalyze(ClientData cdata, Tcl_Interp *interp,
375 int argc, CONST84 char *argv[]);
376 /**< Reanalyze the g_solvsys_cur solver lists after running a procedure. */
377
378 extern int Asc_SolvCheckAndReanalyze(ClientData cdata, Tcl_Interp *interp,
379 int argc, CONST84 char *argv[]);
380 /**<
381 * Checks if the instance modified in the browser is a member of a
382 * whenvarlist and, if it is, reanalyze the g_solvsys_cur solver lists.
383 */
384
385 extern int Asc_SolvSlvResolve(ClientData cdata, Tcl_Interp *interp,
386 int argc, CONST84 char *argv[]);
387 /**< Resolves the g_solvsys_cur, or tries to. */
388
389 extern int Asc_SolvSlvSolve(ClientData cdata, Tcl_Interp *interp,
390 int argc, CONST84 char *argv[]);
391 /**< Solves the g_solvsys_cur, or tries to. */
392
393 extern int Asc_SolvSlvIterate(ClientData cdata, Tcl_Interp *interp,
394 int argc, CONST84 char *argv[]);
395 /**<
396 * Iterates the g_solvsys_cur up to n times for t seconds or until some*
397 * error or convergence occurs. At least 1 iteration in any case.
398 * If t not given, 5 cpu seconds assumed.<br><br>
399 *
400 * Registered as: slv_iterate n t
401 */
402
403 extern int Asc_SolvAvailSolver(ClientData cdata, Tcl_Interp *interp,
404 int argc, CONST84 char *argv[]);
405 /**<
406 * Returns the list of linked solver names.
407 * If a solver in not linked, the first three char of its name
408 * will be no_.<br><br>
409 *
410 * Registered as: slv_available <no args>
411 */
412
413 extern int Asc_SolvLinsolNames(ClientData cdata, Tcl_Interp *interp,
414 int argc, CONST84 char *argv[]);
415 /**<
416 * Returns the list of linsolqr factor methods separated
417 * by commas. Split at commas to extract names.<br><br>
418 *
419 * Registered as: slv_linsol_names <no args>
420 */
421
422 extern int Asc_SolvEligSolver(ClientData cdata, Tcl_Interp *interp,
423 int argc, CONST84 char *argv[]);
424 /**<
425 * Returns a boolean of whether the current solver is eligible on
426 * current problem.
427 * If any third argument is present, displays eligibility of all
428 * solvers on stderr for current problem.
429 * Swiped Karl code in slv_interface
430 */
431
432 extern int Asc_SolvSelectSolver(ClientData cdata, Tcl_Interp *interp,
433 int argc, CONST84 char *argv[]);
434 /**<
435 * Sets solver to N, if N available.
436 * On return the Tcl interpreter result is set to the selected solver number.
437 *
438 * @param cdata Not used.
439 * @param interp The Tcl interpreter.
440 * @param argc The number of argv elements - must be 2.
441 * @param argv argv[1] should contain the number of the solver
442 * to select as a string.
443 * @return TCL_OK if the solver was selected, TCL_ERROR otherwise.
444 */
445
446 extern int Asc_SolvGetSelectedSolver(ClientData cdata, Tcl_Interp *interp,
447 int argc, CONST84 char *argv[]);
448 /**<
449 * Gets the number of the selected solver.
450 * On return the Tcl interpreter result is set to the selected solver number.
451 *
452 * @param cdata Not used.
453 * @param interp The Tcl interpreter.
454 * @param argc The number of argv elements - must be 1.
455 * @param argv Not used.
456 * @return TCL_OK if the solver was selected, TCL_ERROR otherwise.
457 */
458
459 extern int Asc_SolvImportQlfdid(ClientData cdata, Tcl_Interp *interp,
460 int argc, CONST84 char *argv[]);
461 /**<
462 * Import qlfdid to solver context.
463 * Will take a fully qualified ascend name and will search for the
464 * instance with that name. Will leave g_solvsys_cur looking at the
465 * named instance if successful.
466 * Uses Asc_BrowQlfdidSearchCmd().
467 * If a called with an id and a third argument, will return 0 if an
468 * import is allowable, or 1 if it is not, without actually importing.
469 * e.g. set notok [slv_import_qlfdid fred.model test]
470 * Does NOT presolve. leaves solver number set to previous number if
471 * solver previously occupied.<br><br>
472 *
473 * Registered as : slv_import_qlfdid
474 */
475
476 extern int Asc_SolvFlushSolver(ClientData cdata, Tcl_Interp *interp,
477 int argc, CONST84 char *argv[]);
478 /**<
479 * Clear out the solver.
480 * Free all memory associated with all solver engines.
481 */
482
483 extern int Asc_SolvMakeIndependent(ClientData cdata, Tcl_Interp *interp,
484 int argc, CONST84 char *argv[]);
485 /**<
486 * Move vars (given by index #) to the unassigned region of the slv0
487 * matrix if possible. Returns indices of vars that can't be moved
488 * because structural infeasibility would occur.
489 * Returns tcl_Error if too many vars are specified or slv0 otherwise
490 * not ready.
491 * May have the side effect of repartitioning if needed.
492 * Will fail if the mtx does not have the incidence pattern in it,
493 * which is generally only the case at the end of slv_presolve.
494 * The cost data will also be updated if necessary.<br><br>
495 *
496 * Registered as: slv_set_independent <index> [index ...]
497 */
498
499 extern int Asc_SolvGetLnmEpsilon(ClientData cdata, Tcl_Interp *interp,
500 int argc, CONST84 char *argv[]);
501 /**< Get epsilon used in lnm (modified log ) calculation. */
502
503 extern int Asc_SolvSetLnmEpsilon(ClientData cdata, Tcl_Interp *interp,
504 int argc, CONST84 char *argv[]);
505 /**< Set epsilon used in lnm (modified log ) calculation. 0.5 > eps > 0.0. */
506
507 extern int Asc_SolvSetCHaltFlag(ClientData cdata, Tcl_Interp *interp,
508 int argc, CONST84 char *argv[]);
509 /**<
510 * Tcl function for setting the halt flag for a solver.
511 * integer is an integer value, 0 or nonzero. If 0 will turn the
512 * flag off. Otherwise will turn the flag on.
513 *
514 * Registered as: slv_set_haltflag integer.
515 */
516
517 extern int Asc_SolvHelpList(ClientData cdata, Tcl_Interp *interp,
518 int argc, CONST84 char *argv[]);
519 /**<
520 * slvhelp command for tcl.
521 * No arg or "s" -> list names only. "l" -> short explanations also.<br><br>
522 *
523 * Registered as: slvhelp [s,l]
524 */
525
526 extern int Asc_SolvNearBounds(ClientData cdata, Tcl_Interp *interp,
527 int argc, CONST84 char *argv[]);
528 /**<
529 * See function of same name in c for documentation.<br><br>
530 *
531 * Registered as: slv_near_bounds
532 */
533
534 extern int Asc_SolvFarFromNominal(ClientData cdata, Tcl_Interp *interp,
535 int argc, CONST84 char *argv[]);
536 /**<
537 * See function of same name in c for documentation.<br><br>
538 *
539 * Registered as: slv_far_from_nominals
540 */
541
542 #endif /* ASCTK_SOLVERPROC_H */
543

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