/[ascend]/trunk/base/generic/solver/slv.c
ViewVC logotype

Contents of /trunk/base/generic/solver/slv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download) (as text)
Wed Nov 30 05:53:20 2005 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-csrc
File size: 62986 byte(s)
My first commit:
Added 'error_reporter' for standardised error reporting
Working on getting external functions running again
Also: issue 130, issue 68, issue 131, issue 89, issue 127, issue 138, issue 94.
1 /*
2 * SLV: Ascend Nonlinear Solver
3 * by Karl Michael Westerberg
4 * Created: 2/6/90
5 * Version: $Revision: 1.51 $
6 * Version control file: $RCSfile: slv.c,v $
7 * Date last modified: $Date: 1998/04/26 22:47:53 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the SLV solver.
11 *
12 * Copyright (C) 1990 Karl Michael Westerberg
13 * Copyright (C) 1993 Joseph Zaher
14 * Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan
15 *
16 * The SLV solver is free software; you can redistribute
17 * it and/or modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of the
19 * License, or (at your option) any later version.
20 *
21 * The SLV solver is distributed in hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with the program; if not, write to the Free Software Foundation,
28 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
29 * COPYING. COPYING is found in ../compiler.
30 *
31 */
32
33 #include <math.h>
34 #include <stdarg.h>
35 #include "utilities/ascConfig.h"
36 #include "compiler/instance_enum.h"
37 #include "compiler/fractions.h"
38 #include "compiler/compiler.h"
39 #include "utilities/ascMalloc.h"
40 #include "utilities/ascPanic.h"
41 #include "compiler/dimen.h"
42 #include "compiler/atomvalue.h"
43 #include "solver/mtx.h"
44 #include "solver/linsol.h"
45 #include "solver/linsolqr.h"
46 #include "solver/slv_types.h"
47 #include "solver/var.h"
48 #include "solver/rel.h"
49 #include "solver/logrel.h"
50 #include "solver/discrete.h"
51 #include "solver/conditional.h"
52 #include "solver/bnd.h"
53 #include "solver/bndman.h"
54 #include "solver/system.h"
55 #include "solver/slv_server.h"
56 #include "solver/slv_common.h"
57 #include "solver/slv_client.h"
58 #include "solver/analyze.h"
59
60
61 #define NEEDSTOBEDONE 0
62
63 /**
64 *** Include all of the solvers involved,
65 *** even if they are not linked later
66 *** Defines are to take care of the unlinked ones.
67 **/
68 #if 0
69 #include "solver/slv0.h"
70 #include "solver/slv1.h"
71 #include "solver/slv2.h"
72 #include "solver/slv3.h"
73 #include "solver/slv4.h"
74 #include "solver/slv5.h"
75 #include "solver/slv6.h"
76 #include "solver/slv7.h"
77 #include "solver/slv8.h"
78 #include "solver/slv9.h"
79
80 #endif
81
82
83 struct slv_system_structure {
84 int solver;
85 int serial_id; /* through time, two systems may have the same pointer
86 * but never simultaneously. The serial_id provides a
87 * unique tag that will never repeat. Clients concerned
88 * with identity but not capable of tracking time must
89 * use the serial_id for checks.
90 */
91 SlvBackendToken instance; /* should be void * in the most generic case */
92
93 /* All solver handles. sysI can't be dereferenced outside slvI.c
94 * should be an array of pointers to arrays of the functions provided
95 * by dynamically loaded clients, or at least by the client which this
96 * system is currently supporting.
97 */
98
99 SlvClientToken ct;
100 /* This is a pointer that the client returns on registration.
101 * If it is not null, the registration was successful.
102 * This token will be handed back to the client code on all calls
103 * originating from here.
104 */
105
106 dof_t dof; /* non linear blocks */
107 dof_t logdof; /* logical blocks */
108
109 /* In the following NULL terminated lists, note that snum and mnum
110 * are the lengths of the arrays WITHOUT the NULL pointer at the end.
111 * Note objs is a list of relations that are objectives
112 * (e_maximize,e_minimize). this list will include the first included obj.
113 */
114 struct {
115 int snum; /* length of the solver list */
116 int mnum; /* length of the master list */
117 struct var_variable **solver;
118 struct var_variable **master;
119 } vars;
120
121 struct {
122 int snum; /* length of the solver list */
123 int mnum; /* length of the master list */
124 struct dis_discrete **solver;
125 struct dis_discrete **master;
126 } dvars;
127
128 struct {
129 int snum; /* length of the solver list */
130 int mnum; /* length of the master list */
131 struct rel_relation **solver;
132 struct rel_relation **master;
133 } rels;
134
135 struct {
136 int snum;
137 int mnum;
138 struct rel_relation **solver;
139 struct rel_relation **master;
140 } objs;
141
142 struct {
143 int snum; /* length of the solver list */
144 int mnum; /* length of the master list */
145 struct rel_relation **solver;
146 struct rel_relation **master;
147 } condrels;
148
149 struct {
150 int snum; /* length of the solver list */
151 int mnum; /* length of the master list */
152 struct logrel_relation **solver;
153 struct logrel_relation **master;
154 } logrels;
155
156 struct {
157 int snum; /* length of the solver list */
158 int mnum; /* length of the master list */
159 struct logrel_relation **solver;
160 struct logrel_relation **master;
161 } condlogrels;
162
163 struct {
164 int snum; /* length of the solver list */
165 int mnum; /* length of the master list */
166 struct w_when **solver;
167 struct w_when **master;
168 } whens;
169
170 struct {
171 int snum; /* length of the solver list */
172 int mnum; /* length of the master list */
173 struct bnd_boundary **solver;
174 struct bnd_boundary **master;
175 } bnds;
176
177 struct {
178 int snum;
179 int mnum;
180 struct var_variable **solver;
181 struct var_variable **master;
182 } pars;
183
184 struct {
185 int snum;
186 int mnum;
187 struct var_variable **solver;
188 struct var_variable **master;
189 } unattached;
190
191 struct {
192 int snum;
193 int mnum;
194 struct dis_discrete **solver;
195 struct dis_discrete **master;
196 } disunatt;
197
198 /* the data that follows is for internal consumption only. */
199 struct {
200 int num_extrels;
201 struct ExtRelCache **erlist;
202 } extrels;
203
204 struct rel_relation *obj; /* selected for optimization from list */
205 struct var_variable *objvar; /* selected for optimization from list */
206 struct gl_list_t *symbollist; /* list of symbol values struct used to */
207 /* assign an integer value to a symbol value */
208 struct {
209 struct var_variable *ubuf; /* data space for unclassified real ATOMs */
210 struct dis_discrete *udbuf; /* data space for unclassified discrete ATOM */
211 struct var_variable *pbuf; /* data space for real ATOMs that are pars */
212 struct var_variable *vbuf; /* data space for real ATOMs that are vars */
213 struct dis_discrete *dbuf; /* data space for discrete ATOMs that are vars*/
214 struct rel_relation *rbuf; /* data space for real rel constraints */
215 struct rel_relation *cbuf; /* data space for conditional rel */
216 struct rel_relation *obuf; /* data space for real relation objectives */
217 struct logrel_relation *lbuf; /* data space for logical rel */
218 struct logrel_relation *clbuf; /* data space for conditional logical rel*/
219 struct w_when *wbuf; /* data space for whens */
220 struct bnd_boundary *bbuf; /* data space for boundaries */
221 struct var_variable **incidence; /* all relation incidence list memory */
222 struct rel_relation **varincidence; /* all variable incidence list memory */
223 struct dis_discrete **logincidence; /* all logrel incidence list memory */
224 long incsize; /* size of incidence array */
225 long varincsize; /* size of varincidence array */
226 long logincsize; /* size of discrete incidence array */
227 #if NEEDSTOBEDONE
228 /* we should be group allocating this data, but aren't */
229 struct ExtRelCache *ebuf; /* data space for all extrel caches */
230 #endif
231 } data;
232
233 int32 nmodels;
234 int32 need_consistency; /*
235 * consistency analysis required for conditional
236 * model ?
237 */
238 real64 objvargrad; /* maximize -1 minimize 1 noobjvar 0 */
239 };
240
241
242 /*********************************************************************\
243 global variable used to communicate information between solvers and
244 an interface, whether a calculation should be halted or not.
245 0 means go on. any other value may contain additional information
246 content.
247 \*********************************************************************/
248 int Solv_C_CheckHalt_Flag = 0;
249
250 int g_SlvNumberOfRegisteredClients; /* see header */
251
252 static SlvFunctionsT SlvClientsData[SLVMAXCLIENTS];
253 /* making ANSI assumption that RegisteredClients is init to 0/NULLs */
254
255
256 /*
257 * global variables used to destroy:
258 * the cases and the gllist inside each when,
259 * the list of whens in each discrete variable, and
260 * the list of logical relations in each boundary, correspondingly.
261 * This number are as the same as those given in the solver and master
262 * lists, however, these lists are destroyed before the buffers are
263 * destroyed, so the information is gone before I can use it.
264 */
265 static int g_number_of_whens;
266 static int g_number_of_dvars;
267 static int g_number_of_bnds;
268
269 /* the macro NORC is just a short name for the global int */
270 #define NORC g_SlvNumberOfRegisteredClients
271
272 /* The macro SCD returns the ith SlvFunctionsT that the
273 * ith client to register filled out.
274 */
275 #define SCD(i) SlvClientsData[(i)]
276
277 /* the macro SNUM returnsthe number from a slv_system_t */
278 #define SNUM(sys) ((sys)->solver)
279
280 /* the macro LS returns 1 if sys->solvers is in range 0..NORC, else 0.
281 * sys should not be null
282 */
283 #define LS(sys) ( SNUM(sys) >= 0 && SNUM(sys) < NORC )
284 #define LSI(i) ( (i) >= 0 && (i) < NORC )
285
286 /* The macro SF returns the pointer to the client supplied func or char if
287 * the client supplied one, OTHERWISE NULL.
288 * This should only be called with nonNULL sys after CF is happy.
289 * SFI takes the index i rather than from a sys. same as SF OTHERWISE.
290 * CF range checks and returns a function pointer.
291 */
292 #define SF(sys,ptr) ( SCD(SNUM(sys)).ptr )
293 #define SFI(i,ptr) ( SCD(i).ptr )
294 #define CF(sys,ptr) ( LS(sys) ? SCD(SNUM(sys)).ptr : NULL )
295
296 #define SFUN(p) if ((p) != NULL) ascfree(p)
297
298 /*********************************************************************\
299 server functions.
300 \*********************************************************************/
301
302 int slv_register_client(SlvRegistration registerfunc, char *func, char *file)
303 {
304 /* this needs work still, particularly of the dynamic loading sort.
305 * it would be good if here we farmed out the dynamic loading
306 * to another file so we don't have to crap this one all up.
307 */
308 int status;
309
310 (void)func; /* stop gcc whine about unused parameter */
311 (void)file; /* stop gcc whine about unused parameter */
312
313 status = registerfunc(&(SCD(NORC)));
314 if (!status) { /* ok */
315 SCD(NORC).number = NORC;
316 NORC++;
317 } else {
318 FPRINTF(stderr,"Client %d registration failure (%d)!\n",NORC,status);
319 }
320 return status;
321 }
322
323 slv_system_t slv_create(void)
324 {
325 slv_system_t sys;
326 static unsigned nextid = 1;
327 sys = (slv_system_t)asccalloc(1,sizeof(struct slv_system_structure) );
328 /* all lists, sizes, pointers DEFAULT to 0/NULL */
329 sys->solver = -1; /* a nonregistration */
330 sys->serial_id = nextid++;
331 return(sys);
332 }
333
334 unsigned slv_serial_id(slv_system_t sys)
335 {
336 return sys->serial_id;
337 }
338
339 static
340 void slv_destroy_dvar_buffer(struct dis_discrete *dbuf)
341 {
342 int c;
343 struct dis_discrete *cur_dis;
344 for (c=0;c<g_number_of_dvars;c++){
345 cur_dis = &(dbuf[c]);
346 dis_destroy(cur_dis);
347 }
348 ascfree(dbuf);
349 }
350
351 static
352 void slv_destroy_when_buffer(struct w_when *wbuf)
353 {
354 int c;
355 struct w_when *cur_when;
356 for (c=0;c<g_number_of_whens;c++){
357 cur_when = &(wbuf[c]);
358 when_destroy(cur_when);
359 }
360 ascfree(wbuf);
361 }
362
363 static
364 void slv_destroy_bnd_buffer(struct bnd_boundary *bbuf)
365 {
366 int c;
367 struct bnd_boundary *cur_bnd;
368 for (c=0;c<g_number_of_bnds;c++){
369 cur_bnd = &(bbuf[c]);
370 bnd_destroy(cur_bnd);
371 }
372 ascfree(bbuf);
373 }
374
375 int slv_destroy(slv_system_t sys)
376 {
377 int ret = 0;
378 if (sys->ct != NULL) {
379 if ( CF(sys,cdestroy) == NULL ) {
380 FPRINTF(stderr,"PANIC: SlvClientToken 0x%p not freed by %s",
381 sys->ct,SF(sys,name));
382 } else {
383 if ( SF(sys,cdestroy)(sys,sys->ct) ) {
384 ret++;
385 }
386 }
387 }
388 if (ret) {
389 FPRINTF(stderr,"ascend solver: PANIC: slv_system_t 0x%p not freed.",sys);
390 } else {
391 if (sys->data.ubuf != NULL) ascfree(sys->data.ubuf);
392 sys->data.ubuf = NULL;
393 if (sys->data.udbuf != NULL) ascfree(sys->data.udbuf);
394 sys->data.udbuf = NULL;
395 if (sys->data.pbuf != NULL) ascfree(sys->data.pbuf);
396 sys->data.pbuf = NULL;
397 if (sys->data.vbuf != NULL) ascfree(sys->data.vbuf);
398 sys->data.vbuf = NULL;
399 if (sys->data.dbuf != NULL) {
400 slv_destroy_dvar_buffer(sys->data.dbuf);
401 sys->data.dbuf = NULL;
402 }
403 if (sys->data.rbuf != NULL) ascfree(sys->data.rbuf);
404 sys->data.rbuf = NULL;
405 if (sys->data.cbuf != NULL) ascfree(sys->data.cbuf);
406 sys->data.cbuf = NULL;
407 if (sys->data.obuf != NULL) ascfree(sys->data.obuf);
408 sys->data.obuf = NULL;
409 if (sys->data.lbuf != NULL) ascfree(sys->data.lbuf);
410 sys->data.lbuf = NULL;
411 if (sys->data.clbuf != NULL) ascfree(sys->data.clbuf);
412 sys->data.clbuf = NULL;
413 if (sys->data.wbuf != NULL) {
414 slv_destroy_when_buffer(sys->data.wbuf);
415 sys->data.wbuf = NULL;
416 }
417 if (sys->data.bbuf != NULL) {
418 slv_destroy_bnd_buffer(sys->data.bbuf);
419 sys->data.bbuf = NULL;
420 }
421 if (sys->data.incidence != NULL) ascfree(sys->data.incidence);
422 sys->data.incidence = NULL;
423 if (sys->data.varincidence != NULL) ascfree(sys->data.varincidence);
424 sys->data.varincidence = NULL;
425 if (sys->data.logincidence != NULL) ascfree(sys->data.logincidence);
426 sys->data.incidence = NULL;
427 ascfree( (POINTER)sys );
428 }
429 return ret;
430 }
431
432 void slv_destroy_client(slv_system_t sys)
433 {
434
435 if (sys->ct != NULL) {
436 if ( CF(sys,cdestroy) == NULL ) {
437 FPRINTF(stderr,"SlvClientToken 0x%p not freed in slv_destroy_client",
438 sys->ct);
439 } else {
440 if ( SF(sys,cdestroy)(sys,sys->ct) ) {
441 FPRINTF(stderr,"ASCEND solver: SlvClientToken not freed");
442 } else {
443 sys->ct = NULL;
444 }
445 }
446 }
447 }
448
449
450 SlvBackendToken slv_instance(slv_system_t sys)
451 {
452 if (sys == NULL) {
453 FPRINTF(stderr,"ERROR: slv_instance called with NULL system\n");
454 return NULL;
455 } else {
456 return sys->instance;
457 }
458 }
459
460 void slv_set_instance(slv_system_t sys,SlvBackendToken instance)
461 {
462 if (sys == NULL) {
463 FPRINTF(stderr,"ERROR: slv_set_instance called with NULL system\n");
464 return;
465 } else {
466 sys->instance = instance;
467 }
468 }
469
470 dof_t *slv_get_dofdata(slv_system_t sys)
471 {
472 return &(sys->dof);
473 }
474
475 dof_t *slv_get_log_dofdata(slv_system_t sys)
476 {
477 return &(sys->logdof);
478 }
479
480 int32 slv_get_num_models(slv_system_t sys)
481 {
482 if (sys == NULL) {
483 FPRINTF(stderr,"ERROR: slv_get_num_models called with NULL system\n");
484 return 0;
485 } else {
486 return sys->nmodels;
487 }
488 }
489 void slv_set_num_models(slv_system_t sys, int32 nmod)
490 {
491 if (sys == NULL) {
492 FPRINTF(stderr,"ERROR: slv_set_num_models called with NULL system\n");
493 } else {
494 sys->nmodels = nmod;
495 }
496 }
497
498 void slv_set_master_var_list(slv_system_t sys,
499 struct var_variable **vlist, int size)
500 {
501 SFUN(sys->vars.master);
502 sys->vars.mnum = size;
503 sys->vars.master = vlist;
504 }
505
506 void slv_set_master_par_list(slv_system_t sys,
507 struct var_variable **vlist, int size)
508 {
509 SFUN(sys->pars.master);
510 sys->pars.mnum = size;
511 sys->pars.master = vlist;
512 }
513
514 void slv_set_master_unattached_list(slv_system_t sys,
515 struct var_variable **vlist, int size)
516 {
517 SFUN(sys->unattached.master);
518 sys->unattached.mnum = size;
519 sys->unattached.master = vlist;
520 }
521
522 void slv_set_master_dvar_list(slv_system_t sys,
523 struct dis_discrete **dlist, int size)
524 {
525 SFUN(sys->dvars.master);
526 sys->dvars.mnum = size;
527 sys->dvars.master = dlist;
528 }
529
530 void slv_set_master_disunatt_list(slv_system_t sys,
531 struct dis_discrete **dlist, int size)
532 {
533 SFUN(sys->disunatt.master);
534 sys->disunatt.mnum = size;
535 sys->disunatt.master = dlist;
536 }
537
538 void slv_set_master_rel_list(slv_system_t sys,struct rel_relation **rlist,
539 int size)
540 {
541 SFUN(sys->rels.master);
542 sys->rels.mnum = size;
543 sys->rels.master = rlist;
544 }
545
546
547 void slv_set_master_condrel_list(slv_system_t sys,struct rel_relation **rlist,
548 int size)
549 {
550 SFUN(sys->condrels.master);
551 sys->condrels.mnum = size;
552 sys->condrels.master = rlist;
553 }
554
555 void slv_set_master_obj_list(slv_system_t sys,struct rel_relation **rlist,
556 int size)
557 {
558 SFUN(sys->objs.master);
559 sys->objs.mnum = size;
560 sys->objs.master = rlist;
561 }
562
563 void slv_set_master_logrel_list(slv_system_t sys,
564 struct logrel_relation **lrlist,
565 int size)
566 {
567 SFUN(sys->logrels.master);
568 sys->logrels.mnum = size;
569 sys->logrels.master = lrlist;
570 }
571
572 void slv_set_master_condlogrel_list(slv_system_t sys,
573 struct logrel_relation **lrlist,
574 int size)
575 {
576 SFUN(sys->condlogrels.master);
577 sys->condlogrels.mnum = size;
578 sys->condlogrels.master = lrlist;
579 }
580
581 void slv_set_master_when_list(slv_system_t sys,
582 struct w_when **wlist,
583 int size)
584 {
585 SFUN(sys->whens.master);
586 sys->whens.mnum = size;
587 sys->whens.master = wlist;
588 }
589
590 void slv_set_master_bnd_list(slv_system_t sys,
591 struct bnd_boundary **blist,
592 int size)
593 {
594 SFUN(sys->bnds.master);
595 sys->bnds.mnum = size;
596 sys->bnds.master = blist;
597 }
598
599 void slv_set_symbol_list(slv_system_t sys,
600 struct gl_list_t *sv)
601 {
602 if (sys->symbollist != NULL) {
603 DestroySymbolValuesList(sys->symbollist);
604 }
605 sys->symbollist = sv;
606 }
607
608 void slv_set_var_buf(slv_system_t sys, struct var_variable *vbuf)
609 {
610 if (sys->data.vbuf !=NULL ) {
611 Asc_Panic(2,"slv_set_var_buf",
612 "ERROR: bad call to slv_set_var_buf. Bye!\n");
613 } else {
614 sys->data.vbuf = vbuf;
615 }
616 }
617
618
619 void slv_set_par_buf(slv_system_t sys, struct var_variable *pbuf)
620 {
621 if (sys->data.pbuf !=NULL ) {
622 Asc_Panic(2,"slv_set_par_buf",
623 "ERROR: bad call to slv_set_par_buf. Bye!\n");
624 } else {
625 sys->data.pbuf = pbuf;
626 }
627 }
628
629 void slv_set_unattached_buf(slv_system_t sys, struct var_variable *ubuf)
630 {
631 if (sys->data.ubuf !=NULL ) {
632 Asc_Panic(2,"slv_set_unattached_buf",
633 "ERROR: bad call to slv_set_unattached_buf. Bye!\n");
634 } else {
635 sys->data.ubuf = ubuf;
636 }
637 }
638
639 void slv_set_dvar_buf(slv_system_t sys, struct dis_discrete *dbuf, int len)
640 {
641 if (sys->data.dbuf !=NULL ) {
642 Asc_Panic(2,"slv_set_dvar_buf",
643 "ERROR: bad call to slv_set_dvar_buf. Bye!\n");
644 } else {
645 sys->data.dbuf = dbuf;
646 g_number_of_dvars = len;
647 }
648 }
649
650
651 void slv_set_disunatt_buf(slv_system_t sys, struct dis_discrete *udbuf)
652 {
653 if (sys->data.udbuf !=NULL ) {
654 Asc_Panic(2,"slv_set_disunatt_buf",
655 "ERROR: bad call to slv_set_disunatt_buf. Bye!\n");
656 } else {
657 sys->data.udbuf = udbuf;
658 }
659 }
660
661 void slv_set_rel_buf(slv_system_t sys, struct rel_relation *rbuf)
662 {
663 if (sys->data.rbuf !=NULL ) {
664 Asc_Panic(2,"slv_set_rel_buf",
665 "ERROR: bad call to slv_set_rel_buf. Bye!\n");
666 } else {
667 sys->data.rbuf = rbuf;
668 }
669 }
670
671
672 void slv_set_condrel_buf(slv_system_t sys, struct rel_relation *cbuf)
673 {
674 if (sys->data.cbuf !=NULL ) {
675 Asc_Panic(2,"slv_set_condrel_buf",
676 "ERROR: bad call to slv_set_condrel_buf. Bye!\n");
677 } else {
678 sys->data.cbuf = cbuf;
679 }
680 }
681
682 void slv_set_obj_buf(slv_system_t sys, struct rel_relation *obuf)
683 {
684 if (sys->data.obuf !=NULL ) {
685 Asc_Panic(2,"slv_set_obj_buf",
686 "ERROR: bad call to slv_set_obj_buf. Bye!\n");
687 } else {
688 sys->data.obuf = obuf;
689 }
690 }
691
692 void slv_set_logrel_buf(slv_system_t sys, struct logrel_relation *lbuf)
693 {
694 if (sys->data.lbuf !=NULL ) {
695 Asc_Panic(2,"slv_set_logrel_buf",
696 "ERROR: bad call to slv_set_logrel_buf. Bye!\n");
697 } else {
698 sys->data.lbuf = lbuf;
699 }
700 }
701
702
703 void slv_set_condlogrel_buf(slv_system_t sys, struct logrel_relation *clbuf)
704 {
705 if (sys->data.clbuf !=NULL ) {
706 Asc_Panic(2,"slv_set_condlogrel_buf",
707 "ERROR: bad call to slv_set_condlogrel_buf. Bye!\n");
708 } else {
709 sys->data.clbuf = clbuf;
710 }
711 }
712
713 void slv_set_when_buf(slv_system_t sys, struct w_when *wbuf, int len)
714 {
715 if (sys->data.wbuf !=NULL ) {
716 Asc_Panic(2,"slv_set_when_buf",
717 "ERROR: bad call to slv_set_when_buf. Bye!\n");
718 } else {
719 sys->data.wbuf = wbuf;
720 g_number_of_whens = len;
721 }
722 }
723
724 void slv_set_bnd_buf(slv_system_t sys, struct bnd_boundary *bbuf, int len)
725 {
726 if (sys->data.bbuf !=NULL ) {
727 Asc_Panic(2,"slv_set_bnd_buf",
728 "ERROR: bad call to slv_set_bnd_buf. Bye!\n");
729 } else {
730 sys->data.bbuf = bbuf;
731 g_number_of_bnds = len;
732 }
733 }
734
735 void slv_set_incidence(slv_system_t sys, struct var_variable **incidence,long s)
736 {
737 if (sys->data.incidence !=NULL || incidence == NULL) {
738 Asc_Panic(2,"slv_set_incidence",
739 "ERROR: bad call to slv_set_incidence. Bye!\n");
740 } else {
741 sys->data.incidence = incidence;
742 sys->data.incsize = s;
743 }
744 }
745
746 void slv_set_var_incidence(slv_system_t sys, struct rel_relation **varincidence,long s)
747 {
748 if (sys->data.varincidence !=NULL || varincidence == NULL) {
749 Asc_Panic(2,"slv_set_varincidence",
750 "ERROR: bad call to slv_set_incidence. Bye!\n");
751 } else {
752 sys->data.varincidence = varincidence;
753 sys->data.varincsize = s;
754 }
755 }
756
757 void slv_set_logincidence(slv_system_t sys, struct dis_discrete **logincidence,
758 long s)
759 {
760 if (sys->data.logincidence !=NULL) {
761 Asc_Panic(2,"slv_set_logincidence",
762 "ERROR: bad call to slv_set_logincidence. Bye!\n");
763 } else {
764 sys->data.logincidence = logincidence;
765 sys->data.incsize = s;
766 }
767 }
768
769 void slv_set_extrel_list(slv_system_t sys,struct ExtRelCache **erlist,
770 int size)
771 {
772 if (sys->extrels.erlist !=NULL ) {
773 Asc_Panic(2,"slv_set_extrel_list",
774 "ERROR: bad call to slv_set_extrel_list. Bye!\n");
775 }
776 sys->extrels.num_extrels = size;
777 sys->extrels.erlist = erlist;
778 }
779
780 struct ExtRelCache **slv_get_extrel_list(slv_system_t sys)
781 {
782 return sys->extrels.erlist;
783 }
784
785 int slv_get_num_extrels(slv_system_t sys)
786 {
787 return sys->extrels.num_extrels;
788 }
789
790
791 /*********************************************************************\
792 client functions.
793 \*********************************************************************/
794 int Solv_C_CheckHalt()
795 {
796 if (Solv_C_CheckHalt_Flag)
797 return 1;
798 else
799 return 0;
800 }
801
802 const char *slv_solver_name(int index)
803 {
804 static char errname[] = "ErrorSolver";
805 if (index >= 0 && index < NORC) {
806 if ( SFI(index,name) == NULL ) {
807 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_solver_name called with nameless index\n");
808 return errname;
809 } else {
810 return SFI(index,name);
811 }
812 } else {
813 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_solver_name called with unregistered index");
814 return errname;
815 }
816 }
817
818 const mtx_block_t *slv_get_solvers_blocks(slv_system_t sys)
819 {
820 if (sys == NULL) {
821 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_get_solvers_blocks called with NULL system");
822 return NULL;
823 } else {
824 return &(sys->dof.blocks);
825 }
826 }
827
828 const mtx_block_t *slv_get_solvers_log_blocks(slv_system_t sys)
829 {
830 if (sys == NULL) {
831 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_get_solvers_log_blocks called with NULL system");
832 return NULL;
833 } else {
834 return &(sys->logdof.blocks);
835 }
836 }
837
838 void slv_set_solvers_blocks(slv_system_t sys,int len, mtx_region_t *data)
839 {
840 if (sys == NULL || len < 0) {
841 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_blocks called with NULL system or bad len.\n");
842 } else {
843 if (len && data==NULL) {
844 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_blocks called with bad data.\n");
845 } else {
846 if (sys->dof.blocks.nblocks && sys->dof.blocks.block != NULL) {
847 ascfree(sys->dof.blocks.block);
848 }
849 sys->dof.blocks.block = data;
850 sys->dof.blocks.nblocks = len;
851 }
852 }
853 }
854
855 void slv_set_solvers_log_blocks(slv_system_t sys,int len, mtx_region_t *data)
856 {
857 if (sys == NULL || len < 0) {
858 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_log_blocks called with NULL system or bad len\n");
859 } else {
860 if (len && data==NULL) {
861 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_log_blocks called with bad data.\n");
862 } else {
863 if (sys->logdof.blocks.nblocks && sys->logdof.blocks.block != NULL) {
864 ascfree(sys->logdof.blocks.block);
865 }
866 sys->logdof.blocks.block = data;
867 sys->logdof.blocks.nblocks = len;
868 }
869 }
870 }
871
872 void slv_check_var_initialization(slv_system_t sys){
873 struct var_variable **vp;
874 for (vp = slv_get_solvers_var_list(sys); *vp != NULL; vp++) {
875 if (!AtomAssigned((struct Instance *)var_instance(*vp))) {
876 var_set_value(*vp,var_nominal(*vp));
877 }
878 }
879 }
880
881 void slv_check_dvar_initialization(slv_system_t sys)
882 {
883 struct dis_discrete **vp;
884
885 for (vp = slv_get_solvers_dvar_list(sys); *vp != NULL; vp++) {
886 if (!AtomAssigned((struct Instance *)dis_instance(*vp))) {
887 dis_set_boolean_value(*vp,1);
888 }
889 }
890 }
891
892
893 void slv_bnd_initialization(slv_system_t sys)
894 {
895 struct bnd_boundary **bp;
896 int32 value;
897
898 for (bp = slv_get_solvers_bnd_list(sys); *bp != NULL; bp++) {
899 value = bndman_calc_satisfied(*bp);
900 bnd_set_cur_status(*bp,value);
901 bnd_set_pre_status(*bp,value);
902 bnd_set_crossed(*bp,FALSE);
903 if (bnd_kind(*bp) == e_bnd_rel) {
904 value = bndman_calc_at_zero(*bp);
905 bnd_set_at_zero(*bp,value);
906 } else {
907 bnd_set_at_zero(*bp,FALSE);
908 }
909 }
910 }
911
912
913 void slv_set_solvers_var_list(slv_system_t sys,
914 struct var_variable **vlist, int size)
915 {
916 if (sys->vars.master == NULL) {
917 FPRINTF(stderr,
918 "slv_set_solvers_var_list called before slv_set_master_var_list\n");
919 return; /* must be error */
920 }
921 sys->vars.snum = size;
922 sys->vars.solver = vlist;
923 }
924
925
926 void slv_set_solvers_par_list(slv_system_t sys,
927 struct var_variable **vlist, int size)
928 {
929 if (sys->pars.master == NULL ) {
930 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_set_solvers_par_list called before slv_set_master_par_list");
931 } /* might be ok */
932 sys->pars.snum = size;
933 sys->pars.solver = vlist;
934 }
935
936 void slv_set_solvers_unattached_list(slv_system_t sys,
937 struct var_variable **vlist, int size)
938 {
939 if (sys->unattached.master == NULL) {
940 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_set_solvers_unattached_list called before slv_set_master_unattached_list");
941 } /* might be ok */
942 sys->unattached.snum = size;
943 sys->unattached.solver = vlist;
944 }
945
946 void slv_set_solvers_dvar_list(slv_system_t sys,
947 struct dis_discrete **dlist, int size)
948 {
949 if (sys->dvars.master == NULL) {
950 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_dvar_list called before slv_set_master_dvar_list");
951 return; /* must be error */
952 }
953 sys->dvars.snum = size;
954 sys->dvars.solver = dlist;
955 }
956
957 void slv_set_solvers_disunatt_list(slv_system_t sys,
958 struct dis_discrete **dlist, int size)
959 {
960 if (sys->disunatt.master == NULL) {
961 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_set_solvers_disunatt_list called before slv_set_master_disunatt_list");
962 } /* might be ok */
963 sys->disunatt.snum = size;
964 sys->disunatt.solver = dlist;
965 }
966
967 void slv_set_solvers_rel_list(slv_system_t sys,
968 struct rel_relation **rlist, int size)
969 {
970 /* Give relation list to the system itself. */
971 if (sys->rels.master == NULL) {
972 error_reporter(ASC_PROG_ERROR,NULL,0,"slv_set_solvers_rel_list called before slv_set_master_rel_list");
973 return; /* can't be right */
974 }
975 sys->rels.snum = size;
976 sys->rels.solver = rlist;
977 }
978
979
980 void slv_set_solvers_obj_list(slv_system_t sys,
981 struct rel_relation **rlist, int size)
982 {
983 /* Give relation list to the system itself. */
984 if (sys->objs.master == NULL) {
985 FPRINTF(stderr,
986 "slv_set_solvers_obj_list called before slv_set_master_rel_list\n");
987 return;
988 }
989 sys->objs.snum = size;
990 sys->objs.solver = rlist;
991 }
992
993 void slv_set_solvers_condrel_list(slv_system_t sys,
994 struct rel_relation **rlist, int size)
995 {
996 /* Give relation list to the system itself. */
997 if (sys->condrels.master == NULL) {
998 FPRINTF(stderr,"%s %s\n",
999 "slv_set_solvers_condrel_list called before",
1000 "slv_set_master_condrel_list");
1001 return;
1002 }
1003 sys->condrels.snum = size;
1004 sys->condrels.solver = rlist;
1005 }
1006
1007
1008 void slv_set_solvers_logrel_list(slv_system_t sys,
1009 struct logrel_relation **lrlist, int size)
1010 {
1011 /* Give logrelation list to the system itself. */
1012 if (sys->logrels.master == NULL) {
1013 FPRINTF(stderr,
1014 "slv_set_solvers_logrel_list called before slv_set_master_logrel_list\n");
1015 return; /* can't be right */
1016 }
1017 sys->logrels.snum = size;
1018 sys->logrels.solver = lrlist;
1019 }
1020
1021 void slv_set_solvers_condlogrel_list(slv_system_t sys,
1022 struct logrel_relation **lrlist, int size)
1023 {
1024 /* Give logrelation list to the system itself. */
1025 if (sys->condlogrels.master == NULL) {
1026 FPRINTF(stderr,
1027 "slv_set_solvers_condlogrel_list called before slv_set_master_logrel_list\n");
1028 return; /* can't be right */
1029 }
1030 sys->condlogrels.snum = size;
1031 sys->condlogrels.solver = lrlist;
1032 }
1033
1034 void slv_set_solvers_when_list(slv_system_t sys,
1035 struct w_when **wlist, int size)
1036 {
1037 if (sys->whens.master == NULL) {
1038 FPRINTF(stderr,
1039 "slv_set_solvers_when_list called before slv_set_master_when_list\n");
1040 return;
1041 }
1042 sys->whens.snum = size;
1043 sys->whens.solver = wlist;
1044 }
1045
1046 void slv_set_solvers_bnd_list(slv_system_t sys,
1047 struct bnd_boundary **blist, int size)
1048 {
1049 if (sys->bnds.master == NULL) {
1050 FPRINTF(stderr,
1051 "slv_set_solvers_bnd_list called before slv_set_master_bnd_list\n");
1052 return;
1053 }
1054 sys->bnds.snum = size;
1055 sys->bnds.solver = blist;
1056 }
1057
1058 struct var_variable **slv_get_solvers_var_list(slv_system_t sys)
1059 {
1060 if (sys->vars.solver == NULL) {
1061 FPRINTF(stderr,"slv_get_solvers_var_list returning NULL?\n");
1062 }
1063 return sys->vars.solver;
1064 }
1065
1066 struct var_variable **slv_get_solvers_par_list(slv_system_t sys)
1067 {
1068 if (sys->pars.solver == NULL) {
1069 FPRINTF(stderr,"slv_get_solvers_par_list returning NULL?\n");
1070 }
1071 return sys->pars.solver;
1072 }
1073
1074 struct var_variable **slv_get_solvers_unattached_list(slv_system_t sys)
1075 {
1076 if (sys->unattached.solver == NULL) {
1077 FPRINTF(stderr,"slv_get_solvers_unattached_list returning NULL?\n");
1078 }
1079 return sys->unattached.solver;
1080 }
1081
1082 struct dis_discrete **slv_get_solvers_dvar_list(slv_system_t sys)
1083 {
1084 if (sys->dvars.solver == NULL) {
1085 FPRINTF(stderr,"dvar_list is NULL\n");
1086 }
1087 return sys->dvars.solver;
1088 }
1089
1090 struct dis_discrete **slv_get_solvers_disunatt_list(slv_system_t sys)
1091 {
1092 if (sys->disunatt.solver == NULL) {
1093 FPRINTF(stderr,"slv_get_solvers_disunatt_list returning NULL?\n");
1094 }
1095 return sys->disunatt.solver;
1096 }
1097
1098 struct var_variable **slv_get_master_var_list(slv_system_t sys)
1099 {
1100 if (sys->vars.master == NULL) {
1101 FPRINTF(stderr,"slv_get_master_var_list returning NULL?\n");
1102 }
1103 return sys->vars.master;
1104 }
1105
1106
1107 struct var_variable **slv_get_master_par_list(slv_system_t sys)
1108 {
1109 if (sys->pars.master == NULL) {
1110 FPRINTF(stderr,"slv_get_master_par_list returning NULL?\n");
1111 }
1112 return sys->pars.master;
1113 }
1114
1115 struct var_variable **slv_get_master_unattached_list(slv_system_t sys)
1116 {
1117 if (sys->unattached.master == NULL) {
1118 FPRINTF(stderr,"slv_get_solvers_unattached_list returning NULL?\n");
1119 }
1120 return sys->unattached.master;
1121 }
1122
1123 struct dis_discrete **slv_get_master_dvar_list(slv_system_t sys)
1124 {
1125 if (sys->dvars.master == NULL) {
1126 FPRINTF(stderr,"dvar_list is NULL\n");
1127 }
1128 return sys->dvars.master;
1129 }
1130
1131 struct dis_discrete **slv_get_master_disunatt_list(slv_system_t sys)
1132 {
1133 if (sys->disunatt.master == NULL) {
1134 FPRINTF(stderr,"slv_get_solvers_disunatt_list returning NULL?\n");
1135 }
1136 return sys->disunatt.master;
1137 }
1138
1139 struct rel_relation **slv_get_solvers_rel_list(slv_system_t sys)
1140 {
1141 if (sys->rels.solver == NULL) {
1142 FPRINTF(stderr, "slv_get_solvers_rel_list returning NULL?\n");
1143 }
1144 return sys->rels.solver;
1145 }
1146
1147 struct rel_relation **slv_get_solvers_condrel_list(slv_system_t sys)
1148 {
1149 if (sys->condrels.solver == NULL) {
1150 FPRINTF(stderr, "condrel_list is NULL?\n");
1151 }
1152 return sys->condrels.solver;
1153 }
1154
1155 struct rel_relation **slv_get_solvers_obj_list(slv_system_t sys)
1156 {
1157 if (sys->objs.solver == NULL) {
1158 FPRINTF(stderr, "slv_get_solvers_obj_list returning NULL?\n");
1159 }
1160 return sys->objs.solver;
1161 }
1162
1163 struct logrel_relation **slv_get_solvers_logrel_list(slv_system_t sys)
1164 {
1165 if (sys->logrels.solver == NULL) {
1166 FPRINTF(stderr, "logrel_list is NULL\n");
1167 }
1168 return sys->logrels.solver;
1169 }
1170
1171 struct logrel_relation **slv_get_solvers_condlogrel_list(slv_system_t sys)
1172 {
1173 if (sys->condlogrels.solver == NULL) {
1174 FPRINTF(stderr, "logrel_list is NULL\n");
1175 }
1176 return sys->condlogrels.solver;
1177 }
1178
1179 struct w_when **slv_get_solvers_when_list(slv_system_t sys)
1180 {
1181 if (sys->whens.solver == NULL) {
1182 FPRINTF(stderr, "when_list is NULL\n");
1183 }
1184 return sys->whens.solver;
1185 }
1186
1187 struct bnd_boundary **slv_get_solvers_bnd_list(slv_system_t sys)
1188 {
1189 if (sys->bnds.solver == NULL) {
1190 FPRINTF(stderr, "bnd_list is NULL\n");
1191 }
1192 return sys->bnds.solver;
1193 }
1194
1195 struct rel_relation **slv_get_master_rel_list(slv_system_t sys)
1196 {
1197 if (sys->rels.master == NULL) {
1198 FPRINTF(stderr, "slv_get_master_rel_list returning NULL?\n");
1199 }
1200 return sys->rels.master;
1201 }
1202
1203
1204 struct rel_relation **slv_get_master_condrel_list(slv_system_t sys)
1205 {
1206 if (sys->condrels.master == NULL) {
1207 FPRINTF(stderr, "condrel_list is NULL\n");
1208 }
1209 return sys->condrels.master;
1210 }
1211
1212 struct rel_relation **slv_get_master_obj_list(slv_system_t sys)
1213 {
1214 if (sys->objs.master == NULL) {
1215 FPRINTF(stderr, "slv_get_master_obj_list returning NULL?\n");
1216 }
1217 return sys->objs.master;
1218 }
1219
1220
1221 struct logrel_relation **slv_get_master_logrel_list(slv_system_t sys)
1222 {
1223 if (sys->logrels.master == NULL) {
1224 FPRINTF(stderr, "logrel_list is NULL\n");
1225 }
1226 return sys->logrels.master;
1227 }
1228
1229 struct logrel_relation **slv_get_master_condlogrel_list(slv_system_t sys)
1230 {
1231 if (sys->condlogrels.master == NULL) {
1232 FPRINTF(stderr, "logrel_list is NULL\n");
1233 }
1234 return sys->condlogrels.master;
1235 }
1236
1237
1238 struct w_when **slv_get_master_when_list(slv_system_t sys)
1239 {
1240 if (sys->whens.master == NULL) {
1241 FPRINTF(stderr, "when_list is NULL\n");
1242 }
1243 return sys->whens.master;
1244 }
1245
1246 struct bnd_boundary **slv_get_master_bnd_list(slv_system_t sys)
1247 {
1248 if (sys->bnds.master == NULL) {
1249 FPRINTF(stderr, "bnd_list is NULL\n");
1250 }
1251 return sys->bnds.master;
1252 }
1253
1254 struct gl_list_t *slv_get_symbol_list(slv_system_t sys)
1255 {
1256 if (sys==NULL) {
1257 FPRINTF(stderr,"slv_get_symbol_list called with NULL system.\n");
1258 return NULL;
1259 }
1260 return sys->symbollist;
1261 }
1262
1263
1264 int slv_get_num_solvers_vars(slv_system_t sys)
1265 {
1266 if (sys==NULL) {
1267 FPRINTF(stderr,"slv_get_num_solvers_vars called with NULL system.\n");
1268 return 0;
1269 }
1270 return sys->vars.snum;
1271 }
1272
1273
1274 int slv_get_num_solvers_pars(slv_system_t sys)
1275 {
1276 if (sys==NULL) {
1277 FPRINTF(stderr,"slv_get_num_solvers_pars called with NULL system.\n");
1278 return 0;
1279 }
1280 return sys->pars.snum;
1281 }
1282
1283 int slv_get_num_solvers_unattached(slv_system_t sys)
1284 {
1285 if (sys==NULL) {
1286 FPRINTF(stderr,"slv_get_num_solvers_unattached called with NULL system.\n");
1287 return 0;
1288 }
1289 return sys->unattached.snum;
1290 }
1291
1292 int slv_get_num_solvers_dvars(slv_system_t sys)
1293 {
1294 if (sys==NULL) {
1295 FPRINTF(stderr,"slv_get_num_solvers_dvars called with NULL system.\n");
1296 return 0;
1297 }
1298 return sys->dvars.snum;
1299 }
1300
1301 int slv_get_num_solvers_disunatt(slv_system_t sys)
1302 {
1303 if (sys==NULL) {
1304 FPRINTF(stderr,"slv_get_num_solvers_disunatt called with NULL system.\n");
1305 return 0;
1306 }
1307 return sys->disunatt.snum;
1308 }
1309
1310
1311 int slv_get_num_solvers_rels(slv_system_t sys)
1312 {
1313 if (sys==NULL) {
1314 FPRINTF(stderr,"slv_get_num_solvers_rels called with NULL system.\n");
1315 return 0;
1316 }
1317 return sys->rels.snum;
1318 }
1319
1320
1321 int slv_get_num_solvers_condrels(slv_system_t sys)
1322 {
1323 if (sys==NULL) {
1324 FPRINTF(stderr,"slv_get_num_solvers_condrels called with NULL system.\n");
1325 return 0;
1326 }
1327 return sys->condrels.snum;
1328 }
1329
1330 int slv_get_num_solvers_objs(slv_system_t sys)
1331 {
1332 if (sys==NULL) {
1333 FPRINTF(stderr,"slv_get_num_solvers_objs called with NULL system.\n");
1334 return 0;
1335 }
1336 return sys->objs.snum;
1337 }
1338
1339 int slv_get_num_solvers_logrels(slv_system_t sys)
1340 {
1341 if (sys==NULL) {
1342 FPRINTF(stderr,"slv_get_num_solvers_logrels called with NULL system.\n");
1343 return 0;
1344 }
1345 return sys->logrels.snum;
1346 }
1347
1348 int slv_get_num_solvers_condlogrels(slv_system_t sys)
1349 {
1350 if (sys==NULL) {
1351 FPRINTF(stderr,
1352 "slv_get_num_solvers_condlogrels called with NULL system.\n");
1353 return 0;
1354 }
1355 return sys->condlogrels.snum;
1356 }
1357
1358 int slv_get_num_solvers_whens(slv_system_t sys)
1359 {
1360 if (sys==NULL) {
1361 FPRINTF(stderr,"slv_get_num_solvers_whens called with NULL system.\n");
1362 return 0;
1363 }
1364 return sys->whens.snum;
1365 }
1366
1367 int slv_get_num_solvers_bnds(slv_system_t sys)
1368 {
1369 if (sys==NULL) {
1370 FPRINTF(stderr,"slv_get_num_solvers_bnds called with NULL system.\n");
1371 return 0;
1372 }
1373 return sys->bnds.snum;
1374 }
1375
1376 int slv_get_num_master_vars(slv_system_t sys)
1377 {
1378 if (sys==NULL) {
1379 FPRINTF(stderr,"slv_get_num_master_vars called with NULL system.\n");
1380 return 0;
1381 }
1382 return sys->vars.mnum;
1383 }
1384
1385
1386 int slv_get_num_master_pars(slv_system_t sys)
1387 {
1388 if (sys==NULL) {
1389 FPRINTF(stderr,"slv_get_num_master_pars called with NULL system.\n");
1390 return 0;
1391 }
1392 return sys->pars.mnum;
1393 }
1394 int slv_get_num_master_unattached(slv_system_t sys)
1395 {
1396 if (sys==NULL) {
1397 FPRINTF(stderr,"slv_get_num_master_unattached called with NULL system.\n");
1398 return 0;
1399 }
1400 return sys->unattached.mnum;
1401 }
1402
1403 int slv_get_num_master_dvars(slv_system_t sys)
1404 {
1405 if (sys==NULL) {
1406 FPRINTF(stderr,"slv_get_num_master_dvars called with NULL system.\n");
1407 return 0;
1408 }
1409 return sys->dvars.mnum;
1410 }
1411
1412 int slv_get_num_master_disunatt(slv_system_t sys)
1413 {
1414 if (sys==NULL) {
1415 FPRINTF(stderr,"slv_get_num_master_disunatt called with NULL system.\n");
1416 return 0;
1417 }
1418 return sys->disunatt.mnum;
1419 }
1420
1421 int slv_get_num_master_rels(slv_system_t sys)
1422 {
1423 if (sys==NULL) {
1424 FPRINTF(stderr,"slv_get_num_master_rels called with NULL system.\n");
1425 return 0;
1426 }
1427 return sys->rels.mnum;
1428 }
1429
1430
1431 int slv_get_num_master_condrels(slv_system_t sys)
1432 {
1433 if (sys==NULL) {
1434 FPRINTF(stderr,"slv_get_num_master_condrels called with NULL system.\n");
1435 return 0;
1436 }
1437 return sys->condrels.mnum;
1438 }
1439
1440 int slv_get_num_master_objs(slv_system_t sys)
1441 {
1442 if (sys==NULL) {
1443 FPRINTF(stderr,"slv_get_num_master_objs called with NULL system.\n");
1444 return 0;
1445 }
1446 return sys->objs.mnum;
1447 }
1448
1449 int slv_get_num_master_logrels(slv_system_t sys)
1450 {
1451 if (sys==NULL) {
1452 FPRINTF(stderr,"slv_get_num_master_logrels called with NULL system.\n");
1453 return 0;
1454 }
1455 return sys->logrels.mnum;
1456 }
1457
1458 int slv_get_num_master_condlogrels(slv_system_t sys)
1459 {
1460 if (sys==NULL) {
1461 FPRINTF(stderr,
1462 "slv_get_num_master_logrels called with NULL system.\n");
1463 return 0;
1464 }
1465 return sys->condlogrels.mnum;
1466 }
1467
1468 int slv_get_num_master_whens(slv_system_t sys)
1469 {
1470 if (sys==NULL) {
1471 FPRINTF(stderr,"slv_get_num_master_whens called with NULL system.\n");
1472 return 0;
1473 }
1474 return sys->whens.mnum;
1475 }
1476
1477 int slv_get_num_master_bnds(slv_system_t sys)
1478 {
1479 if (sys==NULL) {
1480 FPRINTF(stderr,"slv_get_num_master_bnds called with NULL system.\n");
1481 return 0;
1482 }
1483 return sys->bnds.mnum;
1484 }
1485
1486 void slv_set_obj_relation(slv_system_t sys,struct rel_relation *obj)
1487 {
1488 if (sys==NULL) {
1489 FPRINTF(stderr,"slv_set_obj_relation called with NULL system.\n");
1490 return;
1491 }
1492 sys->obj = obj;
1493 }
1494
1495 struct rel_relation *slv_get_obj_relation(slv_system_t sys)
1496 {
1497 if (sys==NULL) {
1498 FPRINTF(stderr,"slv_get_obj_relation called with NULL system.\n");
1499 return NULL;
1500 }
1501 return sys->obj;
1502 }
1503
1504 void slv_set_obj_variable(slv_system_t sys,struct var_variable *objvar,
1505 unsigned maximize)
1506 {
1507 if (sys==NULL) {
1508 FPRINTF(stderr,"slv_set_obj_variable called with NULL system.\n");
1509 return;
1510 }
1511 sys->objvar = objvar;
1512 if (objvar!=NULL) {
1513 if (maximize) {
1514 sys->objvargrad = -1;
1515 } else {
1516 sys->objvargrad = 1;
1517 }
1518 } else {
1519 sys->objvargrad = 0;
1520 }
1521 }
1522
1523 struct var_variable *slv_get_obj_variable(slv_system_t sys)
1524 {
1525 if (sys==NULL) {
1526 FPRINTF(stderr,"slv_get_obj_variable called with NULL system.\n");
1527 return NULL;
1528 }
1529 return sys->objvar;
1530 }
1531
1532 real64 slv_get_obj_variable_gradient(slv_system_t sys)
1533 {
1534 if (sys==NULL) {
1535 FPRINTF(stderr,"slv_get_obj_variable_gradient called with NULL system.\n");
1536 return 0.0;
1537 }
1538 return sys->objvargrad;
1539 }
1540
1541
1542 void slv_set_need_consistency(slv_system_t sys, int32 need_consistency)
1543 {
1544 if (sys==NULL) {
1545 FPRINTF(stderr,"slv_set_need_consistency called with NULL system.\n");
1546 return;
1547 }
1548
1549 sys->need_consistency = need_consistency;
1550 }
1551
1552
1553 int32 slv_need_consistency(slv_system_t sys)
1554 {
1555 if (sys==NULL) {
1556 FPRINTF(stderr,"slv_need_consistency called with NULL system.\n");
1557 return 0;
1558 }
1559 return sys->need_consistency;
1560 }
1561
1562 /* dont call this with null! */
1563 static int slv_count_vars(var_filter_t *vfilter, struct var_variable **vlist)
1564 {
1565 int ret = 0;
1566 assert(vlist!=NULL);
1567 while(*vlist!=NULL) {
1568 ret += var_apply_filter(*vlist,vfilter);
1569 vlist++;
1570 }
1571 return ret;
1572 }
1573
1574 /* dont call this with null! */
1575 static int slv_count_rels(rel_filter_t *rfilter, struct rel_relation **rlist)
1576 {
1577 int ret = 0;
1578 assert(rlist!=NULL);
1579 while(*rlist!=NULL) {
1580 ret += rel_apply_filter(*rlist,rfilter);
1581 rlist++;
1582 }
1583 return ret;
1584 }
1585
1586 /* dont call this with null! */
1587 static int slv_count_dvars(dis_filter_t *disfilter,
1588 struct dis_discrete **dlist)
1589 {
1590 int ret = 0;
1591 assert(dlist!=NULL);
1592 while(*dlist!=NULL) {
1593 ret += dis_apply_filter(*dlist,disfilter);
1594 dlist++;
1595 }
1596 return ret;
1597 }
1598
1599 /* dont call this with null! */
1600 static int slv_count_logrels(logrel_filter_t *lrfilter,
1601 struct logrel_relation **lrlist)
1602 {
1603 int ret = 0;
1604 assert(lrlist!=NULL);
1605 while(*lrlist!=NULL) {
1606 ret += logrel_apply_filter(*lrlist,lrfilter);
1607 lrlist++;
1608 }
1609 return ret;
1610 }
1611
1612 /* dont call this with null! */
1613 static int slv_count_whens(when_filter_t *wfilter,struct w_when **wlist)
1614 {
1615 int ret = 0;
1616 assert(wlist!=NULL);
1617 while(*wlist!=NULL) {
1618 ret += when_apply_filter(*wlist,wfilter);
1619 wlist++;
1620 }
1621 return ret;
1622 }
1623
1624 /* dont call this with null! */
1625 static int slv_count_bnds(bnd_filter_t *bfilter,struct bnd_boundary **blist)
1626 {
1627 int ret = 0;
1628 assert(blist!=NULL);
1629 while(*blist!=NULL) {
1630 ret += bnd_apply_filter(*blist,bfilter);
1631 blist++;
1632 }
1633 return ret;
1634 }
1635
1636 int slv_count_solvers_vars(slv_system_t sys, var_filter_t *vf)
1637 {
1638 if (sys==NULL || sys->vars.solver == NULL || vf == NULL) {
1639 FPRINTF(stderr,"slv_count_solvers_vars called with NULL\n");
1640 return 0;
1641 }
1642 return slv_count_vars(vf,sys->vars.solver);
1643 }
1644
1645
1646 int slv_count_solvers_pars(slv_system_t sys, var_filter_t *vf)
1647 {
1648 if (sys==NULL || sys->pars.solver == NULL || vf == NULL) {
1649 FPRINTF(stderr,"slv_count_solvers_pars called with NULL\n");
1650 return 0;
1651 }
1652 return slv_count_vars(vf,sys->pars.solver);
1653 }
1654
1655 int slv_count_solvers_unattached(slv_system_t sys, var_filter_t *vf)
1656 {
1657 if (sys==NULL || sys->unattached.solver == NULL || vf == NULL) {
1658 FPRINTF(stderr,"slv_count_solvers_unattached called with NULL\n");
1659 return 0;
1660 }
1661 return slv_count_vars(vf,sys->unattached.solver);
1662 }
1663
1664 int slv_count_solvers_dvars(slv_system_t sys, dis_filter_t *dvf)
1665 {
1666 if (sys==NULL || sys->dvars.solver == NULL || dvf == NULL) {
1667 FPRINTF(stderr,"slv_count_solvers_dvars called with NULL\n");
1668 return 0;
1669 }
1670 return slv_count_dvars(dvf,sys->dvars.solver);
1671 }
1672
1673 int slv_count_solvers_disunatt(slv_system_t sys, dis_filter_t *dvf)
1674 {
1675 if (sys==NULL || sys->disunatt.solver == NULL || dvf == NULL) {
1676 FPRINTF(stderr,"slv_count_solvers_disunatt called with NULL\n");
1677 return 0;
1678 }
1679 return slv_count_dvars(dvf,sys->disunatt.solver);
1680 }
1681
1682 int slv_count_solvers_rels(slv_system_t sys, rel_filter_t *rf)
1683 {
1684 if (sys==NULL || sys->rels.solver == NULL || rf == NULL) {
1685 FPRINTF(stderr,"slv_count_solvers_rels called with NULL\n");
1686 return 0;
1687 }
1688 return slv_count_rels(rf,sys->rels.solver);
1689 }
1690
1691
1692 int slv_count_solvers_condrels(slv_system_t sys, rel_filter_t *rf)
1693 {
1694 if (sys==NULL || sys->condrels.solver == NULL || rf == NULL) {
1695 FPRINTF(stderr,"slv_count_solvers_condrels called with NULL\n");
1696 return 0;
1697 }
1698 return slv_count_rels(rf,sys->condrels.solver);
1699 }
1700
1701 int slv_count_solvers_objs(slv_system_t sys, rel_filter_t *rf)
1702 {
1703 if (sys==NULL || sys->objs.solver == NULL || rf == NULL) {
1704 FPRINTF(stderr,"slv_count_solvers_objs called with NULL\n");
1705 return 0;
1706 }
1707 return slv_count_rels(rf,sys->objs.solver);
1708 }
1709
1710 int slv_count_solvers_logrels(slv_system_t sys, logrel_filter_t *lrf)
1711 {
1712 if (sys==NULL || sys->logrels.solver == NULL || lrf == NULL) {
1713 FPRINTF(stderr,"slv_count_solvers_logrels called with NULL\n");
1714 return 0;
1715 }
1716 return slv_count_logrels(lrf,sys->logrels.solver);
1717 }
1718
1719
1720 int slv_count_solvers_condlogrels(slv_system_t sys, logrel_filter_t *lrf)
1721 {
1722 if (sys==NULL || sys->condlogrels.solver == NULL || lrf == NULL) {
1723 FPRINTF(stderr,"slv_count_solvers_condlogrels called with NULL\n");
1724 return 0;
1725 }
1726 return slv_count_logrels(lrf,sys->condlogrels.solver);
1727 }
1728
1729 int slv_count_solvers_whens(slv_system_t sys, when_filter_t *wf)
1730 {
1731 if (sys==NULL || sys->whens.solver == NULL || wf == NULL) {
1732 FPRINTF(stderr,"slv_count_solvers_whens called with NULL\n");
1733 return 0;
1734 }
1735 return slv_count_whens(wf,sys->whens.solver);
1736 }
1737
1738 int slv_count_solvers_bnds(slv_system_t sys, bnd_filter_t *bf)
1739 {
1740 if (sys==NULL || sys->bnds.solver == NULL || bf == NULL) {
1741 FPRINTF(stderr,"slv_count_solvers_bnds called with NULL\n");
1742 return 0;
1743 }
1744 return slv_count_bnds(bf,sys->bnds.solver);
1745 }
1746
1747 int slv_count_master_vars(slv_system_t sys, var_filter_t *vf)
1748 {
1749 if (sys==NULL || sys->vars.master == NULL || vf == NULL) {
1750 FPRINTF(stderr,"slv_count_master_vars called with NULL\n");
1751 return 0;
1752 }
1753 return slv_count_vars(vf,sys->vars.master);
1754 }
1755
1756
1757 int slv_count_master_pars(slv_system_t sys, var_filter_t *vf)
1758 {
1759 if (sys==NULL || sys->pars.master == NULL || vf == NULL) {
1760 FPRINTF(stderr,"slv_count_master_pars called with NULL\n");
1761 return 0;
1762 }
1763 return slv_count_vars(vf,sys->pars.master);
1764 }
1765
1766 int slv_count_master_unattached(slv_system_t sys, var_filter_t *vf)
1767 {
1768 if (sys==NULL || sys->unattached.master == NULL || vf == NULL) {
1769 FPRINTF(stderr,"slv_count_master_unattached called with NULL\n");
1770 return 0;
1771 }
1772 return slv_count_vars(vf,sys->unattached.master);
1773 }
1774
1775 int slv_count_master_dvars(slv_system_t sys, dis_filter_t *dvf)
1776 {
1777 if (sys==NULL || sys->dvars.master == NULL || dvf == NULL) {
1778 FPRINTF(stderr,"slv_count_master_dvars called with NULL\n");
1779 return 0;
1780 }
1781 return slv_count_dvars(dvf,sys->dvars.master);
1782 }
1783
1784 int slv_count_master_disunatt(slv_system_t sys, dis_filter_t *dvf)
1785 {
1786 if (sys==NULL || sys->disunatt.master == NULL || dvf == NULL) {
1787 FPRINTF(stderr,"slv_count_master_disunatt called with NULL\n");
1788 return 0;
1789 }
1790 return slv_count_dvars(dvf,sys->disunatt.master);
1791 }
1792
1793 int slv_count_master_rels(slv_system_t sys, rel_filter_t *rf)
1794 {
1795 if (sys==NULL || sys->rels.master == NULL || rf == NULL) {
1796 FPRINTF(stderr,"slv_count_master_rels called with NULL\n");
1797 return 0;
1798 }
1799 return slv_count_rels(rf,sys->rels.master);
1800 }
1801
1802 int slv_count_master_condrels(slv_system_t sys, rel_filter_t *rf)
1803 {
1804 if (sys==NULL || sys->condrels.master == NULL || rf == NULL) {
1805 FPRINTF(stderr,"slv_count_master_rels called with NULL\n");
1806 return 0;
1807 }
1808 return slv_count_rels(rf,sys->condrels.master);
1809 }
1810
1811 int slv_count_master_objs(slv_system_t sys, rel_filter_t *rf)
1812 {
1813 if (sys==NULL || sys->objs.master == NULL || rf == NULL) {
1814 FPRINTF(stderr,"slv_count_master_objs called with NULL\n");
1815 return 0;
1816 }
1817 return slv_count_rels(rf,sys->objs.master);
1818 }
1819
1820 int slv_count_master_logrels(slv_system_t sys, logrel_filter_t *lrf)
1821 {
1822 if (sys==NULL || sys->logrels.master == NULL || lrf == NULL) {
1823 FPRINTF(stderr,"slv_count_master_logrels called with NULL\n");
1824 return 0;
1825 }
1826 return slv_count_logrels(lrf,sys->logrels.master);
1827 }
1828
1829 int slv_count_master_condlogrels(slv_system_t sys, logrel_filter_t *lrf)
1830 {
1831 if (sys==NULL || sys->condlogrels.master == NULL || lrf == NULL) {
1832 FPRINTF(stderr,"slv_count_master_condlogrels called with NULL\n");
1833 return 0;
1834 }
1835 return slv_count_logrels(lrf,sys->condlogrels.master);
1836 }
1837
1838 int slv_count_master_whens(slv_system_t sys, when_filter_t *wf)
1839 {
1840 if (sys==NULL || sys->whens.master == NULL || wf == NULL) {
1841 FPRINTF(stderr,"slv_count_master_whens called with NULL\n");
1842 return 0;
1843 }
1844 return slv_count_whens(wf,sys->whens.master);
1845 }
1846
1847 int slv_count_master_bnds(slv_system_t sys, bnd_filter_t *bf)
1848 {
1849 if (sys==NULL || sys->bnds.master == NULL || bf == NULL) {
1850 FPRINTF(stderr,"slv_count_master_bnds called with NULL\n");
1851 return 0;
1852 }
1853 return slv_count_bnds(bf,sys->bnds.master);
1854 }
1855
1856 static void printwarning(const char * fname, slv_system_t sys)
1857 {
1858 FPRINTF(stderr,
1859 "WARNING: %s called with bad registered client (%s).\n",fname,
1860 slv_solver_name(sys->solver));
1861 }
1862
1863 static void printinfo(slv_system_t sys, const char *rname)
1864 {
1865 if (CF(sys,name) == NULL ) {
1866 FPRINTF(stderr,
1867 "INFORMATION: Client %s does not support function %s\n",
1868 slv_solver_name(sys->solver),rname);
1869 }
1870 }
1871
1872 int slv_eligible_solver(slv_system_t sys)
1873 {
1874 if ( CF(sys,celigible) == NULL ) {
1875 printwarning("slv_eligible_solver",sys);
1876 return 0;
1877 }
1878 return SF(sys,celigible)(sys);
1879 }
1880
1881
1882
1883 int slv_select_solver(slv_system_t sys,int solver)
1884 {
1885 int status_index;
1886 if (sys ==NULL) {
1887 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_select_solver called with NULL system\n");
1888 return -1;
1889 }
1890 if (LSI(solver)) {
1891 if (sys->ct != NULL && solver != sys->solver) {
1892 if ( CF(sys,cdestroy) != NULL) {
1893 SF(sys,cdestroy)(sys,sys->ct);
1894 sys->ct = NULL;
1895 } else {
1896 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_select_solver destroy failed due to bad client %s\n",
1897 slv_solver_name(sys->solver));
1898 return sys->solver;
1899 }
1900 }
1901 if (sys->ct != NULL) {
1902 return sys->solver;
1903 }
1904 status_index = solver;
1905 sys->solver = solver;
1906 if ( CF(sys,ccreate) != NULL) {
1907 sys->ct = SF(sys,ccreate)(sys,&status_index);
1908 } else {
1909 FPRINTF(stderr,
1910 "ERROR: slv_select_solver create failed due to bad client %s\n",
1911 slv_solver_name(sys->solver));
1912 return sys->solver;
1913 }
1914 if (sys->ct==NULL) {
1915 error_reporter(ASC_PROG_WARNING,NULL,0,"SlvClientCreate failed in slv_select_solver\n");
1916 sys->solver = -1;
1917 } else {
1918 if (status_index) {
1919 error_reporter(ASC_PROG_WARNING,NULL,0,"SlvClientCreate succeeded with warning %d %s\n",
1920 status_index," in slv_select_solver");
1921 }
1922 /* we could do a better job explaining the client warnings... */
1923 sys->solver = solver;
1924 }
1925 } else {
1926 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_select_solver called with unknown client (%d)\n",
1927 solver);
1928 return -1;
1929 }
1930 return sys->solver;
1931 }
1932
1933
1934 int slv_switch_solver(slv_system_t sys,int solver)
1935 {
1936 int status_index;
1937
1938 if (sys ==NULL) {
1939 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_switch_solver called with NULL system\n");
1940 return -1;
1941 }
1942 if (LSI(solver)) {
1943 status_index = solver;
1944 sys->solver = solver;
1945 if ( CF(sys,ccreate) != NULL) {
1946 sys->ct = SF(sys,ccreate)(sys,&status_index);
1947 } else {
1948 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_switch_solver create failed due to bad client %s\n",
1949 slv_solver_name(sys->solver));
1950 return sys->solver;
1951 }
1952 if (sys->ct==NULL) {
1953 FPRINTF(stderr,"ERROR: SlvClientCreate failed in slv_switch_solver\n");
1954 sys->solver = -1;
1955 } else {
1956 if (status_index) {
1957 error_reporter(ASC_PROG_WARNING,NULL,0,"SlvClientCreate succeeded with warning %d %s\n",
1958 status_index," in slv_switch_solver");
1959 }
1960 sys->solver = solver;
1961 }
1962 } else {
1963 error_reporter(ASC_PROG_WARNING,NULL,0,"slv_switch_solver called with unknown client (%d)\n",solver);
1964 return -1;
1965 }
1966 return sys->solver;
1967 }
1968
1969 void slv_set_char_parameter(char **cp, char *newvalue)
1970 {
1971 if (cp != NULL) {
1972 if (*cp != NULL) {
1973 ascfree(*cp);
1974 }
1975 *cp = ascstrdup(newvalue);
1976 }
1977 }
1978
1979 void slv_destroy_parms(slv_parameters_t *p) {
1980 int32 i,n,j;
1981 for (i = 0; i < p->num_parms; i++) {
1982 switch(p->parms[i].type) {
1983 case char_parm:
1984 ascfree(p->parms[i].info.c.value);
1985 for (j = 0; j < p->parms[i].info.c.high; j++) {
1986 ascfree(p->parms[i].info.c.argv[j]);
1987 }
1988 ascfree(p->parms[i].info.c.argv);
1989 /* FALL THROUGH */
1990 case int_parm:
1991 case bool_parm:
1992 case real_parm:
1993 ascfree(p->parms[i].name);
1994 ascfree(p->parms[i].interface_label);
1995 ascfree(p->parms[i].description);
1996 break;
1997 default:
1998 error_reporter(ASC_PROG_WARNING,NULL,0,"Unrecognized parameter type in slv_destroy_parms\n");
1999 }
2000 }
2001 if (p->parms && p->dynamic_parms) {
2002 ascfree(p->parms);
2003 }
2004 }
2005
2006 int32 slv_define_parm(slv_parameters_t *p,
2007 enum parm_type type,
2008 char *name,
2009 char *interface_label,
2010 char *description,
2011 union parm_arg value,
2012 union parm_arg low,
2013 union parm_arg high,
2014 int32 display)
2015 {
2016 int32 len,length,i, err=1;
2017 if (p == NULL) {
2018 return -1;
2019 }
2020 length = p->num_parms;
2021
2022 switch (type) {
2023 case int_parm:
2024 err = 0;
2025 p->parms[length].info.i.value = value.argi;
2026 p->parms[length].info.i.low = low.argi;
2027 p->parms[length].info.i.high = high.argi;
2028 break;
2029
2030 case bool_parm:
2031 err = 0;
2032 p->parms[length].info.b.value = value.argb;
2033 p->parms[length].info.b.low = low.argb;
2034 p->parms[length].info.b.high = high.argb;
2035 break;
2036
2037 case real_parm:
2038 err = 0;
2039 p->parms[length].info.r.value = value.argr;
2040 p->parms[length].info.r.low = low.argr;
2041 p->parms[length].info.r.high = high.argr;
2042 break;
2043
2044 case char_parm:
2045 err = 0;
2046 p->parms[length].info.c.argv =
2047 (char **)ascmalloc(high.argi*sizeof(char *));
2048 for (i = 0; i < high.argi; i++) {
2049 len = strlen(low.argv[i]);
2050 p->parms[length].info.c.argv[i] =(char *)ascmalloc(len+1*sizeof(char));
2051 strcpy(p->parms[length].info.c.argv[i],low.argv[i]);
2052 }
2053
2054 p->parms[length].info.c.value =
2055 (char *)ascmalloc(strlen(value.argc)+1*sizeof(char));
2056 strcpy(p->parms[length].info.c.value,value.argc);
2057
2058 p->parms[length].info.c.high = high.argi;
2059 break;
2060
2061 default:
2062 return -1;
2063 }
2064 if (!err) {
2065 p->parms[length].type = type;
2066 p->parms[length].number = length;
2067
2068 len = strlen(name);
2069 p->parms[length].name = (char *)ascmalloc(len+1*sizeof(char));
2070 strcpy(p->parms[length].name,name);
2071
2072 len = strlen(interface_label);
2073 p->parms[length].interface_label = (char *)ascmalloc(len+1*sizeof(char));
2074 strcpy(p->parms[length].interface_label,interface_label);
2075
2076 len = strlen(description);
2077 p->parms[length].description = (char *)ascmalloc(len+1*sizeof(char));
2078 strcpy(p->parms[length].description,description);
2079
2080 p->parms[length].display = display;
2081 } else {
2082 p->parms[length].type = -1;
2083 }
2084 p->num_parms++;
2085 return p->num_parms;
2086 }
2087
2088 int slv_get_selected_solver(slv_system_t sys)
2089 {
2090 if (sys!=NULL) return sys->solver;
2091 return -1;
2092 }
2093
2094 int32 slv_get_default_parameters(int index,
2095 slv_parameters_t *parameters)
2096 {
2097 if (index >= 0 && index < NORC) {
2098 if ( SFI(index,getdefparam) == NULL ) {
2099 FPRINTF(stderr,"ERROR: slv_get_default_parameters called with parameterless index\n");
2100 return 0;
2101 } else {
2102 /* send NULL system when setting up interface */
2103 SFI(index,getdefparam)(NULL,NULL,parameters);
2104 return 1;
2105 }
2106 } else {
2107 FPRINTF(stderr,"ERROR: slv_get_default_parameters called with unregistered index\n");
2108 return 0;
2109 }
2110 }
2111
2112 void slv_get_parameters(slv_system_t sys,slv_parameters_t *parameters)
2113 {
2114 if ( CF(sys,getparam) == NULL ) {
2115 printwarning("slv_get_parameters",sys);
2116 return;
2117 }
2118 SF(sys,getparam)(sys,sys->ct,parameters);
2119 }
2120
2121
2122 void slv_set_parameters(slv_system_t sys,slv_parameters_t *parameters)
2123 {
2124 if ( CF(sys,setparam) == NULL ) {
2125 printwarning("slv_set_parameters",sys);
2126 return;
2127 }
2128 if (parameters->whose != sys->solver) {
2129 FPRINTF(stderr,"ERROR: slv_set_parameters can give parameters from %s",
2130 "one client to a different client\n");
2131 return;
2132 }
2133 SF(sys,setparam)(sys,sys->ct,parameters);
2134 }
2135
2136 void slv_get_status(slv_system_t sys, slv_status_t *status)
2137 {
2138 if ( CF(sys,getstatus) == NULL ) {
2139 printwarning("slv_get_status",sys);
2140 return;
2141 }
2142 SF(sys,getstatus)(sys,sys->ct,status);
2143 }
2144
2145 linsol_system_t slv_get_linsol_sys(slv_system_t sys)
2146 {
2147 if (CF(sys,getlinsol) == NULL ) {
2148 printinfo(sys,"slv_get_linsol_sys");
2149 return NULL;
2150 }
2151 return SF(sys,getlinsol)(sys,sys->ct);
2152 }
2153
2154 mtx_matrix_t slv_get_sys_mtx(slv_system_t sys)
2155 {
2156 if (CF(sys,getsysmtx) == NULL ) {
2157 printinfo(sys,"slv_get_sys_mtx");
2158 return NULL;
2159 }
2160 return SF(sys,getsysmtx)(sys,sys->ct);
2161 }
2162
2163 linsolqr_system_t slv_get_linsolqr_sys(slv_system_t sys)
2164 {
2165 if (CF(sys,getlinsys) == NULL ) {
2166 printinfo(sys,"slv_get_linsolqr_sys");
2167 return NULL;
2168 }
2169 return SF(sys,getlinsys)(sys,sys->ct);
2170 }
2171
2172 void slv_dump_internals(slv_system_t sys,int level)
2173 {
2174 if (CF(sys,dumpinternals) == NULL ) {
2175 printinfo(sys,"slv_dump_internals");
2176 return;
2177 }
2178 SF(sys,dumpinternals)(sys,sys->ct,level);
2179 }
2180
2181 void slv_presolve(slv_system_t sys)
2182 {
2183 if ( CF(sys,presolve) == NULL ) {
2184 printwarning("slv_presolve",sys);
2185 return;
2186 }
2187 SF(sys,presolve)(sys,sys->ct);
2188 }
2189
2190 void slv_resolve(slv_system_t sys)
2191 {
2192 if ( CF(sys,resolve) == NULL ) {
2193 printwarning("slv_resolve",sys);
2194 return;
2195 }
2196 SF(sys,resolve)(sys,sys->ct);
2197 }
2198
2199 void slv_iterate(slv_system_t sys)
2200 {
2201 if ( CF(sys,iterate) == NULL ) {
2202 printwarning("slv_iterate",sys);
2203 return;
2204 }
2205 SF(sys,iterate)(sys,sys->ct);
2206 }
2207
2208 void slv_solve(slv_system_t sys)
2209 {
2210 if ( CF(sys,solve) == NULL ) {
2211 printwarning("slv_solve",sys);
2212 return;
2213 }
2214 SF(sys,solve)(sys,sys->ct);
2215 }
2216
2217
2218 SlvClientToken slv_get_client_token(slv_system_t sys)
2219 {
2220 if (sys==NULL) {
2221 FPRINTF(stderr,"slv_get_client_token called with NULL system.\n");
2222 return NULL;
2223 }
2224 return sys->ct;
2225 }
2226
2227
2228 void slv_set_client_token(slv_system_t sys, SlvClientToken ct)
2229 {
2230 if (sys==NULL) {
2231 FPRINTF(stderr,"slv_set_client_token called with NULL system.\n");
2232 return;
2233 }
2234 sys->ct = ct;
2235 }
2236
2237 void slv_set_solver_index(slv_system_t sys, int solver)
2238 {
2239 if (sys==NULL) {
2240 FPRINTF(stderr,"slv_set_solver_index called with NULL system.\n");
2241 return;
2242 }
2243 sys->solver = solver;
2244 }
2245
2246 /*********************************************************************\
2247 unregistered client functions that need to go elsewhere(other files).
2248 hereunder are utility calls which are unstandardized
2249 \*********************************************************************/
2250
2251 boolean slv_change_basis(slv_system_t sys, int32 var, mtx_range_t *rng)
2252 {
2253 (void)sys;
2254 (void)var;
2255 (void)rng;
2256 Asc_Panic(2, "slv_change_basis", "fix me");
2257 return 0;
2258 }
2259
2260 /*
2261 * This routine is provided as the start of some report generation
2262 * capabilities. It operates off the main solve system and
2263 * writes out the relation residuals and variable values for
2264 * the entire problem to the named file.
2265 * Isn't very bright.
2266 */
2267
2268 void slv_print_output(FILE *out, slv_system_t sys)
2269 {
2270 struct rel_relation **rp;
2271 struct var_variable **vp;
2272 int nrels, nvars,c;
2273
2274 vp = slv_get_master_var_list(sys);
2275 nvars = slv_get_num_master_vars(sys);
2276 FPRINTF(out,"%-6s %-12s\n",
2277 "INDEX","LEVEL");
2278 for (c=0; c<nvars; c++) {
2279 FPRINTF(out," % -6d % -12.8e\n",c, var_value(vp[c]));
2280 }
2281 PUTC('\n',out);
2282
2283 rp = slv_get_master_rel_list(sys);
2284 nrels = slv_get_num_master_rels(sys);
2285 FPRINTF(out,"%-6s %-12s\n",
2286 "INDEX","RESDUAL");
2287 for (c=0; c<nrels; c++) {
2288 FPRINTF(out," % -6d % -12.8e\n",c, rel_residual(rp[c]));
2289 }
2290 }
2291
2292 int32 slv_obj_select_list(slv_system_t sys,int32 **rip)
2293 {
2294 int32 len,count,i, *ra;
2295 static rel_filter_t rfilter;
2296 struct rel_relation **rlist=NULL;
2297 len = slv_get_num_solvers_objs(sys);
2298 ra = *rip = (int32 *)ascmalloc((len+1)*sizeof(int32 *));
2299 rfilter.matchbits = (REL_INCLUDED);
2300 rfilter.matchvalue =(REL_INCLUDED);
2301 rlist = slv_get_solvers_obj_list(sys);
2302 count = 0;
2303 for (i = 0; i < len; i++) {
2304 if (rel_apply_filter(rlist[i],&rfilter)) {
2305 ra[count] = i;
2306 count++;
2307 }
2308 }
2309 ra[count] = -1;
2310 return count;
2311 }
2312
2313 int32 slv_get_obj_num(slv_system_t sys)
2314 {
2315 int32 len,i;
2316 struct rel_relation *obj;
2317 struct rel_relation **rlist=NULL;
2318 len = slv_get_num_solvers_objs(sys);
2319 rlist = slv_get_solvers_obj_list(sys);
2320 obj = slv_get_obj_relation(sys);
2321 if (obj != NULL) {
2322 for (i = 0; i < len; i++) {
2323 if (rlist[i] == obj) {
2324 return i;
2325 }
2326 }
2327 }
2328 return -1;
2329 }
2330
2331 int32 slv_near_bounds(slv_system_t sys,real64 epsilon,
2332 int32 **vip)
2333 {
2334 int32 len,i, *va, index;
2335 real64 comp;
2336 static var_filter_t vfilter;
2337 struct var_variable **vlist=NULL;
2338 len = slv_get_num_solvers_vars(sys);
2339 va = *vip = (int32 *)ascmalloc((2*len+2)*sizeof(int32 *));
2340 vfilter.matchbits = (VAR_FIXED | VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2341 vfilter.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2342 vlist = slv_get_solvers_var_list(sys);
2343 va[0] = va[1] = 0;
2344 index = 2;
2345 for (i = 0; i < len; i++) {
2346 if (var_apply_filter(vlist[i],&vfilter)) {
2347 comp = (var_value(vlist[i]) - var_lower_bound(vlist[i]))
2348 / var_nominal(vlist[i]);
2349 if (comp < epsilon) {
2350 va[index] = i;
2351 index++;
2352 va[0]++;
2353 }
2354 }
2355 }
2356 for (i = 0; i < len; i++) {
2357 if (var_apply_filter(vlist[i],&vfilter)) {
2358 comp = (var_upper_bound(vlist[i]) - var_value(vlist[i]))
2359 / var_nominal(vlist[i]);
2360 if (comp < epsilon) {
2361 va[index] = i;
2362 index++;
2363 va[1]++;
2364 }
2365 }
2366 }
2367 return index - 2;
2368 }
2369
2370 int32 slv_far_from_nominals(slv_system_t sys,real64 bignum,
2371 int32 **vip)
2372 {
2373 int32 len,i, *va, index;
2374 real64 comp;
2375 static var_filter_t vfilter;
2376 struct var_variable **vlist=NULL;
2377 len = slv_get_num_solvers_vars(sys);
2378 va = *vip = (int32 *)ascmalloc((len+1)*sizeof(int32 *));
2379 vfilter.matchbits = (VAR_FIXED | VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2380 vfilter.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2381 vlist = slv_get_solvers_var_list(sys);
2382 index = 0;
2383 for (i = 0; i < len; i++) {
2384 if (var_apply_filter(vlist[i],&vfilter)) {
2385 comp = fabs(var_value(vlist[i]) - var_nominal(vlist[i]))
2386 / var_nominal(vlist[i]);
2387 if (comp > bignum) {
2388 va[index] = i;
2389 index++;
2390 }
2391 }
2392 }
2393 return index;
2394 }
2395

Properties

Name Value
svn:executable *

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