COPASI API  4.40.278
CIndexedPriorityQueue Class Reference

#include <CIndexedPriorityQueue.h>

Public Member Functions

void buildHeap ()
 
 CIndexedPriorityQueue ()
 
void clear ()
 
C_FLOAT64 getKey (const size_t index) const
 
void initializeIndexPointer (const size_t numberOfReactions)
 
size_t insertStochReaction (const size_t index, const C_FLOAT64 key)
 
C_FLOAT64 operator[] (const size_t pos) const
 
size_t pushPair (const size_t index, const C_FLOAT64 key)
 
size_t removeStochReaction (const size_t index)
 
size_t size () const
 
size_t topIndex () const
 
C_FLOAT64 topKey () const
 
void updateNode (const size_t index, const C_FLOAT64 key)
 
 ~CIndexedPriorityQueue ()
 

Private Member Functions

void heapify (const size_t pos)
 
size_t leftChild (const size_t pos) const
 
size_t parent (const size_t pos) const
 
size_t rightChild (const size_t pos) const
 
void swapNodes (const size_t index1, const size_t index2)
 
void updateAux (const size_t position)
 

Private Attributes

std::vector< PQNodemHeap
 
std::vector< size_t > mIndexPointer
 

Friends

std::ostream & operator<< (std::ostream &os, const CIndexedPriorityQueue &d)
 

Detailed Description

The CIndexedPriorityQueue class provides an indexed priority queue. Each element consistes of a pair of values, a key and an index.

The elements in the queue are ordered according to the value of their key. Since for stochastic simulations the minimum time is required, the queue is ordered so that the element with the minimum key value is at the top. This is the opposite of the normal ordering of priority queues.

The index can be used to access elements from positions other than at the front of the queue.

The indexed priority queue as applied to stochastic simulations is described in "Efficient Exact Stochastic Simulation of Chemical Systems with Many Species and Many Channels", Gibson and Bruck, J. Phys. Chem. A 104 (2000) 1876-1889

Constructor & Destructor Documentation

◆ CIndexedPriorityQueue()

CIndexedPriorityQueue::CIndexedPriorityQueue ( )

Constructor

◆ ~CIndexedPriorityQueue()

CIndexedPriorityQueue::~CIndexedPriorityQueue ( )

Destructor

Member Function Documentation

◆ buildHeap()

void CIndexedPriorityQueue::buildHeap ( )

Build moves entries until the correct ordering is achieved.

References C_INVALID_INDEX, heapify(), and mHeap.

Referenced by CStochNextReactionMethod::setupPriorityQueue().

◆ clear()

void CIndexedPriorityQueue::clear ( )

◆ getKey()

C_FLOAT64 CIndexedPriorityQueue::getKey ( const size_t  index) const
inline

gets the key from a given index

Returns
Returns the key

References mHeap, and mIndexPointer.

Referenced by CStochNextReactionMethod::updatePriorityQueue(), and CHybridMethod::updateTauMu().

◆ heapify()

void CIndexedPriorityQueue::heapify ( const size_t  pos)
private

Make a tree rooted at a given position into a heap

Parameters
posThe root position of the tree to heapify

References leftChild(), mHeap, rightChild(), and swapNodes().

Referenced by buildHeap(), and removeStochReaction().

◆ initializeIndexPointer()

void CIndexedPriorityQueue::initializeIndexPointer ( const size_t  numberOfReactions)

Initializes the vector mIndexPointer. The vector will be <numberOfReactions> long and every pointer will be -1, because none of the nodes can be found in the tree so far. Insert the stochastic reactions into the tree with insertStochReaction()

added by juergen 26 July, 2002

References C_INVALID_INDEX, and mIndexPointer.

Referenced by CHybridMethod::setupPriorityQueue().

◆ insertStochReaction()

size_t CIndexedPriorityQueue::insertStochReaction ( const size_t  index,
const C_FLOAT64  key 
)

Inserts the node with the given index and key into the tree. The index has to exist in the index array of course.

added by juergen 26 July, 2002

References mHeap, mIndexPointer, parent(), and swapNodes().

Referenced by CHybridMethod::partitionSystem(), and CHybridMethod::setupPriorityQueue().

◆ leftChild()

