COPASI API  4.16.103
CBitPatternTreeNode.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CBitPatternTreeNode.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2010/01/29 21:59:25 $
7 // End CVS Header
8 
9 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
11 // and The University of Manchester.
12 // All rights reserved.
13 
14 #include "copasi.h"
15 
16 #include "CBitPatternTreeNode.h"
17 #include "CStepMatrixColumn.h"
18 
20  mIndex(0),
21  mpZeroSet(NULL),
22  mIgnoreCheck(false),
23  mpUnsetChild(NULL),
24  mpSetChild(NULL),
25  mpStepMatrixColumn(NULL)
26 {}
27 
29  const std::vector< CStepMatrixColumn * > & patterns):
30  mIndex(index),
31  mpZeroSet(NULL),
32  mIgnoreCheck(false),
33  mpUnsetChild(NULL),
34  mpSetChild(NULL),
35  mpStepMatrixColumn(NULL)
36 {
37  // Note: patterns may contain NULL pointers
38  switch (patterns.size())
39  {
40  case 0:
41  assert(false);
42  break;
43 
44  case 1:
45  {
46  std::vector< CStepMatrixColumn * >::const_iterator it = patterns.begin();
47 
48  // This should never happen.
49  assert(*it != NULL);
50 
51  mpZeroSet = new CZeroSet((*it)->getZeroSet());
52  mpStepMatrixColumn = *it;
53  }
54  break;
55 
56  default:
57  {
58  std::vector< CStepMatrixColumn * >::const_iterator it = patterns.begin();
59  std::vector< CStepMatrixColumn * >::const_iterator end = patterns.end();
60 
61  // This should never happen.
62 
63  for (; it != end; ++it)
64  {
65  if (*it != NULL)
66  {
67  break;
68  }
69  }
70 
71  // This should never happen.
72  assert(*it != NULL);
73 
74  CStepMatrixColumn * pFirstColumn = *it;
75 
76  mpZeroSet = new CZeroSet(pFirstColumn->getZeroSet());
77  size_t Count = 1;
78 
79  for (++it; it != end; ++it)
80  {
81  if (*it != NULL)
82  {
83  *mpZeroSet |= (*it)->getZeroSet();
84  Count++;
85  }
86  }
87 
88  if (Count != 1)
89  {
90  splitPatterns(patterns);
91  }
92  else
93  {
94  mpStepMatrixColumn = pFirstColumn;
95  }
96  }
97  break;
98  }
99 }
100 
102 {
106 }
107 
109 {
110  return mpStepMatrixColumn;
111 }
112 
113 void CBitPatternTreeNode::splitPatterns(const std::vector< CStepMatrixColumn * > & patterns)
114 {
115  size_t Index = mIndex;
117 
118  std::vector< CStepMatrixColumn * > SetPatterns;
119  std::vector< CStepMatrixColumn * > UnsetPatterns;
120 
121  while (UnsetPatterns.empty() || SetPatterns.empty())
122  {
123  SetPatterns.clear();
124  UnsetPatterns.clear();
125 
126  mIndex = Index;
127  Bit = mIndex;
128 
129  std::vector< CStepMatrixColumn * >::const_iterator it = patterns.begin();
130  std::vector< CStepMatrixColumn * >::const_iterator end = patterns.end();
131 
132  for (; it != end; ++it)
133  {
134  if (*it != NULL)
135  {
136  if ((*it)->getZeroSet().isSet(Bit))
137  {
138  SetPatterns.push_back((*it));
139  }
140  else
141  {
142  UnsetPatterns.push_back((*it));
143  }
144  }
145  }
146 
147  Index = nextAvailableIndex();
148  }
149 
150  mpUnsetChild = new CBitPatternTreeNode(Index, UnsetPatterns);
151 
152  if (mpUnsetChild->getZeroSet() == *mpZeroSet)
153  {
154  mpUnsetChild->mIgnoreCheck = true;
155  }
156 
157  mpSetChild = new CBitPatternTreeNode(Index, SetPatterns);
158 
159  if (mpSetChild->getZeroSet() == *mpZeroSet)
160  {
161  mpSetChild->mIgnoreCheck = true;
162  }
163 }
164 
166 {
167  return mIndex + 1;
168 }
169 
171 {
172  if (mpStepMatrixColumn != NULL)
173  {
174  return 1;
175  }
176 
177  size_t Count = 0;
178 
179  if (mpUnsetChild != NULL)
180  {
181  Count = mpUnsetChild->getChildrenCount();
182  }
183 
184  if (mpSetChild != NULL)
185  {
186  Count += mpSetChild->getChildrenCount();
187  }
188 
189  return Count;
190 }
const CStepMatrixColumn * getStepMatrixColumn() const
#define pdelete(p)
Definition: copasi.h:215
const CZeroSet & getZeroSet() const
CBitPatternTreeNode * mpUnsetChild
size_t nextAvailableIndex() const
virtual ~CBitPatternTreeNode(void)
CStepMatrixColumn * mpStepMatrixColumn
const CZeroSet & getZeroSet() const
CBitPatternTreeNode * mpSetChild
size_t getChildrenCount() const
void splitPatterns(const std::vector< CStepMatrixColumn * > &patterns)