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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 301 - (show annotations) (download) (as text)
Mon Feb 20 07:39:14 2006 UTC (16 years, 9 months ago) by johnpye
File MIME type: text/x-csrc
File size: 4500 byte(s)
Documentation and indentation changes
1 /*
2 ASCEND Solver Interface
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include <solver/incidence.h>
20
21 #include <utilities/ascSignal.h>
22 #include <utilities/ascMalloc.h>
23 #include <utilities/error.h>
24 #include <utilities/mem.h>
25 #include <utilities/set.h>
26 #include <general/list.h>
27 #include <general/mathmacros.h>
28
29 #include <compiler/instance_enum.h>
30
31 #include "discrete.h"
32 #include "conditional.h"
33 #include "logrel.h"
34 #include "bnd.h"
35 #include "mtx.h"
36 #include "linsol.h"
37 #include "linsolqr.h"
38
39 #include "slv_common.h"
40
41 #include "slv_client.h"
42
43 /*
44 --removed some old notes from 1996-1997, please see code repository--
45 */
46 int
47 build_incidence_data(CONST slv_system_t sys, incidence_vars_t *pd){
48
49 int32 mord=-1, row,col,var,rel,plrow,plcol,uninclow;
50 var_filter_t vincident;
51 rel_filter_t ractive;
52
53 vincident.matchbits = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);
54 vincident.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE );
55
56 ractive.matchbits = (REL_ACTIVE);
57 ractive.matchvalue = (REL_ACTIVE );
58
59 if (ISNULL(sys) || ISNULL(pd)) {
60 ERROR_REPORTER_HERE(ASC_PROG_ERR,"called with NULL!");
61 return 1; /* ERROR */
62 }
63
64 pd->vlist = slv_get_solvers_var_list(sys); /* O(1) */
65 pd->rlist = slv_get_solvers_rel_list(sys); /* O(1) */
66 if (pd->vlist==NULL || pd->rlist==NULL) {
67 ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Nothing to plot!");
68 return 1;
69 }
70 pd->neqn = slv_count_solvers_rels(sys,&ractive); /* O(neqn) */
71 pd->nprow = pd->neqn; /* number of rows we are plotting */
72 pd->nvar = slv_get_num_solvers_vars(sys); /* O(1) */
73 pd->npcol = slv_count_solvers_vars(sys,&vincident); /* O(npcols) */
74 pd->nfakevar = pd->npcol; /* this could change with autoslack solvers */
75 pd->pr2e = (int *)ascmalloc(sizeof(int)*(pd->nprow +1)); /* speed of these */
76 pd->e2pr = (int *)ascmalloc(sizeof(int)*(pd->neqn +1));
77 pd->pc2v = (int *)ascmalloc(sizeof(int)*(pd->npcol +1));
78 pd->v2pc = (int *)ascmalloc(sizeof(int)*(pd->nvar +1));
79 pd->vfixed = (char *)asccalloc((pd->nvar +1),sizeof(char));
80 if ( ISNULL(pd->pr2e) || ISNULL(pd->e2pr) ||
81 ISNULL(pd->pc2v) || ISNULL(pd->v2pc) ||
82 ISNULL(pd->vfixed) ) {
83 ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Insufficient memory!");
84 return 1;
85 }
86 mord = MAX(pd->neqn,pd->nvar);
87
88 /* fix up row permutations */
89 plrow=plcol=-1;
90 uninclow=pd->neqn; /* set lowwater mark for unincluded eqns */
91 for (row=0;row<mord;row++) {
92 rel = row;
93 if (rel < pd->neqn) {
94 if (rel_included(pd->rlist[rel]) && rel_active(pd->rlist[rel])) { /* rel_included uses ChildByChar */
95 plrow++;
96 pd->pr2e[plrow] = rel;
97 pd->e2pr[rel] = plrow;
98 } else {
99 uninclow--;
100 pd->pr2e[uninclow] = rel;
101 pd->e2pr[rel] = uninclow;
102 }
103 } /* else skip this row: it is nothing */
104 }
105
106 for (col = 0; col < mord; col++) { /* O(mord) */
107 var = col;
108 if (var < pd->nvar) {
109 /* set fixed flag vector whether incident or not */
110 if (var_fixed(pd->vlist[var])) { /* uses ChildByChar: not so fast */
111 pd->vfixed[var]=1;
112 }
113 if (var_incident(pd->vlist[var]) && var_active(pd->vlist[var])) { /* O(1) */
114 plcol++;
115 pd->pc2v[plcol] = var;
116 pd->v2pc[var] = plcol;
117 } else {
118 /* nonincident vars dont get plot cols */
119 pd->v2pc[var] = -1; /* be safe if someone asks */
120 }
121 } /* else skip this col: it is nothing */
122 }
123 return 0; /* OK */
124 }
125
126 /*
127 Note, simplified this code since there was no case where 'non-owned' data was being used in incidence_vars_t.
128 */
129 void
130 free_incidence_data(incidence_vars_t *pd) {
131
132 if (pd != NULL) {
133 ascfree(pd->pr2e); pd->pr2e=NULL;
134 ascfree(pd->e2pr); pd->e2pr=NULL;
135 ascfree(pd->pc2v); pd->pc2v=NULL;
136 ascfree(pd->v2pc); pd->v2pc=NULL;
137 ascfree(pd->vfixed); pd->vfixed=NULL;
138 }
139 }
140

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