size_t CIndexedPriorityQueue::leftChild ( const size_t  pos) const
inlineprivate

Provide the position in the heap of the left child of the current node.

Parameters
posThe current node position
Returns
The left child position

Referenced by heapify(), and updateAux().

◆ operator[]()

C_FLOAT64 CIndexedPriorityQueue::operator[] ( const size_t  pos) const
inline
Returns
Returns the key

References mHeap.

◆ parent()

size_t CIndexedPriorityQueue::parent ( const size_t  pos) const
inlineprivate

Provide the position in the heap of the parent to a node. The positions are numbered from zero; a parent position less than zero implies that the current node is already at the top of the tree.

Parameters
posThe current node position
Returns
The parent node position

Referenced by insertStochReaction(), and updateAux().

◆ pushPair()

size_t CIndexedPriorityQueue::pushPair ( const size_t  index,
const C_FLOAT64  key 
)

Push an index/key pair onto the queue

Parameters
indexThe index used to access the node
keyThe key value used to determine the priority

References CCopasiMessage::ERROR, mHeap, and mIndexPointer.

Referenced by CStochNextReactionMethod::setupPriorityQueue().

◆ removeStochReaction()

size_t CIndexedPriorityQueue::removeStochReaction ( const size_t  index)

Deletes the node in the tree with the given index. The pointer in the index array is removed.

added by juergen 26 July, 2002

References C_INVALID_INDEX, heapify(), mHeap, mIndexPointer, and swapNodes().

Referenced by CHybridMethod::partitionSystem().

◆ rightChild()

size_t CIndexedPriorityQueue::rightChild ( const size_t  pos) const
inlineprivate

Provide the position in the heap of the right child of the current node.

Parameters
posThe current node position
Returns
The right child position

Referenced by heapify(), and updateAux().

◆ size()

size_t CIndexedPriorityQueue::size ( ) const
inline

Return the size of the heap

References mHeap.

Referenced by CHybridMethod::doSingleStep().

◆ swapNodes()

void CIndexedPriorityQueue::swapNodes ( const size_t  index1,
const size_t  index2 
)
private

Swap a pair of nodes and update the index structure accordingly.

References C_FLOAT64, mHeap, and mIndexPointer.

Referenced by heapify(), insertStochReaction(), removeStochReaction(), and updateAux().

◆ topIndex()

size_t CIndexedPriorityQueue::topIndex ( ) const

Get the index associated with the highest priority node

Returns
The index

References C_INVALID_INDEX, and mHeap.

Referenced by CStochNextReactionMethod::doSingleStep(), and CHybridMethod::getStochTimeAndIndex().

◆ topKey()

C_FLOAT64 CIndexedPriorityQueue::topKey ( ) const

Get the key value associated with the highest priority node

Returns
The key value

References mHeap.

Referenced by CStochNextReactionMethod::doSingleStep(), and CHybridMethod::getStochTimeAndIndex().

◆ updateAux()

void CIndexedPriorityQueue::updateAux ( const size_t  position)
private

Used by the updateNode function. Update the node at a given position.

References C_FLOAT64, C_INVALID_INDEX, leftChild(), mHeap, min, parent(), rightChild(), and swapNodes().

Referenced by updateNode().

◆ updateNode()

void CIndexedPriorityQueue::updateNode ( const size_t  index,
const C_FLOAT64  key 
)

Update the key value of a node at a given index. This also moves the node to the correct position if neccessary.

Parameters
indexThe index used to access the node
keyThe key value used to determine the priority

References mHeap, mIndexPointer, and updateAux().

Referenced by CStochNextReactionMethod::updatePriorityQueue(), CHybridMethod::updatePriorityQueue(), and CHybridMethod::updateTauMu().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const CIndexedPriorityQueue d 
)
friend

insert operator

Member Data Documentation

◆ mHeap

std::vector<PQNode> CIndexedPriorityQueue::mHeap
private

◆ mIndexPointer

std::vector<size_t> CIndexedPriorityQueue::mIndexPointer
private

The vector which stores a pointer to each indexed node on the heap

Referenced by clear(), getKey(), initializeIndexPointer(), insertStochReaction(), pushPair(), removeStochReaction(), swapNodes(), and updateNode().


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