1 |
/* |
2 |
* Boundary Module |
3 |
* Created: 04/97 |
4 |
* Version: $Revision: 1.8 $ |
5 |
* Version control file: $RCSfile: bnd.c,v $ |
6 |
* Date last modified: $Date: 1997/07/18 12:13:54 $ |
7 |
* Last modified by: $Author: mthomas $ |
8 |
* |
9 |
* This file is part of the SLV solver. |
10 |
* |
11 |
* The SLV solver is free software; you can redistribute |
12 |
* it and/or modify it under the terms of the GNU General Public License as |
13 |
* published by the Free Software Foundation; either version 2 of the |
14 |
* License, or (at your option) any later version. |
15 |
* |
16 |
* The SLV solver is distributed in hope that it will be |
17 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 |
* General Public License for more details. |
20 |
* |
21 |
* You should have received a copy of the GNU General Public License |
22 |
* along with the program; if not, write to the Free Software Foundation, |
23 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
24 |
* COPYING. COPYING is found in ../compiler. |
25 |
* |
26 |
*/ |
27 |
|
28 |
#include <math.h> |
29 |
#include "utilities/ascConfig.h" |
30 |
#include "utilities/ascMalloc.h" |
31 |
#include "general/list.h" |
32 |
#include "general/dstring.h" |
33 |
#include "compiler/compiler.h" |
34 |
#include "compiler/fractions.h" |
35 |
#include "compiler/instance_enum.h" |
36 |
#include "compiler/extfunc.h" |
37 |
#include "compiler/extcall.h" |
38 |
#include "compiler/functype.h" |
39 |
#include "compiler/safe.h" |
40 |
#include "compiler/dimen.h" |
41 |
#include "compiler/types.h" |
42 |
#include "compiler/find.h" |
43 |
#include "compiler/atomvalue.h" |
44 |
#include "compiler/instquery.h" |
45 |
#include "compiler/mathinst.h" |
46 |
#include "compiler/parentchild.h" |
47 |
#include "compiler/instance_io.h" |
48 |
#define _SLV_SERVER_C_SEEN_ |
49 |
#include "utilities/mem.h" |
50 |
#include "solver/mtx.h" |
51 |
#include "solver/slv_types.h" |
52 |
#include "solver/var.h" |
53 |
#include "solver/rel.h" |
54 |
#include "solver/discrete.h" |
55 |
#include "solver/conditional.h" |
56 |
#include "solver/logrel.h" |
57 |
#include "solver/bnd.h" |
58 |
#include "solver/slv_server.h" |
59 |
|
60 |
#define IPTR(i) ((struct Instance *)(i)) |
61 |
#ifndef DEFTOLERANCE |
62 |
#define DEFTOLERANCE 1e-08 |
63 |
#endif /* DEFTOLERANCE */ |
64 |
|
65 |
|
66 |
struct bnd_boundary *bnd_create(struct bnd_boundary *newbnd) |
67 |
{ |
68 |
|
69 |
if (newbnd==NULL) { |
70 |
newbnd = (struct bnd_boundary *)ascmalloc( sizeof(struct bnd_boundary) ); |
71 |
assert(newbnd!=NULL); |
72 |
memset((char *)&(newbnd->cond),0,sizeof(union bnd_union)); |
73 |
newbnd->kind = e_bnd_undefined; |
74 |
newbnd->logrels = NULL; |
75 |
newbnd->tolerance = DEFTOLERANCE; |
76 |
newbnd->mindex = -1; |
77 |
newbnd->sindex = -1; |
78 |
newbnd->model = -1; |
79 |
newbnd->flags = BND_IN_LOGREL; |
80 |
} else { |
81 |
memset((char *)&(newbnd->cond),0,sizeof(union bnd_union)); |
82 |
newbnd->kind = e_bnd_undefined; |
83 |
newbnd->logrels = NULL; |
84 |
newbnd->tolerance = DEFTOLERANCE; |
85 |
newbnd->mindex = -1; |
86 |
newbnd->sindex = -1; |
87 |
newbnd->model = -1; |
88 |
newbnd->flags = BND_IN_LOGREL; |
89 |
} |
90 |
return(newbnd); |
91 |
} |
92 |
|
93 |
|
94 |
void bnd_destroy(struct bnd_boundary *bnd) |
95 |
{ |
96 |
if (bnd==NULL) return; |
97 |
if (bnd->logrels != NULL) { |
98 |
gl_destroy(bnd->logrels); |
99 |
bnd->logrels = NULL; |
100 |
} |
101 |
} |
102 |
|
103 |
|
104 |
enum bnd_enum bnd_kind(struct bnd_boundary *bnd) |
105 |
{ |
106 |
assert(bnd!=NULL); |
107 |
return bnd->kind; |
108 |
} |
109 |
|
110 |
|
111 |
void bnd_set_kind(struct bnd_boundary *bnd, enum bnd_enum kind) |
112 |
{ |
113 |
assert(bnd!=NULL); |
114 |
bnd->kind = kind; |
115 |
} |
116 |
|
117 |
|
118 |
void bnd_set_logrels(struct bnd_boundary *bnd, |
119 |
struct gl_list_t *logrels) |
120 |
{ |
121 |
assert(bnd!=NULL); |
122 |
bnd->logrels = logrels; |
123 |
} |
124 |
|
125 |
|
126 |
struct gl_list_t *bnd_logrels(struct bnd_boundary *bnd) |
127 |
{ |
128 |
assert(bnd!=NULL); |
129 |
return bnd->logrels; |
130 |
} |
131 |
|
132 |
|
133 |
void bnd_set_tolerance(struct bnd_boundary *bnd,real64 tolerance) |
134 |
{ |
135 |
assert(bnd!=NULL); |
136 |
bnd->tolerance = tolerance; |
137 |
} |
138 |
|
139 |
|
140 |
real64 bnd_tolerance(struct bnd_boundary *bnd) |
141 |
{ |
142 |
assert(bnd!=NULL); |
143 |
return bnd->tolerance; |
144 |
} |
145 |
|
146 |
|
147 |
char *bnd_make_name(slv_system_t sys,struct bnd_boundary *bnd) |
148 |
{ |
149 |
enum bnd_enum kind; |
150 |
struct rel_relation *rel; |
151 |
struct logrel_relation *lrel; |
152 |
|
153 |
kind = bnd_kind(bnd); |
154 |
if (kind == e_bnd_rel) { |
155 |
rel = bnd_rel(bnd_real_cond(bnd)); |
156 |
return WriteInstanceNameString(IPTR(rel_instance(rel)), |
157 |
IPTR(slv_instance(sys))); |
158 |
} else { |
159 |
lrel = bnd_logrel(bnd_log_cond(bnd)); |
160 |
return WriteInstanceNameString(IPTR(logrel_instance(lrel)), |
161 |
IPTR(slv_instance(sys))); |
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
int32 bnd_mindex( struct bnd_boundary *bnd) |
167 |
{ |
168 |
return( bnd->mindex ); |
169 |
} |
170 |
|
171 |
|
172 |
void bnd_set_mindex( struct bnd_boundary *bnd, int32 index) |
173 |
{ |
174 |
bnd->mindex = index; |
175 |
} |
176 |
|
177 |
|
178 |
int32 bnd_sindex( const struct bnd_boundary *bnd) |
179 |
{ |
180 |
return( bnd->sindex ); |
181 |
} |
182 |
|
183 |
|
184 |
void bnd_set_sindex( struct bnd_boundary *bnd, int32 index) |
185 |
{ |
186 |
bnd->sindex = index; |
187 |
} |
188 |
|
189 |
|
190 |
int32 bnd_model(const struct bnd_boundary *bnd) |
191 |
{ |
192 |
return((const int32) bnd->model ); |
193 |
} |
194 |
|
195 |
|
196 |
void bnd_set_model( struct bnd_boundary *bnd, int32 index) |
197 |
{ |
198 |
bnd->model = index; |
199 |
} |
200 |
|
201 |
|
202 |
struct var_variable **bnd_real_incidence(struct bnd_boundary *bnd) |
203 |
{ |
204 |
enum bnd_enum kind; |
205 |
struct var_variable **incidence; |
206 |
struct rel_relation *rel; |
207 |
kind = bnd_kind(bnd); |
208 |
if (kind == e_bnd_rel) { |
209 |
rel = bnd_rel(bnd_real_cond(bnd)); |
210 |
incidence = rel_incidence_list_to_modify(rel); |
211 |
return incidence; |
212 |
} else { |
213 |
FPRINTF(stderr,"bnd_real_incidence called with incorrect boundary\n"); |
214 |
return NULL; |
215 |
} |
216 |
} |
217 |
|
218 |
|
219 |
int32 bnd_n_real_incidences(struct bnd_boundary *bnd) |
220 |
{ |
221 |
enum bnd_enum kind; |
222 |
int32 n_incidences; |
223 |
struct rel_relation *rel; |
224 |
kind = bnd_kind(bnd); |
225 |
if (kind == e_bnd_rel) { |
226 |
rel = bnd_rel(bnd_real_cond(bnd)); |
227 |
n_incidences = rel_n_incidences(rel); |
228 |
return n_incidences; |
229 |
} else { |
230 |
FPRINTF(stderr,"bnd_n_real_incidences called with incorrect boundary\n"); |
231 |
return 0; |
232 |
} |
233 |
} |
234 |
|
235 |
|
236 |
int32 bnd_apply_filter( const struct bnd_boundary *bnd, bnd_filter_t *filter) |
237 |
{ |
238 |
if (bnd==NULL || filter==NULL) { |
239 |
FPRINTF(stderr,"bnd_apply_filter miscalled with NULL\n"); |
240 |
return FALSE; |
241 |
} |
242 |
return ( (filter->matchbits & bnd->flags) == |
243 |
(filter->matchbits & filter->matchvalue) ); |
244 |
} |
245 |
|
246 |
|
247 |
uint32 bnd_flags( struct bnd_boundary *bnd) |
248 |
{ |
249 |
if (bnd==NULL) { |
250 |
FPRINTF(stderr,"bnd_flags called with NULL boundary\n"); |
251 |
return (0x0); |
252 |
} else { |
253 |
return bnd->flags; |
254 |
} |
255 |
} |
256 |
|
257 |
|
258 |
void bnd_set_flags(struct bnd_boundary *bnd, unsigned int flags) |
259 |
{ |
260 |
if (bnd==NULL) { |
261 |
FPRINTF(stderr,"bnd_set_flags called with NULL boundary\n"); |
262 |
return; |
263 |
} |
264 |
bnd->flags = flags; |
265 |
} |
266 |
|
267 |
|
268 |
uint32 bnd_flagbit(struct bnd_boundary *bnd, uint32 one) |
269 |
{ |
270 |
if (bnd==NULL) { |
271 |
FPRINTF(stderr,"ERROR: bnd_flagbit called with bad bnd.\n"); |
272 |
return 0; |
273 |
} |
274 |
return (bnd->flags & one); |
275 |
} |
276 |
|
277 |
|
278 |
void bnd_set_flagbit(struct bnd_boundary *bnd, uint32 field,uint32 one) |
279 |
{ |
280 |
if (one) { |
281 |
bnd->flags |= field; |
282 |
} else { |
283 |
bnd->flags &= ~field; |
284 |
} |
285 |
} |
286 |
|
287 |
|
288 |
int32 bnd_status_cur( struct bnd_boundary *bnd) |
289 |
{ |
290 |
if (bnd==NULL) { |
291 |
FPRINTF(stderr,"bnd_status_cur called with NULL boundary\n"); |
292 |
FPRINTF(stderr,"returning 0\n"); |
293 |
return 0; |
294 |
} else { |
295 |
if (bnd_cur_status(bnd)) { |
296 |
return 1; |
297 |
} else { |
298 |
return 0; |
299 |
} |
300 |
} |
301 |
} |
302 |
|
303 |
|
304 |
int32 bnd_status_pre( struct bnd_boundary *bnd) |
305 |
{ |
306 |
if (bnd==NULL) { |
307 |
FPRINTF(stderr,"bnd_status_pre called with NULL boundary\n"); |
308 |
FPRINTF(stderr,"returning 0\n"); |
309 |
return 0; |
310 |
} else { |
311 |
if (bnd_pre_status(bnd)) { |
312 |
return 1; |
313 |
} else { |
314 |
return 0; |
315 |
} |
316 |
} |
317 |
} |
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|