/[ascend]/trunk/ascend4/solver/logrelman.c
ViewVC logotype

Contents of /trunk/ascend4/solver/logrelman.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (18 years, 7 months ago) by aw0a
File MIME type: text/x-csrc
File size: 4831 byte(s)
Setting up web subdirectory in repository
1 /*
2 * Logical Relation Manipulator Module
3 * Created: 04/97
4 * Version: $Revision: 1.4 $
5 * Version control file: $RCSfile: logrelman.c,v $
6 * Date last modified: $Date: 1997/07/18 12:14:40 $
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 "compiler/instance_enum.h"
31 #include "compiler/fractions.h"
32 #include "compiler/compiler.h"
33 #include "utilities/ascMalloc.h"
34 #include "compiler/functype.h"
35 #include "compiler/safe.h"
36 #include "compiler/extfunc.h"
37 #include "compiler/dimen.h"
38 #include "compiler/types.h"
39 #include "compiler/exprs.h"
40 #include "compiler/find.h"
41 #include "general/list.h"
42 #include "compiler/atomvalue.h"
43 #include "compiler/mathinst.h"
44 #include "compiler/relation_type.h"
45 #include "compiler/relation.h"
46 #include "compiler/packages.h"
47 #include "compiler/extcall.h"
48 #include "compiler/logical_relation.h"
49 #include "compiler/logrelation.h"
50 #include "compiler/logrel_util.h"
51 #include "compiler/logrel_io.h"
52 #define _SLV_SERVER_C_SEEN_
53 #include "solver/mtx.h"
54 #include "solver/slv_types.h"
55 #include "solver/var.h"
56 #include "solver/rel.h"
57 #include "solver/discrete.h"
58 #include "solver/conditional.h"
59 #include "solver/bnd.h"
60 #include "solver/logrel.h"
61 #include "solver/logrelman.h"
62 #include "solver/slv_server.h"
63
64 #define IPTR(i) ((struct Instance *)(i))
65
66
67 void logrelman_get_incidence(struct logrel_relation *lrel,
68 dis_filter_t *filter,
69 mtx_matrix_t mtx)
70 {
71 const struct dis_discrete **list;
72 mtx_coord_t nz;
73 int c,len;
74
75 assert(lrel!=NULL && filter !=NULL && mtx != NULL);
76 nz.row = logrel_sindex(lrel);
77 len = logrel_n_incidences(lrel);
78
79 list = logrel_incidence_list(lrel);
80 for (c=0; c < len; c++) {
81 if( dis_apply_filter(list[c],filter) ) {
82 nz.col = dis_sindex(list[c]);
83 mtx_fill_org_value(mtx,&nz,1.0);
84 }
85 }
86 }
87
88
89 int32 logrelman_eval(struct logrel_relation *lrel, int32 *status)
90 {
91 int32 res;
92 assert(lrel!=NULL);
93
94 *status = (int32) LogRelCalcResidual(logrel_instance(lrel),&res);
95 if (*status) { /* an error occured */
96 res = 0;
97 }
98 logrel_set_residual(lrel,res);
99 return res;
100 }
101
102
103 boolean logrelman_calc_satisfied( struct logrel_relation *lrel)
104 {
105 real64 res;
106 res = logrel_residual(lrel);
107
108 if( res==0) {
109 logrel_set_satisfied(lrel,FALSE);
110 } else {
111 logrel_set_satisfied(lrel,TRUE);
112 }
113 return( logrel_satisfied(lrel) );
114 }
115
116
117 int32 *logrelman_directly_solve(struct logrel_relation *lrel,
118 struct dis_discrete *solvefor,
119 int *able, int *nsolns, int perturb,
120 struct gl_list_t *insts)
121 {
122 int32 *value;
123 int ndvars,n;
124 const struct dis_discrete **dvlist;
125 unsigned long dvindex; /* index to the compiler */
126 ndvars = logrel_n_incidences(lrel);
127 dvlist = logrel_incidence_list(lrel);
128 dvindex = 0;
129 for (n=0;n <ndvars; n++) {
130 if (dvlist[n]==solvefor) {
131 dvindex = n+1; /*compiler counts from 1 */
132 break;
133 }
134 }
135
136 value = LogRelFindBoolValues(IPTR(logrel_instance(lrel)),&(dvindex),
137 able,nsolns,perturb,insts);
138 return value;
139 }
140
141
142 char *logrelman_make_string_infix(slv_system_t sys,
143 struct logrel_relation *lrel, int style)
144 {
145 char *sbeg;
146
147 if (style) {
148 sbeg = WriteLogRelToString(logrel_instance(lrel),slv_instance(sys));
149 } else {
150 sbeg = (char *)ascmalloc(60);
151 if (sbeg==NULL) return sbeg;
152 sprintf(sbeg,"logrelman_make_string_infix not implemented.");
153 }
154 return(sbeg);
155 }
156
157
158 char *logrelman_make_string_postfix(slv_system_t sys,
159 struct logrel_relation *lrel, int style)
160 {
161 char *sbeg;
162
163 if (style) {
164 sbeg = WriteLogRelPostfixToString(logrel_instance(lrel),slv_instance(sys));
165 } else {
166 sbeg = (char *)ascmalloc(60);
167 if (sbeg==NULL) return sbeg;
168 sprintf(sbeg,"logrelman_make_string_postfix not implemented.");
169
170 }
171 return(sbeg);
172 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22