1 |
/* |
2 |
* Logical Relation utility functions for Ascend |
3 |
* by Vicente Rico-Ramirez |
4 |
* Version: $Revision: 1.9 $ |
5 |
* Version control file: $RCSfile: logrel_util.h,v $ |
6 |
* Date last modified: $Date: 1997/07/29 15:52:48 $ |
7 |
* Last modified by: $Author: rv2a $ |
8 |
* |
9 |
* This file is part of the Ascend Language Interpreter. |
10 |
* |
11 |
* Copyright (C) 1997 Carnegie Mellon University |
12 |
* |
13 |
* This file is part of the Ascend Interpreter. |
14 |
* The Ascend Interpreter is free software; you can redistribute |
15 |
* it and/or modify it under the terms of the GNU General Public License as |
16 |
* published by the Free Software Foundation; either version 2 of the |
17 |
* License, or (at your option) any later version. |
18 |
* |
19 |
* Ascend is distributed in hope that it will be |
20 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
* General Public License for more details. |
23 |
* |
24 |
* You should have received a copy of the GNU General Public License |
25 |
* along with the program; if not, write to the Free Software Foundation, |
26 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
27 |
* COPYING. |
28 |
* |
29 |
*/ |
30 |
|
31 |
/** @file |
32 |
* Logical Relation utility functions for Ascend. |
33 |
* <pre> |
34 |
* When #including logrel_util.h, make sure these files are #included first: |
35 |
* #include "utilities/ascConfig.h" |
36 |
* #include "compiler.h" |
37 |
* #include "logrelation.h" |
38 |
* #include "instance_enum.h" |
39 |
* #include "fractions.h" |
40 |
* #include "dimen.h" |
41 |
* </pre> |
42 |
*/ |
43 |
|
44 |
#ifndef __LOGRELATION_UTIL_H_SEEN__ |
45 |
#define __LOGRELATION_UTIL_H_SEEN__ |
46 |
|
47 |
extern enum Expr_enum LogRelRelop(CONST struct logrelation *lrel); |
48 |
/**< |
49 |
* <!-- enum Expr_enum LogRelRelop(lrel) --> |
50 |
* <!-- CONST struct logrelation *lrel; --> |
51 |
* Return the type of the logical relation operator of the relation: |
52 |
* - e_boolean_eq equality constraint |
53 |
* - e_boolean_neq non-equality contraint |
54 |
*/ |
55 |
|
56 |
extern unsigned long NumberBoolVars(CONST struct logrelation *lrel); |
57 |
/**< |
58 |
* <!-- unsigned long NumberBoolVars(lrel) --> |
59 |
* <!-- struct logrelation *lrel; --> |
60 |
* This will indicate the number of distinct boolean atoms to which this |
61 |
* logical relation points. This number contains both fixed and non-fixed |
62 |
* atoms. |
63 |
*/ |
64 |
|
65 |
extern struct Instance *LogRelBoolVar(CONST struct logrelation *lrel, |
66 |
unsigned long varnum); |
67 |
/**< |
68 |
* <!-- struct Instance *LogRelBoolVar(lrel,varnum) --> |
69 |
* <!-- struct logrelation *lrel; --> |
70 |
* <!-- unsigned long varnum; --> |
71 |
* This will return the varnum'th boolean variable. |
72 |
*/ |
73 |
|
74 |
extern unsigned long NumberRelations(CONST struct logrelation *lrel); |
75 |
/**< |
76 |
* <!-- unsigned long NumberRelations(lrel) --> |
77 |
* <!-- struct logrelation *lrel; --> |
78 |
* This will indicate the number of distinct relations to which this |
79 |
* logical relation points. This number contains both conditional |
80 |
* relations and conditional logrelations. |
81 |
*/ |
82 |
|
83 |
extern struct Instance *LogRelRelation(CONST struct logrelation *lrel, |
84 |
unsigned long relnum); |
85 |
/**< |
86 |
* <!-- struct Instance *LogRelRelation(lrel,relnum) --> |
87 |
* <!-- struct logrelation *lrel; --> |
88 |
* <!-- unsigned long relnum; --> |
89 |
* This will return the relnum'th relation in the satisfied rel list. |
90 |
*/ |
91 |
|
92 |
/*--------------------------------------------------------------------------- |
93 |
* Logical Relation specific code. |
94 |
* Very little sanity checking is done. |
95 |
*--------------------------------------------------------------------------- |
96 |
*/ |
97 |
|
98 |
extern unsigned long LogRelLength(CONST struct logrelation *lrel, int lhs); |
99 |
/**< |
100 |
* <!-- unsigned long LogRelLength(lrel,lhs) --> |
101 |
* <!-- const struct logrelation *lrel; --> |
102 |
* <!-- int lhs; --> |
103 |
* If lhs is true, return the number of terms on the left hand side of the |
104 |
* logical relation; otherwise, return the number of terms on the right |
105 |
* hand side of the logical relation. |
106 |
*/ |
107 |
|
108 |
extern CONST struct logrel_term |
109 |
*LogRelTerm(CONST struct logrelation *lrel, |
110 |
unsigned long pos, |
111 |
int lhs); |
112 |
/**< |
113 |
* <!-- const struct logrel_term *LogRelTerm(lrel,pos,lhs) --> |
114 |
* <!-- const struct logrelation *lrel; --> |
115 |
* <!-- unsigned long pos; --> |
116 |
* <!-- int lhs; --> |
117 |
* If lhs is true, return the term in position pos of the left hand side; |
118 |
* otherwise, return the term in position pos of the right hand side. |
119 |
* A bizarre thing about this operator: 1<=pos<=LogRelLength(lrel,lhs). |
120 |
* This is a holdover from gllist days. |
121 |
*/ |
122 |
|
123 |
#ifdef NDEBUG |
124 |
#define NewLogRelTerm(r,p,l) \ |
125 |
LOGA_TERM( (l)!=0 ? (&((r)->token.lhs[(p)])) : (&((r)->token.rhs[(p)])) ) |
126 |
#else |
127 |
#define NewLogRelTerm(r,p,l) NewLogRelTermF((r),(p),(l)) |
128 |
#endif |
129 |
/**< |
130 |
* If lhs is true, return the term in position p of the left hand side; |
131 |
* otherwise, return the term in position p of the right hand side. |
132 |
* For this operator: 0 <= p < LogRelLength(lrel,lhs) as a C array. |
133 |
* Once Everybody gets their damn hands off LogRelTerm(), switch its |
134 |
* semantics and eliminate one of this pair. |
135 |
* @param r const struct logrelation*, logical relation to query. |
136 |
* @param p unsigned long, position to return. |
137 |
* @param l int, TRUE to return from left hand side, FALSE then from rhs. |
138 |
* @return The term as an CONST struct logrel_term*. |
139 |
* @see NewLogRelTermF() |
140 |
*/ |
141 |
extern CONST struct logrel_term |
142 |
*NewLogRelTermF(CONST struct logrelation *lrel, unsigned long apos, int lhs); |
143 |
/**< |
144 |
* <!-- const struct logrel_term *NewLogRelTerm(lrel,apos,lhs) --> |
145 |
* <!-- const struct logrelation *lrel; --> |
146 |
* <!-- unsigned long apos; --> |
147 |
* <!-- int lhs; --> |
148 |
* <!-- If lhs is true, return the term in position apos of the left hand side; --> |
149 |
* <!-- otherwise, return the term in position pos of the right hand side. --> |
150 |
* <!-- For this operator: 0 <= apos < LogRelLength(lrel,lhs) as a C array. --> |
151 |
* <!-- Once Everybody gets their damn hands off LogRelTerm, switch its --> |
152 |
* <!-- semantics and eliminate one of this pair. --> |
153 |
* Implementation function for NewLogRelTerm(). Do not use this |
154 |
* function directly - use NewLogRelTerm() instead. |
155 |
*/ |
156 |
|
157 |
#ifdef NDEBUG |
158 |
#define LogRelSideTerm(rs,p) LOGA_TERM(&((rs)[(p)])) |
159 |
#else |
160 |
#define LogRelSideTerm(rs,p) LogRelSideTermF((rs),(p)) |
161 |
#endif |
162 |
/**< |
163 |
* Return the term in position p of the side. |
164 |
* For this operator: 0 <= p < length of the side. |
165 |
* @param rs CONST union LogRelTermUnion*, side. |
166 |
* @param p unsigned long, position to return. |
167 |
* @return The term as an CONST struct logrel_term*. |
168 |
* @see LogRelSideTermF() |
169 |
*/ |
170 |
extern CONST struct logrel_term |
171 |
*LogRelSideTermF(CONST union LogRelTermUnion *lrelside, unsigned long apos); |
172 |
/**< |
173 |
* <!-- CONST struct logrel_term *LogRelSideTerm(lrelside,apos) --> |
174 |
* <!-- CONST union LogRelTermUnion *lrelside --> |
175 |
* <!-- unsigned long apos; --> |
176 |
* <!-- Return the term in position apos of the side. --> |
177 |
* <!-- For this operator: 0 <= apos < length of the side. --> |
178 |
* Implementation function for LogRelSideTerm(). Do not use this |
179 |
* function directly - use LogRelSideTerm() instead. |
180 |
*/ |
181 |
|
182 |
#ifdef NDEBUG |
183 |
#define LogRelTermType(rtp) ((rtp)->t) |
184 |
#else |
185 |
#define LogRelTermType(rtp) LogRelTermTypeF(rtp) |
186 |
#endif |
187 |
/**< |
188 |
* Return the type of the logical relation term rtp. |
189 |
* WARNING: if ALLOCATED_TESTS is active, rtp must be an allocated term; |
190 |
* automatic variables will cause an assert() to fail. |
191 |
* @param rtp const struct logrel_term*, the term to query. |
192 |
* @return The type of the term as an enum Expr_enum. |
193 |
* @see LogRelTermTypeF() |
194 |
*/ |
195 |
extern enum Expr_enum LogRelTermTypeF(CONST struct logrel_term *term); |
196 |
/**< |
197 |
* <!-- enum Expr_enum LogRelTermType(term) --> |
198 |
* <!-- const struct logrel_term *term; --> |
199 |
* <!-- return the type of the logical relation term. --> |
200 |
* <!-- WARNING: if ALLOCATED_TESTS is active, term must be an allocated term; --> |
201 |
* <!-- automatic variables will cause an assert() to fail. --> |
202 |
* Implementation function for LogRelTermType(). Do not use this |
203 |
* function directly - use LogRelTermType() instead. |
204 |
*/ |
205 |
|
206 |
extern unsigned long LogTermBoolVarNumber(CONST struct logrel_term *term); |
207 |
/**< |
208 |
* <!-- unsigned long LogTermBoolVarNumber(term) --> |
209 |
* <!-- const struct logrel_term *term; --> |
210 |
* Return the index into the logical relation variable list. |
211 |
*/ |
212 |
|
213 |
extern int LogTermBoolean(CONST struct logrel_term *term); |
214 |
/**< |
215 |
* <!-- int LogTermBoolean(term) --> |
216 |
* <!-- const struct logrel_term *term; --> |
217 |
* Return the boolean value from an e_boolean type logical relation term. |
218 |
*/ |
219 |
|
220 |
extern int LogTermInteger(CONST struct logrel_term *term); |
221 |
/**< |
222 |
* <!-- int LogTermInteger(term); --> |
223 |
* <!-- CONST struct logrel_term *term; --> |
224 |
* Return the integer value from an e_int type logical relation term. |
225 |
*/ |
226 |
|
227 |
extern int LogTermIntegerBoolValue(CONST struct logrel_term *term); |
228 |
/**< |
229 |
* <!-- int LogTermInteger(term); --> |
230 |
* <!-- CONST struct logrel_term *term; --> |
231 |
* Return a 0-1 value from an e_int type logical relation term. |
232 |
*/ |
233 |
|
234 |
extern int LogTermBoolVar(CONST struct logrelation *lrel, |
235 |
CONST struct logrel_term *term); |
236 |
/**< |
237 |
* <!-- int LogTermBoolVar(lrel,term) --> |
238 |
* <!-- const struct logrelation *lrel; --> |
239 |
* <!-- const struct logrel_term *term; --> |
240 |
* Return the integar value from a e_var type logical relation term. |
241 |
*/ |
242 |
|
243 |
extern int LogTermSatisfied(CONST struct logrelation *lrel, |
244 |
CONST struct logrel_term *term, |
245 |
int perturb, |
246 |
struct gl_list_t *instances); |
247 |
/**< |
248 |
* <!-- int LogTermSatisfied(lrel,term); --> |
249 |
* <!-- CONST struct logrelation *lrel; --> |
250 |
* <!-- CONST struct logrel_term *term; --> |
251 |
* <!-- int perturb; --> |
252 |
* <!-- struct gl_list_t *instances; --> |
253 |
* Return the truth value of a SATISFIED logical relation term. |
254 |
* If perturb, and the instances pointed by the SATISFIED term is included |
255 |
* in the list instances, the truth value of the SATISFIED term is |
256 |
* inverted. |
257 |
*/ |
258 |
|
259 |
extern CONST struct Name *LogTermSatName(CONST struct logrel_term *term); |
260 |
/**< |
261 |
* <!-- struct Name *LogTermSatName(term) --> |
262 |
* <!-- const struct logrel_term *term; --> |
263 |
* Return the name of the conditional equation specified in an |
264 |
* e_satisfied term |
265 |
*/ |
266 |
|
267 |
extern unsigned long LogTermSatRelNumber(CONST struct logrel_term *term); |
268 |
/**< |
269 |
* <!-- unsigned long LogTermSatRelNumber(term) --> |
270 |
* <!-- const struct logrel_term *term; --> |
271 |
* Return the index into the logical relation relations list. |
272 |
*/ |
273 |
|
274 |
extern double LogTermSatTolerance(CONST struct logrel_term *term); |
275 |
/**< |
276 |
* <!-- double *LogTermSatTolerance(term) --> |
277 |
* <!-- const struct logrel_term *term; --> |
278 |
* Return the real value specified as the tolerance of an e_satisfied term |
279 |
*/ |
280 |
|
281 |
extern CONST dim_type *LogTermSatDimensions(CONST struct logrel_term *term); |
282 |
/**< |
283 |
* <!-- const dim_type *LogTermSatDimensions(term) --> |
284 |
* <!-- const struct logrel_term *term; --> |
285 |
* Return the dimensions of the real value specified in the tolerance of |
286 |
* an e_satisfied term |
287 |
*/ |
288 |
|
289 |
extern unsigned long LogRelDepth(CONST struct logrelation *lrel); |
290 |
/**< |
291 |
* <!-- unsigned long LogRelDepth(lrel) --> |
292 |
* <!-- struct logrelation *lrel; --> |
293 |
* Return the depth of stack required to evaluate this logical relation. |
294 |
*/ |
295 |
|
296 |
/*--------------------------------------------------------------------------- |
297 |
* TokenRelation Infix operations. |
298 |
*--------------------------------------------------------------------------- |
299 |
*/ |
300 |
|
301 |
/* |
302 |
* The four defines following return term pointers. |
303 |
* struct logrel_term *r, *t; |
304 |
* r = LogTermUniLeft(t); for example. |
305 |
* These should be implemented as functions which assert type |
306 |
* and revert to macros with NDEBUG. |
307 |
*/ |
308 |
#define LogTermUniLeft(t) ( ((struct LogRelUnary *)t) -> left) |
309 |
/**< |
310 |
* Retrieve the lhs of a unary logical relation. |
311 |
* Parameter and return values are <code>struct logrel_term*</code>. |
312 |
*/ |
313 |
#define LogTermBinLeft(t) ( ((struct LogRelBinary *)t) -> left) |
314 |
/**< |
315 |
* Retrieve the lhs of a binary logical relation. |
316 |
* Parameter and return values are <code>struct logrel_term*</code>. |
317 |
*/ |
318 |
#define LogTermBinRight(t) ( ((struct LogRelBinary *)t) -> right) |
319 |
/**< |
320 |
* Retrieve the rhs of a binary logical relation. |
321 |
* Parameter and return values are <code>struct logrel_term*</code>. |
322 |
*/ |
323 |
|
324 |
extern struct logrel_term *LogRelINF_Lhs(CONST struct logrelation *lrel); |
325 |
/**< |
326 |
* Returns the lhs of an infix logical relation. This may be NULL, |
327 |
* if the logical relation has not been set for infix scanning. |
328 |
*/ |
329 |
|
330 |
extern struct logrel_term *LogRelINF_Rhs(CONST struct logrelation *lrel); |
331 |
/**< |
332 |
* Return the rhs of an infix logical relation. This may be NULL |
333 |
* if the logical relation has not been set up for infix scanning. |
334 |
*/ |
335 |
|
336 |
extern CONST struct gl_list_t *LogRelBoolVarList(CONST struct logrelation *lrel); |
337 |
/**< |
338 |
* <!-- const struct gl_list_t *LogRelBoolVarList(lr); --> |
339 |
* <!-- const struct logrelation *lr; --> |
340 |
* Returns the unique incident variable list which is owned by the |
341 |
* logical relation. *DO NOT MODIFY*. It is for the convenience of those |
342 |
* desirous of a READ_ONLY look. It is a list of instance pointers, |
343 |
* which maybe NULL. |
344 |
*/ |
345 |
|
346 |
extern CONST struct gl_list_t *LogRelSatRelList(CONST struct logrelation *lrel); |
347 |
/**< |
348 |
* <!-- const struct gl_list_t *LogRelSatRelList(lr); --> |
349 |
* <!-- const struct logrelation *lr; --> |
350 |
* Returns the unique relation list which is owned by the |
351 |
* logical relation. *DO NOT MODIFY*. It is for the convenience of those |
352 |
* desirous of a READ_ONLY look. It is a list of instance pointers, |
353 |
* which maybe NULL. |
354 |
*/ |
355 |
|
356 |
ASC_DLLSPEC int LogRelResidual(CONST struct logrelation *lrel); |
357 |
/**< |
358 |
* <!-- int LogRelResidual(lrel) --> |
359 |
* <!-- const struct logrelation *lrel; --> |
360 |
* Return the boolean residual of the logical relation. |
361 |
*/ |
362 |
|
363 |
extern void SetLogRelResidual(struct logrelation *lrel, int value); |
364 |
/**< |
365 |
* <!-- void SetLogRelResidual(lrel,value) --> |
366 |
* <!-- struct logrelation *lrel; --> |
367 |
* <!-- int value; --> |
368 |
* Set the value of the logical relation residual. |
369 |
*/ |
370 |
|
371 |
ASC_DLLSPEC int LogRelIsCond(CONST struct logrelation *lrel); |
372 |
/**< |
373 |
* <!-- int LogRelIsCond(lrel) --> |
374 |
* <!-- const struct logrelation *lrel; --> |
375 |
* Return the value of the logiscond flag of the logicalrelation. |
376 |
*/ |
377 |
|
378 |
extern void SetLogRelIsCond(struct logrelation *lrel); |
379 |
/**< |
380 |
* <!-- void SetLogRelIsCond(lrel) --> |
381 |
* <!-- struct logrelation *lrel; --> |
382 |
* Sets the value of the logiscond field of the logical relation to 1 |
383 |
*/ |
384 |
|
385 |
extern int LogRelNominal(CONST struct logrelation *lrel); |
386 |
/**< |
387 |
* <!-- int LogRelNominal(lrel) --> |
388 |
* <!-- const struct logrelation *lrel; --> |
389 |
* Return the nominal of the logical relation. |
390 |
*/ |
391 |
|
392 |
extern void SetLogRelNominal(struct logrelation *lrel, int i); |
393 |
/**< |
394 |
* <!-- void SetLogRelNominal(lrel,i) --> |
395 |
* <!-- struct logrelation *lrel; --> |
396 |
* <!-- int i; --> |
397 |
* Sets the value of the nominal field of the logical relation to the |
398 |
* value of i |
399 |
*/ |
400 |
|
401 |
extern int FindTolInSatTermOfLogRel(struct Instance *lrelinst, |
402 |
struct Instance *condinst, |
403 |
double *tolerance); |
404 |
/**< |
405 |
* <!-- status = FindTolInSatTermOfLogRel(lrelinst,condinst); --> |
406 |
* <!-- struct Instance *lrelinst; --> |
407 |
* <!-- struct Instance *condinst; --> |
408 |
* <!-- int status; --> |
409 |
* <!-- double *tolerance; --> |
410 |
* Look in the logrelation instance lrelinst for a SATISFIED term involving |
411 |
* the instance condinst. When found, it will find the obtain tolerance |
412 |
* specified in the SATISFIED term (if such a value is given) and it will |
413 |
* assign it to the *tolerance. If the condinst is a logrel (mistakenly), |
414 |
* or if the SATISFIED term does not specify a value for the tolerance, |
415 |
* it will assign the default value DEFTOLERANCE to *tolerance. |
416 |
* status !=0 indicates it did not find a term containing the instance. |
417 |
*/ |
418 |
|
419 |
/* |
420 |
*--------------------------------------------------------------------------- |
421 |
* Calculation routines |
422 |
*--------------------------------------------------------------------------- |
423 |
*/ |
424 |
|
425 |
/* |
426 |
* Calculation of the Logical Residuals of a logical relation : |
427 |
* LogRelCalcResidualPostfix |
428 |
* LogRelCalcResidualInfix |
429 |
* and calculation of the values(s) of a boolean variable which make a |
430 |
* logical relation to be satisfied: |
431 |
* LogRelFindBoolValues |
432 |
* |
433 |
* IMPORTANT: |
434 |
* The solution of conditional model implicates the presence of |
435 |
* SATISFIED terms (satisfaction of Boundary conditions) |
436 |
* in some of the logical relations. Because the freedom that the |
437 |
* modeling language gives to the user, sometimes is very difficult |
438 |
* to know if the change of the truth value of a SATISFIED term is |
439 |
* really meaningful to the configuration of the conditional problem. |
440 |
* A boundary may be crossed, but still the boolean dependent on that |
441 |
* condition may not change; furthermore, even a change in that boolean |
442 |
* may not affect the configuration of the problem because a change |
443 |
* of configuration may require the satisfaction of several conditions |
444 |
* simultaneously. |
445 |
* The easier way to test if the crossing of a boundary affects the current |
446 |
* configuration is to solve the logical relations assuming such a |
447 |
* crossing and finding if the configuration of the problem changes. |
448 |
* This task is performed here by using the "perturb" flag and a list |
449 |
* of pointers to the relation instance which constitutes the boundary(ies). |
450 |
* The activation of the perturbation flag causes the calculation |
451 |
* routines to INVERT the truth value of the SATISFIED terms containing |
452 |
* the relation instances pointed by the list of pointers. |
453 |
* The flag and the list of pointers are needed because the SATISFIED term |
454 |
* is not an instance by itself and we have access to it only trough the |
455 |
* logrel instance. |
456 |
* Another option would be to modify the values of the variables incident |
457 |
* in the boundary until the truth value of the SATISFIED changes by itself, |
458 |
* but this would have to be iteratively (i.e. more expensive), since it |
459 |
* would be required to perform gradient calculations in |
460 |
* order to know how the change of the value of some variable will modify |
461 |
* the residual of the boundary. Other question that we would need to |
462 |
* answer is how many variables should be modified simultaneously,etc. |
463 |
* Notice that this is not necessary because we do not care about a change |
464 |
* in the real values of the variables incident in the boundary (and, as |
465 |
* a matter of fact, we do not want ot modify the current values), we only |
466 |
* want to know what would it happen with the value of logical variables |
467 |
* if the truth value of the SATISFIED term changes. |
468 |
* |
469 |
* A third option would be to keep the information about the number |
470 |
* of subregions in the conditional model and the values for the booleans |
471 |
* which make them active. This is unaceptable for problems involving |
472 |
* a big number of boundary conditions, since the problem is combinatorial. |
473 |
* |
474 |
* IN GENERAL, ANY USER INTERESTED IN THESE CALCULATION ROUTINES FOR |
475 |
* PURPOSES OF SOLVING PURE LOGIC PROBLEMS (NOT CONTAINING BOUNDARIES), |
476 |
* SHOULD NOT CONSIDER THE |
477 |
* PARAMETERS EXPLAINED ABOVE. IT IS RECOMMENDED THAT HE/SHE SHOULD |
478 |
* USE THE MACRO |
479 |
* LogRelCalcResidual |
480 |
* WHICH CALL THE CALCULATION ROUTINES WITHOUT CONSIDERING THOSE |
481 |
* PARAMETERS. |
482 |
*/ |
483 |
|
484 |
extern int LogRelCalcResidualPostfix(struct Instance *i, |
485 |
int *res, |
486 |
int perturb, |
487 |
struct gl_list_t *instances); |
488 |
/**< |
489 |
* <!-- status = int LogRelCalcResidualPostfix(i,res,perturb,instances); --> |
490 |
* <!-- struct Instance *i; --> |
491 |
* <!-- int *res; --> |
492 |
* <!-- int perturb; --> |
493 |
* <!-- struct gl_list_t *instances; --> |
494 |
* <!-- int status; --> |
495 |
* Sets *res to the logical residual of the logical relation. The logical |
496 |
* residual is evaluating by comparing the truth values of the two terms |
497 |
* of the logical relation. If the logical relation is an equality, a |
498 |
* residual of 1 (TRUE) means that the two terms has the same truth value, |
499 |
* if they do not, the residual is zero. Similar reasoning applies when |
500 |
* the logical relation is an inequality. |
501 |
* Uses postfix evaluation. |
502 |
* If *perturb !=0, that means that we will invert the truth value of |
503 |
* the SATISFIED terms involving the relation instances pointed by the |
504 |
* gl_list. |
505 |
* status != 0 implies a problem. |
506 |
*/ |
507 |
|
508 |
extern int LogRelCalcResidualInfix(struct Instance *i, |
509 |
int *res, |
510 |
int perturb, |
511 |
struct gl_list_t *instances); |
512 |
/**< |
513 |
* <!-- status = LogRelCalcResidualInfix(i,res,perturb,instances); --> |
514 |
* <!-- struct Instance *i; --> |
515 |
* <!-- int *res; --> |
516 |
* <!-- int perturb; --> |
517 |
* <!-- struct gl_list_t *instances; --> |
518 |
* <!-- int status; --> |
519 |
* Sets *res to the logical residual of the logical relation. The logical |
520 |
* residual is evaluating by comparing the truth values of the two terms |
521 |
* of the logical relation. If the logical relation is an equality, a |
522 |
* residual of 1 (TRUE) means that the two terms has the same truth value, |
523 |
* if they do not, the residual is zero. Similar reasoning applies when |
524 |
* the logical relation is an inequality. |
525 |
* Uses infix evaluation. |
526 |
* If *perturb !=0, that means that we will invert the truth value of |
527 |
* the SATISFIED terms involving the relation instances pointed by the |
528 |
* gl_list |
529 |
* status != 0 implies a problem. |
530 |
*/ |
531 |
|
532 |
extern int *LogRelFindBoolValues(struct Instance *i, |
533 |
unsigned long *dvarnum, |
534 |
int *able, |
535 |
int *nsolns, |
536 |
int perturb, |
537 |
struct gl_list_t *instances); |
538 |
/**< |
539 |
* <!-- soln_list = LogRelFindBoolValues(i,dvarnum,able,nsolns,perturb,instances); --> |
540 |
* <!-- struct Instance *i; --> |
541 |
* <!-- long *dvarnum; --> |
542 |
* <!-- int *able; --> |
543 |
* <!-- int *nsolns; --> |
544 |
* <!-- int perturb; --> |
545 |
* <!-- struct gl_list_t *instances; --> |
546 |
* <!-- int *soln_list; --> |
547 |
* |
548 |
* LogRelFindBoolValues WILL find a booolean solution if there is one. |
549 |
* The user must pass in a pointer to a |
550 |
* struct logrelation. The calling function should check able and/or |
551 |
* nsolns before accessing the information in the soln_list. |
552 |
* nsolns < 0 : severe problems, soln_list will be NULL |
553 |
* nsolns = 0 : No solution found |
554 |
* nsolns > 0 : The soln_status equals the number of roots found |
555 |
* nsolns is at most two for logical operations. |
556 |
* The calling function should NOT free the soln_list. |
557 |
* If *perturb !=0, that means that we will invert the truth value of |
558 |
* the SATISFIED terms involving the relation instances pointed by the |
559 |
* gl_list in order to find the boolean values wanted. |
560 |
*/ |
561 |
|
562 |
#define LogRelCalcResidual(i,r) LogRelCalcResidualPostfix(i,r,0,NULL) |
563 |
/**< |
564 |
* Macro for users interested in the calculation of pure logic relations. |
565 |
* Not conditional modeling. |
566 |
*/ |
567 |
|
568 |
#endif /* __LOGRELATION_UTIL_H_SEEN__ */ |
569 |
|