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