1 |
/* |
2 |
* SLV: Ascend Numeric Solver |
3 |
* by Karl Michael Westerberg |
4 |
* Created: 2/6/90 |
5 |
* Version: $Revision: 1.41 $ |
6 |
* Version control file: $RCSfile: rel.h,v $ |
7 |
* Date last modified: $Date: 1998/02/05 15:59:24 $ |
8 |
* Last modified by: $Author: ballan $ |
9 |
* |
10 |
* This file is part of the SLV solver. |
11 |
* |
12 |
* Copyright (C) 1990 Karl Michael Westerberg |
13 |
* Copyright (C) 1993 Joseph Zaher |
14 |
* Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan |
15 |
* |
16 |
* The SLV solver is free software; you can redistribute |
17 |
* it and/or modify it under the terms of the GNU General Public License as |
18 |
* published by the Free Software Foundation; either version 2 of the |
19 |
* License, or (at your option) any later version. |
20 |
* |
21 |
* The SLV solver is distributed in hope that it will be |
22 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 |
* General Public License for more details. |
25 |
* |
26 |
* You should have received a copy of the GNU General Public License |
27 |
* along with the program; if not, write to the Free Software Foundation, |
28 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
29 |
* COPYING. COPYING is found in ../compiler. |
30 |
* |
31 |
*/ |
32 |
|
33 |
/* |
34 |
* Contents: Relation module (ascend) |
35 |
* |
36 |
* Authors: Karl Westerberg |
37 |
* Joseph Zaher |
38 |
* |
39 |
* Dates: 06/90 - original version |
40 |
* 04/94 - added rel_apply_filter() which uses the new |
41 |
* rel_filter_t data structure for perfoming all |
42 |
* relation filtering needs (eliminating the |
43 |
* filter module) |
44 |
* |
45 |
* Description: This is the ascend version of the rel module. This |
46 |
* version should be used by any user who receives his/her |
47 |
* equations directly from an instance tree created by the |
48 |
* ASCEND compiler. |
49 |
*/ |
50 |
|
51 |
#ifndef rel__already_included |
52 |
#define rel__already_included |
53 |
|
54 |
/* |
55 |
* requires #include "var.h" |
56 |
*/ |
57 |
|
58 |
/* |
59 |
* rel_relation data type and basic type operators. |
60 |
*/ |
61 |
|
62 |
#define rel_TOK_less 0x1 |
63 |
#define rel_TOK_equal 0x2 |
64 |
#define rel_TOK_greater 0x4 |
65 |
|
66 |
struct rel_extnode { |
67 |
int32 whichvar; |
68 |
struct ExtRelCache *cache; /* pointer to private structure */ |
69 |
}; |
70 |
|
71 |
enum rel_enum { |
72 |
e_rel_minimize, |
73 |
e_rel_maximize, |
74 |
e_rel_equal, |
75 |
e_rel_not_equal, |
76 |
e_rel_less, |
77 |
e_rel_greater, |
78 |
e_rel_lesseq, |
79 |
e_rel_greatereq |
80 |
}; |
81 |
/* |
82 |
* enum rel_enum: |
83 |
* The exact operator of a relation. |
84 |
*/ |
85 |
enum backend_enum { |
86 |
e_rel_token, |
87 |
e_rel_glassbox, |
88 |
e_rel_blackbox |
89 |
}; |
90 |
|
91 |
struct rel_relation { |
92 |
SlvBackendToken instance; |
93 |
struct rel_extnode *nodeinfo; /* Not NULL if blackbox relation */ |
94 |
struct var_variable **incidence; |
95 |
/* array of atomic vars and nonvars in rel */ |
96 |
/* |
97 |
* For future use: |
98 |
* |
99 |
* struct var_variable **incidentals; array of nonvars, |
100 |
* once solveratoms arrive. |
101 |
* |
102 |
* int32 n_incidentals; |
103 |
*/ |
104 |
enum backend_enum type; /* tokens, glassbox or blackbox */ |
105 |
int32 n_incidences; /* length of incidence. */ |
106 |
int32 mindex; /* index in the slv_system_t master list */ |
107 |
int32 sindex; /* index in the slv_system_t solver list */ |
108 |
int32 model; /* index of a hypothetical MODEL rel is from */ |
109 |
uint32 flags; /* flags */ |
110 |
}; |
111 |
/* |
112 |
* if you mess with the above struct, change the defaults for it in .c file |
113 |
*/ |
114 |
|
115 |
|
116 |
extern struct rel_relation *rel_create(SlvBackendToken ,struct rel_relation *); |
117 |
/* |
118 |
* rel_create(instance,rel) |
119 |
* rel = rel_create(instance,NULL) |
120 |
* struct rel_relation *rel; |
121 |
* SlvBackendToken instance; |
122 |
* |
123 |
* Creates a relation given the relation instance. |
124 |
* If the rel supplied is NULL, we allocate the memory for the |
125 |
* rel we return, else we just init the memory you hand us and |
126 |
* return it to you. |
127 |
* We set the fields instance, nodeinfo, type following |
128 |
* the instance. Setting the rest of the information is the job |
129 |
* of the bridge building function between the ascend instance |
130 |
* tree (or other relation back end) and the slv_system_t. |
131 |
* In particular, the incidence list and indexing info is not |
132 |
* handled here. |
133 |
*/ |
134 |
|
135 |
extern void rel_destroy(struct rel_relation *); |
136 |
/* |
137 |
* rel_destroy(rel) |
138 |
* struct rel_relation *rel; |
139 |
* |
140 |
* Destroys a relation. |
141 |
*/ |
142 |
|
143 |
extern void rel_write_name(slv_system_t,struct rel_relation *,FILE *); |
144 |
/* |
145 |
* rel_write_name(sys,rel,file); |
146 |
* Writes a name to the file given. Handles NULL inputs gracefully. |
147 |
* Does not print any whitespace, including carriage returns. |
148 |
* Is faster than slv_print_var_name. |
149 |
* If sys is NULL, writes full ascend name. If file or rel is NULL |
150 |
* does not write. |
151 |
*/ |
152 |
|
153 |
typedef struct rel_filter_structure { |
154 |
uint32 matchbits; |
155 |
uint32 matchvalue; |
156 |
} rel_filter_t; |
157 |
|
158 |
extern SlvBackendToken rel_instance(struct rel_relation *); |
159 |
/* |
160 |
* rel_instance(rel) |
161 |
* struct rel_relation *rel; |
162 |
* |
163 |
* Returns the instance pointer from a rel. |
164 |
*/ |
165 |
|
166 |
|
167 |
extern struct rel_extnode *rel_extnodeinfo(struct rel_relation *); |
168 |
extern void rel_set_extnodeinfo(struct rel_relation *,struct rel_extnode *); |
169 |
/* |
170 |
* struct rel_relation *rel; |
171 |
* struct rel_extnode *nodeinfo; |
172 |
* |
173 |
* struct rel_extnode *nodeinfo = rel_extnodeinfo(rel); |
174 |
* rel_set_extnodeinfo(rel,nodeinfo); |
175 |
* Fetches the pointer to the external node information structure for |
176 |
* a relation. If this is NULL, which will be the case for most |
177 |
* relations, then there are no external call nodes present. |
178 |
*/ |
179 |
|
180 |
extern int32 rel_extwhichvar(struct rel_relation *); |
181 |
extern void rel_set_extwhichvar(struct rel_relation *,int); |
182 |
/* |
183 |
* struct rel_relation *rel; |
184 |
* int32 whichvar; |
185 |
* |
186 |
* This applies ONLY to rels that have external nodes ! |
187 |
* Relations that have external nodes have associated with them an |
188 |
* index into the argument list from which the relation was constructed. |
189 |
* rel_whichvar returns that index. e.g. if when this relation was |
190 |
* constructed from an external procedure call, the number of output |
191 |
* variables was 4, and the number of inputs was 6, valid results from |
192 |
* this rel_whichvar would be 7, 8, 9, 10. |
193 |
* A return value <= 0 is an error. |
194 |
*/ |
195 |
|
196 |
extern boolean rel_less(struct rel_relation *); |
197 |
extern boolean rel_equal(struct rel_relation *); |
198 |
extern boolean rel_greater(struct rel_relation *); |
199 |
/* |
200 |
* le = rel_less(rel) |
201 |
* eq = rel_equal(rel) |
202 |
* gr = rel_greater(rel) |
203 |
* boolean le,eq,gr; |
204 |
* struct rel_relation *rel; |
205 |
* |
206 |
* Returns true if the given relation is satisfied if the |
207 |
* operator in question is among those that make up the |
208 |
* comparator of the relation. (e.g. rel_less is satisfied |
209 |
* by (<>,<.<=). |
210 |
* le==TRUE implies rel would be satisfied if lhs < rhs |
211 |
* gr==TRUE implies rel would be satisfied if lhs > rhs |
212 |
* eq==TRUE implies rel would be satisfied if lhs ~ rhs |
213 |
*/ |
214 |
|
215 |
extern enum rel_enum rel_relop(struct rel_relation *); |
216 |
/* |
217 |
* relop = rel_relop(rel); |
218 |
* rel_enum relop; |
219 |
* struct rel_relation *rel; |
220 |
* Returns the type of the relational operator of a given relation. |
221 |
*/ |
222 |
|
223 |
extern char *rel_make_name(slv_system_t,struct rel_relation *); |
224 |
/* |
225 |
* name = rel_make_name(sys,rel) |
226 |
* slv_system_t sys; |
227 |
* struct rel_relation *rel; |
228 |
* char *name; |
229 |
* |
230 |
* Copies of the relation instance name can be made and returned. |
231 |
* The string returned should be freed when no longer in use. |
232 |
*/ |
233 |
|
234 |
extern int32 rel_mindex(struct rel_relation *); |
235 |
extern void rel_set_mindex(struct rel_relation *,int32); |
236 |
/* |
237 |
* index = rel_mindex(rel) |
238 |
* rel_set_mindex(rel,index) |
239 |
* int32 index; |
240 |
* struct rel_relation *rel; |
241 |
* |
242 |
* Sets or retrieves the index number of the given relation as it |
243 |
* appears in a slv_system_t master relation list. |
244 |
*/ |
245 |
|
246 |
extern int32 rel_sindex(const struct rel_relation *); |
247 |
extern void rel_set_sindex(struct rel_relation *,int32); |
248 |
/* |
249 |
* index = rel_sindex(rel) |
250 |
* rel_set_sindex(rel,index) |
251 |
* int32 index; |
252 |
* struct rel_relation *rel; |
253 |
* |
254 |
* Sets or retrieves the index number of the given relation as it |
255 |
* appears in a solvers relation list. The index is most often used |
256 |
* to assign the relation to a specific original row of a matrix. |
257 |
*/ |
258 |
|
259 |
|
260 |
extern int32 rel_model(const struct rel_relation *); |
261 |
extern void rel_set_model(struct rel_relation *,int32); |
262 |
/* |
263 |
* index = rel_model(rel) |
264 |
* rel_set_model(rel,index) //SERVER ONLY |
265 |
* int32 index; |
266 |
* struct rel_relation *rel; |
267 |
* |
268 |
* Sets or retrieves the model number of the given relation. |
269 |
* In a hierarchy, relations come in groups associated with |
270 |
* models. Models are numbered from 1 to some upper limit. |
271 |
*/ |
272 |
|
273 |
extern real64 rel_residual(struct rel_relation *); |
274 |
extern void rel_set_residual(struct rel_relation *,real64); |
275 |
/* |
276 |
* residual = rel_residual(rel) |
277 |
* rel_set_residual(rel,residual) |
278 |
* real64 residual; |
279 |
* struct rel_relation *rel; |
280 |
* |
281 |
* Sets or retrieves the residual field of the given relation. |
282 |
* Note that the residual is not actually computed by rel_residual: |
283 |
* there is no guarantee (from this function) that the residual is |
284 |
* actually correct. |
285 |
*/ |
286 |
|
287 |
extern real64 rel_nominal(struct rel_relation *); |
288 |
/* |
289 |
* nominal = rel_nominal(rel) |
290 |
* real64 nominal; |
291 |
* struct rel_relation *rel; |
292 |
* |
293 |
* Retrieves the nominal field of the given relation. |
294 |
* No slv client has any business being able to set the nominal, |
295 |
* so no such operator is provided. |
296 |
*/ |
297 |
|
298 |
extern void rel_set_nominal(struct rel_relation *,real64); |
299 |
/* |
300 |
* Breaking above 'rule' for time being |
301 |
*/ |
302 |
|
303 |
#ifdef NDEBUG |
304 |
#define rel_n_incidences(r) ((r)->n_incidences) |
305 |
#define rel_set_incidences(r,n,ilist) \ |
306 |
(r)->n_incidences=(n); (r)->incidence = (ilist) |
307 |
#else |
308 |
#define rel_n_incidences(r) rel_n_incidencesF(r) |
309 |
#define rel_set_incidences(r,n,ilist) rel_set_incidencesF((r),(n),(ilist)) |
310 |
#endif /* NDEBUG */ |
311 |
|
312 |
extern int32 rel_n_incidencesF(struct rel_relation *); |
313 |
extern void rel_set_incidencesF(struct rel_relation *, |
314 |
int32,struct var_variable **); |
315 |
/* |
316 |
* rel_n_incidences(rel) |
317 |
* rel_set_incidences(rel,n,ilist) //SERVER ONLY |
318 |
* struct rel_relation *rel; |
319 |
* struct var_variable **ilist; |
320 |
* int32 n; |
321 |
* |
322 |
* rel_n_incidences returns the length of the incidence_list. |
323 |
* Not everything in the incidence list is necessarily a |
324 |
* variable for your particular solver -- check the flags. |
325 |
* Solver clients should not call rel_set_incidences, |
326 |
* it is only for use by constructors of bridges to relation |
327 |
* back ends. |
328 |
*/ |
329 |
|
330 |
extern const struct var_variable **rel_incidence_list(struct rel_relation *); |
331 |
extern struct var_variable |
332 |
**rel_incidence_list_to_modify(struct rel_relation *); |
333 |
/* |
334 |
* va = rel_incidence_list(rel) |
335 |
* struct rel_relation *rel; |
336 |
* struct var_variable **va; |
337 |
* |
338 |
* Returns a pointer to an array rel_n_incidences(rel) long of vars. |
339 |
* Each element of the array is a struct var_variable *. |
340 |
* Check the var sindex to see where each might go in a jacobian. |
341 |
* If there is no incidence, NULL is returned. |
342 |
* Pointers in this array will be unique. |
343 |
* The list belongs to the relation. Do not destroy it. Do not change it. |
344 |
* |
345 |
* VA IS NOT a NULL-TERMINATED LIST. |
346 |
*/ |
347 |
|
348 |
/* |
349 |
* relation filtration functions. |
350 |
* We have a lot (32) of binary (one bit) flags a client may want to query |
351 |
* in arbitrary combinations and paying attention to only certain of |
352 |
* the bits. We will provide a set of macros and functions for each of |
353 |
* these bits and for operations on the whole set. |
354 |
*/ |
355 |
|
356 |
extern int32 rel_apply_filter(const struct rel_relation *,rel_filter_t *); |
357 |
/* |
358 |
* value = rel_apply_filter(rel,filter) |
359 |
* int32 value; |
360 |
* struct rel_relation *rel; |
361 |
* rel_filter_t *filter; |
362 |
* |
363 |
* Returns 1 only if all of the positions specified in |
364 |
* filter->matchbits have the same values in |
365 |
* filter->matchvalue and the relation's flags value. |
366 |
* Bits set to 0 in filter->matchbits are ignored for the test. |
367 |
* |
368 |
* EXAMPLE: |
369 |
* To find out if a relation is an unsatisfied equality: |
370 |
* We don't care about anything except satisfaction and equality, |
371 |
* so set filter->matchbits = (REL_SATISFIED | REL_EQUALITY); |
372 |
* We want relation NOT satisfied, so leave REL_SATISFIED = 0 |
373 |
* in filter->matchvalue, i.e. filter->matchvalue = REL_EQUALITY; |
374 |
* Usually it is most convenient to just declare a rel_filter_t filt; |
375 |
* locally in a function and then take the address of it (&filt) after |
376 |
* setting filt.matchbits = (| of all your interesting bits) and |
377 |
* setting filt.matchvalue = (| of the bits you want to be TRUE). |
378 |
*/ |
379 |
|
380 |
extern uint32 rel_flags(struct rel_relation *); |
381 |
extern void rel_set_flags(struct rel_relation *,uint32); |
382 |
/* |
383 |
* struct rel_relation *rel; |
384 |
* uint32 flags; |
385 |
* |
386 |
* rel_flags(rel) returns the flags field of the relation. |
387 |
* rel_set_flags(rel,flags) sets the entire flag field to the |
388 |
* value of flags given. |
389 |
*/ |
390 |
|
391 |
extern uint32 rel_flagbit(struct rel_relation *,uint32); |
392 |
/* |
393 |
* rel_flagbit(rel,name); |
394 |
* struct rel_relation *rel; |
395 |
* uint32 name; |
396 |
* name should be a REL_xx flag defined above) |
397 |
* Returns the value of the bit specified from the relation flags. |
398 |
*/ |
399 |
|
400 |
extern void rel_set_flagbit(struct rel_relation *,uint32, uint32); |
401 |
/* |
402 |
* struct rel_relation *rel; |
403 |
* uint32 NAME,oneorzero; |
404 |
* rel_set_flagbit(rel,NAME,oneorzero) |
405 |
* |
406 |
* Sets the bit, which should be referred to by its macro name, |
407 |
* on if oneorzero is >0 and off is oneorzero is 0. |
408 |
* The macro names are the defined up at the top of this file. |
409 |
* |
410 |
* Example: rel_set_flags(rel,REL_PARTITION,1) turns on the |
411 |
* REL_PARTITION bit. |
412 |
* What it really does is: |
413 |
* if (oneorzero) { |
414 |
* rel->flags |= field; |
415 |
* } else { |
416 |
* rel->flags &= ~field; |
417 |
* } |
418 |
* In unix, see also man 3f bit or man not. |
419 |
*/ |
420 |
|
421 |
/* |
422 |
* the bit flags. explained afterward. several are for use of |
423 |
* transient clients and should be ignored by solver engines |
424 |
*/ |
425 |
#define REL_PARTITION 0x1 |
426 |
#define REL_TORN 0x2 |
427 |
#define REL_INTERFACE 0x4 |
428 |
#define REL_INCLUDED 0x8 |
429 |
/* |
430 |
* INCLUDED is as yet a funny one. treat it as readonly because |
431 |
* you can only change it using a real function and not the |
432 |
* bit manipulation functions. It is here in the bits because |
433 |
* it is useful in filters sometimes. |
434 |
*/ |
435 |
#define REL_OBJNEGATE 0x10 |
436 |
#define REL_BLACKBOX 0x20 |
437 |
#define REL_SATISFIED 0x40 |
438 |
#define REL_EQUALITY 0x80 |
439 |
#define REL_INBLOCK 0x100 |
440 |
/* Conditional Modeling */ |
441 |
#define REL_INWHEN 0x200 |
442 |
#define REL_ACTIVE 0x400 |
443 |
#define REL_INVARIANT 0x800 |
444 |
/* Conditional Relations (Boundaries) */ |
445 |
#define REL_CONDITIONAL 0x1000 |
446 |
#define REL_IN_CUR_SUBREGION 0x2000 |
447 |
/* |
448 |
* temporary relation that doesn't exist independently in the backend, |
449 |
* but is made by some process of the backend or the solver client. |
450 |
*/ |
451 |
#define REL_GENERATED 0x10000 |
452 |
|
453 |
/* |
454 |
* REL_PARTITION reordering clients. is it in the interesting region |
455 |
* REL_TORN reordering clients output. is it a tear. |
456 |
* REL_INTERFACE solvers, ui clients. user suggests it's a tear eqn. |
457 |
* REL_INCLUDED solvers, ui clients. user wants eqn in problem. |
458 |
* bit should be treated as readonly. use rel_set_* |
459 |
* to change. |
460 |
* REL_OBJNEGATE rel module. read_only for clients. |
461 |
* REL_BLACKBOX rel module. read_only for clients. |
462 |
* REL_SATISFIED has rel been pronounced satisfied by someone? |
463 |
* bit should be treated as readonly. use rel_set_* |
464 |
* to change. |
465 |
* REL_EQUALITY is relation an equality? readonly for clients. |
466 |
* REL_INBLOCK is the relation in the current block of registered |
467 |
* client? for clients. |
468 |
* REL_INWHEN is relation in a when? readonly for clients. |
469 |
* REL_ACTIVE is this relation currently a part of my problem ? |
470 |
* REL_INVARIANT is this relation an invariant in the conditional |
471 |
* modeling analysis |
472 |
* REL_CONDITIONAL is relation conditional? readonly for clients |
473 |
* REL_IN_CUR_SUBREGION is the relation in the subregion currently |
474 |
* analyzed ? |
475 |
* |
476 |
* REL_GENERATED is rel fake and cooked up for this system only? |
477 |
*/ |
478 |
|
479 |
/* |
480 |
* the bit flag lookups |
481 |
*/ |
482 |
#ifdef NDEBUG |
483 |
#define rel_partition(r) ((r)->flags & REL_PARTITION) |
484 |
#define rel_torn(r) ((r)->flags & REL_TORN) |
485 |
#define rel_interface(r) ((r)->flags & REL_INTERFACE) |
486 |
#define rel_obj_negate(r) ((r)->flags & REL_OBJNEGATE) |
487 |
#define rel_blackbox(r) ((r)->flags & REL_BLACKBOX) |
488 |
#define rel_satisfied(r) ((r)->flags & REL_SATISFIED) |
489 |
#define rel_equality(r) ((r)->flags & REL_EQUALITY) |
490 |
#define rel_in_block(r) ((r)->flags & REL_INBLOCK) |
491 |
#define rel_in_when(r) ((r)->flags & REL_INWHEN) |
492 |
#define rel_active(r) ((r)->flags & REL_ACTIVE) |
493 |
#define rel_invariant(r) ((r)->flags & REL_INVARIANT) |
494 |
#define rel_conditional(r) ((r)->flags & REL_CONDITIONAL) |
495 |
#define rel_in_cur_subregion(r) ((r)->flags & REL_IN_CUR_SUBREGION) |
496 |
#define rel_generated(r) ((r)->flags & REL_GENERATED) |
497 |
#else |
498 |
#define rel_partition(r) rel_flagbit((r),REL_PARTITION) |
499 |
#define rel_torn(r) rel_flagbit((r),REL_TORN) |
500 |
#define rel_interface(r) rel_flagbit((r),REL_INTERFACE) |
501 |
#define rel_obj_negate(r) rel_flagbit((r),REL_OBJNEGATE) |
502 |
#define rel_blackbox(r) rel_flagbit((r),REL_BLACKBOX) |
503 |
#define rel_satisfied(r) rel_flagbit((r),REL_SATISFIED) |
504 |
#define rel_equality(r) rel_flagbit((r),REL_EQUALITY) |
505 |
#define rel_in_block(r) rel_flagbit((r),REL_INBLOCK) |
506 |
#define rel_in_when(r) rel_flagbit((r),REL_INWHEN) |
507 |
#define rel_active(r) rel_flagbit((r),REL_ACTIVE) |
508 |
#define rel_invariant(r) rel_flagbit((r),REL_INVARIANT) |
509 |
#define rel_conditional(r) rel_flagbit((r),REL_CONDITIONAL) |
510 |
#define rel_in_cur_subregion(r) rel_flagbit((r),REL_IN_CUR_SUBREGION) |
511 |
#define rel_generated(r) rel_flagbit((r),REL_GENERATED) |
512 |
#endif /* NDEBUG */ |
513 |
|
514 |
/* |
515 |
* bit flag assignments. any value other than 0 for bv turns the |
516 |
* named flag to 1. 0 sets it to 0. |
517 |
* Many of these bits have read-only semantics for clients. |
518 |
* Take care when setting them. |
519 |
*/ |
520 |
#define rel_set_partition(r,bv) rel_set_flagbit((r),REL_PARTITION,(bv)) |
521 |
#define rel_set_torn(r,bv) rel_set_flagbit((r),REL_TORN,(bv)) |
522 |
#define rel_set_interface(r,bv) rel_set_flagbit((r),REL_INTERFACE,(bv)) |
523 |
#define rel_set_obj_negate(r,bv) rel_set_flagbit((r),REL_OBJNEGATE,(bv)) |
524 |
#define rel_set_blackbox(r,bv) rel_set_flagbit((r),REL_BLACKBOX,(bv)) |
525 |
#define rel_set_satisfied(r,bv) rel_set_flagbit((r),REL_SATISFIED,(bv)) |
526 |
#define rel_set_equality(r,bv) rel_set_flagbit((r),REL_EQUALITY,(bv)) |
527 |
#define rel_set_in_block(r,bv) rel_set_flagbit((r),REL_INBLOCK,(bv)) |
528 |
#define rel_set_in_when(r,bv) rel_set_flagbit((r),REL_INWHEN,(bv)) |
529 |
#define rel_set_active(r,bv) rel_set_flagbit((r),REL_ACTIVE,(bv)) |
530 |
#define rel_set_invariant(r,bv) rel_set_flagbit((r),REL_INVARIANT,(bv)) |
531 |
#define rel_set_conditional(r,bv) \ |
532 |
rel_set_flagbit((r),REL_CONDITIONAL,(bv)) |
533 |
#define rel_set_in_cur_subregion(r,bv) \ |
534 |
rel_set_flagbit((r),REL_IN_CUR_SUBREGION,(bv)) |
535 |
#define rel_set_generated(r,bv) rel_set_flagbit((r),REL_GENERATED,(bv)) |
536 |
|
537 |
extern uint32 rel_included(struct rel_relation *); |
538 |
extern void rel_set_included(struct rel_relation *,uint32); |
539 |
/* |
540 |
* included = rel_included(rel) |
541 |
* rel_set_included(rel,included) |
542 |
* uint32 included; |
543 |
* struct rel_relation *rel; |
544 |
* |
545 |
* Sets or retrieves the included field of the given relation. |
546 |
* This has side effect on the ascend instance, so it isn't |
547 |
* implemented with the rest of the macros above. This needs to |
548 |
* change. |
549 |
*/ |
550 |
|
551 |
/* |
552 |
* in_block = rel_in_block(rel) |
553 |
* rel_set_in_block(rel,in_block) |
554 |
* uint32 in_block; |
555 |
* struct rel_relation *rel; |
556 |
* |
557 |
* Sets or retrieves the INBLOCK member of the given relation flags |
558 |
* which determines if the relation is within the current block. |
559 |
*/ |
560 |
|
561 |
/* |
562 |
* rel_obj_negate(rel) |
563 |
* struct rel_relation *rel; |
564 |
* |
565 |
* Returns TRUE if relation is of type e_maximize. |
566 |
* Returns FALSE if relation is of type e_minimize. |
567 |
* Note: should only be used on objectives. other relations |
568 |
* will give a meaningless result (probably FALSE). |
569 |
*/ |
570 |
|
571 |
/* |
572 |
* satisfied = rel_satisfied(rel) |
573 |
* rel_set_satisfied(rel,satisfied) |
574 |
* uint32 satisfied; |
575 |
* struct rel_relation *rel; |
576 |
* |
577 |
* Sets or retrieves the satisfied field of the given relation (see |
578 |
* rel_residual() for disclaimer). |
579 |
*/ |
580 |
|
581 |
/* |
582 |
* equality = rel_equality(rel) |
583 |
* rel_set_equality(rel,equality) |
584 |
* uint32 equality; |
585 |
* struct rel_relation *rel; |
586 |
* |
587 |
* TRUE if relation is of form lhs = rhs. |
588 |
*/ |
589 |
|
590 |
extern real64 rel_multiplier(struct rel_relation *); |
591 |
extern void rel_set_multiplier(struct rel_relation *,real64); |
592 |
/* |
593 |
* (won a temporary reprieve. this should be a system property, not rel.) |
594 |
* multiplier = rel_multiplier(rel) |
595 |
* rel_set_multiplier(rel,multiplier) |
596 |
* real64 multiplier; |
597 |
* struct rel_relation *rel; |
598 |
* |
599 |
* Sets or retrieves the multiplier field of the given relation. |
600 |
* This is expected to be computed as a lagrange multiplier which will |
601 |
* relate the gradient of the relation rel with that of some objective |
602 |
* function. |
603 |
*/ |
604 |
|
605 |
/* |
606 |
* rel_relation utility functions. |
607 |
* |
608 |
* Things for the server side only. Not visible to clients. |
609 |
* |
610 |
* Ok, really nosy clients courting death can cheat. Don't cry when |
611 |
* they break. |
612 |
* We make absolutely no commitment to being compatible with this portion |
613 |
* of the header at any time in the future. |
614 |
*/ |
615 |
#ifdef _SLV_SERVER_C_SEEN_ |
616 |
/* |
617 |
*requires #include "expr.h" |
618 |
* requires #include "types.h" |
619 |
* requires #include "extfunc.h" |
620 |
* requires #include "relation.h" |
621 |
* requires #include "packages.h" |
622 |
* requires #include "extcall.h" |
623 |
* requires #include "mtx.h" |
624 |
*/ |
625 |
|
626 |
extern double g_external_tolerance; /* DEFAULT 1e-12 */ |
627 |
|
628 |
struct ExtRelCache { |
629 |
int32 nodestamp; |
630 |
struct ExternalFunc *efunc; /* pre_slv, eval and deriv funcs */ |
631 |
SlvBackendToken data; /* only passed on pre_slv */ |
632 |
struct gl_list_t *arglist; /* only passed on pre_slv */ |
633 |
struct gl_list_t *inputlist; |
634 |
void *user_data; /* user data */ |
635 |
int32 ninputs, noutputs; |
636 |
double *inputs; |
637 |
double *outputs; |
638 |
double *jacobian; |
639 |
unsigned newcalc_done :1; /* bits needed to control */ |
640 |
unsigned first_func_eval :1; /* recalculation. until we can */ |
641 |
unsigned first_deriv_eval :1; /* do proper block coding */ |
642 |
}; |
643 |
|
644 |
extern struct ExtRelCache *rel_extcache(struct rel_relation *); |
645 |
extern void rel_set_extcache(struct rel_relation *,struct ExtRelCache *); |
646 |
/* |
647 |
* cache = rel_extcache(rel); |
648 |
* rel_set_extcache(rel,cache); |
649 |
* struct rel_relation *rel; |
650 |
* struct ExtRelCache *cache; |
651 |
* |
652 |
* This applies ONLY to rels that have external nodes ! |
653 |
* Ensure this by calling rel_extnodeinfo FIRST ! |
654 |
* This is the gateway to the external relation information |
655 |
* stashed away to make processing of external relations efficient. |
656 |
* See the file extrel.[ch] for functions to deal with the external |
657 |
* relations cache, unless of course you are a client in which CASE |
658 |
* don't. |
659 |
*/ |
660 |
|
661 |
/* |
662 |
* The following aren't commented because Kirk Abbott didn't comment them. |
663 |
* It's all server magic anyway? |
664 |
*/ |
665 |
|
666 |
extern struct ExtRelCache *CreateExtRelCache(struct ExtCallNode *); |
667 |
struct ExtRelCache *CreateCacheFromInstance(SlvBackendToken); |
668 |
extern void ExtRel_DestroyCache(struct ExtRelCache *); |
669 |
extern int32 ExtRel_PreSolve(struct ExtRelCache *, int32 setup); |
670 |
extern real64 ExtRel_Evaluate_RHS(struct rel_relation *); |
671 |
extern real64 ExtRel_Evaluate_LHS(struct rel_relation *); |
672 |
extern real64 ExtRel_Diffs_RHS(struct rel_relation *, var_filter_t *, |
673 |
int32, mtx_matrix_t); |
674 |
extern real64 ExtRel_Diffs_LHS(struct rel_relation *, var_filter_t *, |
675 |
int32, mtx_matrix_t); /* not implemented */ |
676 |
|
677 |
#endif /* _SLV_SERVER_C_SEEN_ */ |
678 |
|
679 |
/* |
680 |
* Things dead. |
681 |
*/ |
682 |
/* DEFUNCT |
683 |
* extern struct rel_relation *rel_objcreate(SlvBackendToken, boolean); |
684 |
* rel = rel_objcreate(instance,negate) |
685 |
* struct rel_relation *rel; |
686 |
* boolean negate; |
687 |
* SlvBackendToken instance; |
688 |
* |
689 |
* Creates an objective relation given the relation instance. |
690 |
* The other fields are given default values. The lhs will be NULL. |
691 |
* objrels may not have extrel caches. Use a dummy relation if |
692 |
* necessary. Negate must be TRUE for a maximize relation, FALSE for |
693 |
* a minimize relation. |
694 |
*/ |
695 |
|
696 |
/* DEFUNCT |
697 |
* If you're smart enough to understand the answer to this question, |
698 |
* then you should be asking the instance directly, not asking us. |
699 |
* extern enum rel_enum rel_type(struct rel_relation *); |
700 |
* rtype = rel_type(rel); |
701 |
* rel_enum rtype; |
702 |
* struct rel_relation *rel; |
703 |
* Returns the type of a given relation. This indicates whether the |
704 |
* the relation is a token, opcode, glassbox, or blackbox relation. |
705 |
*/ |
706 |
|
707 |
/* DEFUNCT for now. |
708 |
* extern boolean rel_in_subregion(struct rel_relation *); |
709 |
* in_subregion = rel_in_subregion(rel) |
710 |
* boolean in_subregion; |
711 |
* struct rel_relation *rel; |
712 |
* |
713 |
* Computes if the conditions of the relation are all met by the |
714 |
* current values of the subregion field of each relevant boundary. |
715 |
* It will return TRUE even if there are no conditions. |
716 |
*/ |
717 |
|
718 |
/* DEFUNCT the solver has no business knowing about sides. this is the |
719 |
* compilers job. temporarily still active. |
720 |
* extern expr_t rel_lhs(struct rel_relation *); |
721 |
* extern expr_t rel_rhs(struct rel_relation *); |
722 |
* lhs = rel_lhs(rel) |
723 |
* rhs = rel_rhs(rel) |
724 |
* expr_t lhs,rhs; |
725 |
* struct rel_relation *rel; |
726 |
* |
727 |
* Fetches the (internal copy of the) rhs and lhs of the relation. |
728 |
* The user should not modify the expression, nor should the user |
729 |
* use the expression after the relation is destroyed or the |
730 |
* lhs/rhs has been re-set. |
731 |
*/ |
732 |
|
733 |
|
734 |
#endif /* rel__already_included */ |