![]() |
Dynamic C-server Queueing System Simulation
1.0
Simulating data for delay prediction
|
#include <station.h>
Public Member Functions | |
station (long init_mxN, C_type C_para, event_type dept_para, float t=0, int init_n=0) | |
station (long init_mxN, C_type C_para, float init_dept, float t=0, int init_n=0) | |
station (long init_mxN, int init_C, float init_dept, float t=0, int init_n=0) | |
station (long init_mxN, int init_C, event_type init_dept, float t=0, int init_n=0) | |
void | print_station_status (float t) |
Beautifully outputs station status to the console. More... | |
int | find_min_k () |
Finds the server index which has the minimal departure time. More... | |
float | find_min_td () |
Finds the minimum departure time of all the servers working. More... | |
void | server_updates (float t) |
Makes server updates. More... | |
int | departure_updates (float t) |
Makes departure updates. More... | |
void | add_customer_to_station (float t, int customer_id) |
Add a single customer to the front of the system. More... | |
void | write_to_csv (std::string file_name) |
Writes the station::counter_variable to a csv file. More... | |
std::vector< std::tuple< int, float, int, int, float, float > > | get_counter_variable () |
Gives back the station::counter_variable. More... | |
int | find_queue_len () |
void | logger (int station_id, float t) |
Beautifully outputs station status a file in folder logs. More... | |
void | logger (std::string station_id, float t) |
Beautifully outputs station status a file in folder logs. More... | |
void | reset_queue (float t) |
Resets the queue. More... | |
float | minimum_residual_time (float t) |
Gives the minimum residual time i.e. time left for next departure. More... | |
std::tuple< int, int, int > | access_system_state (float t) |
void | initialize_CSV (std::string file_name) |
void | dump_counter_variable_memory (std::string file_name) |
void | dump_counter_variable_memory () |
Private Types | |
using | C_type = std::function< int(float t)> |
using | event_type = std::function< float(float t)> |
Private Attributes | |
long | mxN |
std::vector< int > | server_status |
std::vector< int > | current_customer |
std::queue< int > | current_queue |
std::vector< float > | td |
int | c |
int | n |
int | Na |
std::vector< std::tuple< int, float, int, int, float, float > > | counter_variable |
C_type | C |
event_type | DepartureTimes |
Station class implements a single Queueing System.
|
private |
Function type float -> int
|
private |
Function type float -> float
|
inline |
|
inline |
|
inline |
|
inline |
std::tuple< int, int, int > station::access_system_state | ( | float | t | ) |
Server update function
void station::add_customer_to_station | ( | float | t, |
int | customer_id | ||
) |
Add a single customer to the front of the system.
t | The time variable. |
customer_id | id of the customer which is to be added. Maintain a counter for the customers. Call this function whenever the time variable reaches an arrival time. |
Increases the number of customer present in the system. Creates a new entry in station::counter_variable for the
incoming customer. The customer is sent to the first empty server or in case no empty server is found,
to the back of the queue. (station::current_queue).
Example:
int station::departure_updates | ( | float | t | ) |
Makes departure updates.
t | The time variable. |
Removes the customer whose service is completed at time t. Updates the entry in station::counter_variable for the
outgoing customer. A new customer is added to the server or else server is closed if the server status was 2 or
the server is set to idle if the system is empty.
Example:
void station::dump_counter_variable_memory | ( | std::string | file_name | ) |
void station::dump_counter_variable_memory | ( | ) |
int station::find_min_k | ( | ) |
Finds the server index which has the minimal departure time.
Finds the server index with departure time with a simple loop. Completed in O(mxN).
float station::find_min_td | ( | ) |
Finds the minimum departure time of all the servers working.
Uses station::find_min_k .
int station::find_queue_len | ( | ) |
std::vector< std::tuple< int, float, int, int, float, float > > station::get_counter_variable | ( | ) |
Gives back the station::counter_variable.
Example:
void station::initialize_CSV | ( | std::string | file_name | ) |
void station::logger | ( | int | station_id, |
float | t | ||
) |
Beautifully outputs station status a file in folder logs.
station_id | Used when the stations are sequential. Used mostly in tandem class. |
t | Time variable |
void station::logger | ( | std::string | station_id, |
float | t | ||
) |
Beautifully outputs station status a file in folder logs.
station_id | Used when a uninque name is to be given to the text file. |
t | Time variable. |
float station::minimum_residual_time | ( | float | t | ) |
Gives the minimum residual time i.e. time left for next departure.
The minimum residual time is directlty related to the waiting time of a customer.
t | Time variable |
void station::print_station_status | ( | float | t | ) |
Beautifully outputs station status to the console.
t | The time variable |
void station::reset_queue | ( | float | t | ) |
Resets the queue.
Resets station::server_status,station::current_customer,station::current_queue and station::td.
Also clears station::counter_variable. Use when a queue is to be used afresh.
void station::server_updates | ( | float | t | ) |
Makes server updates.
t | The time variable. |
This function is required when the servers are dynamic. This
code manages the opening and closing of servers.Directly modifies station::server_status
Whenever the number of active server changes, the following rules govern the opening and closing:
void station::write_to_csv | ( | std::string | file_name | ) |
Writes the station::counter_variable to a csv file.
file_name | The name of the csv file to be created. |
|
private |
Number of servers.
|
private |
Server update function
|
private |
0 - Customer id 1 - Time of arrival 2 - Number of people in system at arrival 3 - Number of people in queue at arrival 4 - Service times 5 - Departure times
|
private |
The current customers present in the server.
|
private |
The current queue of the system.
|
private |
Service time generator.
|
private |
max Number of Servers
|
private |
Number of customers in system
|
private |
Cummulative number of arrivals.
|
private |
Present status of the server
-1 : Server is closed
2 : Server is working but will be closed on service completion
0 : Server empty
1 : Server.
|
private |
Departure times.