COPASI API
4.40.278
|
#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< PQNode > | mHeap |
std::vector< size_t > | mIndexPointer |
Friends | |
std::ostream & | operator<< (std::ostream &os, const CIndexedPriorityQueue &d) |
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
CIndexedPriorityQueue::CIndexedPriorityQueue | ( | ) |
Constructor
CIndexedPriorityQueue::~CIndexedPriorityQueue | ( | ) |
Destructor
void CIndexedPriorityQueue::buildHeap | ( | ) |
Build moves entries until the correct ordering is achieved.
References C_INVALID_INDEX, heapify(), and mHeap.
Referenced by CStochNextReactionMethod::setupPriorityQueue().
void CIndexedPriorityQueue::clear | ( | ) |
References mHeap, and mIndexPointer.
Referenced by CHybridMethod::setupPriorityQueue(), and CStochNextReactionMethod::setupPriorityQueue().
|
inline |
gets the key from a given index
References mHeap, and mIndexPointer.
Referenced by CStochNextReactionMethod::updatePriorityQueue(), and CHybridMethod::updateTauMu().
|
private |
Make a tree rooted at a given position into a heap
pos | The root position of the tree to heapify |
References leftChild(), mHeap, rightChild(), and swapNodes().
Referenced by buildHeap(), and removeStochReaction().
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().
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().
|
inlineprivate |
Provide the position in the heap of the left child of the current node.
pos | The current node position |
Referenced by heapify(), and updateAux().
|
inline |
References mHeap.
|
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.
pos | The current node position |
Referenced by insertStochReaction(), and updateAux().
size_t CIndexedPriorityQueue::pushPair | ( | const size_t | index, |
const C_FLOAT64 | key | ||
) |
Push an index/key pair onto the queue
index | The index used to access the node |
key | The key value used to determine the priority |
References CCopasiMessage::ERROR, mHeap, and mIndexPointer.
Referenced by CStochNextReactionMethod::setupPriorityQueue().
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().
|
inlineprivate |
Provide the position in the heap of the right child of the current node.
pos | The current node position |
Referenced by heapify(), and updateAux().
|
inline |
|
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().
size_t CIndexedPriorityQueue::topIndex | ( | ) | const |
Get the index associated with the highest priority node
References C_INVALID_INDEX, and mHeap.
Referenced by CStochNextReactionMethod::doSingleStep(), and CHybridMethod::getStochTimeAndIndex().
C_FLOAT64 CIndexedPriorityQueue::topKey | ( | ) | const |
Get the key value associated with the highest priority node
References mHeap.
Referenced by CStochNextReactionMethod::doSingleStep(), and CHybridMethod::getStochTimeAndIndex().
|
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().
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.
index | The index used to access the node |
key | The key value used to determine the priority |
References mHeap, mIndexPointer, and updateAux().
Referenced by CStochNextReactionMethod::updatePriorityQueue(), CHybridMethod::updatePriorityQueue(), and CHybridMethod::updateTauMu().
|
friend |
insert operator
|
private |
The vector which stores the heap
Referenced by buildHeap(), clear(), getKey(), heapify(), insertStochReaction(), operator[](), pushPair(), removeStochReaction(), size(), swapNodes(), topIndex(), topKey(), updateAux(), and updateNode().
|
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().