COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
CBitPatternMethod Class Reference

#include <CBitPatternMethod.h>

Inheritance diagram for CBitPatternMethod:
Inheritance graph
[legend]
Collaboration diagram for CBitPatternMethod:
Collaboration graph
[legend]

Public Member Functions

virtual bool calculate ()
 
 CBitPatternMethod (const CBitPatternMethod &src, const CCopasiContainer *pParent=NULL)
 
virtual bool initialize ()
 
 ~CBitPatternMethod ()
 
- Public Member Functions inherited from CEFMMethod
 CEFMMethod (const CEFMMethod &src, const CCopasiContainer *pParent=NULL)
 
virtual bool isValidProblem (const CCopasiProblem *pProblem)
 
virtual ~CEFMMethod ()
 
- Public Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiMethod &src, const CCopasiContainer *pParent=NULL)
 
const CCopasiMethod::SubTypegetSubType () const
 
const CCopasiTask::TypegetType () const
 
virtual void load (CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
 
virtual void print (std::ostream *ostream) const
 
virtual void printResult (std::ostream *ostream) const
 
virtual bool setCallBack (CProcessReport *pCallBack)
 
virtual ~CCopasiMethod ()
 
- Public Member Functions inherited from CCopasiParameterGroup
bool addGroup (const std::string &name)
 
bool addParameter (const CCopasiParameter &parameter)
 
bool addParameter (const std::string &name, const CCopasiParameter::Type type)
 
template<class CType >
bool addParameter (const std::string &name, const CCopasiParameter::Type type, const CType &value)
 
void addParameter (CCopasiParameter *pParameter)
 
CCopasiParameterGroupassertGroup (const std::string &name)
 
template<class CType >
CCopasiParameterassertParameter (const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
 
index_iterator beginIndex () const
 
name_iterator beginName () const
 
 CCopasiParameterGroup (const CCopasiParameterGroup &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameterGroup (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &objectType="ParameterGroup")
 
void clear ()
 
virtual bool elevateChildren ()
 
index_iterator endIndex () const
 
name_iterator endName () const
 
CCopasiParameterGroupgetGroup (const std::string &name)
 
const CCopasiParameterGroupgetGroup (const std::string &name) const
 
CCopasiParameterGroupgetGroup (const size_t &index)
 
const CCopasiParameterGroupgetGroup (const size_t &index) const
 
size_t getIndex (const std::string &name) const
 
std::string getKey (const std::string &name) const
 
std::string getKey (const size_t &index) const
 
virtual const std::string & getName (const size_t &index) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
CCopasiParametergetParameter (const std::string &name)
 
const CCopasiParametergetParameter (const std::string &name) const
 
CCopasiParametergetParameter (const size_t &index)
 
const CCopasiParametergetParameter (const size_t &index) const
 
CCopasiParameter::Type getType (const std::string &name) const
 
CCopasiParameter::Type getType (const size_t &index) const
 
std::string getUniqueParameterName (const CCopasiParameter *pParameter) const
 
const CCopasiParameter::ValuegetValue (const std::string &name) const
 
const CCopasiParameter::ValuegetValue (const size_t &index) const
 
CCopasiParameter::ValuegetValue (const std::string &name)
 
CCopasiParameter::ValuegetValue (const size_t &index)
 
CCopasiParameterGroupoperator= (const CCopasiParameterGroup &rhs)
 
bool removeParameter (const std::string &name)
 
bool removeParameter (const size_t &index)
 
template<class CType >
bool setValue (const std::string &name, const CType &value)
 
template<class CType >
bool setValue (const size_t &index, const CType &value)
 
size_t size () const
 
bool swap (const size_t &iFrom, const size_t &iTo)
 
bool swap (index_iterator &from, index_iterator &to)
 
virtual ~CCopasiParameterGroup ()
 
- Public Member Functions inherited from CCopasiParameter
 CCopasiParameter (const CCopasiParameter &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameter (const std::string &name, const Type &type, const void *pValue=NULL, const CCopasiContainer *pParent=NULL, const std::string &objectType="Parameter")
 
virtual CCopasiObjectName getCN () const
 
virtual const std::string & getKey () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const CCopasiParameter::TypegetType () const
 
const ValuegetValue () const
 
ValuegetValue ()
 
virtual voidgetValuePointer () const
 
CCopasiObjectgetValueReference () const
 
bool isValidValue (const C_FLOAT64 &value) const
 
bool isValidValue (const C_INT32 &value) const
 
bool isValidValue (const unsigned C_INT32 &value) const
 
bool isValidValue (const bool &value) const
 
bool isValidValue (const std::string &value) const
 
bool isValidValue (const CCopasiObjectName &value) const
 
bool isValidValue (const std::vector< CCopasiParameter * > &value) const
 
CCopasiParameteroperator= (const CCopasiParameter &rhs)
 
template<class CType >
bool setValue (const CType &value)
 
bool setValue (const std::vector< CCopasiParameter * > &value)
 
virtual ~CCopasiParameter ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Static Public Member Functions

static bool CalculateKernel (CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)
 
static void GCD (C_INT64 &m, C_INT64 &n)
 
- Static Public Member Functions inherited from CEFMMethod
static CEFMMethodcreateMethod (CCopasiMethod::SubType subType=CCopasiMethod::EFMAlgorithm)
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 

Protected Member Functions

 CBitPatternMethod (const CCopasiContainer *pParent=NULL)
 
 CBitPatternMethod (const CCopasiMethod::SubType subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CEFMMethod
 CEFMMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiParameterGroup
 CCopasiParameterGroup ()
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 

Protected Attributes

bool mContinueCombination
 
CMatrix< C_INT64mExpandedStoiTranspose
 
size_t mhProgressCounter
 
size_t mhProgressCounter2
 
size_t mMinimumSetSize
 
std::vector< CStepMatrixColumn * > mNewColumns
 
CModelmpModel
 
unsigned C_INT32 mProgressCounter
 
unsigned C_INT32 mProgressCounter2
 
unsigned C_INT32 mProgressCounter2Max
 
unsigned C_INT32 mProgressCounterMax
 
CStepMatrixmpStepMatrix
 
std::vector< std::pair< size_t,
bool > > 
mReactionForward
 
CVector< size_t > mReactionPivot
 
size_t mStep
 
- Protected Attributes inherited from CEFMMethod
std::vector< CFluxMode > * mpFluxModes
 
std::vector< const CReaction * > * mpReorderedReactions
 
- Protected Attributes inherited from CCopasiMethod
CProcessReportmpCallBack
 
- Protected Attributes inherited from CCopasiParameter
std::string mKey
 
CCopasiObjectmpValueReference
 
size_t mSize
 
Value mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 

Private Member Functions

void addMode (const CFluxMode &mode)
 
void buildFluxModeMatrix (CStepMatrix *fluxModeMatrix, std::stack< CStepMatrixColumn * > kernelStack)
 
void buildFluxModes ()
 
void buildKernelMatrix (CMatrix< C_INT64 > &kernel)
 
void combine (const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative, const std::vector< CStepMatrixColumn * > NullColumns)
 
void findRemoveInvalidColumns (const std::vector< CStepMatrixColumn * > &nullColumns)
 
void getAllUnsetBitIndexes (const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
 
void getUnsetBitIndexes (const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
 
void initObjects ()
 
CMatrix< C_INT64performRankTest (CStepMatrixColumn *pIntersectColumn)
 

Friends

CEFMMethodCEFMMethod::createMethod (CCopasiMethod::SubType subType)
 

Additional Inherited Members

- Public Types inherited from CCopasiMethod
enum  SubType {
  unset = 0, RandomSearch, RandomSearchMaster, SimulatedAnnealing,
  CoranaWalk, DifferentialEvolution, ScatterSearch, GeneticAlgorithm,
  EvolutionaryProgram, SteepestDescent, HybridGASA, GeneticAlgorithmSR,
  HookeJeeves, LevenbergMarquardt, NelderMead, SRES,
  Statistics, ParticleSwarm, Praxis, TruncatedNewton,
  Newton, deterministic, LSODAR, directMethod,
  stochastic, tauLeap, adaptiveSA, hybrid,
  hybridLSODA, hybridODE45, DsaLsodar, tssILDM,
  tssILDMModified, tssCSP, mcaMethodReder, scanMethod,
  lyapWolf, sensMethod, EFMAlgorithm, EFMBitPatternTreeAlgorithm,
  EFMBitPatternAlgorithm, Householder, crossSectionMethod, linearNoiseApproximation
}
 
- Public Types inherited from CCopasiParameterGroup
typedef parameterGroup::iterator index_iterator
 
typedef
CCopasiContainer::objectMap::iterator 
name_iterator
 
typedef std::vector
< CCopasiParameter * > 
parameterGroup
 
- Public Types inherited from CCopasiParameter
enum  Type {
  DOUBLE = 0, UDOUBLE, INT, UINT,
  BOOL, GROUP, STRING, CN,
  KEY, FILE, EXPRESSION, INVALID
}
 
- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Attributes inherited from CCopasiMethod
static const std::string SubTypeName []
 
static const char * XMLSubType []
 
- Static Public Attributes inherited from CCopasiParameter
static const std::string TypeName []
 
static const char * XMLType []
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 34 of file CBitPatternMethod.h.

Constructor & Destructor Documentation

CBitPatternMethod::CBitPatternMethod ( const CCopasiContainer pParent = NULL)
protected

Default constructor

Parameters
constCCopasiContainer * pParent (Default: NULL)

Definition at line 27 of file CBitPatternMethod.cpp.

References initObjects().

27  :
29  mpModel(NULL),
37  mReactionPivot(0),
39  mpStepMatrix(NULL),
40  mMinimumSetSize(0),
41  mStep(0),
43 {
44  initObjects();
45 }
unsigned C_INT32 mProgressCounterMax
unsigned C_INT32 mProgressCounter2Max
unsigned C_INT32 mProgressCounter
CStepMatrix * mpStepMatrix
CMatrix< C_INT64 > mExpandedStoiTranspose
std::vector< std::pair< size_t, bool > > mReactionForward
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2
CBitPatternMethod::CBitPatternMethod ( const CCopasiMethod::SubType  subType,
const CCopasiContainer pParent = NULL 
)
protected

Constructor to be called by derived methods

Parameters
constCCopasiMethod::SubType subType
constCCopasiContainer * pParent (Default: NULL)

Definition at line 47 of file CBitPatternMethod.cpp.

References initObjects().

48  :
49  CEFMMethod(CCopasiTask::fluxMode, subType, pParent),
50  mpModel(NULL),
58  mReactionPivot(0),
60  mpStepMatrix(NULL),
61  mMinimumSetSize(0),
62  mStep(0),
64 {
65  initObjects();
66 }
unsigned C_INT32 mProgressCounterMax
unsigned C_INT32 mProgressCounter2Max
unsigned C_INT32 mProgressCounter
CStepMatrix * mpStepMatrix
CMatrix< C_INT64 > mExpandedStoiTranspose
std::vector< std::pair< size_t, bool > > mReactionForward
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2
CBitPatternMethod::CBitPatternMethod ( const CBitPatternMethod src,
const CCopasiContainer pParent = NULL 
)

Copy Constructor

Parameters
constCBitPatternMethod & src

Definition at line 68 of file CBitPatternMethod.cpp.

References initObjects().

69  :
70  CEFMMethod(src, pParent),
71  mpModel(src.mpModel),
83  mStep(src.mStep),
85 {
86  initObjects();
87 }
unsigned C_INT32 mProgressCounterMax
unsigned C_INT32 mProgressCounter2Max
unsigned C_INT32 mProgressCounter
CStepMatrix * mpStepMatrix
CMatrix< C_INT64 > mExpandedStoiTranspose
std::vector< std::pair< size_t, bool > > mReactionForward
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2
CBitPatternMethod::~CBitPatternMethod ( )

Destructor

Definition at line 89 of file CBitPatternMethod.cpp.

90 {
91 }

Member Function Documentation

void CBitPatternMethod::addMode ( const CFluxMode mode)
private

Add the flux mode to the list only if the reversed does not exist

Parameters
constCFluxMode & mode

Definition at line 650 of file CBitPatternMethod.cpp.

References CEFMMethod::mpFluxModes.

Referenced by buildFluxModes().

651 {
652  std::vector< CFluxMode >::iterator itMode = mpFluxModes->begin();
653  std::vector< CFluxMode >::iterator endMode = mpFluxModes->end();
654 
655  for (; itMode != endMode; ++itMode)
656  {
657  if (itMode->isReversed(mode))
658  {
659  return;
660  }
661  }
662 
663  mpFluxModes->push_back(mode);
664  return;
665 }
std::vector< CFluxMode > * mpFluxModes
Definition: CEFMMethod.h:91
void CBitPatternMethod::buildFluxModeMatrix ( CStepMatrix fluxModeMatrix,
std::stack< CStepMatrixColumn * >  kernelStack 
)
private

Definition at line 955 of file CBitPatternMethod.cpp.

References CStepMatrix::add(), CMatrix< CType >::numCols(), CMatrix< CType >::numRows(), performRankTest(), and CStepMatrixColumn::push_front().

957 {
958  CStepMatrixColumn * KernelCol;
959  unsigned int col, row;
960 
961  while (!kernelStack.empty())
962  {
963  KernelCol = kernelStack.top();
964 #ifdef COPASI_DEBUG_TRACE
965  DebugFile << "Current Column: " << *KernelCol << std::endl;
966 #endif // COPASI_DEBUG_TRACE
967  CMatrix<C_INT64> RankKernel = performRankTest(KernelCol);
968 #ifdef COPASI_DEBUG_TRACE
969  DebugFile << "New Rank Kernel " << RankKernel << std::endl;
970 #endif // COPASI_DEBUG_TRACE
971 
972  if (RankKernel.numCols() == 1)
973  {
974  fluxModeMatrix->add(KernelCol);
975  }
976  else if (RankKernel.numCols() > 1)
977  {
978  for (col = 0; col < RankKernel.numCols(); col++)
979  {
980  KernelCol = new CStepMatrixColumn(RankKernel.numRows());
981 
982  for (row = 0; row < RankKernel.numRows(); row++)
983  {
984  KernelCol->push_front(RankKernel(row, col));
985  }
986 
987  kernelStack.push(KernelCol);
988  }
989  }
990 
991  kernelStack.pop();
992  }
993 }
void push_front(const C_INT64 &value)
virtual size_t numRows() const
Definition: CMatrix.h:138
void add(CStepMatrixColumn *pColumn)
Definition: CStepMatrix.h:50
CMatrix< C_INT64 > performRankTest(CStepMatrixColumn *pIntersectColumn)
virtual size_t numCols() const
Definition: CMatrix.h:144
void CBitPatternMethod::buildFluxModes ( )
private

Postprocess the step matrix to construct the flux modes.

Definition at line 423 of file CBitPatternMethod.cpp.

References addMode(), CVectorCore< CType >::array(), CMatrix< CType >::array(), CStepMatrix::begin(), C_FLOAT64, C_INT64, CalculateKernel(), CStepMatrix::end(), getUnsetBitIndexes(), mExpandedStoiTranspose, CEFMMethod::mpReorderedReactions, mpStepMatrix, mReactionForward, CMatrix< CType >::numCols(), and CVectorCore< CType >::size().

Referenced by calculate().

424 {
427 
428  CVector< size_t > Indexes;
429  size_t NumSpecies = mExpandedStoiTranspose.numCols();
430 
431  for (; it != end; ++it)
432  {
433  getUnsetBitIndexes(*it, Indexes);
434 
435  size_t NumReactions = Indexes.size();
436 
437  // Remove trivial modes, i.e., reversible reactions
438  if (NumReactions == 2 &&
439  (*mpReorderedReactions)[mReactionForward[Indexes[0]].first] ==
440  (*mpReorderedReactions)[mReactionForward[Indexes[1]].first])
441  {
442  continue;
443  }
444 
445  // Build the stoichiometry matrix reduced to the reactions participating in the current mode.
446  CMatrix< C_INT64 > A(NumReactions, NumSpecies);
447 
448  size_t * pIndex = Indexes.array();
449  size_t * pIndexEnd = pIndex + NumReactions;
450  C_INT64 * pARow = A.array();
451 
452  for (; pIndex != pIndexEnd; ++pIndex, pARow += NumSpecies)
453  {
454  memcpy(pARow, &mExpandedStoiTranspose(*pIndex, 0), NumSpecies * sizeof(C_INT64));
455  }
456 
457  // Calculate the kernel of the matrix
458  CMatrix< C_INT64 > ExpandedStoiTranspose(A);
459  CMatrix< C_INT64 > Kernel;
460  CVector< size_t > Pivot;
461  CalculateKernel(ExpandedStoiTranspose, Kernel, Pivot);
462 
463  size_t NumCols = Kernel.numCols();
464 
465  // Now we create the flux mode as we have the multiplier and reaction indexes.
466  // We need to invert the sign of the multiplier for reactions which are not forward.
467  // A flux mode is reversible if all reactions are reversible;
468 
469  C_INT64 * pColumn = Kernel.array();
470  C_INT64 * pColumnEnd = pColumn + NumCols;
471 
472  for (; pColumn != pColumnEnd; ++pColumn)
473  {
474  std::map< size_t, C_FLOAT64 > Reactions;
475  bool Reversible = true;
476 
477  pIndex = Indexes.array();
478  C_INT64 * pFluxMultiplier = pColumn;
479 
480  for (; pIndex != pIndexEnd; ++pIndex, pFluxMultiplier += NumCols)
481  {
482  if (*pFluxMultiplier < 0)
483  {
484  break;
485  }
486  else if (*pFluxMultiplier < 0)
487  {
488  continue;
489  }
490 
491  std::pair< size_t, bool > & ReactionForward = mReactionForward[*pIndex];
492 
493  Reactions[ReactionForward.first] =
494  (C_FLOAT64)((ReactionForward.second == true) ? *pFluxMultiplier : -*pFluxMultiplier);
495 
496  if (!(*mpReorderedReactions)[ReactionForward.first]->isReversible())
497  {
498  Reversible = false;
499  }
500  }
501 
502  if (pIndex != pIndexEnd)
503  {
504  continue;
505  }
506 
507  addMode(CFluxMode(Reactions, Reversible));
508  }
509  }
510 }
CStepMatrixColumn *const * const_iterator
Definition: CStepMatrix.h:29
#define C_INT64
Definition: copasi.h:88
const_iterator begin() const
const_iterator end() const
void addMode(const CFluxMode &mode)
std::vector< const CReaction * > * mpReorderedReactions
Definition: CEFMMethod.h:96
CStepMatrix * mpStepMatrix
size_t size() const
Definition: CVector.h:100
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
CMatrix< C_INT64 > mExpandedStoiTranspose
std::vector< std::pair< size_t, bool > > mReactionForward
virtual size_t numCols() const
Definition: CMatrix.h:144
void getUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
virtual CType * array()
Definition: CMatrix.h:337
static bool CalculateKernel(CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)
void CBitPatternMethod::buildKernelMatrix ( CMatrix< C_INT64 > &  kernel)
private

Construct the kernel matrix

Parameters
CMatrix<C_FLOAT64> & kernel

Definition at line 343 of file CBitPatternMethod.cpp.

References CMatrix< CType >::array(), CCopasiVector< T >::begin(), C_FLOAT64, C_INT64, CalculateKernel(), CCopasiVector< T >::end(), CModel::getReactions(), CModel::getRedStoi(), mExpandedStoiTranspose, min, mpModel, CEFMMethod::mpReorderedReactions, mReactionForward, mReactionPivot, CMatrix< CType >::numCols(), CMatrix< CType >::numRows(), CMatrix< CType >::resize(), and CMatrix< CType >::size().

Referenced by initialize().

344 {
345  // Calculate the kernel matrix
346  // of the reduced stoichiometry matrix to get the kernel matrix for the:
347  // Nullspace Approach to Determine the Elementary Modes of Chemical Reaction Systems (Wagner 2004)
348 
351 
352  size_t ReactionCounter = 0;
353 
354  for (; itReaction != endReaction; ++itReaction, ++ReactionCounter)
355  {
356  if ((*itReaction)->isReversible())
357  {
358  // mpReorderedReactons->push_back(*itReaction);
359  mReactionForward.push_back(std::make_pair(ReactionCounter, false));
360  }
361 
362  mpReorderedReactions->push_back(*itReaction);
363  mReactionForward.push_back(std::make_pair(ReactionCounter, true));
364  }
365 
366  const CMatrix< C_FLOAT64 > & Stoi = mpModel->getRedStoi();
367 
368  size_t NumReactions = Stoi.numCols();
369 
370  size_t NumExpandedReactions = mReactionForward.size();
371 
372  size_t NumSpecies = Stoi.numRows();
373 
374  size_t Dim = std::min(NumExpandedReactions, NumSpecies);
375 
376  if (Dim == 0)
377  {
378  return;
379  }
380 
381  mExpandedStoiTranspose.resize(NumExpandedReactions, NumSpecies);
382 
383  const C_FLOAT64 *pStoi = Stoi.array();
384  const C_FLOAT64 *pStoiEnd = pStoi + Stoi.size();
385  const C_FLOAT64 *pStoiRowEnd;
386 
387  C_INT64 *pExpandedStoiTranspose;
388  C_INT64 *pExpandedStoiTransposeColumn = mExpandedStoiTranspose.array();
389 
390  std::vector< const CReaction * >::const_iterator itReactionPivot;
391  std::vector< const CReaction * >::const_iterator endReactionPivot;
392  std::vector< std::pair< size_t, bool > >::const_iterator itReactionExpansion;
393 
394  for (; pStoi != pStoiEnd; ++pExpandedStoiTransposeColumn)
395  {
396  pStoiRowEnd = pStoi + NumReactions;
397  pExpandedStoiTranspose = pExpandedStoiTransposeColumn;
398  itReactionExpansion = mReactionForward.begin();
399 
400  for (; pStoi < pStoiRowEnd; ++pStoi, pExpandedStoiTranspose += NumSpecies, ++itReactionExpansion)
401  {
402  // TODO We should check the we have integer stoichiometry.
403  if (itReactionExpansion->second == false)
404  {
405  *pExpandedStoiTranspose = (C_INT64) - floor(*pStoi + 0.5);
406 
407  // Advance the iterators
408  ++itReactionExpansion;
409  pExpandedStoiTranspose += NumSpecies;
410  }
411 
412  *pExpandedStoiTranspose = (C_INT64) floor(*pStoi + 0.5);
413  }
414  }
415 
416  // Calculate the kernel of the matrix
417  CMatrix< C_INT64 > ExpandedStoiTranspose(mExpandedStoiTranspose);
418  CalculateKernel(ExpandedStoiTranspose, kernelInt, mReactionPivot);
419 
420  return;
421 }
iterator begin()
virtual size_t numRows() const
Definition: CMatrix.h:138
#define C_INT64
Definition: copasi.h:88
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
std::vector< const CReaction * > * mpReorderedReactions
Definition: CEFMMethod.h:96
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
#define C_FLOAT64
Definition: copasi.h:92
CMatrix< C_INT64 > mExpandedStoiTranspose
virtual size_t size() const
Definition: CMatrix.h:132
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
std::vector< std::pair< size_t, bool > > mReactionForward
CVector< size_t > mReactionPivot
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
#define min(a, b)
Definition: f2c.h:175
static bool CalculateKernel(CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)
bool CBitPatternMethod::calculate ( void  )
virtual

Execute the optimization algorithm calling simulation routine when needed. It is noted that this procedure can give feedback of its progress by the callback function set with SetCallback. @ return success;

Reimplemented from CEFMMethod.

Definition at line 165 of file CBitPatternMethod.cpp.

References CProcessReport::addItem(), buildFluxModes(), C_INT32, combine(), CStepMatrix::compact(), CStepMatrix::convertRow(), findRemoveInvalidColumns(), CProcessReport::finishItem(), CStepMatrix::getFirstUnconvertedRow(), CStepMatrix::getNumUnconvertedRows(), initialize(), mContinueCombination, mhProgressCounter, mhProgressCounter2, CCopasiMethod::mpCallBack, mProgressCounter, mProgressCounter2, mProgressCounter2Max, mProgressCounterMax, mpStepMatrix, mStep, CProcessReport::progressItem(), CStepMatrix::removeInvalidColumns(), and CStepMatrix::splitColumns().

166 {
167  bool Continue = true;
168 
169  if (!initialize())
170  {
171  if (mpCallBack)
173 
174  return false;
175  }
176 
177  while (mpStepMatrix->getNumUnconvertedRows() > 0 &&
178  Continue)
179  {
181 
182  std::vector< CStepMatrixColumn * > PositiveColumns;
183  std::vector< CStepMatrixColumn * > NegativeColumns;
184  std::vector< CStepMatrixColumn * > NullColumns;
185 
186  if (mpStepMatrix->splitColumns(PositiveColumns,
187  NegativeColumns,
188  NullColumns))
189  {
190  // Process each step.
191  // Iterate over all combinations and add/remove columns to the step matrix
192  mProgressCounter2 = 0;
193  mProgressCounter2Max = (unsigned C_INT32)(PositiveColumns.size() * NegativeColumns.size());
194 
195  if (mpCallBack)
197  mpCallBack->addItem("Combinations",
200 
201  for (unsigned int i = 0; i < NegativeColumns.size(); i++)
202  for (unsigned int j = 0; j < PositiveColumns.size(); j++)
203  combine(PositiveColumns[j], NegativeColumns[i], NullColumns);
204 
205  if (mpCallBack)
207 
208  Continue &= mContinueCombination;
209 
210  if (Continue)
211  {
212  // We can now destroy all negative columns, which removes them from
213  // the step matrix.
214  mpStepMatrix->removeInvalidColumns(NegativeColumns);
215 
216  // Remove columns of the step matrix which are no longer extreme rays.
217  findRemoveInvalidColumns(NullColumns);
218 
219  // We compact the step matrix which has empty columns due to the removal of columns above.
221 
222  // Now we can convert the processed row.
224  }
225  }
226 
228 
229  if (mpCallBack)
231  }
232 
233  if (Continue)
234  {
235  buildFluxModes();
236  }
237 
238  if (mpCallBack)
240 
241  return true;
242 }
void removeInvalidColumns(std::vector< CStepMatrixColumn * > &invalidColumns)
void combine(const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative, const std::vector< CStepMatrixColumn * > NullColumns)
size_t getFirstUnconvertedRow() const
unsigned C_INT32 mProgressCounterMax
#define C_INT32
Definition: copasi.h:90
void findRemoveInvalidColumns(const std::vector< CStepMatrixColumn * > &nullColumns)
virtual bool progressItem(const size_t &handle)
bool splitColumns(std::vector< CStepMatrixColumn * > &PositiveColumns, std::vector< CStepMatrixColumn * > &NegativeColumns, std::vector< CStepMatrixColumn * > &NullColumns)
unsigned C_INT32 mProgressCounter2Max
size_t getNumUnconvertedRows() const
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
void convertRow()
unsigned C_INT32 mProgressCounter
virtual bool finishItem(const size_t &handle)
CStepMatrix * mpStepMatrix
void compact()
virtual bool initialize()
CProcessReport * mpCallBack
unsigned C_INT32 mProgressCounter2
bool CBitPatternMethod::CalculateKernel ( CMatrix< C_INT64 > &  matrix,
CMatrix< C_INT64 > &  kernel,
CVector< size_t > &  rowPivot 
)
static

A static method that calculates the kernel of a full column rank matrix. Note, the input matrix is used as work area and will be modified during the calculation.

Parameters
constCMatrix< C_INT64 > & matrix
CMatrix<C_INT64 > & kernel
CVector<size_t > & rowPivot
Returns
bool success

Definition at line 668 of file CBitPatternMethod.cpp.

References abs64, CVectorCore< CType >::array(), CMatrix< CType >::array(), C_FLOAT64, C_INT64, GCD(), max, CMatrix< CType >::numCols(), CMatrix< CType >::numRows(), CMatrix< CType >::resize(), CVector< CType >::resize(), and CMatrix< CType >::size().

Referenced by buildFluxModes(), buildKernelMatrix(), and performRankTest().

671 {
672  // Gaussian elimination
673  size_t NumRows = matrix.numRows();
674  size_t NumCols = matrix.numCols();
675 
676  assert(NumRows > 0);
677  assert(NumCols > 0);
678 
679  // Initialize row pivots
680  rowPivot.resize(NumRows);
681  size_t * pPivot = rowPivot.array();
682 
683  for (size_t i = 0; i < NumRows; i++, pPivot++)
684  {
685  *pPivot = i;
686  }
687 
688  CVector< size_t > RowPivot(rowPivot);
689 
690  CVector< C_INT64 > Identity(NumRows);
691  Identity = 1;
692 
693  C_INT64 * pColumn = matrix.array();
694  C_INT64 * pColumnEnd = pColumn + NumCols;
695 
696  C_INT64 * pActiveRow;
697  C_INT64 * pActiveRowStart = pColumn;
698  C_INT64 * pActiveRowEnd = pColumnEnd;
699 
700  C_INT64 * pRow;
701  C_INT64 * pRowEnd = pColumn + matrix.size();
702 
703  C_INT64 * pCurrent;
704  C_INT64 * pIdentity;
705 
706  CVector< C_INT64 > SwapTmp(NumCols);
707 
708  size_t CurrentRowIndex = 0;
709  size_t CurrentColumnIndex = 0;
710  size_t NonZeroIndex = 0;
711 
712  CVector< bool > IgnoredColumns(NumCols);
713  IgnoredColumns = false;
714  bool * pIgnoredColumn = IgnoredColumns.array();
715  size_t IgnoredColumnCount = 0;
716 
717  // For each column
718  for (; pColumn < pColumnEnd; ++pColumn, ++CurrentColumnIndex, ++pIgnoredColumn)
719  {
720  assert(CurrentColumnIndex == CurrentRowIndex + IgnoredColumnCount);
721 
722  // Find non zero entry in current column.
723  pRow = pActiveRowStart + CurrentColumnIndex;
724  NonZeroIndex = CurrentRowIndex;
725 
726  for (; pRow < pRowEnd; pRow += NumCols, ++NonZeroIndex)
727  {
728  if (*pRow != 0)
729  break;
730  }
731 
732  if (NonZeroIndex >= NumRows)
733  {
734  *pIgnoredColumn = true;
735  IgnoredColumnCount++;
736 
737  continue;
738  }
739 
740  if (NonZeroIndex != CurrentRowIndex)
741  {
742  // Swap rows
743  memcpy(SwapTmp.array(), matrix[CurrentRowIndex], NumCols * sizeof(C_INT64));
744  memcpy(matrix[CurrentRowIndex], matrix[NonZeroIndex], NumCols * sizeof(C_INT64));
745  memcpy(matrix[NonZeroIndex], SwapTmp.array(), NumCols * sizeof(C_INT64));
746 
747  // Record pivot
748  size_t tmp = RowPivot[CurrentRowIndex];
749  RowPivot[CurrentRowIndex] = RowPivot[NonZeroIndex];
750  RowPivot[NonZeroIndex] = tmp;
751 
752  C_INT64 TMP = Identity[CurrentRowIndex];
753  Identity[CurrentRowIndex] = Identity[NonZeroIndex];
754  Identity[NonZeroIndex] = TMP;
755  }
756 
757  if (*(pActiveRowStart + CurrentColumnIndex) < 0)
758  {
759  for (pRow = pActiveRowStart; pRow < pActiveRowEnd; ++pRow)
760  {
761  *pRow *= -1;
762  }
763 
764  Identity[CurrentRowIndex] *= -1;
765  }
766 
767  // For each row
768  pRow = pActiveRowStart + NumCols;
769  pIdentity = Identity.array() + CurrentRowIndex + 1;
770 
771  C_INT64 ActiveRowValue = *(pActiveRowStart + CurrentColumnIndex);
772  *(pActiveRowStart + CurrentColumnIndex) = Identity[CurrentRowIndex];
773 
774  for (; pRow < pRowEnd; pRow += NumCols, ++pIdentity)
775  {
776  C_INT64 RowValue = *(pRow + CurrentColumnIndex);
777 
778  if (RowValue == 0)
779  continue;
780 
781  *(pRow + CurrentColumnIndex) = 0;
782 
783  // compute GCD(*pActiveRowStart, *pRow)
784  C_INT64 GCD1 = abs64(ActiveRowValue);
785  C_INT64 GCD2 = abs64(RowValue);
786 
787  GCD(GCD1, GCD2);
788 
789  C_INT64 alpha = ActiveRowValue / GCD1;
790  C_INT64 beta = RowValue / GCD1;
791 
792  // update rest of row
793  pActiveRow = pActiveRowStart;
794  pCurrent = pRow;
795  *pIdentity *= alpha;
796 
797  GCD1 = abs64(*pIdentity);
798 
799  for (; pActiveRow < pActiveRowEnd; ++pActiveRow, ++pCurrent)
800  {
801  // Assert that we do not have a numerical overflow.
802  assert(fabs(((C_FLOAT64) alpha) * ((C_FLOAT64) * pCurrent) - ((C_FLOAT64) beta) * ((C_FLOAT64) * pActiveRow)) < std::numeric_limits< C_INT64 >::max());
803 
804  *pCurrent = alpha * *pCurrent - beta * *pActiveRow;
805 
806  // We check that the row values do not have any common divisor.
807  if (GCD1 > 1 &&
808  (GCD2 = abs64(*pCurrent)) > 0)
809  {
810  GCD(GCD1, GCD2);
811  }
812  }
813 
814  if (GCD1 > 1)
815  {
816  *pIdentity /= GCD1;
817 
818  pActiveRow = pActiveRowStart;
819  pCurrent = pRow;
820 
821  for (; pActiveRow < pActiveRowEnd; ++pActiveRow, ++pCurrent)
822  {
823  *pCurrent /= GCD1;
824  }
825  }
826  }
827 
828  pActiveRowStart += NumCols;
829  pActiveRowEnd += NumCols;
830  CurrentRowIndex++;
831 
832  // DebugFile << matrix << std::endl;
833  // DebugFile << Identity << std::endl;
834  }
835 
836  assert(CurrentColumnIndex == CurrentRowIndex + IgnoredColumnCount);
837  assert(CurrentColumnIndex == NumCols);
838 
839  // std::cout << matrix << std::endl;
840  // std::cout << IgnoredColumns << std::endl;
841  // std::cout << Identity << std::endl;
842  // std::cout << RowPivot << std::endl << std::endl;
843 
844  size_t KernelRows = NumRows;
845  size_t KernelCols = NumRows + IgnoredColumnCount - NumCols;
846 
847  assert(KernelCols > 0);
848 
849  kernel.resize(KernelRows, KernelCols);
850 
851  CMatrix< C_INT64 > Kernel(KernelRows, KernelCols);
852  Kernel = 0;
853 
854  C_INT64 * pKernelInt = Kernel.array();
855  C_INT64 * pKernelIntEnd = pKernelInt + Kernel.size();
856 
857  pActiveRowStart = matrix[CurrentRowIndex];
858  pActiveRowEnd = matrix[NumRows];
859 
860  // Null space matrix identity part
861  pIdentity = Identity.array() + CurrentRowIndex;
862  C_INT64 * pKernelColumn = Kernel.array();
863 
864  for (; pActiveRowStart < pActiveRowEnd; pActiveRowStart += NumCols, ++pKernelColumn, ++pIdentity)
865  {
866  pKernelInt = pKernelColumn;
867  pIgnoredColumn = IgnoredColumns.array();
868 
869  pRow = pActiveRowStart;
870  pRowEnd = pRow + NumCols;
871 
872  if (*pIdentity < 0)
873  {
874  *pIdentity *= -1;
875 
876  for (; pRow < pRowEnd; ++pRow, ++pIgnoredColumn)
877  {
878  if (*pIgnoredColumn)
879  {
880  continue;
881  }
882 
883  *pKernelInt = - *pRow;
884  pKernelInt += KernelCols;
885  }
886  }
887  else
888  {
889  for (; pRow < pRowEnd; ++pRow, ++pIgnoredColumn)
890  {
891  if (*pIgnoredColumn)
892  {
893  continue;
894  }
895 
896  *pKernelInt = *pRow;
897  pKernelInt += KernelCols;
898  }
899  }
900  }
901 
902  pIdentity = Identity.array() + CurrentRowIndex;
903  pKernelInt = Kernel[CurrentRowIndex];
904 
905  for (; pKernelInt < pKernelIntEnd; pKernelInt += KernelCols + 1, ++pIdentity)
906  {
907  *pKernelInt = *pIdentity;
908  }
909 
910  // Undo the reordering introduced by Gaussian elimination to the kernel matrix.
911  pPivot = RowPivot.array();
912  pRow = Kernel.array();
913  pRowEnd = pRow + Kernel.size();
914 
915  for (; pRow < pRowEnd; ++pPivot, pRow += KernelCols)
916  {
917  memcpy(kernel[*pPivot], pRow, KernelCols * sizeof(C_INT64));
918  }
919 
920  return true;
921 }
static void GCD(C_INT64 &m, C_INT64 &n)
virtual size_t numRows() const
Definition: CMatrix.h:138
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INT64
Definition: copasi.h:88
#define abs64
Definition: copasi.h:94
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
virtual size_t size() const
Definition: CMatrix.h:132
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
#define max(a, b)
Definition: f2c.h:176
void CBitPatternMethod::combine ( const CStepMatrixColumn pPositive,
const CStepMatrixColumn pNegative,
const std::vector< CStepMatrixColumn * >  NullColumns 
)
private

Create all possible linear combinations of the bit pattern nodes pPositive and pNegative and all their child nodes.

Parameters
constCBitPatternTreeNode * pPositive
constCBitPatternTreeNode * pNegative

Definition at line 245 of file CBitPatternMethod.cpp.

References CStepMatrix::addColumn(), CZeroSet::getNumberOfSetBits(), CStepMatrixColumn::getZeroSet(), CZeroSet::intersection(), CZeroSet::isExtremeRay(), mContinueCombination, mhProgressCounter2, mMinimumSetSize, mNewColumns, CCopasiMethod::mpCallBack, mProgressCounter2, mpStepMatrix, CMatrix< CType >::numCols(), performRankTest(), CProcessReport::proceed(), CProcessReport::progressItem(), and CStepMatrix::removeColumn().

Referenced by calculate().

248 {
250  {
252  }
253 
255  {
256  return;
257  }
258 
259  CZeroSet Intersection = CZeroSet::intersection(pPositive->getZeroSet(),
260  pNegative->getZeroSet());
261 
262  // Adjacency test
263  if (Intersection.getNumberOfSetBits() < mMinimumSetSize)
264  {
265  return;
266  }
267 
268  //INSERT RANK TEST HERE
269 
270  CStepMatrixColumn * RankTestColumn = new CStepMatrixColumn(Intersection, pPositive, pNegative);
271  CMatrix<C_INT64> rtKernel = performRankTest(RankTestColumn);
272 
273  if (rtKernel.numCols() > 1)
274  {
275  return;
276  }
277 
278  // Assert columns are not null
279  if (pPositive != NULL && pNegative != NULL)
280  {
281  // We need to check whether the existing matrix contains already a leaf which is a superset
282  if (Intersection.isExtremeRay(NullColumns))
283  {
284  // We are sure that the previous Null Tree did not contain any
285  // super sets, however the new columns may.
286 
287  // We check whether the new columns do not already contain a superset
288  if (Intersection.isExtremeRay(mNewColumns))
289  {
290  CStepMatrixColumn * pColumn = mpStepMatrix->addColumn(Intersection, pPositive, pNegative);
291 
292  // Remove all new column which are no longer extreme rays
293  std::vector< CStepMatrixColumn * >::iterator it = mNewColumns.begin();
294  std::vector< CStepMatrixColumn * >::iterator end = mNewColumns.end();
295 
296  for (; it != end; ++it)
297  {
298  if ((*it) != NULL &&
299  (*it)->getZeroSet() >= Intersection)
300  {
301  // We need to remove the column from the step matrix, which can be done by deleting it.
303  *it = NULL;
304  }
305  }
306 
307  mNewColumns.push_back(pColumn);
308  }
309  }
310 
312 
313  if (mpCallBack)
315  }
316 }
const CZeroSet & getZeroSet() const
virtual bool progressItem(const size_t &handle)
virtual bool proceed()
const size_t & getNumberOfSetBits() const
Definition: CZeroSet.h:85
void removeColumn(CStepMatrixColumn *pColumn)
CStepMatrix * mpStepMatrix
bool isExtremeRay(const std::vector< CStepMatrixColumn * > &columns) const
Definition: CZeroSet.cpp:97
CMatrix< C_INT64 > performRankTest(CStepMatrixColumn *pIntersectColumn)
static CZeroSet intersection(const CZeroSet &set1, const CZeroSet &set2)
Definition: CZeroSet.h:137
virtual size_t numCols() const
Definition: CMatrix.h:144
CStepMatrixColumn * addColumn(const CZeroSet &set, const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative)
CProcessReport * mpCallBack
std::vector< CStepMatrixColumn * > mNewColumns
unsigned C_INT32 mProgressCounter2
void CBitPatternMethod::findRemoveInvalidColumns ( const std::vector< CStepMatrixColumn * > &  nullColumns)
private

Remove the invalid columns from the step matrix

Parameters
conststd::vector< CStepMatrix::iterator > & nullColumns

Definition at line 318 of file CBitPatternMethod.cpp.

References mNewColumns, mpStepMatrix, and CStepMatrix::removeInvalidColumns().

Referenced by calculate().

319 {
320  if (mNewColumns.empty())
321  {
322  return;
323  }
324 
325  // Determine the columns which became invalid.
326  std::vector< CStepMatrixColumn * > InvalidColumns;
327 
328  std::vector< CStepMatrixColumn * >::const_iterator NullIt = nullColumns.begin();
329  std::vector< CStepMatrixColumn * >::const_iterator NullEnd = nullColumns.end();
330 
331  for (; NullIt != NullEnd; ++NullIt)
332  {
333  if (!((*NullIt)->getZeroSet()).isExtremeRay(mNewColumns))
334  {
335  InvalidColumns.push_back(*NullIt);
336  }
337  }
338 
339  mpStepMatrix->removeInvalidColumns(InvalidColumns);
340  mNewColumns.clear();
341 }
void removeInvalidColumns(std::vector< CStepMatrixColumn * > &invalidColumns)
CStepMatrix * mpStepMatrix
std::vector< CStepMatrixColumn * > mNewColumns
static void CBitPatternMethod::GCD ( C_INT64 m,
C_INT64 n 
)
inlinestatic

Calculate the greatest common divisor (GCD) of 2 positive integers. On return m and n contain the GCD

Parameters
C_INT64& m
C_INT64& n

Definition at line 57 of file CBitPatternMethod.h.

Referenced by CalculateKernel().

58  {
59  assert(m > 0 && n > 0);
60 
61  while (m != n)
62  {
63  if (m > n)
64  {
65  m %= n;
66 
67  if (m == 0)
68  {
69  m = n;
70  }
71  }
72  else
73  {
74  n %= m;
75 
76  if (n == 0)
77  {
78  n = m;
79  }
80  }
81  }
82  }
void CBitPatternMethod::getAllUnsetBitIndexes ( const CStepMatrixColumn pColumn,
CVector< size_t > &  indexes 
) const
private

Definition at line 619 of file CBitPatternMethod.cpp.

References CVectorCore< CType >::array(), CStepMatrix::getAllUnsetBitIndexes(), mpStepMatrix, mReactionPivot, and CVectorCore< CType >::size().

Referenced by performRankTest().

621 {
622  mpStepMatrix->getAllUnsetBitIndexes(pColumn, indexes);
623 
624  // Apply the QR pivot
625  size_t * pIndex = indexes.array();
626  size_t * pIndexEnd = pIndex + indexes.size();
627 
628  for (; pIndex != pIndexEnd; ++pIndex)
629  *pIndex = mReactionPivot[*pIndex];
630 
631  //DebugFile << "@CBPM: " << indexes << std::endl;
632 }
void getAllUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
CStepMatrix * mpStepMatrix
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
CVector< size_t > mReactionPivot
void CBitPatternMethod::getUnsetBitIndexes ( const CStepMatrixColumn pColumn,
CVector< size_t > &  indexes 
) const
private

Get the index of the unset bits of the flux mode.

Definition at line 634 of file CBitPatternMethod.cpp.

References CVectorCore< CType >::array(), CStepMatrix::getUnsetBitIndexes(), mpStepMatrix, mReactionPivot, and CVectorCore< CType >::size().

Referenced by buildFluxModes().

636 {
637  mpStepMatrix->getUnsetBitIndexes(pColumn, indexes);
638 
639  // Apply the QR pivot
640  size_t * pIndex = indexes.array();
641  size_t * pIndexEnd = pIndex + indexes.size();
642 
643  for (; pIndex != pIndexEnd; ++pIndex)
644  {
645  *pIndex = mReactionPivot[*pIndex];
646  }
647 }
void getUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
CStepMatrix * mpStepMatrix
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
CVector< size_t > mReactionPivot
bool CBitPatternMethod::initialize ( )
virtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from CEFMMethod.

Definition at line 98 of file CBitPatternMethod.cpp.

References CProcessReport::addItem(), buildKernelMatrix(), C_INT32, CCopasiProblem::getModel(), CStepMatrix::getNumUnconvertedRows(), CCopasiObject::getObjectParent(), CCopasiTask::getProblem(), CEFMMethod::initialize(), mContinueCombination, mhProgressCounter, mMinimumSetSize, CCopasiMethod::mpCallBack, mpModel, mProgressCounter, mProgressCounterMax, mpStepMatrix, mReactionForward, CMatrix< CType >::numCols(), CMatrix< CType >::numRows(), pdelete, pTask, and CStepMatrixColumn::push_front().

Referenced by calculate().

99 {
100  if (!CEFMMethod::initialize())
101  {
102  return false;
103  }
104 
106  mReactionForward.clear();
107 
108  mContinueCombination = true;
109 
110  CEFMTask * pTask = dynamic_cast< CEFMTask *>(getObjectParent());
111 
112  if (pTask == NULL) return false;
113 
114  mpModel = pTask->getProblem()->getModel();
115 
116  if (mpModel == NULL) return false;
117 
118  // We first build the kernel matrix
119  CMatrix< C_INT64 > KernelMatrix;
120  buildKernelMatrix(KernelMatrix);
121 
122  mMinimumSetSize = KernelMatrix.numCols() - 2;
123 
124  std::stack< CStepMatrixColumn * > KernelStack;
125  CStepMatrixColumn * KernelCol;
126 
127  for (unsigned int col = 0; col < KernelMatrix.numCols(); col++)
128  {
129  KernelCol = new CStepMatrixColumn(KernelMatrix.numRows());
130 
131  for (unsigned int row = 0; row < KernelMatrix.numRows(); row++)
132  {
133  KernelCol->push_front(KernelMatrix(row, col));
134  }
135 
136  KernelStack.push(KernelCol);
137  }
138 
139  // Now we create the initial step matrix
140  mpStepMatrix = new CStepMatrix(KernelMatrix);
141  /*mpStepMatrix = new CStepMatrix(KernelMatrix.numRows());
142  buildFluxModeMatrix(mpStepMatrix, KernelStack);
143 
144  DebugFile << *mpStepMatrix << std::endl;*/
145 
146  /*
147  mpStepMatrix = FluxModeMatrix;
148  mpStepMatrix.convertMatrix();
149  */
150 
151  //mpStepMatrix = new CStepMatrix(KernelMatrix);
152 
153  mProgressCounter = 0;
155 
156  if (mpCallBack)
158  mpCallBack->addItem("Current Step",
161 
162  return true;
163 }
void buildKernelMatrix(CMatrix< C_INT64 > &kernel)
#define pdelete(p)
Definition: copasi.h:215
CCopasiProblem * getProblem()
void push_front(const C_INT64 &value)
virtual size_t numRows() const
Definition: CMatrix.h:138
unsigned C_INT32 mProgressCounterMax
#define C_INT32
Definition: copasi.h:90
virtual bool initialize()
Definition: CEFMMethod.cpp:109
CTSSATask * pTask
size_t getNumUnconvertedRows() const
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
unsigned C_INT32 mProgressCounter
CStepMatrix * mpStepMatrix
std::vector< std::pair< size_t, bool > > mReactionForward
virtual size_t numCols() const
Definition: CMatrix.h:144
CProcessReport * mpCallBack
CModel * getModel() const
CCopasiContainer * getObjectParent() const
void CBitPatternMethod::initObjects ( )
private

Initialize the needed CCopasiObjects.

Definition at line 93 of file CBitPatternMethod.cpp.

References CCopasiContainer::addObjectReference(), mProgressCounter, and CCopasiObject::ValueInt.

Referenced by CBitPatternMethod().

94 {
96 }
unsigned C_INT32 mProgressCounter
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
CMatrix< C_INT64 > CBitPatternMethod::performRankTest ( CStepMatrixColumn pIntersectColumn)
private

Performs rank test on given intersection.

Definition at line 923 of file CBitPatternMethod.cpp.

References CVectorCore< CType >::array(), CMatrix< CType >::array(), C_INT64, CalculateKernel(), getAllUnsetBitIndexes(), mExpandedStoiTranspose, CMatrix< CType >::numCols(), and CVectorCore< CType >::size().

Referenced by buildFluxModeMatrix(), and combine().

924 {
925  CVector<size_t> Indexes;
926 
927  getAllUnsetBitIndexes(pIntersectColumn, Indexes);
928 
929  size_t NumReactions = Indexes.size();
930  size_t NumSpecies = mExpandedStoiTranspose.numCols();
931 
932  // Build the stoichiometry matrix reduced to the reactions participating in the current mode.
933  CMatrix< C_INT64 > A(NumReactions, NumSpecies);
934 
935  size_t * pIndex = Indexes.array();
936  size_t * pIndexEnd = pIndex + NumReactions;
937  C_INT64 * pARow = A.array();
938 
939  for (; pIndex != pIndexEnd; ++pIndex, pARow += NumSpecies)
940  {
941  memcpy(pARow, &mExpandedStoiTranspose(*pIndex, 0), NumSpecies * sizeof(C_INT64));
942  }
943 
944  // Calculate the kernel of the matrix
945  CMatrix< C_INT64 > ExpandedStoiTranspose(A);
946  CMatrix< C_INT64 > Kernel;
947  CVector< size_t > Pivot;
948 
949  //DebugFile << ExpandedStoiTranspose << std::endl;
950  CalculateKernel(ExpandedStoiTranspose, Kernel, Pivot);
951 
952  return Kernel;
953 }
#define C_INT64
Definition: copasi.h:88
void getAllUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
CMatrix< C_INT64 > mExpandedStoiTranspose
virtual size_t numCols() const
Definition: CMatrix.h:144
static bool CalculateKernel(CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)

Friends And Related Function Documentation

Member Data Documentation

bool CBitPatternMethod::mContinueCombination
protected

Boolean value indicating whether combination should continue.

Definition at line 257 of file CBitPatternMethod.h.

Referenced by calculate(), combine(), and initialize().

CMatrix< C_INT64 > CBitPatternMethod::mExpandedStoiTranspose
protected

The transpose of the expanded stoichiometry matrix.

Definition at line 232 of file CBitPatternMethod.h.

Referenced by buildFluxModes(), buildKernelMatrix(), and performRankTest().

size_t CBitPatternMethod::mhProgressCounter
protected

Handle to the process report item "Current Step"

Definition at line 202 of file CBitPatternMethod.h.

Referenced by calculate(), and initialize().

size_t CBitPatternMethod::mhProgressCounter2
protected

Handle to the process report item "Combination"

Definition at line 217 of file CBitPatternMethod.h.

Referenced by calculate(), and combine().

size_t CBitPatternMethod::mMinimumSetSize
protected

The minimum set size use to determine whether a linear combination is allowed.

Definition at line 247 of file CBitPatternMethod.h.

Referenced by combine(), and initialize().

std::vector< CStepMatrixColumn * > CBitPatternMethod::mNewColumns
protected

A list of invalid columns currently in the step matrix

Definition at line 242 of file CBitPatternMethod.h.

Referenced by combine(), and findRemoveInvalidColumns().

CModel* CBitPatternMethod::mpModel
protected

A pointer to the model which is analyzed.

Definition at line 187 of file CBitPatternMethod.h.

Referenced by buildKernelMatrix(), and initialize().

unsigned C_INT32 CBitPatternMethod::mProgressCounter
protected

The current step used for process report.

Definition at line 192 of file CBitPatternMethod.h.

Referenced by calculate(), initialize(), and initObjects().

unsigned C_INT32 CBitPatternMethod::mProgressCounter2
protected

The current combination used for process report.

Definition at line 207 of file CBitPatternMethod.h.

Referenced by calculate(), and combine().

unsigned C_INT32 CBitPatternMethod::mProgressCounter2Max
protected

The max combination used for process report.

Definition at line 212 of file CBitPatternMethod.h.

Referenced by calculate().

unsigned C_INT32 CBitPatternMethod::mProgressCounterMax
protected

The max step used for process report.

Definition at line 197 of file CBitPatternMethod.h.

Referenced by calculate(), and initialize().

CStepMatrix* CBitPatternMethod::mpStepMatrix
protected

A pointer to the step matrix for creating the flux modes

Definition at line 237 of file CBitPatternMethod.h.

Referenced by buildFluxModes(), calculate(), combine(), findRemoveInvalidColumns(), getAllUnsetBitIndexes(), getUnsetBitIndexes(), and initialize().

std::vector< std::pair< size_t, bool > > CBitPatternMethod::mReactionForward
protected

A vector to recording the expansion of the stoichiometry matrix.

Definition at line 222 of file CBitPatternMethod.h.

Referenced by buildFluxModes(), buildKernelMatrix(), and initialize().

CVector< size_t > CBitPatternMethod::mReactionPivot
protected

A vector recording the pivots for the QR factorization

Definition at line 227 of file CBitPatternMethod.h.

Referenced by buildKernelMatrix(), getAllUnsetBitIndexes(), and getUnsetBitIndexes().

size_t CBitPatternMethod::mStep
protected

The currently process step

Definition at line 252 of file CBitPatternMethod.h.

Referenced by calculate().


The documentation for this class was generated from the following files: