/[ascend]/trunk/ascend4/solver/slv.c
ViewVC logotype

Contents of /trunk/ascend4/solver/slv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (17 years, 7 months ago) by aw0a
File MIME type: text/x-csrc
File size: 62739 byte(s)
Setting up web subdirectory in repository
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 FPRINTF(stderr,"ERROR: slv_solver_name called with nameless index\n");
808 return errname;
809 } else {
810 return SFI(index,name);
811 }
812 } else {
813 FPRINTF(stderr,"ERROR: slv_solver_name called with unregistered index\n");
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 FPRINTF(stderr,"ERROR: slv_get_solvers_blocks called with NULL system\n");
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 FPRINTF(stderr,
832 "ERROR: slv_get_solvers_log_blocks called with NULL system\n");
833 return NULL;
834 } else {
835 return &(sys->logdof.blocks);
836 }
837 }
838
839 void slv_set_solvers_blocks(slv_system_t sys,int len, mtx_region_t *data)
840 {
841 if (sys == NULL || len < 0) {
842 FPRINTF(stderr,
843 "ERROR: slv_set_solvers_blocks called with NULL system or bad len.\n");
844 } else {
845 if (len && data==NULL) {
846 FPRINTF(stderr,"ERROR: slv_set_solvers_blocks called with bad data.\n");
847 } else {
848 if (sys->dof.blocks.nblocks && sys->dof.blocks.block != NULL) {
849 ascfree(sys->dof.blocks.block);
850 }
851 sys->dof.blocks.block = data;
852 sys->dof.blocks.nblocks = len;
853 }
854 }
855 }
856
857 void slv_set_solvers_log_blocks(slv_system_t sys,int len, mtx_region_t *data)
858 {
859 if (sys == NULL || len < 0) {
860 FPRINTF(stderr,
861 "ERROR:slv_set_solvers_log_blocks called with NULL system or bad len\n");
862 } else {
863 if (len && data==NULL) {
864 FPRINTF(stderr,
865 "ERROR: slv_set_solvers_log_blocks called with bad data.\n");
866 } else {
867 if (sys->logdof.blocks.nblocks && sys->logdof.blocks.block != NULL) {
868 ascfree(sys->logdof.blocks.block);
869 }
870 sys->logdof.blocks.block = data;
871 sys->logdof.blocks.nblocks = len;
872 }
873 }
874 }
875
876 void slv_check_var_initialization(slv_system_t sys){
877 struct var_variable **vp;
878 for (vp = slv_get_solvers_var_list(sys); *vp != NULL; vp++) {
879 if (!AtomAssigned((struct Instance *)var_instance(*vp))) {
880 var_set_value(*vp,var_nominal(*vp));
881 }
882 }
883 }
884
885 void slv_check_dvar_initialization(slv_system_t sys)
886 {
887 struct dis_discrete **vp;
888
889 for (vp = slv_get_solvers_dvar_list(sys); *vp != NULL; vp++) {
890 if (!AtomAssigned((struct Instance *)dis_instance(*vp))) {
891 dis_set_boolean_value(*vp,1);
892 }
893 }
894 }
895
896
897 void slv_bnd_initialization(slv_system_t sys)
898 {
899 struct bnd_boundary **bp;
900 int32 value;
901
902 for (bp = slv_get_solvers_bnd_list(sys); *bp != NULL; bp++) {
903 value = bndman_calc_satisfied(*bp);
904 bnd_set_cur_status(*bp,value);
905 bnd_set_pre_status(*bp,value);
906 bnd_set_crossed(*bp,FALSE);
907 if (bnd_kind(*bp) == e_bnd_rel) {
908 value = bndman_calc_at_zero(*bp);
909 bnd_set_at_zero(*bp,value);
910 } else {
911 bnd_set_at_zero(*bp,FALSE);
912 }
913 }
914 }
915
916
917 void slv_set_solvers_var_list(slv_system_t sys,
918 struct var_variable **vlist, int size)
919 {
920 if (sys->vars.master == NULL) {
921 FPRINTF(stderr,
922 "slv_set_solvers_var_list called before slv_set_master_var_list\n");
923 return; /* must be error */
924 }
925 sys->vars.snum = size;
926 sys->vars.solver = vlist;
927 }
928
929
930 void slv_set_solvers_par_list(slv_system_t sys,
931 struct var_variable **vlist, int size)
932 {
933 if (sys->pars.master == NULL ) {
934 FPRINTF(stderr,
935 "slv_set_solvers_par_list called before slv_set_master_par_list\n");
936 } /* might be ok */
937 sys->pars.snum = size;
938 sys->pars.solver = vlist;
939 }
940
941 void slv_set_solvers_unattached_list(slv_system_t sys,
942 struct var_variable **vlist, int size)
943 {
944 if (sys->unattached.master == NULL) {
945 FPRINTF(stderr,"%s %s\n","slv_set_solvers_unattached_list called",
946 "before slv_set_master_unattached_list");
947 } /* might be ok */
948 sys->unattached.snum = size;
949 sys->unattached.solver = vlist;
950 }
951
952 void slv_set_solvers_dvar_list(slv_system_t sys,
953 struct dis_discrete **dlist, int size)
954 {
955 if (sys->dvars.master == NULL) {
956 FPRINTF(stderr,
957 "slv_set_solvers_dvar_list called before slv_set_master_dvar_list\n");
958 return; /* must be error */
959 }
960 sys->dvars.snum = size;
961 sys->dvars.solver = dlist;
962 }
963
964 void slv_set_solvers_disunatt_list(slv_system_t sys,
965 struct dis_discrete **dlist, int size)
966 {
967 if (sys->disunatt.master == NULL) {
968 FPRINTF(stderr,"%s %s\n","slv_set_solvers_disunatt_list called",
969 "before slv_set_master_disunatt_list");
970 } /* might be ok */
971 sys->disunatt.snum = size;
972 sys->disunatt.solver = dlist;
973 }
974
975 void slv_set_solvers_rel_list(slv_system_t sys,
976 struct rel_relation **rlist, int size)
977 {
978 /* Give relation list to the system itself. */
979 if (sys->rels.master == NULL) {
980 FPRINTF(stderr,
981 "slv_set_solvers_rel_list called before slv_set_master_rel_list\n");
982 return; /* can't be right */
983 }
984 sys->rels.snum = size;
985 sys->rels.solver = rlist;
986 }
987
988
989 void slv_set_solvers_obj_list(slv_system_t sys,
990 struct rel_relation **rlist, int size)
991 {
992 /* Give relation list to the system itself. */
993 if (sys->objs.master == NULL) {
994 FPRINTF(stderr,
995 "slv_set_solvers_obj_list called before slv_set_master_rel_list\n");
996 return;
997 }
998 sys->objs.snum = size;
999 sys->objs.solver = rlist;
1000 }
1001
1002 void slv_set_solvers_condrel_list(slv_system_t sys,
1003 struct rel_relation **rlist, int size)
1004 {
1005 /* Give relation list to the system itself. */
1006 if (sys->condrels.master == NULL) {
1007 FPRINTF(stderr,"%s %s\n",
1008 "slv_set_solvers_condrel_list called before",
1009 "slv_set_master_condrel_list");
1010 return;
1011 }
1012 sys->condrels.snum = size;
1013 sys->condrels.solver = rlist;
1014 }
1015
1016
1017 void slv_set_solvers_logrel_list(slv_system_t sys,
1018 struct logrel_relation **lrlist, int size)
1019 {
1020 /* Give logrelation list to the system itself. */
1021 if (sys->logrels.master == NULL) {
1022 FPRINTF(stderr,
1023 "slv_set_solvers_logrel_list called before slv_set_master_logrel_list\n");
1024 return; /* can't be right */
1025 }
1026 sys->logrels.snum = size;
1027 sys->logrels.solver = lrlist;
1028 }
1029
1030 void slv_set_solvers_condlogrel_list(slv_system_t sys,
1031 struct logrel_relation **lrlist, int size)
1032 {
1033 /* Give logrelation list to the system itself. */
1034 if (sys->condlogrels.master == NULL) {
1035 FPRINTF(stderr,
1036 "slv_set_solvers_condlogrel_list called before slv_set_master_logrel_list\n");
1037 return; /* can't be right */
1038 }
1039 sys->condlogrels.snum = size;
1040 sys->condlogrels.solver = lrlist;
1041 }
1042
1043 void slv_set_solvers_when_list(slv_system_t sys,
1044 struct w_when **wlist, int size)
1045 {
1046 if (sys->whens.master == NULL) {
1047 FPRINTF(stderr,
1048 "slv_set_solvers_when_list called before slv_set_master_when_list\n");
1049 return;
1050 }
1051 sys->whens.snum = size;
1052 sys->whens.solver = wlist;
1053 }
1054
1055 void slv_set_solvers_bnd_list(slv_system_t sys,
1056 struct bnd_boundary **blist, int size)
1057 {
1058 if (sys->bnds.master == NULL) {
1059 FPRINTF(stderr,
1060 "slv_set_solvers_bnd_list called before slv_set_master_bnd_list\n");
1061 return;
1062 }
1063 sys->bnds.snum = size;
1064 sys->bnds.solver = blist;
1065 }
1066
1067 struct var_variable **slv_get_solvers_var_list(slv_system_t sys)
1068 {
1069 if (sys->vars.solver == NULL) {
1070 FPRINTF(stderr,"slv_get_solvers_var_list returning NULL?\n");
1071 }
1072 return sys->vars.solver;
1073 }
1074
1075 struct var_variable **slv_get_solvers_par_list(slv_system_t sys)
1076 {
1077 if (sys->pars.solver == NULL) {
1078 FPRINTF(stderr,"slv_get_solvers_par_list returning NULL?\n");
1079 }
1080 return sys->pars.solver;
1081 }
1082
1083 struct var_variable **slv_get_solvers_unattached_list(slv_system_t sys)
1084 {
1085 if (sys->unattached.solver == NULL) {
1086 FPRINTF(stderr,"slv_get_solvers_unattached_list returning NULL?\n");
1087 }
1088 return sys->unattached.solver;
1089 }
1090
1091 struct dis_discrete **slv_get_solvers_dvar_list(slv_system_t sys)
1092 {
1093 if (sys->dvars.solver == NULL) {
1094 FPRINTF(stderr,"dvar_list is NULL\n");
1095 }
1096 return sys->dvars.solver;
1097 }
1098
1099 struct dis_discrete **slv_get_solvers_disunatt_list(slv_system_t sys)
1100 {
1101 if (sys->disunatt.solver == NULL) {
1102 FPRINTF(stderr,"slv_get_solvers_disunatt_list returning NULL?\n");
1103 }
1104 return sys->disunatt.solver;
1105 }
1106
1107 struct var_variable **slv_get_master_var_list(slv_system_t sys)
1108 {
1109 if (sys->vars.master == NULL) {
1110 FPRINTF(stderr,"slv_get_master_var_list returning NULL?\n");
1111 }
1112 return sys->vars.master;
1113 }
1114
1115
1116 struct var_variable **slv_get_master_par_list(slv_system_t sys)
1117 {
1118 if (sys->pars.master == NULL) {
1119 FPRINTF(stderr,"slv_get_master_par_list returning NULL?\n");
1120 }
1121 return sys->pars.master;
1122 }
1123
1124 struct var_variable **slv_get_master_unattached_list(slv_system_t sys)
1125 {
1126 if (sys->unattached.master == NULL) {
1127 FPRINTF(stderr,"slv_get_solvers_unattached_list returning NULL?\n");
1128 }
1129 return sys->unattached.master;
1130 }
1131
1132 struct dis_discrete **slv_get_master_dvar_list(slv_system_t sys)
1133 {
1134 if (sys->dvars.master == NULL) {
1135 FPRINTF(stderr,"dvar_list is NULL\n");
1136 }
1137 return sys->dvars.master;
1138 }
1139
1140 struct dis_discrete **slv_get_master_disunatt_list(slv_system_t sys)
1141 {
1142 if (sys->disunatt.master == NULL) {
1143 FPRINTF(stderr,"slv_get_solvers_disunatt_list returning NULL?\n");
1144 }
1145 return sys->disunatt.master;
1146 }
1147
1148 struct rel_relation **slv_get_solvers_rel_list(slv_system_t sys)
1149 {
1150 if (sys->rels.solver == NULL) {
1151 FPRINTF(stderr, "slv_get_solvers_rel_list returning NULL?\n");
1152 }
1153 return sys->rels.solver;
1154 }
1155
1156 struct rel_relation **slv_get_solvers_condrel_list(slv_system_t sys)
1157 {
1158 if (sys->condrels.solver == NULL) {
1159 FPRINTF(stderr, "condrel_list is NULL?\n");
1160 }
1161 return sys->condrels.solver;
1162 }
1163
1164 struct rel_relation **slv_get_solvers_obj_list(slv_system_t sys)
1165 {
1166 if (sys->objs.solver == NULL) {
1167 FPRINTF(stderr, "slv_get_solvers_obj_list returning NULL?\n");
1168 }
1169 return sys->objs.solver;
1170 }
1171
1172 struct logrel_relation **slv_get_solvers_logrel_list(slv_system_t sys)
1173 {
1174 if (sys->logrels.solver == NULL) {
1175 FPRINTF(stderr, "logrel_list is NULL\n");
1176 }
1177 return sys->logrels.solver;
1178 }
1179
1180 struct logrel_relation **slv_get_solvers_condlogrel_list(slv_system_t sys)
1181 {
1182 if (sys->condlogrels.solver == NULL) {
1183 FPRINTF(stderr, "logrel_list is NULL\n");
1184 }
1185 return sys->condlogrels.solver;
1186 }
1187
1188 struct w_when **slv_get_solvers_when_list(slv_system_t sys)
1189 {
1190 if (sys->whens.solver == NULL) {
1191 FPRINTF(stderr, "when_list is NULL\n");
1192 }
1193 return sys->whens.solver;
1194 }
1195
1196 struct bnd_boundary **slv_get_solvers_bnd_list(slv_system_t sys)
1197 {
1198 if (sys->bnds.solver == NULL) {
1199 FPRINTF(stderr, "bnd_list is NULL\n");
1200 }
1201 return sys->bnds.solver;
1202 }
1203
1204 struct rel_relation **slv_get_master_rel_list(slv_system_t sys)
1205 {
1206 if (sys->rels.master == NULL) {
1207 FPRINTF(stderr, "slv_get_master_rel_list returning NULL?\n");
1208 }
1209 return sys->rels.master;
1210 }
1211
1212
1213 struct rel_relation **slv_get_master_condrel_list(slv_system_t sys)
1214 {
1215 if (sys->condrels.master == NULL) {
1216 FPRINTF(stderr, "condrel_list is NULL\n");
1217 }
1218 return sys->condrels.master;
1219 }
1220
1221 struct rel_relation **slv_get_master_obj_list(slv_system_t sys)
1222 {
1223 if (sys->objs.master == NULL) {
1224 FPRINTF(stderr, "slv_get_master_obj_list returning NULL?\n");
1225 }
1226 return sys->objs.master;
1227 }
1228
1229
1230 struct logrel_relation **slv_get_master_logrel_list(slv_system_t sys)
1231 {
1232 if (sys->logrels.master == NULL) {
1233 FPRINTF(stderr, "logrel_list is NULL\n");
1234 }
1235 return sys->logrels.master;
1236 }
1237
1238 struct logrel_relation **slv_get_master_condlogrel_list(slv_system_t sys)
1239 {
1240 if (sys->condlogrels.master == NULL) {
1241 FPRINTF(stderr, "logrel_list is NULL\n");
1242 }
1243 return sys->condlogrels.master;
1244 }
1245
1246
1247 struct w_when **slv_get_master_when_list(slv_system_t sys)
1248 {
1249 if (sys->whens.master == NULL) {
1250 FPRINTF(stderr, "when_list is NULL\n");
1251 }
1252 return sys->whens.master;
1253 }
1254
1255 struct bnd_boundary **slv_get_master_bnd_list(slv_system_t sys)
1256 {
1257 if (sys->bnds.master == NULL) {
1258 FPRINTF(stderr, "bnd_list is NULL\n");
1259 }
1260 return sys->bnds.master;
1261 }
1262
1263 struct gl_list_t *slv_get_symbol_list(slv_system_t sys)
1264 {
1265 if (sys==NULL) {
1266 FPRINTF(stderr,"slv_get_symbol_list called with NULL system.\n");
1267 return NULL;
1268 }
1269 return sys->symbollist;
1270 }
1271
1272
1273 int slv_get_num_solvers_vars(slv_system_t sys)
1274 {
1275 if (sys==NULL) {
1276 FPRINTF(stderr,"slv_get_num_solvers_vars called with NULL system.\n");
1277 return 0;
1278 }
1279 return sys->vars.snum;
1280 }
1281
1282
1283 int slv_get_num_solvers_pars(slv_system_t sys)
1284 {
1285 if (sys==NULL) {
1286 FPRINTF(stderr,"slv_get_num_solvers_pars called with NULL system.\n");
1287 return 0;
1288 }
1289 return sys->pars.snum;
1290 }
1291
1292 int slv_get_num_solvers_unattached(slv_system_t sys)
1293 {
1294 if (sys==NULL) {
1295 FPRINTF(stderr,"slv_get_num_solvers_unattached called with NULL system.\n");
1296 return 0;
1297 }
1298 return sys->unattached.snum;
1299 }
1300
1301 int slv_get_num_solvers_dvars(slv_system_t sys)
1302 {
1303 if (sys==NULL) {
1304 FPRINTF(stderr,"slv_get_num_solvers_dvars called with NULL system.\n");
1305 return 0;
1306 }
1307 return sys->dvars.snum;
1308 }
1309
1310 int slv_get_num_solvers_disunatt(slv_system_t sys)
1311 {
1312 if (sys==NULL) {
1313 FPRINTF(stderr,"slv_get_num_solvers_disunatt called with NULL system.\n");
1314 return 0;
1315 }
1316 return sys->disunatt.snum;
1317 }
1318
1319
1320 int slv_get_num_solvers_rels(slv_system_t sys)
1321 {
1322 if (sys==NULL) {
1323 FPRINTF(stderr,"slv_get_num_solvers_rels called with NULL system.\n");
1324 return 0;
1325 }
1326 return sys->rels.snum;
1327 }
1328
1329
1330 int slv_get_num_solvers_condrels(slv_system_t sys)
1331 {
1332 if (sys==NULL) {
1333 FPRINTF(stderr,"slv_get_num_solvers_condrels called with NULL system.\n");
1334 return 0;
1335 }
1336 return sys->condrels.snum;
1337 }
1338
1339 int slv_get_num_solvers_objs(slv_system_t sys)
1340 {
1341 if (sys==NULL) {
1342 FPRINTF(stderr,"slv_get_num_solvers_objs called with NULL system.\n");
1343 return 0;
1344 }
1345 return sys->objs.snum;
1346 }
1347
1348 int slv_get_num_solvers_logrels(slv_system_t sys)
1349 {
1350 if (sys==NULL) {
1351 FPRINTF(stderr,"slv_get_num_solvers_logrels called with NULL system.\n");
1352 return 0;
1353 }
1354 return sys->logrels.snum;
1355 }
1356
1357 int slv_get_num_solvers_condlogrels(slv_system_t sys)
1358 {
1359 if (sys==NULL) {
1360 FPRINTF(stderr,
1361 "slv_get_num_solvers_condlogrels called with NULL system.\n");
1362 return 0;
1363 }
1364 return sys->condlogrels.snum;
1365 }
1366
1367 int slv_get_num_solvers_whens(slv_system_t sys)
1368 {
1369 if (sys==NULL) {
1370 FPRINTF(stderr,"slv_get_num_solvers_whens called with NULL system.\n");
1371 return 0;
1372 }
1373 return sys->whens.snum;
1374 }
1375
1376 int slv_get_num_solvers_bnds(slv_system_t sys)
1377 {
1378 if (sys==NULL) {
1379 FPRINTF(stderr,"slv_get_num_solvers_bnds called with NULL system.\n");
1380 return 0;
1381 }
1382 return sys->bnds.snum;
1383 }
1384
1385 int slv_get_num_master_vars(slv_system_t sys)
1386 {
1387 if (sys==NULL) {
1388 FPRINTF(stderr,"slv_get_num_master_vars called with NULL system.\n");
1389 return 0;
1390 }
1391 return sys->vars.mnum;
1392 }
1393
1394
1395 int slv_get_num_master_pars(slv_system_t sys)
1396 {
1397 if (sys==NULL) {
1398 FPRINTF(stderr,"slv_get_num_master_pars called with NULL system.\n");
1399 return 0;
1400 }
1401 return sys->pars.mnum;
1402 }
1403 int slv_get_num_master_unattached(slv_system_t sys)
1404 {
1405 if (sys==NULL) {
1406 FPRINTF(stderr,"slv_get_num_master_unattached called with NULL system.\n");
1407 return 0;
1408 }
1409 return sys->unattached.mnum;
1410 }
1411
1412 int slv_get_num_master_dvars(slv_system_t sys)
1413 {
1414 if (sys==NULL) {
1415 FPRINTF(stderr,"slv_get_num_master_dvars called with NULL system.\n");
1416 return 0;
1417 }
1418 return sys->dvars.mnum;
1419 }
1420
1421 int slv_get_num_master_disunatt(slv_system_t sys)
1422 {
1423 if (sys==NULL) {
1424 FPRINTF(stderr,"slv_get_num_master_disunatt called with NULL system.\n");
1425 return 0;
1426 }
1427 return sys->disunatt.mnum;
1428 }
1429
1430 int slv_get_num_master_rels(slv_system_t sys)
1431 {
1432 if (sys==NULL) {
1433 FPRINTF(stderr,"slv_get_num_master_rels called with NULL system.\n");
1434 return 0;
1435 }
1436 return sys->rels.mnum;
1437 }
1438
1439
1440 int slv_get_num_master_condrels(slv_system_t sys)
1441 {
1442 if (sys==NULL) {
1443 FPRINTF(stderr,"slv_get_num_master_condrels called with NULL system.\n");
1444 return 0;
1445 }
1446 return sys->condrels.mnum;
1447 }
1448
1449 int slv_get_num_master_objs(slv_system_t sys)
1450 {
1451 if (sys==NULL) {
1452 FPRINTF(stderr,"slv_get_num_master_objs called with NULL system.\n");
1453 return 0;
1454 }
1455 return sys->objs.mnum;
1456 }
1457
1458 int slv_get_num_master_logrels(slv_system_t sys)
1459 {
1460 if (sys==NULL) {
1461 FPRINTF(stderr,"slv_get_num_master_logrels called with NULL system.\n");
1462 return 0;
1463 }
1464 return sys->logrels.mnum;
1465 }
1466
1467 int slv_get_num_master_condlogrels(slv_system_t sys)
1468 {
1469 if (sys==NULL) {
1470 FPRINTF(stderr,
1471 "slv_get_num_master_logrels called with NULL system.\n");
1472 return 0;
1473 }
1474 return sys->condlogrels.mnum;
1475 }
1476
1477 int slv_get_num_master_whens(slv_system_t sys)
1478 {
1479 if (sys==NULL) {
1480 FPRINTF(stderr,"slv_get_num_master_whens called with NULL system.\n");
1481 return 0;
1482 }
1483 return sys->whens.mnum;
1484 }
1485
1486 int slv_get_num_master_bnds(slv_system_t sys)
1487 {
1488 if (sys==NULL) {
1489 FPRINTF(stderr,"slv_get_num_master_bnds called with NULL system.\n");
1490 return 0;
1491 }
1492 return sys->bnds.mnum;
1493 }
1494
1495 void slv_set_obj_relation(slv_system_t sys,struct rel_relation *obj)
1496 {
1497 if (sys==NULL) {
1498 FPRINTF(stderr,"slv_set_obj_relation called with NULL system.\n");
1499 return;
1500 }
1501 sys->obj = obj;
1502 }
1503
1504 struct rel_relation *slv_get_obj_relation(slv_system_t sys)
1505 {
1506 if (sys==NULL) {
1507 FPRINTF(stderr,"slv_get_obj_relation called with NULL system.\n");
1508 return NULL;
1509 }
1510 return sys->obj;
1511 }
1512
1513 void slv_set_obj_variable(slv_system_t sys,struct var_variable *objvar,
1514 unsigned maximize)
1515 {
1516 if (sys==NULL) {
1517 FPRINTF(stderr,"slv_set_obj_variable called with NULL system.\n");
1518 return;
1519 }
1520 sys->objvar = objvar;
1521 if (objvar!=NULL) {
1522 if (maximize) {
1523 sys->objvargrad = -1;
1524 } else {
1525 sys->objvargrad = 1;
1526 }
1527 } else {
1528 sys->objvargrad = 0;
1529 }
1530 }
1531
1532 struct var_variable *slv_get_obj_variable(slv_system_t sys)
1533 {
1534 if (sys==NULL) {
1535 FPRINTF(stderr,"slv_get_obj_variable called with NULL system.\n");
1536 return NULL;
1537 }
1538 return sys->objvar;
1539 }
1540
1541 real64 slv_get_obj_variable_gradient(slv_system_t sys)
1542 {
1543 if (sys==NULL) {
1544 FPRINTF(stderr,"slv_get_obj_variable_gradient called with NULL system.\n");
1545 return 0.0;
1546 }
1547 return sys->objvargrad;
1548 }
1549
1550
1551 void slv_set_need_consistency(slv_system_t sys, int32 need_consistency)
1552 {
1553 if (sys==NULL) {
1554 FPRINTF(stderr,"slv_set_need_consistency called with NULL system.\n");
1555 return;
1556 }
1557
1558 sys->need_consistency = need_consistency;
1559 }
1560
1561
1562 int32 slv_need_consistency(slv_system_t sys)
1563 {
1564 if (sys==NULL) {
1565 FPRINTF(stderr,"slv_need_consistency called with NULL system.\n");
1566 return 0;
1567 }
1568 return sys->need_consistency;
1569 }
1570
1571 /* dont call this with null! */
1572 static int slv_count_vars(var_filter_t *vfilter, struct var_variable **vlist)
1573 {
1574 int ret = 0;
1575 assert(vlist!=NULL);
1576 while(*vlist!=NULL) {
1577 ret += var_apply_filter(*vlist,vfilter);
1578 vlist++;
1579 }
1580 return ret;
1581 }
1582
1583 /* dont call this with null! */
1584 static int slv_count_rels(rel_filter_t *rfilter, struct rel_relation **rlist)
1585 {
1586 int ret = 0;
1587 assert(rlist!=NULL);
1588 while(*rlist!=NULL) {
1589 ret += rel_apply_filter(*rlist,rfilter);
1590 rlist++;
1591 }
1592 return ret;
1593 }
1594
1595 /* dont call this with null! */
1596 static int slv_count_dvars(dis_filter_t *disfilter,
1597 struct dis_discrete **dlist)
1598 {
1599 int ret = 0;
1600 assert(dlist!=NULL);
1601 while(*dlist!=NULL) {
1602 ret += dis_apply_filter(*dlist,disfilter);
1603 dlist++;
1604 }
1605 return ret;
1606 }
1607
1608 /* dont call this with null! */
1609 static int slv_count_logrels(logrel_filter_t *lrfilter,
1610 struct logrel_relation **lrlist)
1611 {
1612 int ret = 0;
1613 assert(lrlist!=NULL);
1614 while(*lrlist!=NULL) {
1615 ret += logrel_apply_filter(*lrlist,lrfilter);
1616 lrlist++;
1617 }
1618 return ret;
1619 }
1620
1621 /* dont call this with null! */
1622 static int slv_count_whens(when_filter_t *wfilter,struct w_when **wlist)
1623 {
1624 int ret = 0;
1625 assert(wlist!=NULL);
1626 while(*wlist!=NULL) {
1627 ret += when_apply_filter(*wlist,wfilter);
1628 wlist++;
1629 }
1630 return ret;
1631 }
1632
1633 /* dont call this with null! */
1634 static int slv_count_bnds(bnd_filter_t *bfilter,struct bnd_boundary **blist)
1635 {
1636 int ret = 0;
1637 assert(blist!=NULL);
1638 while(*blist!=NULL) {
1639 ret += bnd_apply_filter(*blist,bfilter);
1640 blist++;
1641 }
1642 return ret;
1643 }
1644
1645 int slv_count_solvers_vars(slv_system_t sys, var_filter_t *vf)
1646 {
1647 if (sys==NULL || sys->vars.solver == NULL || vf == NULL) {
1648 FPRINTF(stderr,"slv_count_solvers_vars called with NULL\n");
1649 return 0;
1650 }
1651 return slv_count_vars(vf,sys->vars.solver);
1652 }
1653
1654
1655 int slv_count_solvers_pars(slv_system_t sys, var_filter_t *vf)
1656 {
1657 if (sys==NULL || sys->pars.solver == NULL || vf == NULL) {
1658 FPRINTF(stderr,"slv_count_solvers_pars called with NULL\n");
1659 return 0;
1660 }
1661 return slv_count_vars(vf,sys->pars.solver);
1662 }
1663
1664 int slv_count_solvers_unattached(slv_system_t sys, var_filter_t *vf)
1665 {
1666 if (sys==NULL || sys->unattached.solver == NULL || vf == NULL) {
1667 FPRINTF(stderr,"slv_count_solvers_unattached called with NULL\n");
1668 return 0;
1669 }
1670 return slv_count_vars(vf,sys->unattached.solver);
1671 }
1672
1673 int slv_count_solvers_dvars(slv_system_t sys, dis_filter_t *dvf)
1674 {
1675 if (sys==NULL || sys->dvars.solver == NULL || dvf == NULL) {
1676 FPRINTF(stderr,"slv_count_solvers_dvars called with NULL\n");
1677 return 0;
1678 }
1679 return slv_count_dvars(dvf,sys->dvars.solver);
1680 }
1681
1682 int slv_count_solvers_disunatt(slv_system_t sys, dis_filter_t *dvf)
1683 {
1684 if (sys==NULL || sys->disunatt.solver == NULL || dvf == NULL) {
1685 FPRINTF(stderr,"slv_count_solvers_disunatt called with NULL\n");
1686 return 0;
1687 }
1688 return slv_count_dvars(dvf,sys->disunatt.solver);
1689 }
1690
1691 int slv_count_solvers_rels(slv_system_t sys, rel_filter_t *rf)
1692 {
1693 if (sys==NULL || sys->rels.solver == NULL || rf == NULL) {
1694 FPRINTF(stderr,"slv_count_solvers_rels called with NULL\n");
1695 return 0;
1696 }
1697 return slv_count_rels(rf,sys->rels.solver);
1698 }
1699
1700
1701 int slv_count_solvers_condrels(slv_system_t sys, rel_filter_t *rf)
1702 {
1703 if (sys==NULL || sys->condrels.solver == NULL || rf == NULL) {
1704 FPRINTF(stderr,"slv_count_solvers_condrels called with NULL\n");
1705 return 0;
1706 }
1707 return slv_count_rels(rf,sys->condrels.solver);
1708 }
1709
1710 int slv_count_solvers_objs(slv_system_t sys, rel_filter_t *rf)
1711 {
1712 if (sys==NULL || sys->objs.solver == NULL || rf == NULL) {
1713 FPRINTF(stderr,"slv_count_solvers_objs called with NULL\n");
1714 return 0;
1715 }
1716 return slv_count_rels(rf,sys->objs.solver);
1717 }
1718
1719 int slv_count_solvers_logrels(slv_system_t sys, logrel_filter_t *lrf)
1720 {
1721 if (sys==NULL || sys->logrels.solver == NULL || lrf == NULL) {
1722 FPRINTF(stderr,"slv_count_solvers_logrels called with NULL\n");
1723 return 0;
1724 }
1725 return slv_count_logrels(lrf,sys->logrels.solver);
1726 }
1727
1728
1729 int slv_count_solvers_condlogrels(slv_system_t sys, logrel_filter_t *lrf)
1730 {
1731 if (sys==NULL || sys->condlogrels.solver == NULL || lrf == NULL) {
1732 FPRINTF(stderr,"slv_count_solvers_condlogrels called with NULL\n");
1733 return 0;
1734 }
1735 return slv_count_logrels(lrf,sys->condlogrels.solver);
1736 }
1737
1738 int slv_count_solvers_whens(slv_system_t sys, when_filter_t *wf)
1739 {
1740 if (sys==NULL || sys->whens.solver == NULL || wf == NULL) {
1741 FPRINTF(stderr,"slv_count_solvers_whens called with NULL\n");
1742 return 0;
1743 }
1744 return slv_count_whens(wf,sys->whens.solver);
1745 }
1746
1747 int slv_count_solvers_bnds(slv_system_t sys, bnd_filter_t *bf)
1748 {
1749 if (sys==NULL || sys->bnds.solver == NULL || bf == NULL) {
1750 FPRINTF(stderr,"slv_count_solvers_bnds called with NULL\n");
1751 return 0;
1752 }
1753 return slv_count_bnds(bf,sys->bnds.solver);
1754 }
1755
1756 int slv_count_master_vars(slv_system_t sys, var_filter_t *vf)
1757 {
1758 if (sys==NULL || sys->vars.master == NULL || vf == NULL) {
1759 FPRINTF(stderr,"slv_count_master_vars called with NULL\n");
1760 return 0;
1761 }
1762 return slv_count_vars(vf,sys->vars.master);
1763 }
1764
1765
1766 int slv_count_master_pars(slv_system_t sys, var_filter_t *vf)
1767 {
1768 if (sys==NULL || sys->pars.master == NULL || vf == NULL) {
1769 FPRINTF(stderr,"slv_count_master_pars called with NULL\n");
1770 return 0;
1771 }
1772 return slv_count_vars(vf,sys->pars.master);
1773 }
1774
1775 int slv_count_master_unattached(slv_system_t sys, var_filter_t *vf)
1776 {
1777 if (sys==NULL || sys->unattached.master == NULL || vf == NULL) {
1778 FPRINTF(stderr,"slv_count_master_unattached called with NULL\n");
1779 return 0;
1780 }
1781 return slv_count_vars(vf,sys->unattached.master);
1782 }
1783
1784 int slv_count_master_dvars(slv_system_t sys, dis_filter_t *dvf)
1785 {
1786 if (sys==NULL || sys->dvars.master == NULL || dvf == NULL) {
1787 FPRINTF(stderr,"slv_count_master_dvars called with NULL\n");
1788 return 0;
1789 }
1790 return slv_count_dvars(dvf,sys->dvars.master);
1791 }
1792
1793 int slv_count_master_disunatt(slv_system_t sys, dis_filter_t *dvf)
1794 {
1795 if (sys==NULL || sys->disunatt.master == NULL || dvf == NULL) {
1796 FPRINTF(stderr,"slv_count_master_disunatt called with NULL\n");
1797 return 0;
1798 }
1799 return slv_count_dvars(dvf,sys->disunatt.master);
1800 }
1801
1802 int slv_count_master_rels(slv_system_t sys, rel_filter_t *rf)
1803 {
1804 if (sys==NULL || sys->rels.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->rels.master);
1809 }
1810
1811 int slv_count_master_condrels(slv_system_t sys, rel_filter_t *rf)
1812 {
1813 if (sys==NULL || sys->condrels.master == NULL || rf == NULL) {
1814 FPRINTF(stderr,"slv_count_master_rels called with NULL\n");
1815 return 0;
1816 }
1817 return slv_count_rels(rf,sys->condrels.master);
1818 }
1819
1820 int slv_count_master_objs(slv_system_t sys, rel_filter_t *rf)
1821 {
1822 if (sys==NULL || sys->objs.master == NULL || rf == NULL) {
1823 FPRINTF(stderr,"slv_count_master_objs called with NULL\n");
1824 return 0;
1825 }
1826 return slv_count_rels(rf,sys->objs.master);
1827 }
1828
1829 int slv_count_master_logrels(slv_system_t sys, logrel_filter_t *lrf)
1830 {
1831 if (sys==NULL || sys->logrels.master == NULL || lrf == NULL) {
1832 FPRINTF(stderr,"slv_count_master_logrels called with NULL\n");
1833 return 0;
1834 }
1835 return slv_count_logrels(lrf,sys->logrels.master);
1836 }
1837
1838 int slv_count_master_condlogrels(slv_system_t sys, logrel_filter_t *lrf)
1839 {
1840 if (sys==NULL || sys->condlogrels.master == NULL || lrf == NULL) {
1841 FPRINTF(stderr,"slv_count_master_condlogrels called with NULL\n");
1842 return 0;
1843 }
1844 return slv_count_logrels(lrf,sys->condlogrels.master);
1845 }
1846
1847 int slv_count_master_whens(slv_system_t sys, when_filter_t *wf)
1848 {
1849 if (sys==NULL || sys->whens.master == NULL || wf == NULL) {
1850 FPRINTF(stderr,"slv_count_master_whens called with NULL\n");
1851 return 0;
1852 }
1853 return slv_count_whens(wf,sys->whens.master);
1854 }
1855
1856 int slv_count_master_bnds(slv_system_t sys, bnd_filter_t *bf)
1857 {
1858 if (sys==NULL || sys->bnds.master == NULL || bf == NULL) {
1859 FPRINTF(stderr,"slv_count_master_bnds called with NULL\n");
1860 return 0;
1861 }
1862 return slv_count_bnds(bf,sys->bnds.master);
1863 }
1864
1865 static void printwarning(const char * fname, slv_system_t sys)
1866 {
1867 FPRINTF(stderr,
1868 "WARNING: %s called with bad registered client (%s).\n",fname,
1869 slv_solver_name(sys->solver));
1870 }
1871
1872 static void printinfo(slv_system_t sys, const char *rname)
1873 {
1874 if (CF(sys,name) == NULL ) {
1875 FPRINTF(stderr,
1876 "INFORMATION: Client %s does not support function %s\n",
1877 slv_solver_name(sys->solver),rname);
1878 }
1879 }
1880
1881 int slv_eligible_solver(slv_system_t sys)
1882 {
1883 if ( CF(sys,celigible) == NULL ) {
1884 printwarning("slv_eligible_solver",sys);
1885 return 0;
1886 }
1887 return SF(sys,celigible)(sys);
1888 }
1889
1890
1891
1892 int slv_select_solver(slv_system_t sys,int solver)
1893 {
1894 int status_index;
1895 if (sys ==NULL) {
1896 FPRINTF(stderr,"ERROR: slv_select_solver called with NULL system\n");
1897 return -1;
1898 }
1899 if (LSI(solver)) {
1900 if (sys->ct != NULL && solver != sys->solver) {
1901 if ( CF(sys,cdestroy) != NULL) {
1902 SF(sys,cdestroy)(sys,sys->ct);
1903 sys->ct = NULL;
1904 } else {
1905 FPRINTF(stderr,
1906 "ERROR: slv_select_solver destroy failed due to bad client %s\n",
1907 slv_solver_name(sys->solver));
1908 return sys->solver;
1909 }
1910 }
1911 if (sys->ct != NULL) {
1912 return sys->solver;
1913 }
1914 status_index = solver;
1915 sys->solver = solver;
1916 if ( CF(sys,ccreate) != NULL) {
1917 sys->ct = SF(sys,ccreate)(sys,&status_index);
1918 } else {
1919 FPRINTF(stderr,
1920 "ERROR: slv_select_solver create failed due to bad client %s\n",
1921 slv_solver_name(sys->solver));
1922 return sys->solver;
1923 }
1924 if (sys->ct==NULL) {
1925 FPRINTF(stderr,"ERROR: SlvClientCreate failed in slv_select_solver\n");
1926 sys->solver = -1;
1927 } else {
1928 if (status_index) {
1929 FPRINTF(stderr,
1930 "ERROR: SlvClientCreate succeeded with warning %d %s\n",
1931 status_index," in slv_select_solver");
1932 }
1933 /* we could do a better job explaining the client warnings... */
1934 sys->solver = solver;
1935 }
1936 } else {
1937 FPRINTF(stderr,
1938 "ERROR: slv_select_solver called with unknown client (%d)\n",
1939 solver);
1940 return -1;
1941 }
1942 return sys->solver;
1943 }
1944
1945
1946 int slv_switch_solver(slv_system_t sys,int solver)
1947 {
1948 int status_index;
1949
1950 if (sys ==NULL) {
1951 FPRINTF(stderr,"ERROR: slv_switch_solver called with NULL system\n");
1952 return -1;
1953 }
1954 if (LSI(solver)) {
1955 status_index = solver;
1956 sys->solver = solver;
1957 if ( CF(sys,ccreate) != NULL) {
1958 sys->ct = SF(sys,ccreate)(sys,&status_index);
1959 } else {
1960 FPRINTF(stderr,
1961 "ERROR: slv_switch_solver create failed due to bad client %s\n",
1962 slv_solver_name(sys->solver));
1963 return sys->solver;
1964 }
1965 if (sys->ct==NULL) {
1966 FPRINTF(stderr,"ERROR: SlvClientCreate failed in slv_switch_solver\n");
1967 sys->solver = -1;
1968 } else {
1969 if (status_index) {
1970 FPRINTF(stderr,
1971 "ERROR: SlvClientCreate succeeded with warning %d %s\n",
1972 status_index," in slv_switch_solver");
1973 }
1974 sys->solver = solver;
1975 }
1976 } else {
1977 FPRINTF(stderr,
1978 "ERROR: slv_switch_solver called with unknown client (%d)\n",solver);
1979 return -1;
1980 }
1981 return sys->solver;
1982 }
1983
1984 void slv_set_char_parameter(char **cp, char *newvalue)
1985 {
1986 if (cp != NULL) {
1987 if (*cp != NULL) {
1988 ascfree(*cp);
1989 }
1990 *cp = strdup(newvalue);
1991 }
1992 }
1993
1994 void slv_destroy_parms(slv_parameters_t *p) {
1995 int32 i,n,j;
1996 for (i = 0; i < p->num_parms; i++) {
1997 switch(p->parms[i].type) {
1998 case char_parm:
1999 ascfree(p->parms[i].info.c.value);
2000 for (j = 0; j < p->parms[i].info.c.high; j++) {
2001 ascfree(p->parms[i].info.c.argv[j]);
2002 }
2003 ascfree(p->parms[i].info.c.argv);
2004 /* FALL THROUGH */
2005 case int_parm:
2006 case bool_parm:
2007 case real_parm:
2008 ascfree(p->parms[i].name);
2009 ascfree(p->parms[i].interface_label);
2010 ascfree(p->parms[i].description);
2011 break;
2012 default:
2013 FPRINTF(stderr,"Unrecognized parameter type in slv_destroy_parms\n");
2014 }
2015 }
2016 if (p->parms && p->dynamic_parms) {
2017 ascfree(p->parms);
2018 }
2019 }
2020
2021 int32 slv_define_parm(slv_parameters_t *p,
2022 enum parm_type type,
2023 char *name,
2024 char *interface_label,
2025 char *description,
2026 union parm_arg value,
2027 union parm_arg low,
2028 union parm_arg high,
2029 int32 display)
2030 {
2031 int32 len,length,i, err=1;
2032 if (p == NULL) {
2033 return -1;
2034 }
2035 length = p->num_parms;
2036
2037 switch (type) {
2038 case int_parm:
2039 err = 0;
2040 p->parms[length].info.i.value = value.argi;
2041 p->parms[length].info.i.low = low.argi;
2042 p->parms[length].info.i.high = high.argi;
2043 break;
2044
2045 case bool_parm:
2046 err = 0;
2047 p->parms[length].info.b.value = value.argb;
2048 p->parms[length].info.b.low = low.argb;
2049 p->parms[length].info.b.high = high.argb;
2050 break;
2051
2052 case real_parm:
2053 err = 0;
2054 p->parms[length].info.r.value = value.argr;
2055 p->parms[length].info.r.low = low.argr;
2056 p->parms[length].info.r.high = high.argr;
2057 break;
2058
2059 case char_parm:
2060 err = 0;
2061 p->parms[length].info.c.argv =
2062 (char **)ascmalloc(high.argi*sizeof(char *));
2063 for (i = 0; i < high.argi; i++) {
2064 len = strlen(low.argv[i]);
2065 p->parms[length].info.c.argv[i] =(char *)ascmalloc(len+1*sizeof(char));
2066 strcpy(p->parms[length].info.c.argv[i],low.argv[i]);
2067 }
2068
2069 p->parms[length].info.c.value =
2070 (char *)ascmalloc(strlen(value.argc)+1*sizeof(char));
2071 strcpy(p->parms[length].info.c.value,value.argc);
2072
2073 p->parms[length].info.c.high = high.argi;
2074 break;
2075
2076 default:
2077 return -1;
2078 }
2079 if (!err) {
2080 p->parms[length].type = type;
2081 p->parms[length].number = length;
2082
2083 len = strlen(name);
2084 p->parms[length].name = (char *)ascmalloc(len+1*sizeof(char));
2085 strcpy(p->parms[length].name,name);
2086
2087 len = strlen(interface_label);
2088 p->parms[length].interface_label = (char *)ascmalloc(len+1*sizeof(char));
2089 strcpy(p->parms[length].interface_label,interface_label);
2090
2091 len = strlen(description);
2092 p->parms[length].description = (char *)ascmalloc(len+1*sizeof(char));
2093 strcpy(p->parms[length].description,description);
2094
2095 p->parms[length].display = display;
2096 } else {
2097 p->parms[length].type = -1;
2098 }
2099 p->num_parms++;
2100 return p->num_parms;
2101 }
2102
2103 int slv_get_selected_solver(slv_system_t sys)
2104 {
2105 if (sys!=NULL) return sys->solver;
2106 return -1;
2107 }
2108
2109 int32 slv_get_default_parameters(int index,
2110 slv_parameters_t *parameters)
2111 {
2112 if (index >= 0 && index < NORC) {
2113 if ( SFI(index,getdefparam) == NULL ) {
2114 FPRINTF(stderr,"ERROR: slv_get_default_parameters called with parameterless index\n");
2115 return 0;
2116 } else {
2117 /* send NULL system when setting up interface */
2118 SFI(index,getdefparam)(NULL,NULL,parameters);
2119 return 1;
2120 }
2121 } else {
2122 FPRINTF(stderr,"ERROR: slv_get_default_parameters called with unregistered index\n");
2123 return 0;
2124 }
2125 }
2126
2127 void slv_get_parameters(slv_system_t sys,slv_parameters_t *parameters)
2128 {
2129 if ( CF(sys,getparam) == NULL ) {
2130 printwarning("slv_get_parameters",sys);
2131 return;
2132 }
2133 SF(sys,getparam)(sys,sys->ct,parameters);
2134 }
2135
2136
2137 void slv_set_parameters(slv_system_t sys,slv_parameters_t *parameters)
2138 {
2139 if ( CF(sys,setparam) == NULL ) {
2140 printwarning("slv_set_parameters",sys);
2141 return;
2142 }
2143 if (parameters->whose != sys->solver) {
2144 FPRINTF(stderr,"ERROR: slv_set_parameters can give parameters from %s",
2145 "one client to a different client\n");
2146 return;
2147 }
2148 SF(sys,setparam)(sys,sys->ct,parameters);
2149 }
2150
2151 void slv_get_status(slv_system_t sys, slv_status_t *status)
2152 {
2153 if ( CF(sys,getstatus) == NULL ) {
2154 printwarning("slv_get_status",sys);
2155 return;
2156 }
2157 SF(sys,getstatus)(sys,sys->ct,status);
2158 }
2159
2160 linsol_system_t slv_get_linsol_sys(slv_system_t sys)
2161 {
2162 if (CF(sys,getlinsol) == NULL ) {
2163 printinfo(sys,"slv_get_linsol_sys");
2164 return NULL;
2165 }
2166 return SF(sys,getlinsol)(sys,sys->ct);
2167 }
2168
2169 mtx_matrix_t slv_get_sys_mtx(slv_system_t sys)
2170 {
2171 if (CF(sys,getsysmtx) == NULL ) {
2172 printinfo(sys,"slv_get_sys_mtx");
2173 return NULL;
2174 }
2175 return SF(sys,getsysmtx)(sys,sys->ct);
2176 }
2177
2178 linsolqr_system_t slv_get_linsolqr_sys(slv_system_t sys)
2179 {
2180 if (CF(sys,getlinsys) == NULL ) {
2181 printinfo(sys,"slv_get_linsolqr_sys");
2182 return NULL;
2183 }
2184 return SF(sys,getlinsys)(sys,sys->ct);
2185 }
2186
2187 void slv_dump_internals(slv_system_t sys,int level)
2188 {
2189 if (CF(sys,dumpinternals) == NULL ) {
2190 printinfo(sys,"slv_dump_internals");
2191 return;
2192 }
2193 SF(sys,dumpinternals)(sys,sys->ct,level);
2194 }
2195
2196 void slv_presolve(slv_system_t sys)
2197 {
2198 if ( CF(sys,presolve) == NULL ) {
2199 printwarning("slv_presolve",sys);
2200 return;
2201 }
2202 SF(sys,presolve)(sys,sys->ct);
2203 }
2204
2205 void slv_resolve(slv_system_t sys)
2206 {
2207 if ( CF(sys,resolve) == NULL ) {
2208 printwarning("slv_resolve",sys);
2209 return;
2210 }
2211 SF(sys,resolve)(sys,sys->ct);
2212 }
2213
2214 void slv_iterate(slv_system_t sys)
2215 {
2216 if ( CF(sys,iterate) == NULL ) {
2217 printwarning("slv_iterate",sys);
2218 return;
2219 }
2220 SF(sys,iterate)(sys,sys->ct);
2221 }
2222
2223 void slv_solve(slv_system_t sys)
2224 {
2225 if ( CF(sys,solve) == NULL ) {
2226 printwarning("slv_solve",sys);
2227 return;
2228 }
2229 SF(sys,solve)(sys,sys->ct);
2230 }
2231
2232
2233 SlvClientToken slv_get_client_token(slv_system_t sys)
2234 {
2235 if (sys==NULL) {
2236 FPRINTF(stderr,"slv_get_client_token called with NULL system.\n");
2237 return NULL;
2238 }
2239 return sys->ct;
2240 }
2241
2242
2243 void slv_set_client_token(slv_system_t sys, SlvClientToken ct)
2244 {
2245 if (sys==NULL) {
2246 FPRINTF(stderr,"slv_set_client_token called with NULL system.\n");
2247 return;
2248 }
2249 sys->ct = ct;
2250 }
2251
2252 void slv_set_solver_index(slv_system_t sys, int solver)
2253 {
2254 if (sys==NULL) {
2255 FPRINTF(stderr,"slv_set_solver_index called with NULL system.\n");
2256 return;
2257 }
2258 sys->solver = solver;
2259 }
2260
2261 /*********************************************************************\
2262 unregistered client functions that need to go elsewhere(other files).
2263 hereunder are utility calls which are unstandardized
2264 \*********************************************************************/
2265
2266 boolean slv_change_basis(slv_system_t sys, int32 var, mtx_range_t *rng)
2267 {
2268 (void)sys;
2269 (void)var;
2270 (void)rng;
2271 Asc_Panic(2, "slv_change_basis", "fix me");
2272 return 0;
2273 }
2274
2275 /*
2276 * This routine is provided as the start of some report generation
2277 * capabilities. It operates off the main solve system and
2278 * writes out the relation residuals and variable values for
2279 * the entire problem to the named file.
2280 * Isn't very bright.
2281 */
2282
2283 void slv_print_output(FILE *out, slv_system_t sys)
2284 {
2285 struct rel_relation **rp;
2286 struct var_variable **vp;
2287 int nrels, nvars,c;
2288
2289 vp = slv_get_master_var_list(sys);
2290 nvars = slv_get_num_master_vars(sys);
2291 FPRINTF(out,"%-6s %-12s\n",
2292 "INDEX","LEVEL");
2293 for (c=0; c<nvars; c++) {
2294 FPRINTF(out," % -6d % -12.8e\n",c, var_value(vp[c]));
2295 }
2296 PUTC('\n',out);
2297
2298 rp = slv_get_master_rel_list(sys);
2299 nrels = slv_get_num_master_rels(sys);
2300 FPRINTF(out,"%-6s %-12s\n",
2301 "INDEX","RESDUAL");
2302 for (c=0; c<nrels; c++) {
2303 FPRINTF(out," % -6d % -12.8e\n",c, rel_residual(rp[c]));
2304 }
2305 }
2306
2307 int32 slv_obj_select_list(slv_system_t sys,int32 **rip)
2308 {
2309 int32 len,count,i, *ra;
2310 static rel_filter_t rfilter;
2311 struct rel_relation **rlist=NULL;
2312 len = slv_get_num_solvers_objs(sys);
2313 ra = *rip = (int32 *)ascmalloc((len+1)*sizeof(int32 *));
2314 rfilter.matchbits = (REL_INCLUDED);
2315 rfilter.matchvalue =(REL_INCLUDED);
2316 rlist = slv_get_solvers_obj_list(sys);
2317 count = 0;
2318 for (i = 0; i < len; i++) {
2319 if (rel_apply_filter(rlist[i],&rfilter)) {
2320 ra[count] = i;
2321 count++;
2322 }
2323 }
2324 ra[count] = -1;
2325 return count;
2326 }
2327
2328 int32 slv_get_obj_num(slv_system_t sys)
2329 {
2330 int32 len,i;
2331 struct rel_relation *obj;
2332 struct rel_relation **rlist=NULL;
2333 len = slv_get_num_solvers_objs(sys);
2334 rlist = slv_get_solvers_obj_list(sys);
2335 obj = slv_get_obj_relation(sys);
2336 if (obj != NULL) {
2337 for (i = 0; i < len; i++) {
2338 if (rlist[i] == obj) {
2339 return i;
2340 }
2341 }
2342 }
2343 return -1;
2344 }
2345
2346 int32 slv_near_bounds(slv_system_t sys,real64 epsilon,
2347 int32 **vip)
2348 {
2349 int32 len,i, *va, index;
2350 real64 comp;
2351 static var_filter_t vfilter;
2352 struct var_variable **vlist=NULL;
2353 len = slv_get_num_solvers_vars(sys);
2354 va = *vip = (int32 *)ascmalloc((2*len+2)*sizeof(int32 *));
2355 vfilter.matchbits = (VAR_FIXED | VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2356 vfilter.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2357 vlist = slv_get_solvers_var_list(sys);
2358 va[0] = va[1] = 0;
2359 index = 2;
2360 for (i = 0; i < len; i++) {
2361 if (var_apply_filter(vlist[i],&vfilter)) {
2362 comp = (var_value(vlist[i]) - var_lower_bound(vlist[i]))
2363 / var_nominal(vlist[i]);
2364 if (comp < epsilon) {
2365 va[index] = i;
2366 index++;
2367 va[0]++;
2368 }
2369 }
2370 }
2371 for (i = 0; i < len; i++) {
2372 if (var_apply_filter(vlist[i],&vfilter)) {
2373 comp = (var_upper_bound(vlist[i]) - var_value(vlist[i]))
2374 / var_nominal(vlist[i]);
2375 if (comp < epsilon) {
2376 va[index] = i;
2377 index++;
2378 va[1]++;
2379 }
2380 }
2381 }
2382 return index - 2;
2383 }
2384
2385 int32 slv_far_from_nominals(slv_system_t sys,real64 bignum,
2386 int32 **vip)
2387 {
2388 int32 len,i, *va, index;
2389 real64 comp;
2390 static var_filter_t vfilter;
2391 struct var_variable **vlist=NULL;
2392 len = slv_get_num_solvers_vars(sys);
2393 va = *vip = (int32 *)ascmalloc((len+1)*sizeof(int32 *));
2394 vfilter.matchbits = (VAR_FIXED | VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2395 vfilter.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
2396 vlist = slv_get_solvers_var_list(sys);
2397 index = 0;
2398 for (i = 0; i < len; i++) {
2399 if (var_apply_filter(vlist[i],&vfilter)) {
2400 comp = fabs(var_value(vlist[i]) - var_nominal(vlist[i]))
2401 / var_nominal(vlist[i]);
2402 if (comp > bignum) {
2403 va[index] = i;
2404 index++;
2405 }
2406 }
2407 }
2408 return index;
2409 }
2410

Properties

Name Value
svn:executable *

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