-
Notifications
You must be signed in to change notification settings - Fork 2
/
selectionrule.hpp
68 lines (49 loc) · 1.25 KB
/
selectionrule.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include <iostream>
#include <queue>
#include <vector>
#include <exception>
class EmptyQueueException : public std::exception {
virtual const char* what() const throw()
{
return "Empty Queue Exception";
}
};
class SelectionRule {
protected:
int N;
private:
std::vector<char> active;
public:
virtual int next(void) = 0;
virtual void add(int u, int height, int excess) = 0;
virtual bool empty(void) = 0;
virtual void gap(int h) = 0;
void activate(int u) { active[u] = 1; }
void deactivate(int u) { active[u] = 0; }
bool isActive(int u) { return active[u]; }
SelectionRule(int N) : N(N), active(N) {}
virtual ~SelectionRule() {}
};
class HighestLevelRule : virtual public SelectionRule {
private:
int highest;
std::vector<std::queue<int> > hq;
void updateHighest(void);
public:
virtual int next(void);
virtual void add(int u, int height, int excess);
virtual bool empty(void);
virtual void gap(int h);
HighestLevelRule(int N) : SelectionRule(N), highest(-1), hq(N) {}
};
class FIFORule : virtual public SelectionRule {
private:
std::queue<int> q;
public:
virtual int next(void);
virtual void add(int u, int height, int excess);
virtual bool empty(void);
virtual void gap(int h);
FIFORule(int N) : SelectionRule(N) {}
};