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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (show annotations) (download) (as text)
Fri Jan 27 04:23:20 2006 UTC (14 years, 10 months ago) by johnpye
File MIME type: text/x-csrc
File size: 6101 byte(s)
Updating for Jerry's new error_reporter syntax, bug #179
1 /*
2 * SLV: Ascend Numeric Solver
3 * by Karl Michael Westerberg
4 * Created: 2/6/90
5 * Version: $Revision: 1.29 $
6 * Version control file: $RCSfile: system.c,v $
7 * Date last modified: $Date: 2003/01/19 02:16:05 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the SLV solver.
11 *
12 * Copyright (C) 1990 Karl Michael Westerberg
13 * Copyright (C) 1993 Joseph Zaher
14 * Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan
15 *
16 * The SLV solver is free software; you can redistribute
17 * it and/or modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of the
19 * License, or (at your option) any later version.
20 *
21 * The SLV solver is distributed in hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License along with
27 * the program; if not, write to the Free Software Foundation, Inc., 675
28 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
29 * COPYING is found in ../compiler.
30 */
31
32 #include "utilities/ascConfig.h"
33 #include "compiler/instance_enum.h"
34 #include "compiler/compiler.h"
35 #include "compiler/check.h"
36 #include "utilities/ascMalloc.h"
37 #include "general/list.h"
38 #include "general/tm_time.h"
39 #include "solver/mtx.h"
40 #include "solver/slv_types.h"
41 #include "solver/var.h"
42 #include "solver/discrete.h"
43 #include "solver/conditional.h"
44 #include "solver/linsolqr.h"
45 #define _SLV_SERVER_C_SEEN_
46 #include "compiler/extcall.h"
47 #include "solver/rel.h"
48 #include "solver/relman.h"
49 #include "solver/logrel.h"
50 #include "solver/bnd.h"
51 #include "solver/slv_server.h"
52 #include "solver/system.h"
53 #include "solver/analyze.h"
54 #include "solver/linsol.h"
55 #include "solver/slv_common.h"
56 #include "solver/slv_client.h"
57
58 #define IPTR(i) ((struct Instance *) (i))
59 #define DOTIME 1
60
61 slv_system_t system_build(SlvBackendToken inst)
62 {
63 slv_system_t sys;
64 int stat;
65 #if DOTIME
66 double time;
67 time = tm_cpu_time();
68 #endif
69
70 sys = slv_create();
71
72 if (set_solver_types()) {
73 system_destroy(sys);
74 sys = NULL;
75 return sys;
76 }
77 /* THIS MEANS I NEED THE boolean_var DEFINITION IN system.c */
78 if (set_boolean_types()){
79 system_destroy(sys);
80 sys = NULL;
81 return sys;
82 }
83 stat = analyze_make_problem(sys,IPTR(inst));
84 if (!stat) {
85 slv_set_instance(sys,inst);
86 } else {
87 system_destroy(sys);
88 sys = NULL;
89 if (stat==2) {
90 ERROR_REPORTER_START_NOLINE(ASC_USER_ERROR);
91 FPRINTF(ASCERR,"Models sent to solver: \n");
92 FPRINTF(ASCERR,"1 cannot have any pending parts\n");
93 FPRINTF(ASCERR,"2 cannot have NULL or unfinished relations.\n");
94 FPRINTF(ASCERR,"3 must have at least one variable.\n");
95 FPRINTF(ASCERR,"4 must have at least one objective or relation.\n");
96 FPRINTF(ASCERR,"5 must have at all WHEN-controlling values initialized.\n");
97 FPRINTF(ASCERR,"Check pendings and problem structure.\n");
98 error_reporter_end_flush();
99 }
100 }
101 #if DOTIME
102 FPRINTF(stderr,"Time to build system = %g\n", (tm_cpu_time() - time));
103 #endif
104 return(sys);
105 }
106
107 void system_destroy(slv_system_t sys)
108 {
109 int i;
110 struct var_variable **vp, **pp, **up;
111 struct dis_discrete **dp, **udp;
112 struct rel_relation **rp, **crp;
113 struct rel_relation **op;
114 struct logrel_relation **lp, **clp;
115 struct bnd_boundary **bp;
116 struct w_when **wp;
117 struct ExtRelCache **ep;
118 struct gl_list_t *symbollist;
119
120 if( (vp=slv_get_master_var_list(sys))!=NULL ) {
121 ascfree(vp);
122 }
123 if( (pp=slv_get_master_par_list(sys))!=NULL ) {
124 ascfree(pp);
125 }
126 if( (up=slv_get_master_unattached_list(sys))!=NULL ) {
127 ascfree(up);
128 }
129 if( (dp=slv_get_master_dvar_list(sys))!=NULL ) {
130 ascfree(dp);
131 }
132 if( (udp=slv_get_master_disunatt_list(sys))!=NULL ) {
133 ascfree(udp);
134 }
135 if( (rp=slv_get_master_rel_list(sys))!=NULL ) {
136 ascfree(rp);
137 }
138 if( (crp=slv_get_master_condrel_list(sys))!=NULL ) {
139 ascfree(crp);
140 }
141 if( (op=slv_get_master_obj_list(sys))!=NULL ) {
142 ascfree(op);
143 }
144 if( (lp=slv_get_master_logrel_list(sys))!=NULL ) {
145 ascfree(lp);
146 }
147 if( (clp=slv_get_master_condlogrel_list(sys))!=NULL ) {
148 ascfree(clp);
149 }
150 if( (wp=slv_get_master_when_list(sys))!=NULL ) {
151 ascfree(wp);
152 }
153 if( (bp=slv_get_master_bnd_list(sys))!=NULL ) {
154 ascfree(bp);
155 }
156 if( (vp=slv_get_solvers_var_list(sys))!=NULL ) {
157 ascfree(vp);
158 }
159 if( (pp=slv_get_solvers_par_list(sys))!=NULL ) {
160 ascfree(pp);
161 }
162 if( (up=slv_get_solvers_unattached_list(sys))!=NULL ) {
163 ascfree(up);
164 }
165 if( (dp=slv_get_solvers_dvar_list(sys))!=NULL ) {
166 ascfree(dp);
167 }
168 if( (udp=slv_get_solvers_disunatt_list(sys))!=NULL ) {
169 ascfree(udp);
170 }
171 if( (rp=slv_get_solvers_rel_list(sys))!=NULL ) {
172 ascfree(rp);
173 }
174 if( (crp=slv_get_solvers_condrel_list(sys))!=NULL ) {
175 ascfree(crp);
176 }
177 if( (op=slv_get_solvers_obj_list(sys))!=NULL ) {
178 ascfree(op);
179 }
180 if( (lp=slv_get_solvers_logrel_list(sys))!=NULL ) {
181 ascfree(lp);
182 }
183 if( (clp=slv_get_solvers_condlogrel_list(sys))!=NULL ) {
184 ascfree(clp);
185 }
186 if( (wp=slv_get_solvers_when_list(sys))!=NULL ) {
187 ascfree(wp);
188 }
189 if( (bp=slv_get_solvers_bnd_list(sys))!=NULL ) {
190 ascfree(bp);
191 }
192
193 symbollist=slv_get_symbol_list(sys);
194 if(symbollist != NULL) {
195 DestroySymbolValuesList(symbollist);
196 }
197
198 if( (ep=slv_get_extrel_list(sys))!=NULL ) { /* extrels */
199 for( i = 0; ep[i]; i++ ) {
200 ExtRel_PreSolve(ep[i],FALSE); /* allow them to cleanup */
201 ExtRel_DestroyCache(ep[i]);
202 }
203 ascfree(ep);
204 }
205 slv_set_solvers_blocks(sys,0,NULL);
206 slv_set_solvers_log_blocks(sys,0,NULL); /* free blocks lists */
207 slv_destroy(sys); /* frees buf data */
208 }
209
210 void system_free_reused_mem()
211 {
212 mtx_free_reused_mem();
213 linsolqr_free_reused_mem();
214 analyze_free_reused_mem();
215 relman_free_reused_mem();
216 }
217

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