COPASI API  4.16.103
CFluxScore.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CFluxScore.cpp,v $
3 // $Revision: 1.14 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:27:36 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 /**
24  * CFluxScore class.
25  * Used to compare flux modes
26  *
27  * Created for COPASI by Stefan Hoops 2002-05-08
28  * (C) Stefan Hoops 2002
29  */
30 
31 #include <limits.h>
32 
33 #include "copasi.h"
34 #include "CFluxScore.h"
35 
37 
38 CFluxScore::CFluxScore(const std::vector < C_FLOAT64 > & fluxMode)
39 {
41  unsigned char Remainder = fluxMode.size() % (CHAR_BIT * sizeof(unsigned char));
42  size_t imax = fluxMode.size() / (CHAR_BIT * sizeof(unsigned char));
43  unsigned char k, kmax = CHAR_BIT * sizeof(unsigned char);
44 
45  // Size the scoring vector.
46  // Note we have to allocate an extra int if Remainder != 0
47  mScore.resize(imax + (Remainder ? 1 : 0));
48 
49  std::vector < C_FLOAT64 >::const_iterator itMode = fluxMode.begin();
50  unsigned char * pScore = mScore.array();
51  unsigned char * pScoreEnd = pScore + imax;
52 
53  // Set the bits to 1 if the corresponding fluxMode coefficient is non zero.
54  for (; pScore != pScoreEnd; ++pScore)
55  {
56  *pScore = 0;
57 
58  for (k = kmax; k > 0; ++itMode)
59  {
60  k--;
61 
62  if (*itMode != 0)
63  (*pScore) |= (0x01 << k);
64  }
65  }
66 
67  // Do the same for the remaining fluxMode coefficients.
68  if (Remainder)
69  {
70  k = kmax;
71  kmax -= Remainder;
72 
73  *pScore = 0;
74 
75  for (; k > kmax; ++itMode)
76  {
77  k--;
78 
79  if (*itMode != 0)
80  (*pScore) |= (0x01 << k);
81  }
82  }
83 }
84 
86 
87 bool CFluxScore::operator <(const CFluxScore & rhs) const
88 {
89  const unsigned char * pScoreLhs = mScore.array();
90  const unsigned char * pScoreRhs = rhs.mScore.array();
91  const unsigned char * pScoreEnd = pScoreLhs + mScore.size();
92 
93  for (; pScoreLhs != pScoreEnd; ++pScoreLhs, ++pScoreRhs)
94  if (*pScoreLhs != (*pScoreLhs & *pScoreRhs))
95  return false;
96 
97  return true;
98 }
99 
100 std::ostream & operator << (std::ostream & os, const CFluxScore & A)
101 {
102  const unsigned char * pScore = A.mScore.array();
103  const unsigned char * pScoreEnd = pScore + A.mScore.size();
104  unsigned char k, kmax = CHAR_BIT * sizeof(unsigned char);
105 
106  for (k = kmax; pScore != pScoreEnd; ++pScore)
107  {
108  k = kmax;
109 
110  while (k > 0)
111  {
112  k--;
113  os << ((*pScore & (0x01 << k)) >> k);
114  }
115  }
116 
117  os << std::endl;
118 
119  return os;
120 }
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
bool operator<(const CFluxScore &rhs) const
Definition: CFluxScore.cpp:87
CVector< unsigned char > mScore
Definition: CFluxScore.h:36
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
std::ostream & operator<<(std::ostream &os, const CFluxScore &A)
Definition: CFluxScore.cpp:100
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202