/[ascend]/trunk/pygtk/interface/incidencematrix.cpp
ViewVC logotype

Contents of /trunk/pygtk/interface/incidencematrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 234 - (show annotations) (download) (as text)
Sun Jan 29 17:15:47 2006 UTC (17 years, 10 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2339 byte(s)
Plotting of incidence matrix: still need to check that orientation is correct though.
1 #include "incidencematrix.h"
2
3 #include <stdexcept>
4 #include <iostream>
5 using namespace std;
6
7 IncidencePoint::IncidencePoint(const int&row, const int &col, const IncidencePointType &type) : row(row), col(col), type(type){
8 // constructor, IncidencePoint
9 }
10
11 IncidencePoint::IncidencePoint(const IncidencePoint &old) : row(old.row), col(old.col), type(old.type){
12 // copy ctor
13 }
14
15 IncidencePoint::IncidencePoint() : row(-1), col(-1), type(IM_NULL){
16 // default ctor... don't use. need this to keep swig happy for some strange reason.
17 }
18
19 IncidenceMatrix::IncidenceMatrix(Simulation &sim) : sim(sim){
20 // constructor
21 is_built = FALSE;
22 }
23
24 IncidenceMatrix::~IncidenceMatrix(){
25 if(is_built){
26 free_incidence_data(&i);
27 }
28 }
29
30 void
31 IncidenceMatrix::buildPlotData(){
32 int c=-1;
33
34 cerr << "BUILDPLOTDATA" << endl;
35
36 slv_system_t sys = sim.getSystem();
37
38 cerr << "GOT SYSTEM DATA" << endl;
39
40 if(build_incidence_data(sys,&i)) {
41 cerr << "FAILED TO BUILD INCIDENCE DATA" << endl;
42 free_incidence_data(&i);
43 throw runtime_error("IncidenceMatrix::buildPlotData error calculating grid");
44 return;
45 }
46
47 for (int r=0; r < i.nprow; r++) {
48 struct rel_relation *rel = i.rlist[i.pr2e[r]];
49 const struct var_variable **vp = rel_incidence_list(rel);
50
51 if(rel_active(rel)){
52 int nvars = rel_n_incidences(rel);
53 if(rel_included(rel)){
54 for(int v=0; v < nvars; v++ ) {
55 if(var_flags(vp[v]) & VAR_SVAR) {
56 int vndx = var_sindex(vp[v]);
57 c = i.v2pc[vndx];
58 if (i.vfixed[vndx]) {
59 data.push_back(IncidencePoint(r,c,IM_ACTIVE_FIXED));
60 }else{
61 data.push_back(IncidencePoint(r,c,IM_ACTIVE_FREE));
62 }
63 }
64 }
65 }else{ /* hollow squares */
66 for(int v=0; v < nvars; v++ ) {
67 if (var_flags(vp[v]) & VAR_SVAR) {
68 int vndx = var_sindex(vp[v]);
69 c = i.v2pc[vndx];
70 if (i.vfixed[vndx]) {
71 data.push_back(IncidencePoint(r,c,IM_DORMANT_FIXED));
72 } else {
73 data.push_back(IncidencePoint(r,c,IM_DORMANT_FREE));
74 }
75 }
76 }
77 }
78 }
79 }
80
81 is_built = TRUE;
82 }
83
84 const int &
85 IncidenceMatrix::getNumRows() const{
86 return i.nprow;
87 }
88
89 const int &
90 IncidenceMatrix::getNumCols() const{
91 return i.npcol;
92 }
93
94 const vector<IncidencePoint> &
95 IncidenceMatrix::getIncidenceData(){
96 cerr << "GET INCIDENCE DATA" << endl;
97 if(!is_built){
98 buildPlotData();
99 }
100 return data;
101 }

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