1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 1990 Karl Michael Westerberg |
3 |
Copyright (C) 1993 Joseph Zaher |
4 |
Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan |
5 |
Copyright (C) 2006 Carnegie Mellon University |
6 |
|
7 |
This program is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2, or (at your option) |
10 |
any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 |
*//** @defgroup system_var System Variable |
20 |
This module provides a SLV solver (the "client") with access to |
21 |
variables present in the ASCEND compiler (the "server"). |
22 |
|
23 |
Access to ASCEND variables is abstracted so that SLV solvers |
24 |
can theoretically be used to solve other kinds of systems as |
25 |
well. @see analyze.h |
26 |
|
27 |
The idea of a var makes no sense outside the context of |
28 |
a slv_system_t, so some of the functions here may require |
29 |
the passing of a slv_system_t with the var. |
30 |
|
31 |
@TODO |
32 |
At present there is some insanity about asking the instance tree |
33 |
vs asking our data structure about the flag values - This needs to |
34 |
be fixed (see longer BAA comment in var.h). |
35 |
*//* |
36 |
06/90 - original version |
37 |
01/94 - added var_make_name() to create a copy of the |
38 |
instance name |
39 |
04/94 - added var_apply_filter() which uses the new |
40 |
var_filter_t data structure for perfoming all |
41 |
variable filtering needs (eliminating the |
42 |
filter module) |
43 |
08/94 - added var_BackendTokens_to_vars. BAA. |
44 |
|
45 |
Authors: Karl Westerberg and Joseph Zaher |
46 |
Version: $Revision: 1.26 $ |
47 |
Date last modified: $Date: 1998/03/30 22:07:10 $ |
48 |
Last modified by: $Author: rv2a $ |
49 |
*/ |
50 |
|
51 |
#ifndef ASC_VAR_H |
52 |
#define ASC_VAR_H |
53 |
|
54 |
#include <stdio.h> |
55 |
#include <ascend/general/platform.h> |
56 |
#include "slv_types.h" |
57 |
|
58 |
/** @addtogroup system_var |
59 |
@{ |
60 |
*/ |
61 |
|
62 |
/* |
63 |
The first section of flagbit definitions are those flags to be |
64 |
set by the server. Clients should not mess with them unless |
65 |
they are very, very smart. |
66 |
*/ |
67 |
#define VAR_REAL 0x1 |
68 |
/**< don't know what this is good for. */ |
69 |
#define VAR_INCIDENT 0x2 |
70 |
/**< is this variable incident on some equation in the slv_system? */ |
71 |
#define VAR_PVAR 0x4 |
72 |
/**< do we think this var a 'solver_par'? */ |
73 |
#define VAR_SVAR 0x8 |
74 |
/**< do we think this var a 'solver_var'? */ |
75 |
#define VAR_INTEGER 0x10 |
76 |
/**< do we think this var a solver_integer? */ |
77 |
#define VAR_BINARY 0x20 |
78 |
/**< do we think this var a solver_binary? */ |
79 |
#define VAR_SEMICONT 0x40 |
80 |
/**< do we think this var a solver_semi(continuous) ? NEVER USED */ |
81 |
|
82 |
/* |
83 |
Added this one. Not sure if it belongs 'above the line' here or |
84 |
not. -- JP 20061222 |
85 |
*/ |
86 |
#define VAR_DERIV 0x80 |
87 |
/**< var is a derivative of some other var present in the system */ |
88 |
#define VAR_DIFF 0x100 |
89 |
/**< |
90 |
var is differential if is posesses a derivative explicitly stated in the |
91 |
system of equations. Can't have both alg&deriv flags set (unless higher |
92 |
order derivatives have been implemented?) |
93 |
*/ |
94 |
#define VAR_PRE 0x200 |
95 |
/**< var is a pre() var */ |
96 |
|
97 |
/* |
98 |
The remaining flagbit definitions are those flags to be |
99 |
manipulated by registered clients. Unregistered clients |
100 |
should not change these bits unless the manner in which |
101 |
they affect the bits is explained in the header for the |
102 |
unregistered client. |
103 |
*/ |
104 |
|
105 |
#define VAR_PARAM 0x1000 |
106 |
/**< is this variable considered parametric currently? NEVER USED */ |
107 |
#define VAR_FIXED 0x2000 |
108 |
/**< is this variable considered fixed currently? */ |
109 |
#define VAR_INBLOCK 0x4000 |
110 |
/**< is this var in the columns of the block we are currently solving? */ |
111 |
#define VAR_INTERFACE 0x8000 |
112 |
/**< is this var an interface var currently? */ |
113 |
#define VAR_RELAXED 0x10000 |
114 |
/**< is this var currently a relaxed int or binary or semi var? */ |
115 |
#define VAR_ACTIVE 0x20000 |
116 |
/**< is this var currently a part of my problem? */ |
117 |
#define VAR_NONBASIC 0x40000 |
118 |
/**< is this var currently an independent variable (optimization)? */ |
119 |
#define VAR_ACTIVE_AT_BND 0x80000 |
120 |
/**< is this var active in some of the subregions neighboring the |
121 |
boundary on which the problem currently lies ? */ |
122 |
#define VAR_ELIGIBLE 0x100000 |
123 |
/**< is this variable eligible to be fixed (globally)? */ |
124 |
#define VAR_ELIGIBLE_IN_SUBREGION 0x200000 |
125 |
/**< is this variable eligible to be fixed (in current subregion) ? */ |
126 |
#define VAR_POTENTIALLY_FIXED 0x400000 |
127 |
/**< this bit is auxiliar while iteratively and recurively we are |
128 |
performing a combinatorial search, looking for a consitent |
129 |
partition for all the alternatives in an conditional model */ |
130 |
#define VAR_INCIDENT_IN_CASE 0x800000 |
131 |
/**< is this variable incident in some relation of a CASE in a |
132 |
WHEN statement ?. This is for purposes of simplfying the |
133 |
analysis of conditional models */ |
134 |
|
135 |
/** |
136 |
Variable structure. |
137 |
Finally, we have a real structure so that we aren't hanging stuff |
138 |
of the global instance tree. Do not dereference this structure except |
139 |
via macros/functions, because we make no commitments about being |
140 |
backward compatible with such code. |
141 |
|
142 |
struct Instance * and struct var_variable * are no longer synonymous! |
143 |
*/ |
144 |
struct var_variable { |
145 |
SlvBackendToken ratom; /**< the associated ascend ATOM */ |
146 |
struct rel_relation **incidence; /**< array rels which contain var */ |
147 |
struct var_variable *prearg; /**< the argument of a pre() variable */ |
148 |
int32 n_incidences; /**< length of incidence. */ |
149 |
int32 sindex; /**< index in the solver clients list (often column index) */ |
150 |
int32 mindex; /**< index in the slv_system_t master list */ |
151 |
uint32 flags; /**< batch of binary flags. The bit positions are as above */ |
152 |
}; |
153 |
|
154 |
/** Variable filter structure */ |
155 |
typedef struct var_filter_structure { |
156 |
uint32 matchbits; /**< Bits to match. */ |
157 |
uint32 matchvalue; /**< Value to match. */ |
158 |
} var_filter_t; |
159 |
/**< Variable filter type */ |
160 |
|
161 |
#define var_NO_UPPER_BOUND MAXDOUBLE |
162 |
#define var_NO_LOWER_BOUND (-MAXDOUBLE/2) |
163 |
|
164 |
#ifdef NDEBUG |
165 |
# define var_instance(var) ((var)->ratom) |
166 |
#else |
167 |
# define var_instance(var) var_instanceF(var) |
168 |
#endif |
169 |
/**< |
170 |
Returns the ATOM instance associated with the variable. |
171 |
@param var const struct var_variable *, the variable to query. |
172 |
@return Returns the instance as a SlvBackendToken. |
173 |
@see var_instanceF() |
174 |
*/ |
175 |
|
176 |
#ifdef NDEBUG |
177 |
# define var_set_instance(var,inst) ((var)->ratom = (inst)) |
178 |
#else |
179 |
# define var_set_instance(var,inst) var_set_instanceF((var),(inst)) |
180 |
#endif |
181 |
/**< |
182 |
Sets the ATOM instance associated with the variable. |
183 |
@param var struct var_variable *, the variable to modify. |
184 |
@param inst SlvBackendToken, the new instance value. |
185 |
@return No return value. |
186 |
@see var_instanceF() |
187 |
*/ |
188 |
|
189 |
ASC_DLLSPEC SlvBackendToken var_instanceF(const struct var_variable *var); |
190 |
/**< |
191 |
Implementation function for var_instance(). Do not call this |
192 |
function directly - use var_instance() instead. |
193 |
*/ |
194 |
extern void var_set_instanceF(struct var_variable *var, SlvBackendToken i); |
195 |
/**< |
196 |
Implementation function for var_set_instance(). Do not call this |
197 |
function directly - use var_set_instance() instead. |
198 |
*/ |
199 |
|
200 |
extern char *var_make_xname(const struct var_variable *var); |
201 |
/**< |
202 |
Returns the index name, eg x23 rather than full name. |
203 |
See var_make_name() for more information. |
204 |
*/ |
205 |
ASC_DLLSPEC char*var_make_name( |
206 |
const slv_system_t sys, |
207 |
const struct var_variable *var |
208 |
); |
209 |
/**< |
210 |
Creates and returns a sufficiently large string storing the |
211 |
qualified name of var as known by the solver instance tree. |
212 |
If the instance is not found, "?" is returned. The string |
213 |
should be destroyed when no longer in use.<br><br> |
214 |
|
215 |
The name of a var is context dependent, so you have to provide the |
216 |
slv_system_t from which you got the var. |
217 |
*/ |
218 |
|
219 |
ASC_DLLSPEC void var_write_name(const slv_system_t sys, |
220 |
const struct var_variable *var, |
221 |
FILE *file); |
222 |
/**< |
223 |
Writes a name to the file given. Handles NULL inputs gracefully. |
224 |
Does not print any whitespace, including carriage returns. |
225 |
Is faster than slv_print_var_name(). |
226 |
If sys is NULL, writes full ascend name. If file or var is NULL |
227 |
does not write. |
228 |
*/ |
229 |
|
230 |
void var_destroy(struct var_variable *var); |
231 |
/**< |
232 |
Since someone else allocates vars en masse, this just sets |
233 |
our integrity check to ERROR. |
234 |
*/ |
235 |
|
236 |
#ifdef NDEBUG |
237 |
# define var_mindex(var) (var)->mindex |
238 |
#else |
239 |
# define var_mindex(var) var_mindexF(var) |
240 |
#endif |
241 |
/**< |
242 |
Returns the index of the variable as it appears in a variable list. |
243 |
The index is also used to assign the variable to a specific |
244 |
original column of a matrix. |
245 |
@param var const struct var_variable *, the variable to query. |
246 |
@return Returns the index as an int32. |
247 |
@see var_mindexF(). |
248 |
*/ |
249 |
|
250 |
|
251 |
/** |
252 |
Sets the index of the variable as it appears in a variable list. |
253 |
@param var struct var_variable *, the variable to modify. |
254 |
@param index int32, the new value for the index. |
255 |
@return No return value. |
256 |
@see var_set_mindexF(). |
257 |
*/ |
258 |
#ifdef NDEBUG |
259 |
# define var_set_mindex(var,index) (var)->mindex = (index) |
260 |
#else |
261 |
# define var_set_mindex(var,index) var_set_mindexF((var),(index)) |
262 |
ASC_DLLSPEC int32 var_mindexF(const struct var_variable *var); |
263 |
/**< |
264 |
Implementation function for var_mindex(). Do not call this |
265 |
function directly - use var_mindex() instead. |
266 |
*/ |
267 |
#endif |
268 |
|
269 |
|
270 |
extern void var_set_mindexF(struct var_variable *var, int32 mindex); |
271 |
/**< |
272 |
Implementation function for var_set_mindex(). Do not call this |
273 |
function directly - use var_set_mindex() instead. |
274 |
*/ |
275 |
|
276 |
#ifdef NDEBUG |
277 |
# define var_sindex(var) (var)->sindex |
278 |
#else |
279 |
# define var_sindex(var) var_sindexF(var) |
280 |
#endif |
281 |
/**< |
282 |
Returns the index of the variable as it appears in a solvers |
283 |
variable list. The index is also used to assign the variable |
284 |
to a specific original column of a matrix. |
285 |
@param var const struct var_variable *, the variable to query. |
286 |
@return Returns the index as an int32. |
287 |
@see var_sindexF(). |
288 |
*/ |
289 |
|
290 |
#ifdef NDEBUG |
291 |
# define var_set_sindex(var,index) (var)->sindex = (index) |
292 |
#else |
293 |
# define var_set_sindex(var,index) var_set_sindexF((var),(index)) |
294 |
#endif |
295 |
/**< |
296 |
Sets the index of the variable as it appears in a solver's |
297 |
variable list. |
298 |
@param var struct var_variable *, the variable to modify. |
299 |
@param index int32, the new value for the index. |
300 |
@return No return value. |
301 |
@see var_set_sindexF(). |
302 |
*/ |
303 |
|
304 |
ASC_DLLSPEC int32 var_sindexF(const struct var_variable *var); |
305 |
/**< |
306 |
Implementation function for var_sindex(). Do not call this |
307 |
function directly - use var_sindex() instead. |
308 |
*/ |
309 |
ASC_DLLSPEC void var_set_sindexF(struct var_variable *var, int32 sindex); |
310 |
/**< |
311 |
Implementation function for var_set_sindex(). Do not call this |
312 |
function directly - use var_set_sindex() instead. |
313 |
*/ |
314 |
|
315 |
ASC_DLLSPEC real64 var_value(const struct var_variable *var); |
316 |
/**< Returns the value of the variable. */ |
317 |
ASC_DLLSPEC void var_set_value(struct var_variable *var, real64 value); |
318 |
/**< |
319 |
Sets the value of the variable. |
320 |
*/ |
321 |
|
322 |
ASC_DLLSPEC real64 var_nominal(struct var_variable *var); |
323 |
/**< Returns the nominal value of the variable, or 1.0 if it has none. */ |
324 |
ASC_DLLSPEC void var_set_nominal(struct var_variable *var, real64 nominal); |
325 |
/**< |
326 |
Sets the nominal value of the variable. |
327 |
If no nominal field in var, returns 1.0. |
328 |
*/ |
329 |
|
330 |
ASC_DLLSPEC real64 var_lower_bound(struct var_variable *var); |
331 |
/**< Returns the lower bound value of the variable. */ |
332 |
extern void var_set_lower_bound(struct var_variable *var, real64 lower_bound); |
333 |
/**< |
334 |
Sets the lower bound value of the variable. |
335 |
*/ |
336 |
|
337 |
ASC_DLLSPEC real64 var_upper_bound(struct var_variable *var); |
338 |
/**< Returns the upper bound value of the variable. */ |
339 |
extern void var_set_upper_bound(struct var_variable *var, real64 upper_bound); |
340 |
/**< |
341 |
Gets/sets the upper bound value of the variable. |
342 |
*/ |
343 |
|
344 |
double var_odeatol(struct var_variable *var); |
345 |
/**< Returns the ODE absolute error tolerance for the variable, or -1 if not available */ |
346 |
|
347 |
#ifdef NDEBUG |
348 |
# define var_n_incidences(var) ((var)->n_incidences) |
349 |
#else |
350 |
ASC_DLLSPEC int32 var_n_incidencesF(struct var_variable *var); |
351 |
# define var_n_incidences(var) var_n_incidencesF(var) |
352 |
#endif |
353 |
/**< |
354 |
Returns the length of the incidence list. |
355 |
Not everything in the incidence list is necessarily a |
356 |
variable for your particular solver -- check the flags. |
357 |
@param var const struct var_variable *, the variable to query. |
358 |
@return Returns the index as an int32. |
359 |
@see var_n_incidencesF(). |
360 |
*/ |
361 |
|
362 |
#ifdef NDEBUG |
363 |
# define var_set_incidences(var,n,ilist) \ |
364 |
(var)->n_incidences=(n); (var)->incidence = (ilist) |
365 |
#else |
366 |
# define var_set_incidences(var,n,ilist) var_set_incidencesF((var),(n),(ilist)) |
367 |
#endif |
368 |
/**< |
369 |
Sets the incidence list for a variable. |
370 |
Solver clients should not call var_set_incidences(). It is |
371 |
only for use by constructors of bridges to varation back ends. |
372 |
@param var struct var_variable *, the variable to query. |
373 |
@param n int32, length of the new incidence list. |
374 |
@param ilist struct rel_relation **, the new incidence list. |
375 |
@return No return value. |
376 |
@see var_set_incidencesF(). |
377 |
*/ |
378 |
|
379 |
extern void var_set_incidencesF(struct var_variable *var, |
380 |
int32 n, |
381 |
struct rel_relation **ilist); |
382 |
/**< |
383 |
Implementation function for var_set_incidences(). Do not call this |
384 |
function directly - use var_set_incidences() instead. |
385 |
*/ |
386 |
|
387 |
ASC_DLLSPEC struct rel_relation **var_incidence_list_to_modify( |
388 |
struct var_variable *var); |
389 |
/**< Same as var_incidence_list(), except the returned list is modifiable. */ |
390 |
|
391 |
ASC_DLLSPEC const struct rel_relation **var_incidence_list(struct var_variable *var); |
392 |
/**< |
393 |
Returns a pointer to an array var_n_incidences(var) long of vars. |
394 |
Each element of the array is a struct rel_relation *. |
395 |
Check the var sindex to see where each might go in a jacobian. |
396 |
If there is no incidence, NULL is returned. |
397 |
Pointers in this array will be unique. |
398 |
|
399 |
The list belongs to the varation. Do not destroy it. Do not change it. |
400 |
|
401 |
RA IS NOT a NULL-TERMINATED LIST. |
402 |
*/ |
403 |
|
404 |
#ifdef NDEBUG |
405 |
# define var_set_prearg(var,arg) (var)->prearg=(arg) |
406 |
#else |
407 |
# define var_set_prearg(var,arg) var_set_preargF((var),(arg)) |
408 |
#endif |
409 |
/**< |
410 |
Sets the pre() argument for a variable. |
411 |
@param var struct var_variable *, the variable to query. |
412 |
@param ilist struct var_variable *, pre() argument. |
413 |
@return No return value. |
414 |
@see var_set_preargF(). |
415 |
*/ |
416 |
|
417 |
extern void var_set_preargF(struct var_variable *var, |
418 |
struct var_variable *arg); |
419 |
/**< |
420 |
Implementation function for var_set_prearg(). Do not call this |
421 |
function directly - use var_set_prearg() instead. |
422 |
*/ |
423 |
|
424 |
ASC_DLLSPEC const struct var_variable *var_prearg(struct var_variable *var); |
425 |
/**< |
426 |
Returns a pointer to a variable. |
427 |
If the variable is not a pre(), NULL is returned. |
428 |
*/ |
429 |
|
430 |
#ifdef NDEBUG |
431 |
# define var_flags(var) ((var)->flags) |
432 |
#else |
433 |
# define var_flags(var) var_flagsF(var) |
434 |
#endif |
435 |
/**< |
436 |
Returns the flags field of the var. This flags value should |
437 |
be composed of the var_xxx values defined above. |
438 |
@param var const struct var_variable *, the variable to query. |
439 |
@return Returns the index as an int32. |
440 |
@see var_flagsF(). |
441 |
*/ |
442 |
|
443 |
#ifdef NDEBUG |
444 |
# define var_set_flags(var,flags) ((var)->flags = (flags)) |
445 |
#else |
446 |
# define var_set_flags(var,flags) var_set_flagsF((var),(flags)) |
447 |
#endif |
448 |
/**< |
449 |
Sets the entire flag field to the value of flags given. |
450 |
This flags value should be composed of the var_xxx values |
451 |
defined above. |
452 |
@param var struct var_variable *, the variable to query. |
453 |
@param flags uint32, the new flags value. |
454 |
@return No return value. |
455 |
@see var_set_flagsF(). |
456 |
*/ |
457 |
|
458 |
ASC_DLLSPEC uint32 var_flagsF(const struct var_variable *var); |
459 |
/**< |
460 |
Implementation function for var_flags(). Do not call this |
461 |
function directly - use var_flags() instead. |
462 |
*/ |
463 |
extern void var_set_flagsF(struct var_variable *var, uint32 flags); |
464 |
/**< |
465 |
Implementation function for var_set_flags(). Do not call this |
466 |
function directly - use var_set_flags() instead. |
467 |
*/ |
468 |
|
469 |
ASC_DLLSPEC uint32 var_flagbit(const struct var_variable *rel, const uint32 name); |
470 |
/**< |
471 |
Returns the value of the bit specified from the variable flags. |
472 |
name should be a VAR_xx flag defined above. |
473 |
*/ |
474 |
|
475 |
ASC_DLLSPEC void var_set_flagbit(struct var_variable *var, |
476 |
uint32 NAME, |
477 |
uint32 oneorzero); |
478 |
/**< |
479 |
Sets the bit, which should be referred to by its macro name, |
480 |
on if oneorzero is >0 and off is oneorzero is 0. |
481 |
The macro names are the defined up at the top of this file.<br><br> |
482 |
|
483 |
Example: var_set_flags(var,VAR_PARTITION,1) turns on the |
484 |
VAR_PARTITION bit. |
485 |
<pre> |
486 |
What it really does is: |
487 |
if (oneorzero) { |
488 |
var->flags |= field; |
489 |
} else { |
490 |
var->flags &= ~field; |
491 |
} |
492 |
</pre> |
493 |
*/ |
494 |
|
495 |
/* |
496 |
* At present there is some insanity about asking the instance tree |
497 |
* vs asking our data structure about the flag values. This needs to |
498 |
* be fixed. In the process of that fix, we should establish a |
499 |
* protocol that means vars/rels never need to look back at ATOM |
500 |
* instances to be queried during the solution process. Rather, we |
501 |
* need to establish a process in which the var list tells all its |
502 |
* atoms about the solver derived values or the var list updates |
503 |
* its values and flags from the instance tree. |
504 |
* There is a counterpart exercise that needs to go on in the |
505 |
* rel module so that (for remote processing) it is possible to |
506 |
* do everything without looking back at the instance tree. |
507 |
* At present, we will always keep VAR_FIXED in sync with the |
508 |
* instance tree, but the instance tree is the leader. |
509 |
* 6/96. baa |
510 |
*/ |
511 |
|
512 |
ASC_DLLSPEC int32 var_apply_filter(const struct var_variable *var, |
513 |
const var_filter_t *filter); |
514 |
/**< |
515 |
Returns 1 if filter and var flags are compatible, 0 elsewise. |
516 |
See the filter description in rel.h. This is exactly the same. |
517 |
*/ |
518 |
|
519 |
ASC_DLLSPEC uint32 var_fixed(struct var_variable *var); |
520 |
/**< Returns the fixed flag of var. Has side effects in the ascend instance. */ |
521 |
ASC_DLLSPEC void var_set_fixed(struct var_variable *var, uint32 fixed); |
522 |
/**< Sets the fixed flag of var. Has side effects in the ascend instance. */ |
523 |
extern uint32 var_relaxed(struct var_variable *var); |
524 |
/**< Returns the relaxed flag of var. Has side effects in the ascend instance. */ |
525 |
extern void var_set_relaxed(struct var_variable *var, uint32 fixed); |
526 |
/**< Sets the relaxed flag of var. Has side effects in the ascend instance. */ |
527 |
extern uint32 var_interface(struct var_variable *var); |
528 |
/**< Returns the interface flag of var. Has side effects in the ascend instance. */ |
529 |
extern void var_set_interface(struct var_variable *var, uint32 fixed); |
530 |
/**< Sets the interface flag of var. Has side effects in the ascend instance. |
531 |
@todo solver/var.h: var_set_interface() not implemented. Implement or remove. |
532 |
*/ |
533 |
|
534 |
#ifdef NDEBUG |
535 |
# define var_in_block(var) ((var)->flags & VAR_INBLOCK) |
536 |
/**< Returns the in_block flag of var as a uint32. */ |
537 |
# define var_incident(var) ((var)->flags & VAR_INCIDENT) |
538 |
/**< Returns the incident flag of var as a uint32. */ |
539 |
# define var_deriv(var) ((var)->flags & VAR_DERIV) |
540 |
/**< Returns the deriv flag of var as a uint32. */ |
541 |
# define var_diff(var) ((var)->flags & VAR_DIFF) |
542 |
/**< Returns the deriv flag of var as a uint32. */ |
543 |
# define var_pre(var) ((var)->flags & VAR_PRE) |
544 |
/**< Returns the pre flag of var as a uint32. */ |
545 |
# define var_active(var) ((var)->flags & VAR_ACTIVE) |
546 |
/**< Returns the active flag of var as a uint32. */ |
547 |
# define var_nonbasic(var) ((var)->flags & VAR_NONBASIC) |
548 |
/**< Returns the nonbasic flag of var as a uint32. */ |
549 |
# define var_active_at_bnd(var) ((var)->flags & VAR_ACTIVE_AT_BND) |
550 |
/**< Returns the active_at_bnd flag of var as a uint32. */ |
551 |
# define var_eligible(var) ((var)->flags & VAR_ELIGIBLE) |
552 |
/**< Returns the eligible flag of var as a uint32. */ |
553 |
# define var_eligible_in_subregion(var) ((var)->flags & VAR_ELIGIBLE_IN_SUBREGION) |
554 |
/**< Returns the eligible_in_subregion flag of var as a uint32. */ |
555 |
# define var_incident_in_case(var) ((var)->flags & VAR_INCIDENT_IN_CASE) |
556 |
/**< Returns the incident_in_case flag of var as a uint32. */ |
557 |
# define var_potentially_fixed(var) ((var)->flags & VAR_POTENTIALLY_FIXED) |
558 |
/**< Returns the potentially_fixed flag of var as a uint32. */ |
559 |
#else |
560 |
# define var_in_block(var) var_flagbit((var),VAR_INBLOCK) |
561 |
/**< Returns the in_block flag of var as a uint32. */ |
562 |
|
563 |
# define var_incident(var) var_flagbit((var),VAR_INCIDENT) |
564 |
/**< Returns the incident flag of var as a uint32. */ |
565 |
# define var_deriv(var) var_flagbit((var),VAR_DERIV) |
566 |
/**< Returns the deriv flag of var as a uint32. */ |
567 |
# define var_diff(var) var_flagbit((var),VAR_DIFF) |
568 |
/**< Returns the deriv flag of var as a uint32. */ |
569 |
# define var_pre(var) var_flagbit((var),VAR_PRE) |
570 |
/**< Returns the pre flag of var as a uint32. */ |
571 |
# define var_active(var) var_flagbit((var),VAR_ACTIVE) |
572 |
/**< Returns the active flag of var as a uint32. */ |
573 |
# define var_nonbasic(var) var_flagbit((var),VAR_NONBASIC) |
574 |
/**< Returns the nonbasic flag of var as a uint32. */ |
575 |
# define var_active_at_bnd(var) var_flagbit((var),VAR_ACTIVE_AT_BND) |
576 |
/**< Returns the active_at_bnd flag of var as a uint32. */ |
577 |
# define var_eligible(var) var_flagbit((var),VAR_ELIGIBLE) |
578 |
/**< Returns the eligible flag of var as a uint32. */ |
579 |
# define var_eligible_in_subregion(var) var_flagbit((var),VAR_ELIGIBLE_IN_SUBREGION) |
580 |
/**< Returns the eligible_in_subregion flag of var as a uint32. */ |
581 |
# define var_incident_in_case(var) var_flagbit((var),VAR_INCIDENT_IN_CASE) |
582 |
/**< Returns the incident_in_case flag of var as a uint32. */ |
583 |
# define var_potentially_fixed(var) var_flagbit((var),VAR_POTENTIALLY_FIXED) |
584 |
/**< Returns the potentially_fixed flag of var as a uint32. */ |
585 |
#endif /* NDEBUG */ |
586 |
|
587 |
#define var_set_in_block(var,oneorzero) \ |
588 |
var_set_flagbit((var),VAR_INBLOCK,(oneorzero)) |
589 |
/**< Sets the in_block flag of var on (1) or off (0). */ |
590 |
#define var_set_incident(var,oneorzero) \ |
591 |
var_set_flagbit((var),VAR_INCIDENT,(oneorzero)) |
592 |
/**< Sets the incident flag of var on (1) or off (0). */ |
593 |
#define var_set_deriv(var,oneorzero) \ |
594 |
var_set_flagbit((var),VAR_DERIV,(oneorzero)) |
595 |
/**< Sets the deriv flag of var on (1) or off (0). */ |
596 |
#define var_set_diff(var,oneorzero) \ |
597 |
var_set_flagbit((var),VAR_DIFF,(oneorzero)) |
598 |
/**< Sets the algeb flag of var on (1) or off (0). */ |
599 |
#define var_set_pre(var,oneorzero) \ |
600 |
var_set_flagbit((var),VAR_PRE,(oneorzero)) |
601 |
/**< Sets the pre flag of var on (1) or off (0). */ |
602 |
#define var_set_interface(var,oneorzero) \ |
603 |
var_set_flagbit((var),VAR_INTERFACE,(oneorzero)) |
604 |
/**< Sets the interface flag of var on (1) or off (0). */ |
605 |
#define var_set_active(var,oneorzero) \ |
606 |
var_set_flagbit((var),VAR_ACTIVE,(oneorzero)) |
607 |
/**< Sets the active flag of var on (1) or off (0). */ |
608 |
#define var_set_nonbasic(var,oneorzero) \ |
609 |
var_set_flagbit((var),VAR_NONBASIC,(oneorzero)) |
610 |
/**< Sets the nonbasic flag of var on (1) or off (0). */ |
611 |
#define var_set_active_at_bnd(var,oneorzero) \ |
612 |
var_set_flagbit((var),VAR_ACTIVE_AT_BND,(oneorzero)) |
613 |
/**< Sets the active_at_bnd flag of var on (1) or off (0). */ |
614 |
#define var_set_eligible(var,oneorzero) \ |
615 |
var_set_flagbit((var),VAR_ELIGIBLE,(oneorzero)) |
616 |
/**< Sets the eligible flag of var on (1) or off (0). */ |
617 |
#define var_set_eligible_in_subregion(var,oneorzero) \ |
618 |
var_set_flagbit((var),VAR_ELIGIBLE_IN_SUBREGION,(oneorzero)) |
619 |
/**< Sets the eligible_in_subregion flag of var on (1) or off (0). */ |
620 |
#define var_set_incident_in_case(var,oneorzero) \ |
621 |
var_set_flagbit((var),VAR_INCIDENT_IN_CASE,(oneorzero)) |
622 |
/**< Sets the incident_in_case flag of var on (1) or off (0). */ |
623 |
#define var_set_potentially_fixed(var,oneorzero) \ |
624 |
var_set_flagbit((var),VAR_POTENTIALLY_FIXED,(oneorzero)) |
625 |
/**< Sets the potentially_fixed flag of var on (1) or off (0). */ |
626 |
|
627 |
extern struct var_variable ** |
628 |
var_BackendTokens_to_vars(slv_system_t sys, SlvBackendToken *tokenlist, int32 len); |
629 |
/**< |
630 |
varp is NULL iff something is amiss, OTHERWISE it |
631 |
contains len struct var_variable * s. |
632 |
The user should free the array varp when done with it. |
633 |
Some entries in the array varp may be NULL if the tokenlist |
634 |
contains a token which is not from the sys given. |
635 |
tokenlist[i] <--> varp[i];<br><br> |
636 |
|
637 |
The whole point of a slv_system_t is to isolate the client from |
638 |
the compiler backend. Clients who find themselves in need of |
639 |
this function are very much in need of rethinking as well. |
640 |
For that reason, among others, this function is not heavily |
641 |
optimized, it is however reasonable for 1-off jobs.<br><br> |
642 |
|
643 |
CPU Cost = k1*complexity of the instance under sys + |
644 |
k2*number of vars in sys + k3*len. |
645 |
|
646 |
@todo Hasn't been through verification and testing - SQA asleep. |
647 |
*/ |
648 |
|
649 |
/* |
650 |
* What constitutes a solver_var (and some other interesting types) |
651 |
* is controlled by the ascend server via the following functions. |
652 |
* Clients shouldn't use these. |
653 |
*/ |
654 |
|
655 |
#define SOLVER_VAR_STR "solver_var" |
656 |
#define SOLVER_INT_STR "solver_int" |
657 |
#define SOLVER_BINARY_STR "solver_binary" |
658 |
#define SOLVER_SEMI_STR "solver_semi" |
659 |
|
660 |
#define solver_par(i) (0) |
661 |
|
662 |
extern boolean solver_var(SlvBackendToken inst); |
663 |
/**< |
664 |
Returns true if the instance in question matches the currently |
665 |
known definition of solver_var. Since these definitions |
666 |
involve refinement, solver_var() will report TRUE on variables |
667 |
matching any of these types: |
668 |
- solver_var |
669 |
- solver_int |
670 |
- solver_binary |
671 |
- solver_semi |
672 |
|
673 |
SERVER ONLY. clients should just look at the flagbits. |
674 |
*/ |
675 |
extern boolean solver_int(SlvBackendToken inst); |
676 |
/**< |
677 |
Returns true if the instance in question matches the currently |
678 |
known definition of solver_int. |
679 |
SERVER ONLY. clients should just look at the flagbits. |
680 |
*/ |
681 |
extern boolean solver_binary(SlvBackendToken inst); |
682 |
/**< |
683 |
Returns true if the instance in question matches the currently |
684 |
known definition of solver_binary. |
685 |
SERVER ONLY. clients should just look at the flagbits. |
686 |
*/ |
687 |
extern boolean solver_semi(SlvBackendToken inst); |
688 |
/**< |
689 |
Returns true if the instance in question matches the currently |
690 |
known definition of solver_semi. |
691 |
SERVER ONLY. clients should just look at the flagbits. |
692 |
*/ |
693 |
/* For the above... |
694 |
Note that these definitions involve refinement, so |
695 |
solver_var will report TRUE on variables matching any of |
696 |
these types, while solver_binary will only be TRUE on binaries. |
697 |
|
698 |
hierarchy is solvervar-\----solver_int-----solver_binary |
699 |
\-solver_semi |
700 |
|
701 |
*/ |
702 |
|
703 |
extern boolean set_solver_types(void); |
704 |
/**< |
705 |
Sets (changes) the current definition of solver_var to match |
706 |
the current library. Returns 1 if unsuccessful, 0 if ok. |
707 |
If 1, it is useless to invoke the solvers. |
708 |
Also sets all the related types listed above. |
709 |
*/ |
710 |
|
711 |
/* @} */ |
712 |
|
713 |
#endif /* ASC_VAR_H */ |
714 |
|