How to find waiting time in a single server queue system?

Source Code:

//single server queuing system
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, i, a[10], s[10], w[10];
float wa=0.0;
cout<<"\n***SINGLE SERVER QUEUING SYSTEM***"<<endl;
cout<<"Get Ready!!! You are in!!!"<<endl;
cout<<"\nPress any key to run..."<<endl;
getch();
cout<<endl;
cout<<"Enter the number of customers: ";
cin>>n;
cout<<"Enter the arrival times of "<<n<<" customers: ";
for(i=1; i<=n; i++)
cin>>a[i];
cout<<"Enter the service times of "<<n<<" customers: ";
for(i=1; i<=n; i++)
cin>>s[i];
cout<<endl<<"\t---------------------------------------------                       --------------"<<endl;
cout<<"\t|Customer id | Arrival Time | Service Time |                        Waiting Time |"<<endl;
cout<<"\t---------------------------------------------------                  --------"<<endl;
w[1]=0;
for(i=1; i<=n; i++)
{
w[i+1]=w[i]+s[i]-a[i+1];
cout<<"\t|\t"<<i<<"    |\t   "<<a[i]<<"\t    |\t"                           <<s[i]<<"\t   |\t"<<w[i]<<"\t  |"<<endl;
wa+=w[i];
}
cout<<"\t---------------------------------------------------                 --------"<<endl<<endl;
cout<<"Average waiting time = "                                             <<wa/n<<endl<<endl<<endl<<endl;
system("pause");
return 0;
}

Output:


Characteristics or Elements of Queuing System


In order to model queuing systems, we first need to be a bit more precise about what constitutes a queuing system. The three basic elements common to all queuing systems are:
  1. Arrival Process or patterns
  2. Service process or patterns
  3. Queuing discipline


1. Arrival Process or Patterns
Any queuing system must work on something − customers, parts, patients, orders, etc. We generally called them as entities or customers. Before entities can be processed or subjected to waiting, they must first enter the system. Depending on the environment, entities can arrive smoothly or in an unpredictable fashion. They can arrive one at a time or in clumps (e.g., bus loads or batches). They can arrive independently or according to some kind of correlation. 
A special arrival process, which is highly useful for modeling purposes, is the Markov arrival process. Both of these names refer to the situation where entities arrive one at a time and the times between arrivals are exponential random variables. This type of arrival process is memory less, which means that the likelihood of an arrival within the next t minutes is the same no matter how long it has been since the last arrival.
Examples where this occurs are phone calls arriving at an exchange, customers arriving at a fast food restaurant, hits on a web site, and many others.

2. Service Process or Patterns
Once entities have entered the system they must be served. The physical meaning of “service” depends on the system. Customers may go through the checkout process. Parts may go through machining. Patients may go through medical treatment. Orders may be filled. And so on. From a modeling standpoint, the operational characteristics of service matter more than the physical characteristics. Specifically, we care about whether service times are long or short, and whether they are regular or highly variable. We care about whether entities are processed in first-come-first-serve (FCFS) order or according to some kind of priority rule. We care about whether entities are serviced by a single server or by multiple servers working in parallel etc

Markov Service Process
A special service process is the Markov service process, in which entities are processed one at a time in FCFS order and service times are independent and exponential. As with the case of Markov arrivals, a Markov service process is memory less, which means that the expected time until an entity is finished remains constant regardless of how long it has been in service. 
For example, in the Marcrohard example, a Markov service process would imply that the additional time required to resolve a caller’s problem is 15 minutes, no matter how long the technician has already spent talking to the customer. While this may seem unlikely, it does occur when the distribution of service times looks like the case shown in Figure 1. This depicts a case where the average service time is 15 minutes, but many customers require calls much shorter than 15 minutes (e.g., to be reminded of a password or basic procedures) while a few customers require significantly more than 15 minutes (e.g., to perform complex diagnostics or problem resolution). Simply knowing how long a customer has been in service doesn’t tell us enough about what kind of problem the customer has to predict how much more time will be required.

