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

Properties

Name Value
svn:executable *

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