/[ascend]/trunk/base/generic/solver/logrelman.c
ViewVC logotype

Contents of /trunk/base/generic/solver/logrelman.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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