3. Queuing Discipline:
The third required component of a queuing system is a queue, in which entities wait for service.
The number of customer can wait in a line is called system capacity.
The simplest case is an unlimited queue which can accommodate any number of customers.  It is called system with unlimited capacity.
But many systems (e.g., phone exchanges, web servers, call centers), have limits on the number of entities that can be in queue at any given time.
Arrivals that come when the queue is full are rejected (e.g., customers get a busy signal when trying to dial into a call center). Even if the system doesn't have a strict limit on the queue size,
The logical ordering of customer in a waiting line is called Queuing discipline and it determines which customer will be chosen for service. We may say that queuing discipline is a rule to chose the customer for service from the waiting line.
The queuing discipline includes:
i. FIFO (First in First out) : According to this rule, Service is offered on the basis of arrival time of customer. The customer who comes first will get the service first. So in other word the customer who get the service next will be determine on the basis of longest waiting time.
ii. Last in First Out(LIFO): It is usually abbreviated as LIFO, occurs when service is next offered to the customer that arrived recently or which have waiting time least. In the crowded train the passenger getting in or out from the train is an example of LIFO.
iii. Service in Random order (SIRO): it means that a random choice is made between all waiting customers at the time service is offered. I.e a customer is picked up randomly form the waiting queue for the service.
iv. Shortest processing time First (SPT): it means that the customer with shortest service time will be chosen first for the service. i.e. the shortest service time customer will get the priority in the selection process.
v. Priority: a special number is assigned to each customer in the waiting line and it is called priority. Then according to this number, the customer is chosen for service.

Hybrid and Real Time Simulation

Hybrid Simulation:
For most studies, the system under study is clearly either of continuous or discrete nature and it is the determining factor in deciding whether to use an analog or digital computer for system simulation.
If the system being simulated is an interconnection of continuous and discrete subsystem, then such system simulation is known as hybrid simulation. Such hybrid system can be digital computer being linked together
Hybrid simulation required high speed converters to transform signals from analog to digital from and vice-versa.

Real time simulation:
In real time simulation, actual device (which are part of a system) are used in conjunction with either digital computer or hybrid computer. It provides the simulation of the points of systems that do not exist or that cannot be easily used in an experiment. i.e. the basic idea of real time simulation is ‘uses the actual part if they are appropriate to use in experiment otherwise use the simulation of the points of the system’.
A well-known examples is “simulation to train pilots”. It uses the devices for training pilots by giving them the impression that is at the control of an aircraft.
It requires real time simulator of the plane its control system, the weather and other environmental conditions. Sometimes, real time simulation also refers to a computer model of a physical system that can execute at the same rate as actual system can. For example: if a machine takes 10 minutes to fill a tank in real world, the simulation also would take 10 minutes.
Real time simulation of an engineering system becomes possible when replace physical device with virtual device are.

Steps on simulation Study

1. Problem formulation
Every study begins with a statement of the problem, provided by policy makers. Analyst ensures it is clearly understood. If it is developed by analyst policy makers should understand and agree with it.

2. Setting of objectives and overall project plan
The objectives indicate the questions to be answered by simulation. At this point a determination should be made concerning whether simulation is the appropriate methodology. Assuming it is appropriate, the overall project plan should include:

  • A statement of the alternative systems
  • A method for evaluating the effectiveness of these alternatives
  • Plans for the study in terms of the number of people involved
  • Cost of the study
  • The number of days required to accomplish each phase of the work with the anticipated results.

3. Model conceptualization
The construction of a model of a system is probably as much art as science. The art of modeling is enhanced by ability:

  • To abstract the essential features of a problem
  • To select and modify basic assumptions that characterizes the system
  • To enrich and elaborate the model until a useful approximation results
Thus, it is best to start with a simple model and build toward greater complexity. Model conceptualization enhances the quality of the resulting model and increases the confidence of the model user in the application of the model.

4. Data collection
There is a constant interplay between the construction of model and the collection of needed input data. It is done in the early stages. Objective kind of data is collected.

5. Model translation
Real-world systems result in models that require a great deal of information storage and computation. It can be programmed by using simulation languages or special purpose simulation software. Simulation languages are powerful and flexible. Simulation software models development time can be reduced.

6. Verified
It pertains to the computer program and checking the performance. If the input parameters and logical structure are correctly represented, verification is completed.

7. Validated
It is the determination that a model is an accurate representation of the real system. It is achieved through calibration of the model. The calibration of model is an iterative process of comparing the model to actual system behavior and the discrepancies between the two.

