STL Queue, ProcessDeparture Error

I have gotten a bit far into my STL Queue program but am having trouble when it comes to the processDeparture function, I keep getting an error saying:

: no matching function for call to 'std::priority_queue<Event>::push(int&)'
eventListPQueue.push(customer.newDepartureEvent);

Here is my code so far:

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  #include <iostream>
#include <iomanip>
#include <fstream>
#include <queue>

using namespace std;

struct Customer
{
	int currentTime;
	int newDepartureEvent;
	int departureTime;
	int arrivalTime;
	int transactionTime;
    int customerID;
};

struct Event
{
	int newDepartureEvent;
	int departureTime;
    int customerID;
    int transactionTime;
    int arrivalTime;
    int currentTime;

    //Used to compare events and determine highest priority
    bool operator < (const Event& right) const
    {
        return this->arrivalTime < right.arrivalTime;
    }
};

void simulate();
void processArrival(int &currentTime, Event &newEvent, priority_queue<Event> &eventListPQueue, queue<Customer> &bankQueue, bool tellerAvailable);
void processDeparture(Event &newEvent, priority_queue<Event> &eventListPQueue, queue<Customer> &bankQueue, bool tellerAvailable);

int main()
{
    simulate();

    return 0;
}

void simulate()
{
    //Used to read in file
    ifstream File;

    //Declaring local variables
    int data;
    int arrivalEvent = 0;
    int transactionTime = 0;
    bool tellerAvailable = 0;

    //Creating an empty queue called bankQueue to represent a bank line
    //Creating an empty priority queue called eventListPQueue for an event list
    queue <Customer> bankQueue;
    priority_queue <Event> eventListPQueue;

    //Creating and adding arrival events to event list
    File.open("in1.txt");

    //Data file is not empty
    while(File)
    {
        //Getting next arriavl time and transaction time from file
        File >> arrivalEvent >> transactionTime;

        //cout << "test data: " << data << endl;
		cout << "test newArrivalEvent: " << arrivalEvent << endl;
		cout << "test transactionTime: " << transactionTime << endl;

		// a new arrival event containing a and t
		Event event;
		event.arrivalTime = arrivalEvent;
		event.transactionTime = transactionTime;
		eventListPQueue.push(event);	
    }   

    //Closing File
    File.close();

    //An Event loop 
	int currentTime = 0;

	// Event loop 
	while (!eventListPQueue.empty()) {                           // Event list is not empty

		Event newEvent;

		newEvent = eventListPQueue.top();
		currentTime = newEvent.arrivalTime;                      // Get current time       

		if (newEvent.arrivalTime && newEvent.departureTime == 0) {                              // is an arrival event
			processArrival(currentTime, newEvent, eventListPQueue, bankQueue, tellerAvailable);
		}

		else
			processDeparture(newEvent, eventListPQueue, bankQueue, tellerAvailable);
	}

/*
    //Event list is not empty
	while (eventListPQueue.size() > 0 ) 
    {                       

		Event newEvent;
		newEvent = eventListPQueue.top();
  
        //Get current time   
		currentTime = newEvent.arrivalTime;                          

        // is an arrival event
		if (newEvent.arrivalTime)                                
			processArrival(newEvent, eventListPQueue, bankQueue);

		else
			processDeparture(newEvent, eventListPQueue, bankQueue);
*/
	//****************  pseudiocode to fill in  **************************************

	//// Processes an arrival event. 
	//processArrival(arrivalEvent: Event, eventListPQueue : PriorityQueue, bankQueue : Queue) 
	//// Remove this event from the event list 
	//eventListPQueue.remove()    
	//
	//customer = customer referenced in arrivalEvent 
	//if (bankQueue.isEmpty() && tellerAvailable) {

	//	departureTime = currentTime + transaction time in arrivalEvent       
	//	newDepartureEvent = a new departure event with departureTime        
	//	eventListPQueue.add(newDepartureEvent)        
	//	tellerAvailable = false
	//}
	//else       
	//	bankQueue.enqueue(customer)
	//	
	//	// Processes a departure event . 
	//	+processDeparture(departureEvent: Event, eventListPQueue: PriorityQueue, bankQueue: Queue)

	//	// Remove this event from the event list 
	//	eventListPQueue.remove() 
	//	
	//	if (!bankQueue.isEmpty()) { 
	//		
	//		// Customer at front of line begins transaction 
	//		customer = bankQueue.peek()        
	//		bankQueue.dequeue()        
	//		departureTime = currentTime + transaction time in customer       
	//		newDepartureEvent = a new departure event with departureTime        
	//		eventListPQueue.add(newDepartureEvent)
	//	}
	//	else
	//		tellerAvailable = true



}

