Hi,
For my Discrete event simulation assignment, I was advised to use priority queues. I was able to access the perfect top element but when I pop out I get the bottom element! I don't understand where am I going wrong is my comparator function that goes wrong?
Comparator function
1 2 3 4 5 6 7 8 9
|
class CompareEventQueue {
public:
bool operator()(Event& e1, Event& e2) {
if (e1.time == e2.time) {
return (e1.processId > e2.processId);
}
return (e1.time > e2.time);
}
};
|
Priority queue definition is
priority_queue <Event, vector<Event>, CompareEventQueue> eventQueue;
The object Event is of type
1 2 3 4 5 6
|
class Event {
public:
eventType eventStart;
double time; //time units since the start of simulation
int processId;
};
|
So when I insert
EventObject1 ---> (CPUBurstCompletionEvent, 6.59999999, 0)
EventObject2 ---> (arrival, 6.59999999, 1)
So when I access the top element it gives me EventObject1;
Event temp = eventQueue.top();
but when I pop an element out, it pops out EventObject2; weird!!!!! :(.. Some1 plz help me! I am a noob..
This is the link to the image of my eventQueue after I add EventObject1 and EventObject2
http://imageshack.us/photo/my-images/98/screenshot20111009at329.png/