Bank Simulation using STL QUEUE'S

Hi, I am working on a programming exercise using an STL Queue library and am having trouble with the departure and arrival process, and also printing out the my file that is read to read the output below.

I am implementing the < operator in my Event struct since This is how the priority_queue class will compare your Events to determine which ones have higher priority. Events with earlier times should have a greater priority.

Assignment Description:
Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in the bank. Maintain the arrival events and departure events in a priority queue,
sorted by the time of the event. Use an STL Priority Queue

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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <queue>

using namespace std;

struct Customer
{
    int customerID;
};

struct Event
{
    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();

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 <Event> 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 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


	}
}


File that is being read:

1
2
3
4
5
6
7
8
9
10
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
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
1
2
3
4
5
//Data file is not empty
    while(File)
    {
        //Getting next arriavl time and transaction time from file
        File >> arrivalEvent >> transactionTime;


Try:

1
2
3
//Data file is not empty
    while(File >> arrivalEvent >> transactionTime)
    {

Topic archived. No new replies allowed.