1
#ifndef PRIORITYQUEUEWAITINGLIST_HPP_
2
#define PRIORITYQUEUEWAITINGLIST_HPP_
4
#include "WaitingList.hpp"
13
virtual ~WeightedNode() { if(node->GetColor() == COVERED) delete node; };
16
struct less : public std::binary_function<WeightedNode*, WeightedNode*, bool>
18
bool operator()(const WeightedNode* x, const WeightedNode* y) const
20
return x->weight < y->weight;
24
template <typename CalcWeight>
25
class PriorityQueueWaitingList : public VerifyTAPN::WaitingList {
27
typedef std::priority_queue<WeightedNode*, std::vector<WeightedNode*>, less > priority_queue;
29
PriorityQueueWaitingList(): calcWeight(), queue(), actualSize(0) { };
30
virtual ~PriorityQueueWaitingList()
34
WeightedNode* it = queue.top();
40
virtual void Add(Node* node);
42
virtual long long Size() const { return actualSize; };
43
inline virtual long long SizeIncludingCovered() const { return queue.size(); };
44
inline virtual void DecrementActualSize() { actualSize--; };
47
CalcWeight calcWeight;
52
template <typename CalcWeight>
53
void PriorityQueueWaitingList<CalcWeight>::Add(Node* node)
56
assert(node->GetColor()==WAITING);
57
WeightedNode* wnode = new WeightedNode;
59
wnode->weight = calcWeight(node);
65
template <typename CalcWeight>
66
Node* PriorityQueueWaitingList<CalcWeight>::Next()
68
if(Size() == 0) return NULL;
69
WeightedNode* node = queue.top();
70
assert(node->node->GetColor() == WAITING || node->node->GetColor() == COVERED);
71
while(node->node->GetColor() == COVERED){
75
if(node == NULL || node->node == NULL) return NULL;
78
queue.pop(); actualSize--;
79
node->node->Recolor(PASSED);
80
// assert(AllElementsAreWatingOrCovered(stack.begin(), stack.end()));
85
#endif /* PRIORITYQUEUEWAITINGLIST_HPP_ */