8. Experimental Design
The alternatives that are to be simulated must be determined. Which alternatives to simulate may be a function of runs? For each system design, decisions need to be made concerning

  • Length of the initialization period
  • Length of simulation runs
  • Number of replication to be made of each run

9. Production runs and analysis
They are used to estimate measures of performance for the system designs that are being simulated.

10. More runs
Based on the analysis of runs that have been completed, the analyst determines if additional runs are needed and what design those additional experiments should follow.

11. Documentation and Reporting
Two types of documentation:
            i. Program documentation
           ii. Process documentation

i. Program documentation
Can be used again by the same or different analyst’s to understand how the program operates. Further modification will be easier. Model users can change the input parameters for better performance.

ii. Process documentation
Gives the history of a simulation project. The result of all analysis should be reported clearly and concisely in a final report. This enables to review the final formulation and alternatives, results of the experiments and the recommended solution to the problem. The final report provides a vehicle of certification.

12. Implementation
Success depends on the previous steps. If the model user has been thoroughly involved and understands the nature of the model and its outputs, likelihood of a vigorous implementation is enhanced. The simulation model building can be broken into 4 phases.

Applications of Simulation

Manufacturing Applications
1. Analysis of electronics assembly operations
2. Design and evaluation of a selective assembly station for high precision scroll compressor shells.
3. Comparison of dispatching rules for semiconductor manufacturing using large facility models.
4. Evaluation of cluster tool throughput for thin-film head production.
5. Determining optimal lot size for a semiconductor backend factory.
6. Optimization of cycle time and utilization in semiconductor test manufacturing.
7. Analysis of storage and retrieval strategies in a warehouse.
8. Investigation of dynamics in a service oriented supply chain.
9. Model for an Army chemical munitions disposal facility.

Semiconductor Manufacturing
1. Comparison of dispatching rules using large-facility models.
2. The corrupting influence of variability.
3. A new lot-release rule for wafer fabrications.
4. Assessment of potential gains in productivity due to proactive retied management.
5. Comparison of a 200 mm and 300 mm X-ray lithography cell.
6. Capacity planning with time constraints between operations.

Military Applications
1. Modeling leadership effects and recruit type in a Army recruiting station.
2. Design and test of an intelligent controller for autonomous sunder water vehicles.
3. Modeling military requirements for non war fighting operations.
4. Multi-trajectory performance for varying scenario sizes.
5. Using adaptive agents in U.S. Air Force retention.

Advantages and Disadvantages of simulation

 Advantages
 1.      Simulation can also be used to study systems in the design stage.
2.     Simulation models are run rather than solver.
3.    New policies, operating procedures, decision rules, information flow, etc can be explored without disrupting the ongoing operations of the real system.
4.   New hardware designs, physical layouts, transportation systems can be tested without committing resources for their acquisition.
5.     Hypotheses about how or why certain phenomena occur can be tested for feasibility.
6.   Time can be compressed or expanded allowing for a speedup or slowdown of the phenomena under investigation.
7.      Insight can be obtained about the interaction of variables.
8.     Insight can be obtained about the importance of variables to the performance of the system.
9.   Bottleneck analysis can be performed indication where work-in process, information materials and so on are being excessively delayed.
10. A simulation study can help in understanding how the system operates rather than how individuals think the system operates.
11.  “what-if” questions can be answered.  So it is useful in the design of new systems.

Disadvantages
1.      Model building requires special training.
2.      Simulation results may be difficult to interpret.
3.      Simulation modeling and analysis can be time consuming and expensive.
4.      Simulation is used in some cases when an analytical solution is possible or even preferable.

When the simulation is not appropriate?

1.      Simulation should not be used when the problem can be solved using common sense.
2.      Simulation should not be used if the problem can be solved analytically.
3.      Simulation should not be used if it is easier to perform direct experiments.etc
4.      Simulation should be used when the problem cannot be solved using common sense.
5.      Simulation should not be used, if the costs exceeds savings.
6.      Simulation should not be performed, if the resources or time are not available.
7.      If no data is available, not even estimate simulation is not advised.
8.     If there is not enough time or the persons are not available, simulation is not appropriate.
9.    If managers have unreasonable expectation say, too much soon – or the power of simulation is over estimated, simulation may not be appropriate.

10.  If system behavior is too complex or cannot be defined, simulation is not appropriate.