Dynamic C-server Queueing System Simulation  1.0
Simulating data for delay prediction
station.h
Go to the documentation of this file.
1 #include "./../includes.h"
2 #ifndef STATION_H
3 #define STATION_H
4 
8 class station
9 {
10  long mxN;
11  std::vector<int> server_status;
16  std::vector<int> current_customer;
17  std::queue<int> current_queue;
18  std::vector<float> td;
19  int c;
20  int n;
21  int Na;
22  std::vector< std::tuple<int,float,int,int,float,float> > counter_variable;
30  using C_type = std::function<int(float t)>;
31  using event_type = std::function<float(float t)>;
35 public:
36  station(long init_mxN, C_type C_para, event_type dept_para, float t = 0, int init_n = 0)
37  : C(C_para), DepartureTimes(dept_para)
38  {
39  mxN = init_mxN;
40 
41  server_status.assign(mxN, -1);
42  current_customer.assign(mxN, -1);
43  td.assign(mxN, INF);
44  n = init_n;
45  c = 0;
46  this->server_updates((t - int(t)) + int(t) % 1440);
47  Na = n;
48  // Initialising n customers
49  for (int j = 0; j < std::min(n, c); j++)
50  {
51  server_status[j] = 1;
52  td[j] = DepartureTimes(0);
53  current_customer[j] = j;
54  }
55  for (int i = std::min(n, c); i < n; i++)
56  {
57  current_queue.push(i);
58  }
59  }
60 
61  station(long init_mxN, C_type C_para, float init_dept, float t = 0, int init_n = 0)
62  : C(C_para),
63  DepartureTimes([init_dept](float t) -> float { return init_dept; })
64  {
65  mxN = init_mxN;
66 
67  server_status.assign(mxN, -1);
68  current_customer.assign(mxN, -1);
69  td.assign(mxN, INF);
70  n = init_n;
71  c = 0;
72  this->server_updates((t - int(t)) + int(t) % 1440);
73  Na = n;
74  // Initialising n customers
75  for (int j = 0; j < std::min(n, c); j++)
76  {
77  server_status[j] = 1;
78  td[j] = DepartureTimes(0);
79  current_customer[j] = j;
80  }
81  for (int i = std::min(n, c); i < n; i++)
82  {
83  current_queue.push(i);
84  }
85  }
86 
87  station(long init_mxN, int init_C, float init_dept, float t = 0, int init_n = 0)
88  : C([init_C](float t) -> int { return init_C; }),
89  DepartureTimes([init_dept](float t) -> float { return init_dept; })
90  {
91  mxN = init_mxN;
92 
93  server_status.assign(mxN, -1);
94  current_customer.assign(mxN, -1);
95  td.assign(mxN, INF);
96  n = init_n;
97  c = 0;
98  this->server_updates((t - int(t)) + int(t) % 1440);
99  Na = n;
100  // Initialising n customers
101  for (int j = 0; j < std::min(n, c); j++)
102  {
103  server_status[j] = 1;
104  td[j] = DepartureTimes(0);
105  current_customer[j] = j;
106  }
107  for (int i = std::min(n, c); i < n; i++)
108  {
109  current_queue.push(i);
110  }
111  }
112 
113  station(long init_mxN, int init_C, event_type init_dept, float t = 0, int init_n = 0)
114  : C([init_C](float t) -> int { return init_C; }),
115  DepartureTimes(init_dept)
116  {
117  mxN = init_mxN;
118 
119  server_status.assign(mxN, -1);
120  current_customer.assign(mxN, -1);
121  td.assign(mxN, INF);
122  n = init_n;
123  c = 0;
124  this->server_updates((t - int(t)) + int(t) % 1440);
125  Na = n;
126  // Initialising n customers
127  for (int j = 0; j < std::min(n, c); j++)
128  {
129  server_status[j] = 1;
130  td[j] = DepartureTimes(0);
131  current_customer[j] = j;
132  }
133  for (int i = std::min(n, c); i < n; i++)
134  {
135  current_queue.push(i);
136  }
137  }
138 
139  void print_station_status(float t);
140  int find_min_k();
141  float find_min_td();
142  void server_updates(float t);
143  int departure_updates(float t);
144  void add_customer_to_station(float t,int customer_id);
145  void write_to_csv(std::string file_name);
146  std::vector<std::tuple<int, float, int, int, float, float>> get_counter_variable();
147  int find_queue_len();
148  void logger(int station_id, float t);
149  void logger(std::string station_id, float t);
150  void reset_queue(float t);
151  float minimum_residual_time(float t);
152  std::tuple<int,int,int> access_system_state(float t);
153  void initialize_CSV(std::string file_name);
154  void dump_counter_variable_memory(std::string file_name);
156 };
157 
158 
159 std::vector<float> read_csv(std::string filename,int index);
160 #endif
int find_min_k()
Finds the server index which has the minimal departure time.
Definition: station.cpp:11
station(long init_mxN, C_type C_para, event_type dept_para, float t=0, int init_n=0)
Definition: station.h:36
std::vector< int > server_status
Definition: station.h:11
int c
Definition: station.h:19
std::vector< int > current_customer
Definition: station.h:16
std::vector< float > read_csv(std::string filename, int index)
Reads data from a CSV file.
Definition: station.cpp:691
std::queue< int > current_queue
Definition: station.h:17
void print_station_status(float t)
Beautifully outputs station status to the console.
Definition: station.cpp:378
int find_queue_len()
float minimum_residual_time(float t)
Gives the minimum residual time i.e. time left for next departure.
Definition: station.cpp:624
station(long init_mxN, C_type C_para, float init_dept, float t=0, int init_n=0)
Definition: station.h:61
void logger(int station_id, float t)
Beautifully outputs station status a file in folder logs.
Definition: station.cpp:441
std::vector< float > td
Definition: station.h:18
station(long init_mxN, int init_C, event_type init_dept, float t=0, int init_n=0)
Definition: station.h:113
station(long init_mxN, int init_C, float init_dept, float t=0, int init_n=0)
Definition: station.h:87
void server_updates(float t)
Makes server updates.
Definition: station.cpp:58
event_type DepartureTimes
Definition: station.h:33
float find_min_td()
Finds the minimum departure time of all the servers working.
Definition: station.cpp:33
int departure_updates(float t)
Makes departure updates.
Definition: station.cpp:314
C_type C
Definition: station.h:32
void initialize_CSV(std::string file_name)
Definition: station.cpp:633
void add_customer_to_station(float t, int customer_id)
Add a single customer to the front of the system.
Definition: station.cpp:237
int n
Definition: station.h:20
Definition: station.h:8
void dump_counter_variable_memory()
Definition: station.cpp:672
void write_to_csv(std::string file_name)
Writes the station::counter_variable to a csv file.
Definition: station.cpp:578
std::function< int(float t)> C_type
Definition: station.h:30
std::tuple< int, int, int > access_system_state(float t)
Definition: station.cpp:629
std::function< float(float t)> event_type
Definition: station.h:31
void reset_queue(float t)
Resets the queue.
Definition: station.cpp:605
std::vector< std::tuple< int, float, int, int, float, float > > counter_variable
Definition: station.h:22
long mxN
Definition: station.h:10
int Na
Definition: station.h:21
std::vector< std::tuple< int, float, int, int, float, float > > get_counter_variable()
Gives back the station::counter_variable.
Definition: station.cpp:273