/[ascend]/branches/harry/ascend/system/system.c
ViewVC logotype

Contents of /branches/harry/ascend/system/system.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3032 - (show annotations) (download) (as text)
Wed Jul 29 03:30:04 2015 UTC (8 years, 1 month ago) by raymondj
File MIME type: text/x-csrc
File size: 3865 byte(s)
Debugging and testing completely changed ida solver
1 /* ASCEND modelling environment
2 Copyright (C) 1990 Karl Michael Westerberg
3 Copyright (C) 1993 Joseph Zaher
4 Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan
5 Copyright (C) 2006 Carnegie Mellon University
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *//*
20 by Karl Michael Westerberg
21 Created: 2/6/90
22 Last in CVS: $Revision: 1.29 $ $Date: 2003/01/19 02:16:05 $ $Author: ballan $
23 */
24
25 #include "system.h"
26
27 #include <ascend/general/ascMalloc.h>
28 #include <ascend/general/list.h>
29 #include <ascend/general/tm_time.h>
30
31 #include <ascend/compiler/instance_enum.h>
32 #include <ascend/compiler/check.h>
33
34 #include <ascend/linear/mtx.h>
35
36 #include "slv_client.h"
37 #include "diffvars.h"
38
39 #include "relman.h"
40 #include "slv_server.h"
41 #include "analyze.h"
42 #include "k12_analyze.h"
43 #include "slv_common.h"
44 #include "diffvars.h"
45
46 #define IPTR(i) ((struct Instance *) (i))
47 #define DOTIME 1
48
49 int g_use_dersyntax = 1;
50
51 slv_system_t system_build(SlvBackendToken inst){
52 slv_system_t sys;
53 int stat;
54
55 #if DOTIME
56 double comptime;
57 comptime = tm_cpu_time();
58 #endif
59
60 sys = slv_create();
61
62 if (set_solver_types()) {
63 system_destroy(sys);
64 sys = NULL;
65 return sys;
66 }
67 /* THIS MEANS I NEED THE boolean_var DEFINITION IN system.c */
68 if (set_boolean_types()){
69 system_destroy(sys);
70 sys = NULL;
71 return sys;
72 }
73 if (g_use_dersyntax) stat = k12_analyze_make_problem(sys,IPTR(inst));
74 else stat = analyze_make_problem(sys,IPTR(inst));
75 if(stat){
76 system_destroy(sys);
77 sys = NULL;
78 if(stat==2) {
79 ERROR_REPORTER_START_NOLINE(ASC_USER_ERROR);
80 FPRINTF(ASCERR,"Models sent to solver: \n");
81 FPRINTF(ASCERR,"1 cannot have any pending parts\n");
82 FPRINTF(ASCERR,"2 cannot have NULL or unfinished relations.\n");
83 FPRINTF(ASCERR,"3 must have at least one variable.\n");
84 FPRINTF(ASCERR,"4 must have at least one objective or relation.\n");
85 FPRINTF(ASCERR,"5 must have at all WHEN-controlling values initialized.\n");
86 FPRINTF(ASCERR,"Check pendings and problem structure.\n");
87 error_reporter_end_flush();
88 }
89 return sys;
90 }
91
92 slv_set_instance(sys,inst);
93
94 #if DOTIME
95 comptime = tm_cpu_time() - comptime;
96 if(comptime >= 1e-3){
97 CONSOLE_DEBUG("System built (time %5.3f s)",comptime);
98 }else{
99 CONSOLE_DEBUG("System built (time <1ms)");
100 }
101 #endif
102 return(sys);
103 }
104
105 void system_destroy(slv_system_t sys){
106 struct gl_list_t *symbollist;
107 void *l;
108
109 #define FN(FUNCNAME) \
110 l=(void*)FUNCNAME(sys); if(l!=NULL)ASC_FREE(l);
111 #define F(N) FN(slv_get_master_##N##_list)
112 F(var); F(par); F(unattached); F(dvar); F(disunatt); F(rel); F(condrel);
113 F(obj); F(logrel); F(condlogrel); F(when); F(event); F(bnd);
114 #undef F
115
116 #define F(N) FN(slv_get_solvers_##N##_list)
117 F(var); F(par); F(unattached); F(dvar); F(disunatt); F(rel); F(condrel);
118 F(obj); F(logrel); F(condlogrel); F(when); F(event); F(bnd);
119 #undef F
120 #undef FN
121
122 system_diffvars_destroy(sys);
123
124 symbollist=slv_get_symbol_list(sys);
125 if(symbollist != NULL)DestroySymbolValuesList(symbollist);
126
127 slv_set_solvers_blocks(sys,0,NULL);
128 slv_set_solvers_log_blocks(sys,0,NULL); /* free blocks lists */
129 slv_destroy(sys); /* frees buf data */
130 }
131
132 void system_free_reused_mem(){
133 mtx_free_reused_mem();
134 linsolqr_free_reused_mem();
135 analyze_free_reused_mem();
136 relman_free_reused_mem();
137 }
138

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