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

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

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, 9 months ago) by aw0a
File MIME type: text/x-chdr
File size: 15580 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.7 $
6     * Version control file: $RCSfile: conditional.h,v $
7     * Date last modified: $Date: 1998/03/30 22:06:53 $
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     /*
30     * Contents: Conditional module (ascend)
31     *
32     * Dates: 09/96 - original version
33     *
34     * Description: This is the ascend version of the conditional module
35     * This version should be used by any user who receives
36     * his/her equations directly from an instance tree created
37     * by the ASCEND compiler.
38     */
39    
40     #ifndef conditional__already_included
41     #define conditional__already_included
42     /*
43     * requires #include "list.h"
44     * requires #include "base.h"
45     */
46     /*
47     * I have to get rid of this
48     */
49     #ifndef MAX_VAR_IN_LIST
50     #define MAX_VAR_IN_LIST 20
51     #endif /* MAX_VAR_IN_LIST */
52    
53    
54     struct w_when {
55     SlvBackendToken instance; /* the associated ascend ATOM */
56     struct gl_list_t *dvars; /* index of dis vars */
57     struct gl_list_t *cases; /* when_case's */
58     int32 num_cases; /* number of cases in the WHEN */
59     int32 sindex;
60     int32 mindex;
61     int32 model; /* index of a hypothetical MODEL when is from */
62     uint32 flags;
63     };
64    
65     /*
66     * if you mess with the above struct, change the defaults for it in .c file
67     */
68    
69    
70     /*
71     * When functions
72     */
73    
74    
75     extern struct w_when *when_create(SlvBackendToken, struct w_when *);
76     /*
77     * when_create(instance,newwhen)
78     * struct w_when *newwhen;
79     * SlvBackendToken instance;
80     *
81     * Creates a when given the when instance.
82     * If the when supplied is NULL, we allocate the memory for the
83     * when we return, else we just init the memory you hand us and
84     * return it to you.
85     * We set the fields instance. Setting the rest of the information
86     * is the job of the bridge building function between the ascend
87     * instance tree (or other when back end) and the slv_system_t.
88     */
89    
90    
91     extern SlvBackendToken when_instance(struct w_when *);
92     /*
93     * when_instance(when)
94     * struct w_when *when;
95     *
96     * Returns the instance pointer from a when.
97     */
98    
99     extern void when_write_name(slv_system_t,struct w_when *,FILE *);
100     /*
101     * when_write_name(sys,when,file);
102     *
103     * Writes a name to the file given. Handles
104     * If sys is NULL, writes full ascend name. If file or when is NULL
105     * does not write.
106     */
107    
108     extern void when_destroy_cases(struct w_when *);
109     /*
110     * when_destroy_cases(when)
111     * struct w_when *when;
112     *
113     * Destroys a the list of cases of a when.
114     */
115    
116     extern void when_destroy(struct w_when *);
117     /*
118     * when_destroy(when)
119     * struct w_when *when;
120     *
121     * Destroys a when.
122     */
123    
124     extern char *when_make_name(slv_system_t,struct w_when *);
125     /*
126     * name = when_make_name(sys,when)
127     * slv_system_t sys;
128     * struct w_when *when;
129     * char *name;
130     *
131     * Copies of the when instance name can be made and returned.
132     * The string returned should be freed when no longer in use.
133     */
134    
135    
136     extern struct gl_list_t *when_dvars_list( struct w_when *);
137     extern void when_set_dvars_list( struct w_when *, struct gl_list_t *);
138     /*
139     * dvars = when_dvars_list(when)
140     * when_set_dvars_list(when,dvlist)
141     * struct gl_list_t *dvlist;
142     * struct w_when *when;
143     *
144     * Sets or retrieves the list of dis variables of the given when
145     */
146    
147    
148     extern struct gl_list_t *when_cases_list( struct w_when *);
149     extern void when_set_cases_list( struct w_when *, struct gl_list_t *);
150     /*
151     * cases = when_cases_list(when)
152     * when_set_cases_list(when,clist)
153     * struct gl_list_t *clist;
154     * struct w_when *when;
155     *
156     * Sets or retrieves the list of cases of the given when
157     */
158    
159     extern int32 when_num_cases(struct w_when *);
160     extern void when_set_num_cases(struct w_when *,int32);
161     /*
162     * num_cases = when_num_cases(when)
163     * when_set_num_cases(when,num_cases)
164     * int32 num_cases;
165     * struct w_when *when;
166     *
167     * Sets or retrieves the number of cases of the given when as it
168     * appears in a slv_system_t master when list.
169     */
170    
171     extern int32 when_mindex(struct w_when *);
172     extern void when_set_mindex(struct w_when *,int32);
173     /*
174     * index = when_mindex(when)
175     * when_set_mindex(when,index)
176     * int32 index;
177     * struct w_when *when;
178     *
179     * Sets or retrieves the index number of the given when as it
180     * appears in a slv_system_t master when list.
181     */
182    
183     extern int32 when_sindex(struct w_when *);
184     extern void when_set_sindex(struct w_when *,int32);
185     /*
186     * index = when_sindex(when)
187     * when_set_sindex(when,index)
188     * int32 index;
189     * struct w_when *when;
190     *
191     * Sets or retrieves the index number of the given relation as it
192     * appears in a solvers when list.
193     */
194    
195     extern int32 when_model(const struct w_when *);
196     extern void when_set_model(struct w_when *,int32);
197     /*
198     * index = when_model(when)
199     * when_set_model(when,index)
200     * int32 index;
201     * struct w_when *when;
202     *
203     * Sets or retrieves the model number of the given when.
204     * In a hierarchy, whens come associated with
205     * models. Models are numbered from 1 to some upper limit.
206     */
207    
208     typedef struct when_filter_structure {
209     uint32 matchbits;
210     uint32 matchvalue;
211     } when_filter_t;
212    
213    
214     /*
215     * when filtration functions.
216     * We could have 32 binary (one bit) flags a client may want to query
217     * in arbitrary combinations and paying attention to only certain of
218     * the bits. We will provide a set of macros and functions for each of
219     * these bits and for operations on the whole set.
220     */
221    
222     extern int32 when_apply_filter(struct w_when *,when_filter_t *);
223     /*
224     * value = when_apply_filter(when,filter)
225     * int32 value;
226     * struct w_when *when;
227     * when_filter_t *filter;
228     *
229     * Returns 1 only if all of the positions specified in
230     * filter->matchbits have the same values in
231     * filter->matchvalue and the when's flags value.
232     * Bits set to 0 in filter->matchbits are ignored for the test.
233     */
234    
235     extern uint32 when_flags(struct w_when *);
236     extern void when_set_flags(struct w_when *,uint32);
237     /*
238     * struct w_when *when;
239     * uint32 flags;
240     *
241     * when_flags(when) returns the flags field of the when.
242     * when_set_flags(when,flags) sets the entire flag field to the
243     * value of flags given.
244     */
245    
246     extern uint32 when_flagbit(struct w_when *,uint32);
247     /*
248     * when_flagbit(when,name);
249     * struct w_when *when;
250     * uint32 name;
251     * name should be a WHEN_xx flag defined above)
252     * Returns the value of the bit specified from the when flags.
253     */
254    
255     extern void when_set_flagbit(struct w_when *,uint32, uint32);
256     /*
257     * struct w_when *when;
258     * uint32 NAME,oneorzero;
259     * when_set_flagbit(when,NAME,oneorzero)
260     *
261     * Sets the bit, which should be referred to by its macro name,
262     * on if oneorzero is >0 and off is oneorzero is 0.
263     * The macro names are the defined up at the top of this file.
264     *
265     * Example: when_set_flags(when,WHEN_INCLUDED,1) turns on the
266     * WHEN_INCLUDED bit.
267     * What it really does is:
268     * if (oneorzero) {
269     * when->flags |= field;
270     * } else {
271     * when->flags &= ~field;
272     * }
273     * In unix, see also man 3f bit or man not.
274     */
275    
276     /*
277     * the bit flags.
278     */
279    
280     #define WHEN_INWHEN 0x1
281     #define WHEN_INCLUDED 0x2
282     #define WHEN_VISITED 0x4
283     #define WHEN_CHANGES_STRUCTURE 0x8
284    
285     /*
286     * WHEN_INWHEN Is this when nested in another when ?
287     * WHEN_INCLUDED solvers, ui clients. user wants when in problem.
288     * bit should be treated as readonly. use when_set_*
289     * to change.
290     * WHEN_VISITED Required for conditional analysis, for avoiding
291     * to reanalyze a WHEN
292     * WHEN_CHANGES_STRUCTURE Required for conditional analysis. Tells if
293     * the sutructure of the different CASES is all equal or
294     * otherwise
295     */
296    
297     /*
298     * the bit flag lookups
299     */
300     #ifdef NDEBUG
301     #define when_inwhen(w) ((w)->flags & WHEN_INWHEN)
302     #define when_included(w) ((w)->flags & WHEN_INCLUDED)
303     #define when_visited(w) ((w)->flags & WHEN_VISITED)
304     #define when_changes_structure(w) ((w)->flags & WHEN_CHANGES_STRUCTURE)
305     #else
306     #define when_inwhen(w) when_flagbit((w),WHEN_INWHEN)
307     #define when_included(w) when_flagbit((w),WHEN_INCLUDED)
308     #define when_visited(w) when_flagbit((w),WHEN_VISITED)
309     #define when_changes_structure(w) when_flagbit((w),WHEN_CHANGES_STRUCTURE)
310     #endif /* NDEBUG */
311    
312     /*
313     * bit flag assignments. any value other than 0 for bv turns the
314     * named flag to 1. 0 sets it to 0.
315     */
316     #define when_set_inwhen(w,bv) \
317     when_set_flagbit((w),WHEN_INWHEN,(bv))
318     #define when_set_included(w,bv) \
319     when_set_flagbit((w),WHEN_INCLUDED,(bv))
320     #define when_set_visited(w,bv) \
321     when_set_flagbit((w),WHEN_VISITED,(bv))
322     #define when_set_changes_structure(w,bv) \
323     when_set_flagbit((w),WHEN_CHANGES_STRUCTURE,(bv))
324    
325    
326    
327     /*
328     * When Case utility functions
329     */
330    
331    
332     struct when_case {
333     int32 values[MAX_VAR_IN_LIST]; /* values of conditional variables */
334     struct gl_list_t *rels; /* pointer to relations */
335     struct gl_list_t *logrels; /* pointer to logrelations */
336     struct gl_list_t *whens; /* pointer to whens */
337     int32 case_number; /* number of case */
338     int32 num_rels; /* number of relations */
339     int32 num_inc_var; /* number of incident variables */
340     int32 *ind_inc; /* master indeces of incidences */
341     uint32 flags; /* flags ?? */
342     };
343    
344    
345     extern struct when_case *when_case_create(struct when_case *);
346     /*
347     * when_case_create(newcase)
348     * struct when_case *newcase;
349     *
350     * Creates a when case.
351     * If the case supplied is NULL, we allocate the memory for the
352     * case we return, else we just init the memory you hand us and
353     * return it to you.
354     */
355    
356     extern void when_case_destroy(struct when_case *);
357     /*
358     * when_case_destroy(wc)
359     * struct when_case *wc;
360     *
361     * Destroys a when case.
362     */
363    
364     extern int32 *when_case_values_list( struct when_case *);
365     extern void when_case_set_values_list( struct when_case *, int32 *values);
366     /*
367     * values = when_case_values_list(wc)
368     * when_case_set_values_list(wc,vallist)
369     * int32 *vallist;
370     * struct when_case *wc;
371     *
372     * Sets or retrieves the list of values of the given case
373     */
374    
375     extern struct gl_list_t *when_case_rels_list( struct when_case *);
376     extern void when_case_set_rels_list( struct when_case *, struct gl_list_t *);
377     /*
378     * rels = when_case_rels_list(wc)
379     * when_case_set_rels_list(wc,rlist)
380     * struct gl_list_t *rlist;
381     * struct when_case *wc;
382     *
383     * Sets or retrieves the list of rels of the given case
384     */
385    
386     extern struct gl_list_t *when_case_logrels_list( struct when_case *);
387     extern void when_case_set_logrels_list(struct when_case *,struct gl_list_t *);
388     /*
389     * logrels = when_case_logrels_list(wc)
390     * when_case_set_logrels_list(wc,lrlist)
391     * struct gl_list_t *lrlist;
392     * struct when_case *wc;
393     *
394     * Sets or retrieves the list of logrels of the given case
395     */
396    
397     extern struct gl_list_t *when_case_whens_list( struct when_case *);
398     extern void when_case_set_whens_list( struct when_case *, struct gl_list_t *);
399     /*
400     * whens = when_case_whens_list(wc)
401     * when_case_set_whens_list(wc,wlist)
402     * struct gl_list_t *wlist;
403     * struct when_case *wc;
404     *
405     * Sets or retrieves the list of whens nested in the given case
406     */
407    
408     extern int32 when_case_case_number(struct when_case *);
409     extern void when_case_set_case_number(struct when_case *,int32);
410     /*
411     * struct when_case *wc;
412     * int32 case_number;
413     *
414     * when_case_case_number(wc) returns the number of the case wc.
415     * when_case_set_case_number(wc,case_number) sets the case_number field of
416     * a case to the value of the case_number given.
417     */
418    
419     extern int32 when_case_num_rels( struct when_case *);
420     extern void when_case_set_num_rels(struct when_case *, int32);
421     /*
422     * struct when_case *wc;
423     * int32 num_rels;
424     *
425     * when_case_num_rels(wc) returns the number of the relations in wc.
426     * when_case_set_num_rels(wc,num_rels) sets the num_rels field of
427     * a case to the value of the num_rels given.
428     */
429    
430     extern int32 when_case_num_inc_var( struct when_case *);
431     extern void when_case_set_num_inc_var(struct when_case *, int32);
432     /*
433     * struct when_case *wc;
434     * int32 num_inc_var;
435     *
436     * when_case_num_inc_var(wc) returns the number of the variables incident
437     * in the relations contained in wc.
438     * when_case_set_num_inc_var(wc,num_inc_var) sets the num_inc_var field of
439     * a case to the value of the num_inc_var given.
440     */
441    
442     extern int32 *when_case_ind_inc( struct when_case *);
443     extern void when_case_set_ind_inc(struct when_case *, int32*);
444     /*
445     * struct when_case *wc;
446     * int32 *ind_inc;
447     *
448     * when_case_ind_inc(wc) returns the array of the master indices of
449     * the variables incident in the relations contained in wc.
450     * when_case_set_ind_inc(wc,ind_inc) sets the ind_inc pointer of
451     * a case to the value of the array ind_inc given.
452     */
453    
454     typedef struct when_case_filter_structure {
455     uint32 matchbits;
456     uint32 matchvalue;
457     } when_case_filter_t;
458    
459    
460     /*
461     * case filtration functions
462     */
463    
464     extern int32 when_case_apply_filter(struct when_case *,when_case_filter_t *);
465     /*
466     * value = when_case_apply_filter(wc,filter)
467     * int32 value;
468     * struct when_case *wc;
469     * when_case_filter_t *filter;
470     *
471     * Returns 1 only if all of the positions specified in
472     * filter->matchbits have the same values in
473     * filter->matchvalue and the when's flags value.
474     * Bits set to 0 in filter->matchbits are ignored for the test.
475     */
476    
477     extern uint32 when_case_flags(struct when_case *);
478     extern void when_case_set_flags(struct when_case *,uint32);
479     /*
480     * struct when_case *wc;
481     * uint32 flags;
482     *
483     * when_case_flags(wc) returns the flags field of the case wc.
484     * when_case_set_flags(wc,flags) sets the entire flag field to the
485     * value of flags given.
486     */
487    
488     extern uint32 when_case_flagbit(struct when_case *,uint32);
489     /*
490     * when_case_flagbit(wc,name);
491     * struct when_case *wc;
492     * uint32 name;
493     * name should be a WHEN_CASE_xx flag
494     * Returns the value of the bit specified from the case flags.
495     */
496    
497     extern void when_case_set_flagbit(struct when_case *,uint32, uint32);
498     /*
499     * struct when_case *wc;
500     * uint32 NAME,oneorzero;
501     * when_case_set_flagbit(wc,NAME,oneorzero)
502     *
503     * Sets the bit, which should be referred to by its macro name,
504     * on if oneorzero is >0 and off is oneorzero is 0.
505     * The macro names are the defined up at the top of this file.
506     */
507    
508     /*
509     * the bit flags.
510     */
511    
512     #define WHEN_CASE_ACTIVE 0x1
513    
514     /*
515     * WHEN_CASE_ACTIVE Is this case active ?
516     */
517    
518     /*
519     * the bit flag lookups
520     */
521     #ifdef NDEBUG
522     #define when_case_active(c) ((c)->flags & WHEN_CASE_ACTIVE)
523     #else
524     #define when_case_active(c) when_case_flagbit((c),WHEN_CASE_ACTIVE)
525     #endif /* NDEBUG */
526    
527     /*
528     * bit flag assignments. any value other than 0 for bv turns the
529     * named flag to 1. 0 sets it to 0.
530     */
531     #define when_case_set_active(c,bv) \
532     when_case_set_flagbit((c),WHEN_CASE_ACTIVE,(bv))
533    
534     #endif /* conditional__already_included */

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