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

Properties

Name Value
svn:executable *

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