Priority Queue Processing Events | Not Working Correctly

I'm writing a program that simulates a one line banking system and determines the average amount of time spent waiting for the number of customers they process.
I think my error is in processDepartureEvent or createDepartureEvent in Simulation.cpp and EventBuilder.cpp respectively.
any help would be greatly appreciated thanks!
Here is my results: Also the arrival event should increment each time
1
2
3
4
5
6
7
8
9
10
Please Enter a File Name: ../input3.dat
Simulation of Queue Begins: 
Processing arrival event 1 at time: 1 
Processing arrival event 1 at time: 7 
Processing arrival event 1 at time: 12 
Processing arrival event 1 at time: 14 
Processing arrival event 1 at time: 18
 . . . . . Simulation Ends
Final Statistics: Total number of people processed: 5 Total wait time: 0
Average amount of time spent waiting: 0 

It doesn't process the departure events and I can't figure out why.
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
//Simulation.cpp 

#include <iostream>
#include "Simulation.h"


using namespace std;



void Simulation::simulate(){
  int i = 0;
  cout<<endl;
  cout<<"Simulation of Queue Begins: "<<endl;

  currentEvent = eventBuilder.createArrivalEvent(1);

  if (currentEvent.getType() == ARRIVAL) {
    events.enqueue(currentEvent);
  }

  while(!events.isEmpty()) {

    currentEvent = events.peekFront();
    if(currentEvent.getType() == ARRIVAL) {
      processArrival();
      ++i;

    }
    else {
      processDeparture();
    }
    stats.addEvent(currentEvent);
  }

  for (int j = 0; j < i; ++j){
    cout<<". ";
  }
  cout<<endl;
  cout<<"Simulation Ends"<<endl;
  cout<<endl;
  stats.reportStats();
}

void Simulation::processArrival() {

  Event newEvent;

  line.enqueue(currentEvent);
  events.dequeue();

  if(line.isEmpty()){

  newEvent = eventBuilder.createDepartureEvent(currentEvent.getTime(),
                                               currentEvent.getDuration(),
                                               currentEvent.getNumber());

  events.enqueue(newEvent);
  }

  newEvent = eventBuilder.createArrivalEvent(currentEvent.getNumber()+1);

  if (newEvent.getNumber() != 0){
    events.enqueue(newEvent);
  }

}

void Simulation::processDeparture(){
  Event dEvent;
  Event tempEvent;

  //int line = currentEvent.getLine();

  //Removes departure event from line and event list
  line.dequeue();
  events.dequeue();

  if (!line.isEmpty()){
  tempEvent = line.peekFront();


  dEvent = eventBuilder.createDepartureEvent(currentEvent.getTime(),
                                             tempEvent.getDuration(),
                                             tempEvent.getNumber());
  events.enqueue(dEvent);
  }


}


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

#include <iostream>
#include <string>
#include "EventBuilder.h"

EventBuilder::EventBuilder(){
  std::string fileName;

  std::cout<<"Please Enter a File Name: ";
  std::cin>>fileName;


  inputFile.open(fileName);

  //Checking if file is opened
  //If not reprompts client for another file
  while(!inputFile.is_open()){

    std::cout<<"Error! Please enter another File Name: ";
      std::cin>>fileName;

      inputFile.open(fileName);
  }

}

Event EventBuilder::createArrivalEvent(const int number){
  Event ArrivalEvent;
  ArrivalEvent.setType(ARRIVAL);
  Time time;
  Time length;

 if(inputFile >> time >> length) {
    ArrivalEvent.setTime(time);
    ArrivalEvent.setDuration(length);
    ArrivalEvent.setNumber(number);
    //ArrivalEvent.setLine(lineNumber);

  }

  else {
    ArrivalEvent.setNumber(0);
  }

  return ArrivalEvent;

}

Event EventBuilder::createDepartureEvent(const Time& currentEventTime,
                                         const Time& transactionLength,
                                         const int number){

  Event DepartureEvent;
  DepartureEvent.setType(DEPARTURE);
  DepartureEvent.setTime(currentEventTime + transactionLength);

  DepartureEvent.setNumber(number);
  //DepartureEvent.setLine(lineNumber);

  return DepartureEvent;

}


EventBuilder.cpp
Last edited on
Topic archived. No new replies allowed.