Dynamic C-server Queueing System Simulation  1.0
Simulating data for delay prediction
Public Member Functions | Private Types | Private Attributes | List of all members
station Class Reference

#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
 

Detailed Description

Station class implements a single Queueing System.

Member Typedef Documentation

◆ C_type

using station::C_type = std::function<int(float t)>
private

Function type float -> int

◆ event_type

using station::event_type = std::function<float(float t)>
private

Function type float -> float

Constructor & Destructor Documentation

◆ station() [1/4]

station::station ( long  init_mxN,
C_type  C_para,
event_type  dept_para,
float  t = 0,
int  init_n = 0 
)
inline

◆ station() [2/4]

station::station ( long  init_mxN,
C_type  C_para,
float  init_dept,
float  t = 0,
int  init_n = 0 
)
inline

◆ station() [3/4]

station::station ( long  init_mxN,
int  init_C,
float  init_dept,
float  t = 0,
int  init_n = 0 
)
inline

◆ station() [4/4]

station::station ( long  init_mxN,
int  init_C,
event_type  init_dept,
float  t = 0,
int  init_n = 0 
)
inline

Member Function Documentation

◆ access_system_state()

std::tuple< int, int, int > station::access_system_state ( float  t)

Server update function

◆ add_customer_to_station()

void station::add_customer_to_station ( float  t,
int  customer_id 
)

Add a single customer to the front of the system.

Parameters
tThe time variable.
customer_idid 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).

Note
Must be called when time variable reahes next time of arrival.
Warning
Assumes customer id given are sequential integers.

Example:

station temp; //suitably defined
int discrete_events = 0;
int arriving_customer = 0;
float t = 0;
float ta = Ts_generator(t);
while (discrete_events < 50)
{
t = std::min(temp.find_min_td(), ta);
temp.server_updates(t);
if (t == ta)
{
//arrival happening
temp.add_customer_to_station(t, arriving_customer);
arriving_customer++;
ta = Ts_generator(t);
}
else
discrete_events++;
}

◆ departure_updates()

int station::departure_updates ( float  t)

Makes departure updates.

Parameters
tThe 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.

Returns
The customer id of the customer departing.
Note
Must be called when time variable reahes next departure time.

Example:

station temp; //suitably defined
int discrete_events = 0;
int arriving_customer = 0;
float t = 0;
float ta = Ts_generator(t);
while (discrete_events < 50)
{
t = std::min(temp.find_min_td(), ta); //station::find_mid_td
temp.server_updates(t);
if (t == ta)
{
//arrival happening
temp.add_customer_to_station(t, arriving_customer);
arriving_customer++;
ta = Ts_generator(t);
}
else
discrete_events++;
}

◆ dump_counter_variable_memory() [1/2]

void station::dump_counter_variable_memory ( std::string  file_name)

◆ dump_counter_variable_memory() [2/2]

void station::dump_counter_variable_memory ( )

◆ find_min_k()

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).

Returns
Index of the server with minimum departure time.

◆ find_min_td()

float station::find_min_td ( )

Finds the minimum departure time of all the servers working.

Uses station::find_min_k .

See also
station::find_min_k
Returns
Minimum departure time.

◆ find_queue_len()

int station::find_queue_len ( )

◆ get_counter_variable()

std::vector< std::tuple< int, float, int, int, float, float > > station::get_counter_variable ( )

Gives back the station::counter_variable.

Returns
station::counter_variable.

Example:

for(auto&x: MM1.get_counter_variable())
{
if( std::get<0>(x) == customer_departing )
X = std::get<4>(x) - std::get<1>(x);
}

◆ initialize_CSV()

void station::initialize_CSV ( std::string  file_name)

◆ logger() [1/2]

void station::logger ( int  station_id,
float  t 
)

Beautifully outputs station status a file in folder logs.

Parameters
station_idUsed when the stations are sequential. Used mostly in tandem class.
tTime variable

◆ logger() [2/2]

void station::logger ( std::string  station_id,
float  t 
)

Beautifully outputs station status a file in folder logs.

Parameters
station_idUsed when a uninque name is to be given to the text file.
tTime variable.

◆ minimum_residual_time()

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.

Parameters
tTime variable

◆ print_station_status()

void station::print_station_status ( float  t)

Beautifully outputs station status to the console.

Parameters
tThe time variable

◆ reset_queue()

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.

Note
Currently not working.

◆ server_updates()

void station::server_updates ( float  t)

Makes server updates.

Parameters
tThe 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:

  1. Server closure:
    1. The servers currently working(1) are set to 2 ( i.e. will be closed(-1) as soon as server becomes idle(0) again).
    2. If more server needs to be closed after 1. then the idle(0) servers are closed(-1).
  2. Server opening:
    1. The inactive(-1) servers are set to active again and the front the queue is pushed to the newly openend servers and their departure times are generated.
    2. If still more servers are needed, the servers with status 2 are opened(1).
Note
Must be called every time the number of servers (station::c) change value as is defined by the server update function (station::C).
Warning
Assumes that the server update function (station::C) is well-defined.

◆ write_to_csv()

void station::write_to_csv ( std::string  file_name)

Writes the station::counter_variable to a csv file.

Parameters
file_nameThe name of the csv file to be created.

Member Data Documentation

◆ c

int station::c
private

Number of servers.

◆ C

C_type station::C
private

Server update function

◆ counter_variable

std::vector< std::tuple<int,float,int,int,float,float> > station::counter_variable
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

◆ current_customer

std::vector<int> station::current_customer
private

The current customers present in the server.

◆ current_queue

std::queue<int> station::current_queue
private

The current queue of the system.

◆ DepartureTimes

event_type station::DepartureTimes
private

Service time generator.

◆ mxN

long station::mxN
private

max Number of Servers

◆ n

int station::n
private

Number of customers in system

◆ Na

int station::Na
private

Cummulative number of arrivals.

◆ server_status

std::vector<int> station::server_status
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.

◆ td

std::vector<float> station::td
private

Departure times.


The documentation for this class was generated from the following files: