Operation Research
-
Upload
ashutosh-khushu -
Category
Documents
-
view
58 -
download
0
Transcript of Operation Research
Different Types of Queuing Models - Implementation
Under the Guidance of Prof. Soumen Pal
MEE437 – Operations Research
Team Members:
Ujjwal Rangarh (13BCE0014)
Joshua Itty
Rohan Bedi
Ashutosh Khushu
Aravind Raj
Abstract
This project contains the analysis of the four queuing models for Railway Ticket window as an example. One of the expected gains from studying queuing systems is to review the efficiency of the models in terms of utilization and waiting time, hence increasing the number of queues so passengers will not have to wait longer for their ticket. We may use queuing theory to obtain a sample performance result.
This project does a queuing simulation for the four queuing models given. This project includes the answers of both the manual calculations and the programming. The programming has been done in the JAVA. For each model, a separate program has been constructed and each program in itself is a stand-alone program. We have the code, input and output of each queuing model. This study requires an empirical data which may include the variables like, arrival time in the queue of checkout operating unit, departure time, service time, etc. This model is developed for minimize the Passengers waiting time in queue at Railway Ticket Window.
Definition of a Queuing System
A Queueing System can be defined as follows:
"Customers arrive for a given service, wait if the service cannot start immediately and leave after being served."
A queuing system consists of one or more servers that provide service of some sort to arriving customers. Customers who arrive to find all servers busy generally join one or more queues (lines) in front of the servers, hence the name queuing systems. There are several everyday examples that can be described as queuing systems, such as bank-teller service, computer systems, manufacturing systems, maintenance systems, communications systems and so on.
Queueing theory deals with one of the most unpleasant experiences of life, waiting. The term "customer" can be men, products, machines...
The formation of waiting is a common phenomenon which occurs whenever the current demand for a service exceeds the current capacity to provide that service.
History of Queuing Theory• The theory of queueing systems was developed to provide models for forecasting
behaviors of systems subject to random demand.• The first problems addressed concerned congestion of telephone traffic (Erlang, "the
theory of probabilities and telephone conversations ", 1909)• Erlang observed that a telephone system can be modeled by Poisson customer arrivals
and exponentially distributed service times• Molina, Pollaczek, Kolmogorov, Khintchine, Palm, Crommelin followed the track
Notation of Kendall
The following is a standard notation system of queueing systems
T/X/C/K/P/Z with
– T: probability distribution of inter-arrival times– X: probability distribution of service times– C: Number of servers– K: Queue capacity– P: Size of the population– Z: service discipline
Customer Arrival Process (T)
• T can take the following values:– M : markovian (i.e. exponential)– G : general distribution– D : deterministic– Ek : Erlang distribution
• If the arrivals are grouped in lots, we use the notation T[X] where X is the random variable indicating the number of customers at each arrival epoch– P{X=k} = P{k customers arrive at the same time}
• Some arriving customers can leave if the queue is too long
Service Times (X)
• X can take the following values:
– M : markovian (i.e. exponential)
– G : general distribution
– D : deterministic
– Ek : Erlang distribution
k exponential servers with parameter m
Number of Servers (C)
In simple queueing systems, servers are identical.
Queue Capacity (K)
Loss of Customers if the queue is full
Capacity K
Size of the Population
The size of the population can be either finite or infinite. For a finite population, the customer arrival rate is a function of the number of customers in the system: l(n).
Service Discipline
Z can take the following values:
• FCFS or FIFO : First Come First Served
• LCFS or LIFO : Last Come First Served
• RANDOM : service in random order
• HL (Hold On Line) : when an important customer arrives, it takes the head of the queue
• PR ( Preemption) : when an important customer arrives, it is served immediately and the customer under service returns to the queue
• PS (Processor Sharing) : All customers are served simultaneously with service rate inversely proportional to the number of customers
• GD (General Discipline)
Components of a Queuing System
A queuing system is characterised by three components:
- Arrival Process- Service Mechanism- Queue Discipline
Arrival Process
Arrivals may originate from one or several sources referred to as the calling population. The calling population can be limited or 'unlimited'. An example of a limited calling population may be that of a fixed number of machines that fail randomly. The arrival process consists of describing how customers arrive to the system. If Ai is the interarrival time between the arrivals of the (i-1)th and ith customers, we shall denote the mean (or expected) inter-arrival time by E(A) and call it (λ ); = 1/(E(A) the arrival frequency.
Service Mechanism
The service mechanism of a queuing system is specified by the number of servers (denoted by s), each server having its own queue or a common queue and the probability distribution of customer's service time. let Si be the service time of the ith customer, we shall denote the mean service time of a customer by E(S) and µ = 1/(E(S) the service rate of a server.
Queue Discipline
Discipline of a queuing system means the rule that a server uses to choose the next customer from the queue (if any) when the server completes the service of the current customer. Commonly used queue disciplines are:
FIFO - Customers are served on a first-in first-out basis.
LIFO - Customers are served in a last-in first-out manner.
Priority - Customers are served in order of their importance on the basis of their service requirements.
Classification of Queuing Models
Queuing Models, on the basis of their components, can be classified into following four models:
1. Model I:- (M/M/1) : (FCFS/∞/∞)
2. Model II:- (M/M/1) : (FCFS/N/∞)
3. Model III:- (M/M/S) : (FCFS/∞/∞)
4. Model IV:- (M/M/S) : (FCFS/N/∞)
Sample Data
As sample data, we will be using the arrival and service provided to the customers for a period of around 1 hour, from 9 a.m. to 10 a.m. The columns in the table are:
1. Serial Number: It basically depicts the number of customers in the queue2. Arrival Time: The arrival time of customer in the queue3. Inter Arrival Time: The time between the arrival of two consequent customers4. Departure Time: The time between the departure of two consequent customers
5. Service Time: The time taken by the person sitting at the counter to provide service to the customer
S. No. Arrival Time Inter Arrival Time Departure Time Service Time1 9:01 0:00 9:03 0:022 9:04 0:03 9:05 0:013 9:05 0:01 9:07 0:024 9:05 0:00 9:09 0:045 9:06 0:01 9:10 0:046 9:07 0:01 9:11 0:047 9:10 0:03 9:14 0:048 9:13 0:03 9:16 0:039 9:15 0:02 9:18 0:03
10 9:16 0:01 9:19 0:0311 9:16 0:00 9:20 0:0412 9:19 0:03 9:21 0:0213 9:21 0:02 9:22 0:0114 9:22 0:01 9:23 0:0115 9:25 0:03 9:26 0:0116 9:27 0:02 9:29 0:0217 9:28 0:01 9:30 0:0218 9:30 0:02 9:30 0:0019 9:30 0:00 9:32 0:0220 9:33 0:03 9:34 0:0121 9:35 0:02 9:36 0:0122 9:35 0:00 9:38 0:0323 9:36 0:01 9:39 0:0324 9:38 0:02 9:41 0:0225 9:40 0:02 9:43 0:0126 9:42 0:02 9:44 0:0227 9:43 0:01 9:44 0:0123 9:45 0:02 9:45 0:0024 9:46 0:01 9:47 0:0125 9:48 0:02 9:49 0:0126 9:50 0:02 9:51 0:0127 9:51 0:01 9:53 0:0228 9:52 0:01 9:55 0:0329 9:54 0:02 9:57 0:0330 9:58 0:04 9:59 0:01
Methodology
The term queuing system is used to indicate a collection of one or more waiting lines along with collection of servers that provide service to these waiting lines. The example of Railway Station is taken for queuing system discussed in this section include:
A single waiting line and 2 servers.
All results are presented assuming that FCFS(First Come First Serve).
Arrival rate of Passengers in a queuing system and service rate per busy server are constants.
ASSUMPTIONS
Arrivals of Passengers follow a Poisson process
Inter arrival times of a Poisson process are exponentially distributed
Service times are exponentially distributed.
Identical service facilities (same sales checkout service on each server)
No Passenger leaves the queue without being served
FCFS (First Come First Serve)
Model I: Single Server Infinite Capacity (M/M/1): (FCFS/∞/∞)
Poisson Arrivals, Exponential Service, Single Server, First Come First Serve, Infinite Capacity and Infinite Population (source). As the Poisson and exponential distributions are related to each other, both of them are denoted by the symbol “M” due to Markovian property of exponential distribution.
Manual Calculations
1. Mean Arrival Rate (λ) = 31.579
2. Mean Service Rate (µ)=32.143
3. Traffic Intensity (ρ) or the Utilization Factor = λ/ µ = 0.982
4. Value of P0 = 1 – λ/ µ = 0.018
5. Value of Pn = for n=3, Pn = 0.017
6. Expected (average) number of customers in the system (Ls) =
= 55.99
7. Expected (average) number of customers in the queue (Lq) = = 55.008
8. Expected time a customer spends in the system (Ws) = Ls/ λ = 1/( µ - λ) = 1.773
9. Expected waiting time per customer in the queue (Wq) = Lq/ λ = 1.742
CODE
import java.io.*;
import java.math.*;
public class Queuing_Model
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
double[]queue_arrival=new double[200];
int[]hour_arrival=new int[200];
int[]min_arrival=new int[200];
int[]sec_arrival=new int[200];
double[]queue_departure=new double[200];
int[]hour_departure=new int[200];
int[]min_departure=new int[200];
int[]sec_departure=new int[200];
int queue_len=0;
do
{
System.out.print("Enter 1 to add a customer and 0 to stop: ");
int choice=Integer.parseInt(br.readLine());
if(choice==0)
break;
else if(choice!=1 && choice !=0)
{
System.out.println("Please Enter Correct Choice");
continue;
}
System.out.println("Enter Arrival Details");
System.out.print("Enter arrival hours for customer "+(queue_len+1)+": ");
hour_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival minutes for customer "+(queue_len+1)+": ");
min_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival seconds for customer "+(queue_len+1)+": ");
sec_arrival[queue_len]=Integer.parseInt(br.readLine());
queue_arrival[queue_len]=hour_arrival[queue_len]*60.0+min_arrival[queue_len]+sec_arrival[queue_len]/60.0;
System.out.println("Enter Departure Details");
System.out.print("Enter departure hours for customer "+(queue_len+1)+": ");
hour_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure minutes for customer "+(queue_len+1)+": ");
min_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure seconds for customer "+(queue_len+1)+": ");
sec_departure[queue_len]=Integer.parseInt(br.readLine());
queue_departure[queue_len]=hour_departure[queue_len]*60.0+min_departure[queue_len]+sec_departure[queue_len]/60.0;
++queue_len;
}while(true);
double lambda,mu;
lambda=queue_len*1.0/((queue_arrival[queue_len-1]-queue_arrival[0])/60);
mu=queue_len*1.0/((queue_departure[queue_len-1]-queue_departure[0])/60);
System.out.println("\n\n\n\nNumber of Customers in the System: "+queue_len);
System.out.println("Mean Arrival Rate of Customers: "+lambda);
System.out.println("Mean Service Rate of Individual Channel "+mu);
double traffic_intensity=lambda*1.0/mu;
System.out.println("Traffic Intensity or The Utilization Rate: "+traffic_intensity);
double total=1-traffic_intensity;
System.out.println("The value of P0 is: "+total);
System.out.print("Enter the value of n for Pn: ");
int nval=Integer.parseInt(br.readLine());
double pn=Math.pow(traffic_intensity,nval)*total;
System.out.println("The Value of Pn is "+pn);
double ls=lambda*1.0/(mu-lambda);
System.out.println("Expected (Average) number of customers in the system (Ls) = "+ls);
double lq=ls-traffic_intensity;
System.out.println("Expected (Average) number of customers waiting in the queue (Lq) = "+lq);
double ws=ls/lambda;
double wq=lq/lambda;
System.out.println("Expected (Average) time a customer spends in the system = "+ws);
System.out.println("Expected (Average) waiting time of a customer in the queue = "+wq);
}
}
Output
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 2: 9
Enter arrival minutes for customer 2: 4
Enter arrival seconds for customer 2: 0
Enter Departure Details
Enter departure hours for customer 2: 9
Enter departure minutes for customer 2: 5
Enter departure seconds for customer 2: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 3: 9
Enter arrival minutes for customer 3: 5
Enter arrival seconds for customer 3: 0
……………
Number of Customers in the System: 30
Mean Arrival Rate of Customers: 31.578947368421055
Mean Service Rate of Individual Channel 32.14285714285714
Traffic Intensity or The Utilization Rate: 0.9824561403508774
The value of P0 is: 0.01754385964912264
Enter the value of n for Pn: 3
The Value of Pn is 0.016636603198502766
Expected (Average) number of customers in the system (Ls) = 56.00000000000063
Expected (Average) number of customers waiting in the queue (Lq) = 55.017543859649756
Expected (Average) time a customer spends in the system = 1.7733333333333532
Expected (Average) waiting time of a customer in the queue = 1.742222222222242
Model II: Single Server Finite Capacity (M/M/1): (FCFS/N/∞)
In this model, the capacity of the system is limited to N (say). In this model when the number of customers in the system becomes N, no new arrivals can be accommodated, so therefore for this model we have-
Manual Calculations1. Mean Arrival Rate (λ) = 31.579
2. Mean Service Rate (µ)=32.143
3. Limit of the Counter (System) (N) = 10
4. Traffic Intensity (ρ) or the Utilization Factor = λ/ µ = 0.982
5. Value of P0 = = 0.09938
6. Value of Pn = P0* ρ ^n for n=3, Pn = 0.094
7. Expected (average) number of customers in the system (Ls) =
= 4.818
8. Expected (average) number of customers in the queue (Lq) =
= 3.9175
9. Expected time a customer spends in the system (Ws) = 0.1664
10. Expected waiting time per customer in the queue (Wq)
= 0.1353
CODE
import java.io.*;
import java.math.*;
public class Queuing_Model2
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the limit of the counter (system): ");
int n=Integer.parseInt(br.readLine());
double[]queue_arrival=new double[200];
int[]hour_arrival=new int[200];
int[]min_arrival=new int[200];
int[]sec_arrival=new int[200];
double[]queue_departure=new double[200];
int[]hour_departure=new int[200];
int[]min_departure=new int[200];
int[]sec_departure=new int[200];
int queue_len=0;
do
{
System.out.print("Enter 1 to add a customer and 0 to stop: ");
int choice=Integer.parseInt(br.readLine());
if(choice==0)
break;
else if(choice!=1 && choice !=0)
{
System.out.println("Please Enter Correct Choice");
continue;
}
System.out.println("Enter Arrival Details");
System.out.print("Enter arrival hours for customer "+(queue_len+1)+": ");
hour_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival minutes for customer "+(queue_len+1)+": ");
min_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival seconds for customer "+(queue_len+1)+": ");
sec_arrival[queue_len]=Integer.parseInt(br.readLine());
queue_arrival[queue_len]=hour_arrival[queue_len]*60.0+min_arrival[queue_len]+sec_arrival[queue_len]/60.0;
System.out.println("Enter Departure Details");
System.out.print("Enter departure hours for customer "+(queue_len+1)+": ");
hour_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure minutes for customer "+(queue_len+1)+": ");
min_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure seconds for customer "+(queue_len+1)+": ");
sec_departure[queue_len]=Integer.parseInt(br.readLine());
queue_departure[queue_len]=hour_departure[queue_len]*60.0+min_departure[queue_len]+sec_departure[queue_len]/60.0;
++queue_len;
}while(true);
double lambda,mu;
lambda=queue_len*1.0/((queue_arrival[queue_len-1]-queue_arrival[0])/60);
mu=queue_len*1.0/((queue_departure[queue_len-1]-queue_departure[0])/60);
System.out.println("\n\n\n\nNumber of Customers in the System: "+queue_len);
System.out.println("Mean Arrival Rate of Customers: "+lambda);
System.out.println("Mean Service Rate of Individual Channel "+mu);
double traffic_intensity=lambda*1.0/mu;
System.out.println("Traffic Intensity or The Utilization Rate: "+traffic_intensity);
double total=(1-traffic_intensity)*1.0/(1-Math.pow(traffic_intensity,(n+1)));
System.out.println("The Vaue of P0 is "+total);
System.out.print("Enter the value of n for Pn: ");
int nval=Integer.parseInt(br.readLine());
double pn=Math.pow(traffic_intensity,nval)*total;
System.out.println("The Value of Pn is "+pn);
double ls=0.0;
for(int i=1;i<=n;++i)
{
ls=ls+i*Math.pow(traffic_intensity,i)*total;
}
System.out.println("Expected (Average) number of customers in the system (Ls) = "+ls);
double val1=0.0;
for(int i=1;i<=n;++i)
{
val1=val1+Math.pow(traffic_intensity,i)*total;
}
double lq=ls-val1;
System.out.println("Expected (Average) number of customers waiting in the queue (Lq) = "+lq);
double lambda_dash=lambda*1.0*(1-(Math.pow(traffic_intensity,n)*total));
System.out.println("The Value of Lambda Dash: "+lambda_dash);
double ws=ls/lambda_dash;
double wq=lq/lambda_dash;
System.out.println("Expected (Average) time a customer spends in the system = "+ws);
System.out.println("Expected (Average) waiting time of a customer in the queue = "+wq);
}
}
Output
Enter the limit of the counter (system): 10
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 1: 9
Enter arrival minutes for customer 1: 1
Enter arrival seconds for customer 1: 0
Enter Departure Details
Enter departure hours for customer 1: 9
Enter departure minutes for customer 1: 3
Enter departure seconds for customer 1: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 2: 9
Enter arrival minutes for customer 2: 4
Enter arrival seconds for customer 2: 0
Enter Departure Details
Enter departure hours for customer 2: 9
Enter departure minutes for customer 2: 5
Enter departure seconds for customer 2: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 3: 9
Enter arrival minutes for customer 3: 5
Enter arrival seconds for customer 3: 0
Enter Departure Details
Enter departure hours for customer 3: 9
Enter departure minutes for customer 3: 7
Enter departure seconds for customer 3: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 4: 9
Enter arrival minutes for customer 4: 5
Enter arrival seconds for customer 4: 0
Enter Departure Details
Enter departure hours for customer 4: 9
Enter departure minutes for customer 4: 9
Enter departure seconds for customer 4: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 5: 9
Enter arrival minutes for customer 5: 6
Enter arrival seconds for customer 5: 0
Enter Departure Details
Enter departure hours for customer 5: 9
Enter departure minutes for customer 5: 10
Enter departure seconds for customer 5: 0
………………….
Number of Customers in the System: 30
Mean Arrival Rate of Customers: 31.578947368421055
Mean Service Rate of Individual Channel 32.14285714285714
Traffic Intensity or The Utilization Rate: 0.9824561403508774
The Vaue of P0 is 0.09916568281925206
Enter the value of n for Pn: 3
The Value of Pn is 0.09403746661043225
Expected (Average) number of customers in the system (Ls) = 4.823116872328931
Expected (Average) number of customers waiting in the queue (Lq) = 3.9222825551481826
The Value of Lambda Dash: 28.955388766524038
Expected (Average) time a customer spends in the system = 0.1665706135469002
Expected (Average) waiting time of a customer in the queue = 0.13545950243578908
Model III: Multi Server Infinite Capacity (M/M/c): (FCFS/∞/∞)
In this model customers arrive in a Poisson fashion with mean arrival rate λ. There are ‘c’ (fixed) numbers of service stations arranged in parallel, and a customer can go to any of the free counters for his service. The service time at each counter is identical and follows the same exponential distribution law. Service discipline is FCFS and customers are taken from a single queue i.e. any empty channel is filled by the next customer in line.
Manual Calculations
1. Number of Counters (c) = 2
2. Mean Arrival Rate (λ) = 31.579
3. Mean Service Rate (µ)=32.143
4. Limit of the Counter (System) (N) = 10
5. Traffic Intensity (ρ) or the Utilization Factor = λ/c µ = 0.49
6. Value of P0 = = 0.341
7. Value of Pn = for n=3, Pn = 6.026E-10
8. Expected (average) number of customers in the system (Ls) =
= 1.29
9. Expected (average) number of customers in the queue (Lq) =
= 0.31
10. Expected time a customer spends in the system (Ws) = Ls/ λ = 0.04111. Expected waiting time per customer in the queue (Wq) = Lq/ λ = 0.009
12. Probability that the customer has to wait (P (n>=c)) =
= 0.323
13. Probability that the customer enters the service without waiting = 1- Probability that the customer has to wait = 0.67
14. Expected number of idle Counters at any specified time = c – [average number of customers served] = 1.017
CODE
import java.io.*;
import java.math.*;
public class Queuing_Model3
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of counters: ");
int server=Integer.parseInt(br.readLine());
double[]queue_arrival=new double[200];
int[]hour_arrival=new int[200];
int[]min_arrival=new int[200];
int[]sec_arrival=new int[200];
double[]queue_departure=new double[200];
int[]hour_departure=new int[200];
int[]min_departure=new int[200];
int[]sec_departure=new int[200];
int queue_len=0;
do
{
System.out.print("Enter 1 to add a customer and 0 to stop: ");
int choice=Integer.parseInt(br.readLine());
if(choice==0)
break;
else if(choice!=1 && choice !=0)
{
System.out.println("Please Enter Correct Choice");
continue;
}
System.out.println("Enter Arrival Details");
System.out.print("Enter arrival hours for customer "+(queue_len+1)+": ");
hour_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival minutes for customer "+(queue_len+1)+": ");
min_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival seconds for customer "+(queue_len+1)+": ");
sec_arrival[queue_len]=Integer.parseInt(br.readLine());
queue_arrival[queue_len]=hour_arrival[queue_len]*60.0+min_arrival[queue_len]+sec_arrival[queue_len]/60.0;
System.out.println("Enter Departure Details");
System.out.print("Enter departure hours for customer "+(queue_len+1)+": ");
hour_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure minutes for customer "+(queue_len+1)+": ");
min_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure seconds for customer "+(queue_len+1)+": ");
sec_departure[queue_len]=Integer.parseInt(br.readLine());
queue_departure[queue_len]=hour_departure[queue_len]*60.0+min_departure[queue_len]+sec_departure[queue_len]/60.0;
++queue_len;
}while(true);
double lambda,mu;
lambda=queue_len*1.0/((queue_arrival[queue_len-1]-queue_arrival[0])/60);
mu=queue_len*1.0/((queue_departure[queue_len-1]-queue_departure[0])/60);
System.out.println("\n\n\n\nNumber of Customers in the System: "+queue_len);
System.out.println("Mean Arrival Rate of Customers: "+lambda);
System.out.println("Mean Service Rate of Individual Channel "+mu);
double traffic_intensity=lambda*1.0/server/mu;
System.out.println("Traffic Intensity or The Utilization Rate: "+traffic_intensity);
double val1=lambda*1.0/mu;
double total=1;
for(int j=1;j<server;++j)
total=total+Math.pow(val1,j)*1.0/fact(j);
total=total+Math.pow(val1,server)/fact(server)*(server*mu/(server*mu-lambda));
total=1/total;
System.out.println("The Vaue of P0 is "+total);
System.out.print("Enter the value of n for Pn: ");
int nval=Integer.parseInt(br.readLine());
double pn=Math.pow(val1,nval)*total/Math.pow(server,(queue_len-server))/fact(server);
System.out.println("The Value of Pn is "+pn);
double val2=Math.pow((server*mu-lambda),2);
double val3=mu*lambda*Math.pow(val1,server);
double ls=val3/fact(server-1)/val2*total+val1;
System.out.println("Expected (Average) number of customers in the system (Ls) = "+ls);
double lq=ls-val1;
System.out.println("Expected (Average) number of customers waiting in the queue (Lq) = "+lq);
double ws=ls/lambda;
double wq=lq/lambda;
System.out.println("Expected (Average) time a customer spends in the system = "+ws);
System.out.println("Expected (Average) waiting time of a customer in the queue = "+wq);
double prob=mu*Math.pow(val1,server)/fact(server-1)/(server*mu-lambda)*total;
System.out.println("Probability that the Customer has to Wait: "+prob);
System.out.println("Probability that the customer enters the service without waiting: "+(1-prob));
int val6=server-1;
double val4=total*server;
for(int i=1;i<server;++i)
{
double val31=Math.pow(val1,i)*total*1.0/fact(i);
val31=val6*val31;
--val6;
val4=val4+val31;
}
System.out.println("Expected number of Idle Counters at any Specified time :" + val4);
}
public static int fact(int n)
{
int total=1;
for(int i=n;i>=1;--i)
total=total*i;
return total;
}
}
Output
Enter the number of counters: 2
……….
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 29: 9
Enter arrival minutes for customer 29: 54
Enter arrival seconds for customer 29: 0
Enter Departure Details
Enter departure hours for customer 29: 9
Enter departure minutes for customer 29: 57
Enter departure seconds for customer 29: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 30: 9
Enter arrival minutes for customer 30: 58
Enter arrival seconds for customer 30: 0
Enter Departure Details
Enter departure hours for customer 30: 9
Enter departure minutes for customer 30: 59
Enter departure seconds for customer 30: 0
Enter 1 to add a customer and 0 to stop: 0
Number of Customers in the System: 30
Mean Arrival Rate of Customers: 31.578947368421055
Mean Service Rate of Individual Channel 32.14285714285714
Traffic Intensity or The Utilization Rate: 0.4912280701754387
The Vaue of P0 is 0.3411764705882352
Enter the value of n for Pn: 3
The Value of Pn is 6.026271749753577E-10
Expected (Average) number of customers in the system (Ls) = 1.294929006085193
Expected (Average) number of customers waiting in the queue (Lq) = 0.31247286573431565
Expected (Average) time a customer spends in the system = 0.04100608519269778
Expected (Average) waiting time of a customer in the queue = 0.009894974081586662
Probability that the Customer has to Wait: 0.32363261093911255
Probability that the customer enters the service without waiting: 0.6763673890608874
Expected number of Idle Counters at any Specified time :1.0175438596491226
Model IV: Single Server Finite Capacity and Limited Population (M/M/1): (FCFS/n/M)
In some situations, customers arrive from a limited pool of potential customers. Once a unit joins the queue, there is one less unit which could arrive and, therefore, the probability of an arrival is lowered. When a unit is served, it re-joins the pool of potential customers, and the probability of an arrival is, thereby, increased.
In this model, the probability of an arrival depends upon the number of potential customers available to enter the system. Thus, if the total customers’ population is M and n represents the number of customers already in the queuing system, any arrival must come from M-n number that is not yet in the system.
Manual Calculations
1. Maximum number of customers that the person in the window can serve = 10
2. Mean Arrival Rate (λ) = 31.579
3. Mean Service Rate (µ)=32.143
4. Value of P0 = = 1.193E-7
5. Value of Pn = for n=3, Pn = 8.13E-5
6. Expected (average) number of customers in the system (Ls) = = 8.982
7. Expected (average) number of customers in the queue (Lq) = 7.982 =
8. Expected time a customer spends in the system (Ws) = Ls/ λ = 0.2844
9. Expected time a customer spends in the system (Wq) = Lq/ λ = 0.252
CODE
import java.io.*;
import java.math.*;
public class Queuing_Model4
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of limited pool of potential customers (M)i.e., \nthe amount of customers that the person sitting at the counter can serve: ");
int m=Integer.parseInt(br.readLine());
System.out.print("Enter the maximum number of customers possible (n): ");
int n=Integer.parseInt(br.readLine());
double[]queue_arrival=new double[200];
int[]hour_arrival=new int[200];
int[]min_arrival=new int[200];
int[]sec_arrival=new int[200];
double[]queue_departure=new double[200];
int[]hour_departure=new int[200];
int[]min_departure=new int[200];
int[]sec_departure=new int[200];
int queue_len=0;
do
{
System.out.print("Enter 1 to add a customer and 0 to stop: ");
int choice=Integer.parseInt(br.readLine());
if(choice==0)
break;
else if(choice!=1 && choice !=0)
{
System.out.println("Please Enter Correct Choice");
continue;
}
System.out.println("Enter Arrival Details");
System.out.print("Enter arrival hours for customer "+(queue_len+1)+": ");
hour_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival minutes for customer "+(queue_len+1)+": ");
min_arrival[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter arrival seconds for customer "+(queue_len+1)+": ");
sec_arrival[queue_len]=Integer.parseInt(br.readLine());
queue_arrival[queue_len]=hour_arrival[queue_len]*60.0+min_arrival[queue_len]+sec_arrival[queue_len]/60.0;
System.out.println("Enter Departure Details");
System.out.print("Enter departure hours for customer "+(queue_len+1)+": ");
hour_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure minutes for customer "+(queue_len+1)+": ");
min_departure[queue_len]=Integer.parseInt(br.readLine());
System.out.print("Enter departure seconds for customer "+(queue_len+1)+": ");
sec_departure[queue_len]=Integer.parseInt(br.readLine());
queue_departure[queue_len]=hour_departure[queue_len]*60.0+min_departure[queue_len]+sec_departure[queue_len]/60.0;
++queue_len;
}while(true);
double lambda,mu;
lambda=queue_len*1.0/((queue_arrival[queue_len-1]-queue_arrival[0])/60);
mu=queue_len*1.0/((queue_departure[queue_len-1]-queue_departure[0])/60);
System.out.println("\n\n\n\nNumber of Customers in the System: "+queue_len);
System.out.println("Mean Arrival Rate of Customers: "+lambda);
System.out.println("Mean Service Rate of Individual Channel "+mu);
double traffic_intensity=lambda*1.0/mu;
double total=0.0;
for(int i=0;i<=m;++i)
{
double val=fact(m)*1.0/fact(m-i)*Math.pow(traffic_intensity,i);
total=total+val;
}
total=1/total;
System.out.println("The Value of P0 is "+total);
System.out.print("Enter the value of n for Pn: ");
int nval=Integer.parseInt(br.readLine());
double pn=Math.pow(traffic_intensity,nval)*total*fact(m)/fact(m-nval);;
System.out.println("The Value of Pn is "+pn);
double val2=mu/lambda*1.0*(1-total);
double ls=m-val2;
System.out.println("Expected (Average) number of customers in the system (Ls) = "+ls);
double val3=(1-total)*1.0/lambda*(mu+lambda);
double lq=m-val3;
System.out.println("Expected (Average) number of customers waiting in the queue (Lq) = "+lq);
double ws=ls/lambda;
double wq=lq/lambda;
System.out.println("Expected (Average) time a customer spends in the system = "+ws);
System.out.println("Expected (Average) waiting time of a customer in the queue = "+wq);
}
public static int fact(int n)
{
int total=1;
for(int i=n;i>=1;--i)
total=total*i;
return total;
}
}
Output
Enter the number of limited pool of potential customers (M)i.e.,
the amount of customers that the person sitting at the counter can serve: 10
Enter the maximum number of customers possible (n): 10
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 1: 9
Enter arrival minutes for customer 1: 1
Enter arrival seconds for customer 1: 0
Enter Departure Details
Enter departure hours for customer 1: 9
Enter departure minutes for customer 1: 3
Enter departure seconds for customer 1: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 2: 9
Enter arrival minutes for customer 2: 4
Enter arrival seconds for customer 2: 0
Enter Departure Details
Enter departure hours for customer 2: 9
Enter departure minutes for customer 2: 5
Enter departure seconds for customer 2: 0
Enter 1 to add a customer and 0 to stop: 1
Enter Arrival Details
Enter arrival hours for customer 3: 9
Enter arrival minutes for customer 3: 5
Enter arrival seconds for customer 3: 0
Enter Departure Details
Enter departure hours for customer 3: 9
Enter departure minutes for customer 3: 7
Enter departure seconds for customer 3: 0
Enter 1 to add a customer and 0 to stop:
…………………………
Number of Customers in the System: 30
Mean Arrival Rate of Customers: 31.578947368421055
Mean Service Rate of Individual Channel 32.14285714285714
The Value of P0 is 1.1886541705856777E-7
Enter the value of n for Pn: 2
The Value of Pn is 1.0325815731181957E-5
Expected (Average) number of customers in the system (Ls) = 8.982142978130872
Expected (Average) number of customers waiting in the queue (Lq) = 7.982143096996289
Expected (Average) time a customer spends in the system = 0.2844345276408109
Expected (Average) waiting time of a customer in the queue = 0.2527678647382158