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
CBitPatternTreeMethod Class Reference

#include <CBitPatternTreeMethod.h>

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

Public Member Functions

virtual bool calculate ()
 
 CBitPatternTreeMethod (const CBitPatternTreeMethod &src, const CCopasiContainer *pParent=NULL)
 
virtual bool initialize ()
 
 ~CBitPatternTreeMethod ()
 
- 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

 CBitPatternTreeMethod (const CCopasiContainer *pParent=NULL)
 
 CBitPatternTreeMethod (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
 
CBitPatternTreempNullTree
 
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 buildFluxModes ()
 
void buildKernelMatrix (CMatrix< C_INT64 > &kernel)
 
void combine (const CBitPatternTreeNode *pPositive, const CBitPatternTreeNode *pNegative)
 
void findRemoveInvalidColumns (const std::vector< CStepMatrixColumn * > &nullColumns)
 
void getUnsetBitIndexes (const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
 
void initObjects ()
 

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 35 of file CBitPatternTreeMethod.h.

Constructor & Destructor Documentation

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

Default constructor

Parameters
constCCopasiContainer * pParent (Default: NULL)

Definition at line 32 of file CBitPatternTreeMethod.cpp.

References initObjects().

32  :
34  mpModel(NULL),
42  mReactionPivot(0),
44  mpStepMatrix(NULL),
45  mpNullTree(NULL),
46  mMinimumSetSize(0),
47  mStep(0),
49 {
50  initObjects();
51 }
CMatrix< C_INT64 > mExpandedStoiTranspose
unsigned C_INT32 mProgressCounter2
std::vector< std::pair< size_t, bool > > mReactionForward
unsigned C_INT32 mProgressCounter
CBitPatternTree * mpNullTree
unsigned C_INT32 mProgressCounterMax
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2Max
CBitPatternTreeMethod::CBitPatternTreeMethod ( 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 53 of file CBitPatternTreeMethod.cpp.

References initObjects().

54  :
55  CEFMMethod(CCopasiTask::fluxMode, subType, pParent),
56  mpModel(NULL),
64  mReactionPivot(0),
66  mpStepMatrix(NULL),
67  mpNullTree(NULL),
68  mMinimumSetSize(0),
69  mStep(0),
71 {
72  initObjects();
73 }
CMatrix< C_INT64 > mExpandedStoiTranspose
unsigned C_INT32 mProgressCounter2
std::vector< std::pair< size_t, bool > > mReactionForward
unsigned C_INT32 mProgressCounter
CBitPatternTree * mpNullTree
unsigned C_INT32 mProgressCounterMax
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2Max
CBitPatternTreeMethod::CBitPatternTreeMethod ( const CBitPatternTreeMethod src,
const CCopasiContainer pParent = NULL 
)

Copy Constructor

Parameters
constCBitPatternTreeMethod & src

Definition at line 75 of file CBitPatternTreeMethod.cpp.

References initObjects().

76  :
77  CEFMMethod(src, pParent),
78  mpModel(src.mpModel),
91  mStep(src.mStep),
93 {
94  initObjects();
95 }
CMatrix< C_INT64 > mExpandedStoiTranspose
unsigned C_INT32 mProgressCounter2
std::vector< std::pair< size_t, bool > > mReactionForward
unsigned C_INT32 mProgressCounter
CBitPatternTree * mpNullTree
unsigned C_INT32 mProgressCounterMax
CVector< size_t > mReactionPivot
unsigned C_INT32 mProgressCounter2Max
CBitPatternTreeMethod::~CBitPatternTreeMethod ( )

Destructor

Definition at line 97 of file CBitPatternTreeMethod.cpp.

References mpNullTree, and pdelete.

98 {
100 }
#define pdelete(p)
Definition: copasi.h:215
CBitPatternTree * mpNullTree

Member Function Documentation

void CBitPatternTreeMethod::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 674 of file CBitPatternTreeMethod.cpp.

References CEFMMethod::mpFluxModes.

Referenced by buildFluxModes().

675 {
676  std::vector< CFluxMode >::iterator itMode = mpFluxModes->begin();
677  std::vector< CFluxMode >::iterator endMode = mpFluxModes->end();
678 
679  for (; itMode != endMode; ++itMode)
680  {
681  if (itMode->isReversed(mode))
682  {
683  return;
684  }
685  }
686 
687  mpFluxModes->push_back(mode);
688  return;
689 }
std::vector< CFluxMode > * mpFluxModes
Definition: CEFMMethod.h:91
void CBitPatternTreeMethod::buildFluxModes ( )
private

Postprocess the step matrix to construct the flux modes.

Definition at line 462 of file CBitPatternTreeMethod.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().

463 {
466 
467  CVector< size_t > Indexes;
468  size_t NumSpecies = mExpandedStoiTranspose.numCols();
469 
470  for (; it != end; ++it)
471  {
472  getUnsetBitIndexes(*it, Indexes);
473 
474  size_t NumReactions = Indexes.size();
475 
476  // Remove trivial modes, i.e., reversible reactions
477  if (NumReactions == 2 &&
478  (*mpReorderedReactions)[mReactionForward[Indexes[0]].first] ==
479  (*mpReorderedReactions)[mReactionForward[Indexes[1]].first])
480  {
481  continue;
482  }
483 
484  // Build the stoichiometry matrix reduced to the reactions participating in the current mode.
485  CMatrix< C_INT64 > A(NumReactions, NumSpecies);
486 
487  size_t * pIndex = Indexes.array();
488  size_t * pIndexEnd = pIndex + NumReactions;
489  C_INT64 * pARow = A.array();
490 
491  for (; pIndex != pIndexEnd; ++pIndex, pARow += NumSpecies)
492  {
493  memcpy(pARow, &mExpandedStoiTranspose(*pIndex, 0), NumSpecies * sizeof(C_INT64));
494  }
495 
496  // Calculate the kernel of the matrix
497  CMatrix< C_INT64 > ExpandedStoiTranspose(A);
498  CMatrix< C_INT64 > Kernel;
499  CVector< size_t > Pivot;
500  CalculateKernel(ExpandedStoiTranspose, Kernel, Pivot);
501 
502  size_t NumCols = Kernel.numCols();
503 
504  // Now we create the flux mode as we have the multiplier and reaction indexes.
505  // We need to invert the sign of the multiplier for reactions which are not forward.
506  // A flux mode is reversible if all reactions are reversible;
507 
508  C_INT64 * pColumn = Kernel.array();
509  C_INT64 * pColumnEnd = pColumn + NumCols;
510 
511  for (; pColumn != pColumnEnd; ++pColumn)
512  {
513  std::map< size_t, C_FLOAT64 > Reactions;
514  bool Reversible = true;
515 
516  pIndex = Indexes.array();
517  C_INT64 * pFluxMultiplier = pColumn;
518 
519  for (; pIndex != pIndexEnd; ++pIndex, pFluxMultiplier += NumCols)
520  {
521  if (*pFluxMultiplier < 0)
522  {
523  break;
524  }
525  else if (*pFluxMultiplier < 0)
526  {
527  continue;
528  }
529 
530  std::pair< size_t, bool > & ReactionForward = mReactionForward[*pIndex];
531 
532  Reactions[ReactionForward.first] =
533  (C_FLOAT64)((ReactionForward.second == true) ? *pFluxMultiplier : -*pFluxMultiplier);
534 
535  if (!(*mpReorderedReactions)[ReactionForward.first]->isReversible())
536  {
537  Reversible = false;
538  }
539  }
540 
541  if (pIndex != pIndexEnd)
542  {
543  continue;
544  }
545 
546  addMode(CFluxMode(Reactions, Reversible));
547  }
548  }
549 }
CMatrix< C_INT64 > mExpandedStoiTranspose
void getUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
void addMode(const CFluxMode &mode)
CStepMatrixColumn *const * const_iterator
Definition: CStepMatrix.h:29
std::vector< std::pair< size_t, bool > > mReactionForward
#define C_INT64
Definition: copasi.h:88
static bool CalculateKernel(CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)
const_iterator begin() const
const_iterator end() const
std::vector< const CReaction * > * mpReorderedReactions
Definition: CEFMMethod.h:96
size_t size() const
Definition: CVector.h:100
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
void CBitPatternTreeMethod::buildKernelMatrix ( CMatrix< C_INT64 > &  kernel)
private

Construct the kernel matrix

Parameters
CMatrix<C_FLOAT64> & kernel

Definition at line 382 of file CBitPatternTreeMethod.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().

383 {
384  // Calculate the kernel matrix
385  // of the reduced stoichiometry matrix to get the kernel matrix for the:
386  // Nullspace Approach to Determine the Elementary Modes of Chemical Reaction Systems (Wagner 2004)
387 
390 
391  size_t ReactionCounter = 0;
392 
393  for (; itReaction != endReaction; ++itReaction, ++ReactionCounter)
394  {
395  if ((*itReaction)->isReversible())
396  {
397  // mpReorderedReactons->push_back(*itReaction);
398  mReactionForward.push_back(std::make_pair(ReactionCounter, false));
399  }
400 
401  mpReorderedReactions->push_back(*itReaction);
402  mReactionForward.push_back(std::make_pair(ReactionCounter, true));
403  }
404 
405  const CMatrix< C_FLOAT64 > & Stoi = mpModel->getRedStoi();
406 
407  size_t NumReactions = Stoi.numCols();
408 
409  size_t NumExpandedReactions = mReactionForward.size();
410 
411  size_t NumSpecies = Stoi.numRows();
412 
413  size_t Dim = std::min(NumExpandedReactions, NumSpecies);
414 
415  if (Dim == 0)
416  {
417  return;
418  }
419 
420  mExpandedStoiTranspose.resize(NumExpandedReactions, NumSpecies);
421 
422  const C_FLOAT64 *pStoi = Stoi.array();
423  const C_FLOAT64 *pStoiEnd = pStoi + Stoi.size();
424  const C_FLOAT64 *pStoiRowEnd;
425 
426  C_INT64 *pExpandedStoiTranspose;
427  C_INT64 *pExpandedStoiTransposeColumn = mExpandedStoiTranspose.array();
428 
429  std::vector< const CReaction * >::const_iterator itReactionPivot;
430  std::vector< const CReaction * >::const_iterator endReactionPivot;
431  std::vector< std::pair< size_t, bool > >::const_iterator itReactionExpansion;
432 
433  for (; pStoi != pStoiEnd; ++pExpandedStoiTransposeColumn)
434  {
435  pStoiRowEnd = pStoi + NumReactions;
436  pExpandedStoiTranspose = pExpandedStoiTransposeColumn;
437  itReactionExpansion = mReactionForward.begin();
438 
439  for (; pStoi < pStoiRowEnd; ++pStoi, pExpandedStoiTranspose += NumSpecies, ++itReactionExpansion)
440  {
441  // TODO We should check the we have integer stoichiometry.
442  if (itReactionExpansion->second == false)
443  {
444  *pExpandedStoiTranspose = (C_INT64) - floor(*pStoi + 0.5);
445 
446  // Advance the iterators
447  ++itReactionExpansion;
448  pExpandedStoiTranspose += NumSpecies;
449  }
450 
451  *pExpandedStoiTranspose = (C_INT64) floor(*pStoi + 0.5);
452  }
453  }
454 
455  // Calculate the kernel of the matrix
456  CMatrix< C_INT64 > ExpandedStoiTranspose(mExpandedStoiTranspose);
457  CalculateKernel(ExpandedStoiTranspose, kernelInt, mReactionPivot);
458 
459  return;
460 }
CMatrix< C_INT64 > mExpandedStoiTranspose
iterator begin()
virtual size_t numRows() const
Definition: CMatrix.h:138
std::vector< std::pair< size_t, bool > > mReactionForward
#define C_INT64
Definition: copasi.h:88
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
static bool CalculateKernel(CMatrix< C_INT64 > &matrix, CMatrix< C_INT64 > &kernel, CVector< size_t > &rowPivot)
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
CVector< size_t > mReactionPivot
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
virtual size_t size() const
Definition: CMatrix.h:132
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
#define min(a, b)
Definition: f2c.h:175
bool CBitPatternTreeMethod::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 154 of file CBitPatternTreeMethod.cpp.

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

155 {
156  bool Continue = true;
157 
158  if (!initialize())
159  {
160  if (mpCallBack)
162 
163  return false;
164  }
165 
166  while (mpStepMatrix->getNumUnconvertedRows() > 0 &&
167  Continue)
168  {
169 #ifdef COPASI_DEBUG_TRACE
170  DebugFile << "Step Matrix:" << std::endl;
171  DebugFile << *mpStepMatrix << std::endl;
172 #endif // COPASI_DEBUG_TRACE
174 
175  std::vector< CStepMatrixColumn * > PositiveColumns;
176  std::vector< CStepMatrixColumn * > NegativeColumns;
177  std::vector< CStepMatrixColumn * > NullColumns;
178 
179  if (mpStepMatrix->splitColumns(PositiveColumns,
180  NegativeColumns,
181  NullColumns))
182  {
183  // Process each step.
184  // We need to update the bit pattern tree.
186  mpNullTree = new CBitPatternTree(NullColumns);
187 
188  // Bit pattern tree containing the positive columns
189  CBitPatternTree PositiveTree(PositiveColumns);
190 
191  // Convert the negative columns into a bit pattern tree
192  CBitPatternTree NegativeTree(NegativeColumns);
193 
194  // Iterate over all combinations and add/remove columns to the step matrix
195  mProgressCounter2 = 0;
196  mProgressCounter2Max = (unsigned C_INT32)(PositiveTree.size() * NegativeTree.size());
197 
198  if (mpCallBack)
200  mpCallBack->addItem("Combinations",
203 
204  combine(PositiveTree.getRoot(), NegativeTree.getRoot());
205 
206  if (mpCallBack)
208 
209  Continue &= mContinueCombination;
210 
211  if (Continue)
212  {
213  // We can now destroy all negative columns, which removes them from
214  // the step matrix.
215  mpStepMatrix->removeInvalidColumns(NegativeColumns);
216 
217  // Remove columns of the step matrix which are no longer extreme rays.
218  findRemoveInvalidColumns(NullColumns);
219 
220  // We compact the step matrix which has empty columns due to the removal of columns above.
222 
223  // Now we can convert the processed row.
225  }
226  }
227 
229 
230  if (mpCallBack)
232  }
233 
234  if (Continue)
235  {
236  buildFluxModes();
237  }
238 
239  if (mpCallBack)
241 
242  return true;
243 }
void removeInvalidColumns(std::vector< CStepMatrixColumn * > &invalidColumns)
#define pdelete(p)
Definition: copasi.h:215
size_t getFirstUnconvertedRow() const
void combine(const CBitPatternTreeNode *pPositive, const CBitPatternTreeNode *pNegative)
unsigned C_INT32 mProgressCounter2
#define C_INT32
Definition: copasi.h:90
virtual bool progressItem(const size_t &handle)
bool splitColumns(std::vector< CStepMatrixColumn * > &PositiveColumns, std::vector< CStepMatrixColumn * > &NegativeColumns, std::vector< CStepMatrixColumn * > &NullColumns)
unsigned C_INT32 mProgressCounter
CBitPatternTree * mpNullTree
size_t getNumUnconvertedRows() const
unsigned C_INT32 mProgressCounterMax
void findRemoveInvalidColumns(const std::vector< CStepMatrixColumn * > &nullColumns)
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
void convertRow()
virtual bool finishItem(const size_t &handle)
void compact()
unsigned C_INT32 mProgressCounter2Max
CProcessReport * mpCallBack
bool CBitPatternTreeMethod::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 692 of file CBitPatternTreeMethod.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(), and buildKernelMatrix().

695 {
696  // std::cout << matrix << std::endl;
697 
698  // Gaussian elimination
699  size_t NumRows = matrix.numRows();
700  size_t NumCols = matrix.numCols();
701 
702  assert(NumRows > 0);
703  assert(NumCols > 0);
704 
705  // Initialize row pivots
706  rowPivot.resize(NumRows);
707  size_t * pPivot = rowPivot.array();
708 
709  for (size_t i = 0; i < NumRows; i++, pPivot++)
710  {
711  *pPivot = i;
712  }
713 
714  CVector< size_t > RowPivot(rowPivot);
715 
716  CVector< C_INT64 > Identity(NumRows);
717  Identity = 1;
718 
719  C_INT64 * pColumn = matrix.array();
720  C_INT64 * pColumnEnd = pColumn + NumCols;
721 
722  C_INT64 * pActiveRow;
723  C_INT64 * pActiveRowStart = pColumn;
724  C_INT64 * pActiveRowEnd = pColumnEnd;
725 
726  C_INT64 * pRow;
727  C_INT64 * pRowEnd = pColumn + matrix.size();
728 
729  C_INT64 * pCurrent;
730  C_INT64 * pIdentity;
731 
732  CVector< C_INT64 > SwapTmp(NumCols);
733 
734  size_t CurrentRowIndex = 0;
735  size_t CurrentColumnIndex = 0;
736  size_t NonZeroIndex = 0;
737 
738  CVector< bool > IgnoredColumns(NumCols);
739  IgnoredColumns = false;
740  bool * pIgnoredColumn = IgnoredColumns.array();
741  size_t IgnoredColumnCount = 0;
742 
743  // For each column
744  for (; pColumn < pColumnEnd; ++pColumn, ++CurrentColumnIndex, ++pIgnoredColumn)
745  {
746  assert(CurrentColumnIndex == CurrentRowIndex + IgnoredColumnCount);
747 
748  // Find non zero entry in current column.
749  pRow = pActiveRowStart + CurrentColumnIndex;
750  NonZeroIndex = CurrentRowIndex;
751 
752  for (; pRow < pRowEnd; pRow += NumCols, ++NonZeroIndex)
753  {
754  if (*pRow != 0)
755  break;
756  }
757 
758  if (NonZeroIndex >= NumRows)
759  {
760  *pIgnoredColumn = true;
761  IgnoredColumnCount++;
762 
763  continue;
764  }
765 
766  if (NonZeroIndex != CurrentRowIndex)
767  {
768  // Swap rows
769  memcpy(SwapTmp.array(), matrix[CurrentRowIndex], NumCols * sizeof(C_INT64));
770  memcpy(matrix[CurrentRowIndex], matrix[NonZeroIndex], NumCols * sizeof(C_INT64));
771  memcpy(matrix[NonZeroIndex], SwapTmp.array(), NumCols * sizeof(C_INT64));
772 
773  // Record pivot
774  size_t tmp = RowPivot[CurrentRowIndex];
775  RowPivot[CurrentRowIndex] = RowPivot[NonZeroIndex];
776  RowPivot[NonZeroIndex] = tmp;
777 
778  C_INT64 TMP = Identity[CurrentRowIndex];
779  Identity[CurrentRowIndex] = Identity[NonZeroIndex];
780  Identity[NonZeroIndex] = TMP;
781  }
782 
783  if (*(pActiveRowStart + CurrentColumnIndex) < 0)
784  {
785  for (pRow = pActiveRowStart; pRow < pActiveRowEnd; ++pRow)
786  {
787  *pRow *= -1;
788  }
789 
790  Identity[CurrentRowIndex] *= -1;
791  }
792 
793  // For each row
794  pRow = pActiveRowStart + NumCols;
795  pIdentity = Identity.array() + CurrentRowIndex + 1;
796 
797  C_INT64 ActiveRowValue = *(pActiveRowStart + CurrentColumnIndex);
798  *(pActiveRowStart + CurrentColumnIndex) = Identity[CurrentRowIndex];
799 
800  for (; pRow < pRowEnd; pRow += NumCols, ++pIdentity)
801  {
802  C_INT64 RowValue = *(pRow + CurrentColumnIndex);
803 
804  if (RowValue == 0)
805  continue;
806 
807  *(pRow + CurrentColumnIndex) = 0;
808 
809  // compute GCD(*pActiveRowStart, *pRow)
810  C_INT64 GCD1 = abs64(ActiveRowValue);
811  C_INT64 GCD2 = abs64(RowValue);
812 
813  GCD(GCD1, GCD2);
814 
815  C_INT64 alpha = ActiveRowValue / GCD1;
816  C_INT64 beta = RowValue / GCD1;
817 
818  // update rest of row
819  pActiveRow = pActiveRowStart;
820  pCurrent = pRow;
821  *pIdentity *= alpha;
822 
823  GCD1 = abs64(*pIdentity);
824 
825  for (; pActiveRow < pActiveRowEnd; ++pActiveRow, ++pCurrent)
826  {
827  // Assert that we do not have a numerical overflow.
828  assert(fabs(((C_FLOAT64) alpha) * ((C_FLOAT64) * pCurrent) - ((C_FLOAT64) beta) * ((C_FLOAT64) * pActiveRow)) < std::numeric_limits< C_INT64 >::max());
829 
830  *pCurrent = alpha * *pCurrent - beta * *pActiveRow;
831 
832  // We check that the row values do not have any common divisor.
833  if (GCD1 > 1 &&
834  (GCD2 = abs64(*pCurrent)) > 0)
835  {
836  GCD(GCD1, GCD2);
837  }
838  }
839 
840  if (GCD1 > 1)
841  {
842  *pIdentity /= GCD1;
843 
844  pActiveRow = pActiveRowStart;
845  pCurrent = pRow;
846 
847  for (; pActiveRow < pActiveRowEnd; ++pActiveRow, ++pCurrent)
848  {
849  *pCurrent /= GCD1;
850  }
851  }
852  }
853 
854  pActiveRowStart += NumCols;
855  pActiveRowEnd += NumCols;
856  CurrentRowIndex++;
857  }
858 
859  assert(CurrentColumnIndex == CurrentRowIndex + IgnoredColumnCount);
860  assert(CurrentColumnIndex == NumCols);
861 
862  // std::cout << matrix << std::endl;
863  // std::cout << IgnoredColumns << std::endl;
864  // std::cout << Identity << std::endl;
865  // std::cout << RowPivot << std::endl << std::endl;
866 
867  size_t KernelRows = NumRows;
868  size_t KernelCols = NumRows + IgnoredColumnCount - NumCols;
869 
870  assert(KernelCols > 0);
871 
872  kernel.resize(KernelRows, KernelCols);
873 
874  CMatrix< C_INT64 > Kernel(KernelRows, KernelCols);
875  Kernel = 0;
876 
877  C_INT64 * pKernelInt = Kernel.array();
878  C_INT64 * pKernelIntEnd = pKernelInt + Kernel.size();
879 
880  pActiveRowStart = matrix[CurrentRowIndex];
881  pActiveRowEnd = matrix[NumRows];
882 
883  // Null space matrix identity part
884  pIdentity = Identity.array() + CurrentRowIndex;
885  C_INT64 * pKernelColumn = Kernel.array();
886 
887  for (; pActiveRowStart < pActiveRowEnd; pActiveRowStart += NumCols, ++pKernelColumn, ++pIdentity)
888  {
889  pKernelInt = pKernelColumn;
890  pIgnoredColumn = IgnoredColumns.array();
891 
892  pRow = pActiveRowStart;
893  pRowEnd = pRow + NumCols;
894 
895  if (*pIdentity < 0)
896  {
897  *pIdentity *= -1;
898 
899  for (; pRow < pRowEnd; ++pRow, ++pIgnoredColumn)
900  {
901  if (*pIgnoredColumn)
902  {
903  continue;
904  }
905 
906  *pKernelInt = - *pRow;
907  pKernelInt += KernelCols;
908  }
909  }
910  else
911  {
912  for (; pRow < pRowEnd; ++pRow, ++pIgnoredColumn)
913  {
914  if (*pIgnoredColumn)
915  {
916  continue;
917  }
918 
919  *pKernelInt = *pRow;
920  pKernelInt += KernelCols;
921  }
922  }
923  }
924 
925  pIdentity = Identity.array() + CurrentRowIndex;
926  pKernelInt = Kernel[CurrentRowIndex];
927 
928  for (; pKernelInt < pKernelIntEnd; pKernelInt += KernelCols + 1, ++pIdentity)
929  {
930  *pKernelInt = *pIdentity;
931  }
932 
933  // std::cout << Kernel << std::endl;
934  // std::cout << RowPivot << std::endl << std::endl;
935 
936  // Undo the reordering introduced by Gaussian elimination to the kernel matrix.
937  pPivot = RowPivot.array();
938  pRow = Kernel.array();
939  pRowEnd = pRow + Kernel.size();
940 
941  for (; pRow < pRowEnd; ++pPivot, pRow += KernelCols)
942  {
943  memcpy(kernel[*pPivot], pRow, KernelCols * sizeof(C_INT64));
944  }
945 
946  // std::cout << kernel << std::endl << std::endl;
947  // std::cout << rowPivot << std::endl << std::endl;
948 
949  return true;
950 }
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 CBitPatternTreeMethod::combine ( const CBitPatternTreeNode pPositive,
const CBitPatternTreeNode pNegative 
)
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 CBitPatternTreeMethod.cpp.

References CStepMatrix::addColumn(), CZeroSet::getNumberOfSetBits(), CBitPatternTreeNode::getSetChild(), CBitPatternTreeNode::getStepMatrixColumn(), CBitPatternTreeNode::getUnsetChild(), CBitPatternTreeNode::getZeroSet(), CZeroSet::intersection(), CBitPatternTree::isExtremeRay(), CZeroSet::isExtremeRay(), mContinueCombination, mhProgressCounter2, mMinimumSetSize, mNewColumns, CCopasiMethod::mpCallBack, mpNullTree, mProgressCounter2, mpStepMatrix, CProcessReport::proceed(), CProcessReport::progressItem(), and CStepMatrix::removeColumn().

Referenced by calculate().

247 {
249  {
251  }
252 
254  {
255  return;
256  }
257 
258  CZeroSet Intersection = CZeroSet::intersection(pPositive->getZeroSet(),
259  pNegative->getZeroSet());
260 #ifdef COPASI_DEBUG_TRACE
261  DebugFile << "Intersection: " << Intersection << std::endl;
262 
263  // Adjacency test
264  if (Intersection.getNumberOfSetBits() < mMinimumSetSize)
265  {
266  DebugFile << "Intersection fails adjacency test." << std::endl;
267  return;
268  }
269 
270 #endif //COPASI_DEBUG_TRACE
271 
272  const CStepMatrixColumn * pPositiveColumn = pPositive->getStepMatrixColumn();
273 
274  const CStepMatrixColumn * pNegativeColumn = pNegative->getStepMatrixColumn();
275 
276  // Both are leave nodes
277  if (pPositiveColumn != NULL && pNegativeColumn != NULL)
278  {
279  // We need to check whether the existing matrix contains already a leaf which is a superset
280  if (mpNullTree->isExtremeRay(Intersection))
281  {
282  // We are sure that the previous Null Tree did not contain any
283  // super sets, however the new columns may.
284 
285  // We check whether the new columns do not already contain a superset
286  if (Intersection.isExtremeRay(mNewColumns))
287  {
288  CStepMatrixColumn * pColumn = mpStepMatrix->addColumn(Intersection, pPositiveColumn, pNegativeColumn);
289 #ifdef COPASI_DEBUG_TRACE
290  DebugFile << "New Column: " << *pColumn << std::endl;
291 #endif //COPASI_DEBUG_TRACE
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 #ifdef COPASI_DEBUG_TRACE
311  else DebugFile << "Intersection fails - new columns already contain superset." << std::endl;
312 
313 #endif //COPASI_DEBUG_TRACE
314  }
315 
316 #ifdef COPASI_DEBUG_TRACE
317  else DebugFile << "Intersection fails - null tree already contains superset." << std::endl;
318 
319 #endif //COPASI_DEBUG_TRACE
320 
322 
323  if (mpCallBack)
325  }
326  else if (pPositiveColumn != NULL)
327  {
328 #ifdef COPASI_DEBUG_TRACE
329  DebugFile << "Intersection has null negative column." << std::endl;
330 #endif //COPASI_DEBUG_TRACE
331  combine(pPositive, pNegative->getUnsetChild());
332  combine(pPositive, pNegative->getSetChild());
333  }
334  else if (pNegativeColumn != NULL)
335  {
336 #ifdef COPASI_DEBUG_TRACE
337  DebugFile << "Intersection has null positive column." << std::endl;
338 #endif //COPASI_DEBUG_TRACE
339  combine(pPositive->getUnsetChild(), pNegative);
340  combine(pPositive->getSetChild(), pNegative);
341  }
342  else
343  {
344 #ifdef COPASI_DEBUG_TRACE
345  DebugFile << "Intersection has null positive and negative columns." << std::endl;
346 #endif //COPASI_DEBUG_TRACE
347  combine(pPositive->getUnsetChild(), pNegative->getUnsetChild());
348  combine(pPositive->getUnsetChild(), pNegative->getSetChild());
349  combine(pPositive->getSetChild(), pNegative->getUnsetChild());
350  combine(pPositive->getSetChild(), pNegative->getSetChild());
351  }
352 }
const CStepMatrixColumn * getStepMatrixColumn() const
const CBitPatternTreeNode * getUnsetChild() const
void combine(const CBitPatternTreeNode *pPositive, const CBitPatternTreeNode *pNegative)
bool isExtremeRay(const CZeroSet &ray) const
unsigned C_INT32 mProgressCounter2
const CBitPatternTreeNode * getSetChild() const
virtual bool progressItem(const size_t &handle)
CBitPatternTree * mpNullTree
virtual bool proceed()
const size_t & getNumberOfSetBits() const
Definition: CZeroSet.h:85
void removeColumn(CStepMatrixColumn *pColumn)
const CZeroSet & getZeroSet() const
bool isExtremeRay(const std::vector< CStepMatrixColumn * > &columns) const
Definition: CZeroSet.cpp:97
std::vector< CStepMatrixColumn * > mNewColumns
static CZeroSet intersection(const CZeroSet &set1, const CZeroSet &set2)
Definition: CZeroSet.h:137
CStepMatrixColumn * addColumn(const CZeroSet &set, const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative)
CProcessReport * mpCallBack
void CBitPatternTreeMethod::findRemoveInvalidColumns ( const std::vector< CStepMatrixColumn * > &  nullColumns)
private

Remove the invalid columns from the step matrix

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

Definition at line 354 of file CBitPatternTreeMethod.cpp.

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

Referenced by calculate().

355 {
356  if (mNewColumns.empty())
357  {
358  return;
359  }
360 
361  // Convert the new columns into a bit pattern tree
362  CBitPatternTree NewTree(mNewColumns);
363 
364  // Determine the columns which became invalid.
365  std::vector< CStepMatrixColumn * > InvalidColumns;
366 
367  std::vector< CStepMatrixColumn * >::const_iterator it = nullColumns.begin();
368  std::vector< CStepMatrixColumn * >::const_iterator end = nullColumns.end();
369 
370  for (; it != end; ++it)
371  {
372  if (!NewTree.isExtremeRay((*it)->getZeroSet()))
373  {
374  InvalidColumns.push_back(*it);
375  }
376  }
377 
378  mpStepMatrix->removeInvalidColumns(InvalidColumns);
379  mNewColumns.clear();
380 }
void removeInvalidColumns(std::vector< CStepMatrixColumn * > &invalidColumns)
std::vector< CStepMatrixColumn * > mNewColumns
static void CBitPatternTreeMethod::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 58 of file CBitPatternTreeMethod.h.

Referenced by CalculateKernel(), and CStepMatrixColumn::CStepMatrixColumn().

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

Multiply values so that values contains only integers. Get the index of the unset bits of the flux mode.

Definition at line 658 of file CBitPatternTreeMethod.cpp.

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

Referenced by buildFluxModes().

660 {
661  mpStepMatrix->getUnsetBitIndexes(pColumn, indexes);
662 
663  // Apply the QR pivot
664  size_t * pIndex = indexes.array();
665  size_t * pIndexEnd = pIndex + indexes.size();
666 
667  for (; pIndex != pIndexEnd; ++pIndex)
668  {
669  *pIndex = mReactionPivot[*pIndex];
670  }
671 }
void getUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
CVector< size_t > mReactionPivot
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
bool CBitPatternTreeMethod::initialize ( )
virtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from CEFMMethod.

Definition at line 107 of file CBitPatternTreeMethod.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(), pdelete, and pTask.

Referenced by calculate().

108 {
109  if (!CEFMMethod::initialize())
110  {
111  return false;
112  }
113 
115  mReactionForward.clear();
116 
117  mContinueCombination = true;
118 
119  CEFMTask * pTask = dynamic_cast< CEFMTask *>(getObjectParent());
120 
121  if (pTask == NULL) return false;
122 
123  mpModel = pTask->getProblem()->getModel();
124 
125  if (mpModel == NULL) return false;
126 
127  // We first build the kernel matrix
128  CMatrix< C_INT64 > KernelMatrix;
129  buildKernelMatrix(KernelMatrix);
130 #ifdef COPASI_DEBUG_TRACE
131  DebugFile << "Original Kernel Matrix:" << std::endl;
132  DebugFile << KernelMatrix << std::endl;
133 #endif // COPASI_DEBUG_TRACE
134  mMinimumSetSize = KernelMatrix.numCols() - 2;
135 #ifdef COPASI_DEBUG_TRACE
136  DebugFile << "MinSetSize = " << mMinimumSetSize << std::endl;
137 #endif // COPASI_DEBUG_TRACE
138 
139  // Now we create the initial step matrix
140  mpStepMatrix = new CStepMatrix(KernelMatrix);
141 
142  mProgressCounter = 0;
144 
145  if (mpCallBack)
147  mpCallBack->addItem("Current Step",
150 
151  return true;
152 }
#define pdelete(p)
Definition: copasi.h:215
CCopasiProblem * getProblem()
std::vector< std::pair< size_t, bool > > mReactionForward
#define C_INT32
Definition: copasi.h:90
virtual bool initialize()
Definition: CEFMMethod.cpp:109
unsigned C_INT32 mProgressCounter
CTSSATask * pTask
size_t getNumUnconvertedRows() const
unsigned C_INT32 mProgressCounterMax
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
void buildKernelMatrix(CMatrix< C_INT64 > &kernel)
virtual size_t numCols() const
Definition: CMatrix.h:144
CProcessReport * mpCallBack
CModel * getModel() const
CCopasiContainer * getObjectParent() const
void CBitPatternTreeMethod::initObjects ( )
private

Initialize the needed CCopasiObjects.

Definition at line 102 of file CBitPatternTreeMethod.cpp.

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

Referenced by CBitPatternTreeMethod().

103 {
105 }
unsigned C_INT32 mProgressCounter
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)

Friends And Related Function Documentation

Member Data Documentation

bool CBitPatternTreeMethod::mContinueCombination
protected

Boolean value indicating whether combination should continue.

Definition at line 256 of file CBitPatternTreeMethod.h.

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

CMatrix< C_INT64 > CBitPatternTreeMethod::mExpandedStoiTranspose
protected

The transpose of the expanded stoichiometry matrix.

Definition at line 226 of file CBitPatternTreeMethod.h.

Referenced by buildFluxModes(), and buildKernelMatrix().

size_t CBitPatternTreeMethod::mhProgressCounter
protected

Handle to the process report item "Current Step"

Definition at line 196 of file CBitPatternTreeMethod.h.

Referenced by calculate(), and initialize().

size_t CBitPatternTreeMethod::mhProgressCounter2
protected

Handle to the process report item "Combination"

Definition at line 211 of file CBitPatternTreeMethod.h.

Referenced by calculate(), and combine().

size_t CBitPatternTreeMethod::mMinimumSetSize
protected

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

Definition at line 246 of file CBitPatternTreeMethod.h.

Referenced by combine(), and initialize().

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

A list of invalid columns currently in the step matrix

Definition at line 241 of file CBitPatternTreeMethod.h.

Referenced by combine(), and findRemoveInvalidColumns().

CModel* CBitPatternTreeMethod::mpModel
protected

A pointer to the model which is analyzed.

Definition at line 181 of file CBitPatternTreeMethod.h.

Referenced by buildKernelMatrix(), and initialize().

CBitPatternTree* CBitPatternTreeMethod::mpNullTree
protected

The bit pattern tree for the current step

Definition at line 236 of file CBitPatternTreeMethod.h.

Referenced by calculate(), combine(), and ~CBitPatternTreeMethod().

unsigned C_INT32 CBitPatternTreeMethod::mProgressCounter
protected

The current step used for process report.

Definition at line 186 of file CBitPatternTreeMethod.h.

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

unsigned C_INT32 CBitPatternTreeMethod::mProgressCounter2
protected

The current combination used for process report.

Definition at line 201 of file CBitPatternTreeMethod.h.

Referenced by calculate(), and combine().

unsigned C_INT32 CBitPatternTreeMethod::mProgressCounter2Max
protected

The max combination used for process report.

Definition at line 206 of file CBitPatternTreeMethod.h.

Referenced by calculate().

unsigned C_INT32 CBitPatternTreeMethod::mProgressCounterMax
protected

The max step used for process report.

Definition at line 191 of file CBitPatternTreeMethod.h.

Referenced by calculate(), and initialize().

CStepMatrix* CBitPatternTreeMethod::mpStepMatrix
protected

A pointer to the step matrix for creating the flux modes

Definition at line 231 of file CBitPatternTreeMethod.h.

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

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

A vector to recording the expansion of the stoichiometry matrix.

Definition at line 216 of file CBitPatternTreeMethod.h.

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

CVector< size_t > CBitPatternTreeMethod::mReactionPivot
protected

A vector recording the pivots for the QR factorization

Definition at line 221 of file CBitPatternTreeMethod.h.

Referenced by buildKernelMatrix(), and getUnsetBitIndexes().

size_t CBitPatternTreeMethod::mStep
protected

The currently process step

Definition at line 251 of file CBitPatternTreeMethod.h.

Referenced by calculate().


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