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

Annotation of /trunk/ascend4/solver/conditional.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (17 years, 8 months ago) by aw0a
File MIME type: text/x-csrc
File size: 10045 byte(s)
Setting up web subdirectory in repository
1 aw0a 1 /*
2     * Conditional Module
3     * by Vicente Rico-Ramirez
4     * Created: 09/96
5     * Version: $Revision: 1.10 $
6     * Version control file: $RCSfile: conditional.c,v $
7     * Date last modified: $Date: 1998/03/30 22:06:52 $
8     * Last modified by: $Author: rv2a $
9     *
10     * This file is part of the SLV solver.
11     *
12     * The SLV solver is free software; you can redistribute
13     * it and/or modify it under the terms of the GNU General Public License as
14     * published by the Free Software Foundation; either version 2 of the
15     * License, or (at your option) any later version.
16     *
17     * The SLV solver is distributed in hope that it will be
18     * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20     * General Public License for more details.
21     *
22     * You should have received a copy of the GNU General Public License
23     * along with the program; if not, write to the Free Software Foundation,
24     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
25     * COPYING. COPYING is found in ../compiler.
26     *
27     */
28    
29     #include "utilities/ascConfig.h"
30     #include "utilities/ascMalloc.h"
31     #include "general/list.h"
32     #include "general/dstring.h"
33     #include "compiler/instance_enum.h"
34     #include "compiler/compiler.h"
35     #include "compiler/child.h"
36     #include "compiler/fractions.h"
37     #include "compiler/dimen.h"
38     #include "compiler/type_desc.h"
39     #include "compiler/atomvalue.h"
40     #include "compiler/parentchild.h"
41     #include "compiler/instquery.h"
42     #include "compiler/instance_io.h"
43     #include "solver/slv_types.h"
44     #include "solver/var.h"
45     #include "solver/rel.h"
46     #include "solver/discrete.h"
47     #include "solver/conditional.h"
48     #include "solver/logrel.h"
49     #include "solver/bnd.h"
50     #include "solver/slv_server.h"
51     #include "solver/analyze.h"
52    
53    
54     #ifndef IPTR
55     #define IPTR(i) ((struct Instance *)(i))
56     #endif
57     #define WHEN_DEBUG FALSE
58    
59     /*
60     * When utility functions
61     */
62    
63     /* forward declaration */
64     void when_case_destroy(struct when_case *);
65    
66     static const struct w_when g_when_defaults = {
67     NULL, /* instance */
68     NULL, /* variables */
69     NULL, /* cases */
70     -1, /* number of cases */
71     -1, /* mindex */
72     -1, /* sindex */
73     -1, /* model index */
74     (WHEN_INCLUDED) /* flags */
75     };
76    
77    
78     static struct w_when *when_copy(const struct w_when *when)
79     {
80     struct w_when *newwhen;
81     newwhen = (struct w_when *)ascmalloc( sizeof(struct w_when) );
82     *newwhen = *when;
83     return(newwhen);
84     }
85    
86    
87     struct w_when *when_create(SlvBackendToken instance,
88     struct w_when *newwhen)
89     {
90     if (newwhen==NULL) {
91     newwhen = when_copy(&g_when_defaults); /* malloc the when */
92     } else {
93     *newwhen = g_when_defaults; /* init the space we've been sent */
94     }
95     assert(newwhen!=NULL);
96     newwhen->instance = instance;
97     return(newwhen);
98     }
99    
100    
101     void when_destroy_cases(struct w_when *when)
102     {
103     int32 c,len;
104     struct when_case *cur_case;
105    
106     len = gl_length(when->cases);
107     for(c=1;c<=len;c++){
108     cur_case = (struct when_case *)(gl_fetch(when->cases,c));
109     when_case_destroy(cur_case);
110     }
111     gl_destroy(when->cases);
112     }
113    
114    
115     void when_destroy(struct w_when *when)
116     {
117     struct Instance *inst;
118     if (when==NULL) return;
119     if (when->dvars != NULL) {
120     gl_destroy(when->dvars);
121     when->dvars = NULL;
122     }
123     if (when->cases != NULL) {
124     when_destroy_cases(when);
125     when->cases = NULL;
126     }
127     inst = IPTR(when->instance);
128     if (inst) {
129     if (GetInterfacePtr(inst)==when) {
130     SetInterfacePtr(inst,NULL);
131     }
132     }
133     }
134    
135     SlvBackendToken when_instance(struct w_when *when)
136     {
137     if (when==NULL) return NULL;
138     return (SlvBackendToken) when->instance;
139     }
140    
141    
142     void when_write_name(slv_system_t sys,struct w_when *when,
143     FILE *fp)
144     {
145     if (when == NULL || fp==NULL) return;
146     if (sys!=NULL) {
147     WriteInstanceName(fp,when_instance(when),slv_instance(sys));
148     } else {
149     WriteInstanceName(fp,when_instance(when),NULL);
150     }
151     }
152    
153    
154     struct gl_list_t *when_dvars_list( struct w_when *when)
155     {
156     assert(when);
157     return( when->dvars );
158     }
159    
160    
161     void when_set_dvars_list( struct w_when *when, struct gl_list_t *dvlist)
162     {
163     assert(when);
164     when->dvars = dvlist;
165     }
166    
167    
168     struct gl_list_t *when_cases_list( struct w_when *when)
169     {
170     assert(when);
171     return( when->cases );
172     }
173    
174    
175     void when_set_cases_list( struct w_when *when, struct gl_list_t *clist)
176     {
177     assert(when);
178     when->cases = clist;
179     }
180    
181     int32 when_num_cases(struct w_when *when)
182     {
183     return( when->num_cases );
184     }
185    
186     void when_set_num_cases( struct w_when *when, int32 num_cases)
187     {
188     when->num_cases = num_cases;
189     }
190    
191     int32 when_mindex( struct w_when *when)
192     {
193     return( when->mindex );
194     }
195    
196     void when_set_mindex( struct w_when *when, int32 index)
197     {
198     when->mindex = index;
199     }
200    
201    
202     int32 when_sindex( struct w_when *when)
203     {
204     return( when->sindex );
205     }
206    
207     void when_set_sindex( struct w_when *when, int32 index)
208     {
209     when->sindex = index;
210     }
211    
212     int32 when_model(const struct w_when *when)
213     {
214     return((const int32) when->model );
215     }
216    
217     void when_set_model( struct w_when *when, int32 index)
218     {
219     when->model = index;
220     }
221    
222     int32 when_apply_filter(struct w_when *w,
223     when_filter_t *filter)
224     {
225     if (w==NULL || filter==NULL) {
226     FPRINTF(stderr,"when_apply_filter miscalled with NULL\n");
227     return FALSE;
228     }
229     return ( (filter->matchbits & w->flags) ==
230     (filter->matchbits & filter->matchvalue) );
231     }
232    
233    
234     uint32 when_flags( struct w_when *when)
235     {
236     return when->flags;
237     }
238    
239     void when_set_flags(struct w_when *when, uint32 flags)
240     {
241     when->flags = flags;
242     }
243    
244     uint32 when_flagbit(struct w_when *when, uint32 one)
245     {
246     if (when==NULL || when->instance == NULL) {
247     FPRINTF(stderr,"ERROR: when_flagbit called with bad when.\n");
248     return 0;
249     }
250     return (when->flags & one);
251     }
252    
253     void when_set_flagbit(struct w_when *when, uint32 field,
254     uint32 one)
255     {
256     if (one) {
257     when->flags |= field;
258     } else {
259     when->flags &= ~field;
260     }
261     }
262    
263    
264     /*
265     * When Case utility functions
266     */
267    
268    
269     /* we are depending on ansi initialization to 0 for the
270     * values field OF this struct.
271     */
272     static
273     const struct when_case g_case_defaults = {
274     {0}, /* values */
275     NULL, /* relations */
276     NULL, /* logrelations */
277     NULL, /* whens */
278     -1, /* case number */
279     -1, /* number relations */
280     -1, /* number vars */
281     NULL, /* master indeces of incidente vars */
282     (0x0)
283     };
284    
285    
286     static struct when_case *when_case_copy(const struct when_case *wc)
287     {
288     struct when_case *newcase;
289     newcase = (struct when_case *)ascmalloc( sizeof(struct when_case) );
290     *newcase = *wc;
291     return(newcase);
292     }
293    
294    
295     struct when_case *when_case_create(struct when_case *newcase)
296     {
297     if (newcase==NULL) {
298     newcase = when_case_copy(&g_case_defaults); /* malloc the case */
299     } else {
300     *newcase = g_case_defaults; /* init the space we've been sent */
301     }
302     return(newcase);
303     }
304    
305    
306     void when_case_destroy(struct when_case *wc)
307     {
308     if (wc->rels != NULL) {
309     gl_destroy(wc->rels);
310     wc->rels = NULL;
311     }
312     if (wc->logrels != NULL) {
313     gl_destroy(wc->logrels);
314     wc->logrels = NULL;
315     }
316     if (wc->whens != NULL ) {
317     gl_destroy(wc->whens);
318     wc->whens = NULL;
319     }
320     if (wc->ind_inc != NULL ) {
321     ascfree(wc->ind_inc);
322     }
323    
324     ascfree((POINTER)wc);
325     }
326    
327    
328     int32 *when_case_values_list( struct when_case *wc)
329     {
330     assert(wc);
331     return( &(wc->values[0]) );
332     }
333    
334    
335     void when_case_set_values_list( struct when_case *wc, int32 *vallist)
336     {
337     int32 *value,index;
338     assert(wc);
339     value = &(wc->values[0]);
340     for(index=0;index<MAX_VAR_IN_LIST;index++) {
341     *value = *vallist;
342     value++;
343     vallist++;
344     }
345     }
346    
347    
348     struct gl_list_t *when_case_rels_list( struct when_case *wc)
349     {
350     assert(wc);
351     return( wc->rels );
352     }
353    
354    
355     void when_case_set_rels_list( struct when_case *wc, struct gl_list_t *rlist)
356     {
357     assert(wc);
358     wc->rels = rlist;
359     }
360    
361    
362     struct gl_list_t *when_case_logrels_list( struct when_case *wc)
363     {
364     assert(wc);
365     return( wc->logrels );
366     }
367    
368    
369     void when_case_set_logrels_list(struct when_case *wc,
370     struct gl_list_t *lrlist)
371     {
372     assert(wc);
373     wc->logrels = lrlist;
374     }
375    
376    
377     struct gl_list_t *when_case_whens_list( struct when_case *wc)
378     {
379     assert(wc);
380     return( wc->whens );
381     }
382    
383    
384     void when_case_set_whens_list( struct when_case *wc, struct gl_list_t *wlist)
385     {
386     assert(wc);
387     wc->whens = wlist;
388     }
389    
390    
391     int32 when_case_case_number( struct when_case *wc)
392     {
393     assert(wc);
394     return wc->case_number;
395     }
396    
397     void when_case_set_case_number(struct when_case *wc, int32 case_number)
398     {
399     assert(wc);
400     wc->case_number = case_number;
401     }
402    
403     int32 when_case_num_rels( struct when_case *wc)
404     {
405     assert(wc);
406     return wc->num_rels;
407     }
408    
409     void when_case_set_num_rels(struct when_case *wc, int32 num_rels)
410     {
411     assert(wc);
412     wc->num_rels = num_rels;
413     }
414    
415     int32 when_case_num_inc_var( struct when_case *wc)
416     {
417     assert(wc);
418     return wc->num_inc_var;
419     }
420    
421     void when_case_set_num_inc_var(struct when_case *wc, int32 num_inc_var)
422     {
423     assert(wc);
424     wc->num_inc_var = num_inc_var;
425     }
426    
427     int32 *when_case_ind_inc( struct when_case *wc)
428     {
429     assert(wc);
430     return wc->ind_inc;
431     }
432    
433     void when_case_set_ind_inc(struct when_case *wc, int32* ind_inc)
434     {
435     assert(wc);
436     wc->ind_inc = ind_inc;
437     }
438    
439     int32 when_case_apply_filter(struct when_case *wc,
440     when_case_filter_t *filter)
441     {
442     if (wc==NULL || filter==NULL) {
443     FPRINTF(stderr,"when_case_apply_filter miscalled with NULL\n");
444     return FALSE;
445     }
446     return ( (filter->matchbits & wc->flags) ==
447     (filter->matchbits & filter->matchvalue) );
448     }
449    
450     uint32 when_case_flags( struct when_case *wc)
451     {
452     assert(wc);
453     return wc->flags;
454     }
455    
456     void when_case_set_flags(struct when_case *wc, uint32 flags)
457     {
458     assert(wc);
459     wc->flags = flags;
460     }
461    
462     uint32 when_case_flagbit(struct when_case *wc, uint32 one)
463     {
464     if (wc==NULL) {
465     FPRINTF(stderr,"ERROR: when_case_flagbit called with bad case.\n");
466     return 0;
467     }
468     return (wc->flags & one);
469     }
470    
471     void when_case_set_flagbit(struct when_case *wc, uint32 field,
472     uint32 one)
473     {
474     if (one) {
475     wc->flags |= field;
476     } else {
477     wc->flags &= ~field;
478     }
479     }
480    
481    

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