COPASI API
4.16.103
|
#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
Definition at line 78 of file CIndexedPriorityQueue.h.
CIndexedPriorityQueue::CIndexedPriorityQueue | ( | ) |
CIndexedPriorityQueue::~CIndexedPriorityQueue | ( | ) |
void CIndexedPriorityQueue::buildHeap | ( | ) |
Build moves entries until the correct ordering is achieved.
Definition at line 127 of file CIndexedPriorityQueue.cpp.
References C_INVALID_INDEX, heapify(), and mHeap.
Referenced by CStochNextReactionMethod::setupPriorityQueue().
void CIndexedPriorityQueue::clear | ( | ) |
Definition at line 135 of file CIndexedPriorityQueue.cpp.
References mHeap, and mIndexPointer.
Referenced by CStochNextReactionMethod::setupPriorityQueue(), CHybridMethodODE45::setupPriorityQueue(), CHybridMethod::setupPriorityQueue(), and CHybridMethodLSODA::setupPriorityQueue().
|
inline |
gets the key from a given index
Definition at line 172 of file CIndexedPriorityQueue.h.
References mHeap, and mIndexPointer.
Referenced by CStochNextReactionMethod::updatePriorityQueue(), CHybridMethod::updateTauMu(), CHybridMethodLSODA::updateTauMu(), and CHybridMethodODE45::updateTauMu().
|
private |
Make a tree rooted at a given position into a heap
pos | The root position of the tree to heapify |
Definition at line 164 of file CIndexedPriorityQueue.cpp.
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
Definition at line 92 of file CIndexedPriorityQueue.cpp.
References C_INVALID_INDEX, and mIndexPointer.
Referenced by CHybridMethodODE45::setupPriorityQueue(), CHybridMethod::setupPriorityQueue(), and CHybridMethodLSODA::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
Definition at line 68 of file CIndexedPriorityQueue.cpp.
References mHeap, mIndexPointer, parent(), and swapNodes().
Referenced by CHybridMethod::partitionSystem(), CHybridMethodLSODA::partitionSystem(), CHybridMethodODE45::setupPriorityQueue(), CHybridMethod::setupPriorityQueue(), and CHybridMethodLSODA::setupPriorityQueue().
|
inlineprivate |
Provide the position in the heap of the left child of the current node.
pos | The current node position |
Definition at line 216 of file CIndexedPriorityQueue.h.
Referenced by heapify(), and updateAux().
|
inline |
Overloads the [] operator. Gives the index´th element on the heap
Definition at line 161 of file CIndexedPriorityQueue.h.
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 |
Definition at line 209 of file CIndexedPriorityQueue.h.
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 |
Definition at line 102 of file CIndexedPriorityQueue.cpp.
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
Definition at line 44 of file CIndexedPriorityQueue.cpp.
References C_INVALID_INDEX, heapify(), mHeap, mIndexPointer, and swapNodes().
Referenced by CHybridMethod::partitionSystem(), and CHybridMethodLSODA::partitionSystem().
|
inlineprivate |
Provide the position in the heap of the right child of the current node.
pos | The current node position |
Definition at line 223 of file CIndexedPriorityQueue.h.
Referenced by heapify(), and updateAux().
|
inline |
Return the size of the heap
Definition at line 134 of file CIndexedPriorityQueue.h.
References mHeap.
Referenced by CHybridNextReactionLSODAMethod::doSingleStep(), and CHybridNextReactionRKMethod::doSingleStep().
|
private |
Swap a pair of nodes and update the index structure accordingly.
Definition at line 146 of file CIndexedPriorityQueue.cpp.
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
Definition at line 38 of file CIndexedPriorityQueue.cpp.
References mHeap.
Referenced by CStochNextReactionMethod::doSingleStep(), CHybridMethod::getStochTimeAndIndex(), CHybridMethodLSODA::getStochTimeAndIndex(), and CHybridMethodODE45::getStochTimeAndIndex().
C_FLOAT64 CIndexedPriorityQueue::topKey | ( | ) | const |
Get the key value associated with the highest priority node
Definition at line 33 of file CIndexedPriorityQueue.cpp.
References mHeap.
Referenced by CStochNextReactionMethod::doSingleStep(), CHybridMethod::getStochTimeAndIndex(), CHybridMethodLSODA::getStochTimeAndIndex(), and CHybridMethodODE45::getStochTimeAndIndex().
|
private |
Used by the updateNode function. Update the node at a given position.
Definition at line 188 of file CIndexedPriorityQueue.cpp.
References C_FLOAT64, C_INVALID_INDEX, leftChild(), mHeap, min, parent(), rightChild(), and swapNodes().
Referenced by updateNode().
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 |
Definition at line 138 of file CIndexedPriorityQueue.cpp.
References mHeap, mIndexPointer, and updateAux().
Referenced by CStochNextReactionMethod::updatePriorityQueue(), CHybridMethod::updatePriorityQueue(), CHybridMethodLSODA::updatePriorityQueue(), CHybridMethodODE45::updatePriorityQueue(), CHybridMethod::updateTauMu(), CHybridMethodLSODA::updateTauMu(), and CHybridMethodODE45::updateTauMu().
|
friend |
insert operator
Definition at line 286 of file CIndexedPriorityQueue.cpp.
|
private |
The vector which stores the heap
Definition at line 230 of file CIndexedPriorityQueue.h.
Referenced by buildHeap(), clear(), getKey(), heapify(), insertStochReaction(), operator<<(), operator[](), pushPair(), removeStochReaction(), size(), swapNodes(), topIndex(), topKey(), updateAux(), and updateNode().
|
private |
The vector which stores a pointer to each indexed node on the heap
Definition at line 234 of file CIndexedPriorityQueue.h.
Referenced by clear(), getKey(), initializeIndexPointer(), insertStochReaction(), operator<<(), pushPair(), removeStochReaction(), swapNodes(), and updateNode().