void processArrival(int &currentTime, Event &newEvent, priority_queue<Event> &eventListPQueue, queue<Customer> &bankQueue, bool tellerAvailable)
{
	Event grab;
	Event event;
	Event eventCustomer;
	Customer customerIn_line;

	eventListPQueue.pop();                                           // Remove this event from the event list 

	event.customerID++;                                              // customer = customer referenced in arrivalEvent 
	if (bankQueue.empty() && tellerAvailable) {

		grab.departureTime = currentTime + newEvent.transactionTime; //	departureTime = currentTime + transaction time in arrivalEvent       
		grab.newDepartureEvent = grab.departureTime;				 //	newDepartureEvent = a new departure event with departureTime    
		eventListPQueue.push(grab);									 //	eventListPQueue.add(newDepartureEvent)      
		tellerAvailable = false;                                     //	tellerAvailable = false

		

	}
	else {
		customerIn_line.arrivalTime = event.arrivalTime;
		customerIn_line.transactionTime = event.transactionTime;
		bankQueue.push(customerIn_line);                                    //  bankQueue.enqueue(customer) 
	}
}

//Where problem occurs
void processDeparture(Event &newEvent, priority_queue<Event> &eventListPQueue, queue<Customer> &bankQueue, bool tellerAvailable)
{
	eventListPQueue.pop();

	Customer customer;

	if(!bankQueue.empty())
	{
		customer = bankQueue.front();
		bankQueue.pop();
		customer.departureTime = customer.currentTime + customer.transactionTime;
		customer.newDepartureEvent = customer.departureTime;
		eventListPQueue.push(customer.newDepartureEvent);
	}

	else
	{
		tellerAvailable = true;
	}
	
}




File Being used:

1 5
2 5
4 5
20 5
22 5
24 5
26 5
28 5
30 5
88 3

OutPut Wanted:

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
Simulation Begins
Processing customer #1 arrival at time: 1
Processing customer #2 arrival at time: 2
Processing customer #3 arrival at time: 4
Processing customer #1 departure at time: 6
Processing customer #2 departure at time: 11
Processing customer #3 departure at time: 16
Processing customer #4 arrival at time: 20
Processing customer #5 arrival at time: 22
Processing customer #6 arrival at time: 24
Processing customer #4 departure at time: 25
Processing customer #7 arrival at time: 26
Processing customer #8 arrival at time: 28
Processing customer #5 departure at time: 30
Processing customer #9 arrival at time: 30
Processing customer #6 departure at time: 35
Processing customer #7 departure at time: 40
Processing customer #8 departure at time: 45
Processing customer #9 departure at time: 50
Processing customer #10 arrival at time: 88
Processing customer #10 departure at time: 91
Final Statistics: 
    Total number of people processed: 10
    Average amount of time spent waiting: 5.6
Last edited on
Well your newDepartureEvent seems to be a badly named variable to begin with.

> customer.newDepartureEvent = customer.departureTime;
In the couple of places you do use it, it's just a copy of the time.
Just because you name it as 'Event' doesn't make it an Event.


struct Customer ...
struct Event ...
Why do these have so many common members?
Is an event just a Customer + a time ?

Did you just look at your assignment and start writing code, or did you make a plan?
If you're faced with a long road trip, you need to do better than "follow the sun". You need a map.

You need to make an event.
1
2
3
4
5
6
		customer = bankQueue.front();
		bankQueue.pop();
		customer.departureTime = customer.currentTime + customer.transactionTime;
		Event departure;
		departure.members = values;  // TODO: Fix this
		eventListPQueue.push(departure);

This seems to be a repost of http://www.cplusplus.com/forum/beginner/273913/

The same comment re reading file data applies.
Topic archived. No new replies allowed.