Upload
rntime
View
51
Download
0
Tags:
Embed Size (px)
DESCRIPTION
MSC, Computer Science, Semester 2, Practical File, Simulation & Modelling,List of Practicals,Single Channel Queue,Multi Channel Queue,Inventory System,Discrete Distribution,Continuous Distribution,Random Number Generation,Test of Random Numbers,Queuing Model,Acceptance Rejection Technique
Citation preview
PAPER III SECTION II
SIMULATION AND MODELING
INDEX
No.TopicPage No.DateSign
1Single-Channel Queuing Model2-6
2Multi-Channel Queuing Model7-10
3Inventory System11-14
4Discrete Distribution15-25
5Continuous Distribution26-42
6Generation of Random Numbers43-48
7Random Numbers Tests49-64
8Acceptance-Rejection Technique65-69
Practical-01Single-Channel Queuing ModelWrite a C/C++/Excel Program to simulate a Single-Channel Queuing Model.
For C/C++ Programming use the library functions to generate the n-digited random numbers.
For Excel use the in-built function to generate the n-digited random numbers.
Distribution of Time between Arrivals
Accept probability values for the Inter-arrival time between (1 minute 6 minutes). Generate the Random-digit assignment.
Distribution of Service Time
Accept probability values for the Service Time between (1 minute 6 minutes). Generate the Random-digit assignment.
Total No. of Customers N=20.
Prepare a simulation table and answer the following queries such as find
i) Avg. waiting time (minutes)
ii) Probability that a customer has to wait
iii) Probability of idle server
iv) Avg. service time (minutes)
v) Avg. time between arrivals (minutes)
vi) Avg. waiting time of those who wait (minutes)
vii) Avg. time customer spends in the systems (minutes)
Theory: Simulation of queuing system: A queuing system is described by its calling population, the nature of the arrivals
the service mechanism, the system capacity, and the queuing discipline. Thus for simulation of queuing system, we need to generate arrivals and service times. The
time for arrivals and service times should be random( as time represents real world situation). These random times are generated with the help of random nos.
Example: Single Channel Queue
In the single queue, the system works an (First-In-First-Out) FIFO by a single server or channel.
In a single channel queuing system, inter-arrival times and service times are generated from the distributions of random numbers
Given Data:
Distribution of Service Time:Accept probability values for the Service Time between (1 minute 6 minutes). Generate the Random-digit assignment.
Service-Time Distribution:Service Time Distribution
Service Time (Minutes)ProbabilityCumulative Probability
10.100.10
20.200.30
30.300.60
40.250.85
50.100.95
60.051.00
This is service-time distribution in which service time varies from 1 to 6 minutes with the probabilities.
Distribution of Time between Arrivals:Accept probability values for the Inter-arrival time between (1 minute 6 minutes). Generate the Random-digit assignment.This is the simulation study for Single-Channel Queuing System
Distribution of Time between Arrivals
Time between Arrivals (Minutes)ProbabilityCumulative Probability
10.1250.125
20.1250.250
30.1250.375
40.1250.500
50.1250.625
60.1250.750
70.1250.875
80.1251.000
Explanation of Simulation Table for Single Channel Queuing System ColumnDescription
Customerthe customers in order of their arrival.
Inter-arrival Timethe inter-arrival time of the customer at the random fashion.
Arrival Timethe arrival time of the previous customer and the present customer.
Service Timethe estimated time taken by the system to complete the service.
Time Servicethe starting time of the service.
Waiting Time in Queuethe time taken by the customers wait in queue.
Time Service Endsthe time at which the service to customers ends.
Time Customer spendsthe total time taken by the customer to complete its service in the system.
Idle Time of Serverthe time at which server was in idle state.
1.
2.
3.
4.
5.
6.
7.
Simulation Table for Queuing Example:ClockClockClock
CustomerInterarrivalTime(Minutes)Arrival TimeServiceTime(Minutes)TimeServiceBeginsWaiting Timein Queue(Minutes)Time ServiceEndsTime CustomerSpends in System(Minutes)Idle Timeof Server(Minutes)
100400440
2884801244
31921231450
411021441660
551521611830
662132102433
762762703363
812843353790
953323743960
1063953904450
1134244424860
1274934905231
1325115215320
1415245315750
1535545726160
1645926126340
1746346306740
1846716706810
1947137107433
2047537507831
7577463799258628815
VBA Code:
To insert the Visual Basic Code Tools Macro Visual Basic Editor
Module:
Option Explicit
Function Discrete(Prob As Range, Value As Range)
Dim lRowLast, row As Long
Dim UpperLimit As Double, U As Single
U = Rnd()
lRowLast = Prob.Rows.Count
For row = 1 To lRowLast
UpperLimit = Prob.Cells(row, 1).Value
If U 0 has a normal distribution if has a pdf
Algorithm:
Begin
1) Read the randon variable x,mean,variance.
2) if variance > 0
sigma=sqrt(variance)
pdf=(1/(sigma*sqrt(2*3.142)))*exp((-1/2)*(pow((x-
mean)/sigma,2)));
Note : Its not possible to evaluate cdf in close form
End5.5 Weibull DistributionWrite a C/C++/Excel Program to find Probability Distribution Function (pdf) and cumulative Distribution Function (cdf) for Weibull Distribution Accept for a random variable X with the location parameter (, scale parameter ( > 0, and the shape parameter ( > 0 from the user.
Theory: The random variable X has a weibull distribution if its pdf has the form
The three parameters of the weibull distribution are
1. v () ( the location parameter;
2. ( (( > 0) ( the scale parameter.
3. ( (( > 0) -( the shape parameter.
When the v=0, Weibull distribution becomes
When v = 0 and ( = 1. Letting ( = 1 the Weibull Distribution are given by the following
expression.
The mean & variance of the Weibull are given by the following expression :
Where
Algorithm:
Begin
1) Read the random variable x.
2) Read the location parameter v.
3) Read the scale parameter alpha
4) Read the shape parameter beta.
5) if alpha >0 && beta >0
if x > v || v==0
pdf=(beta/alpha)*(pow((x-v)/alpha,beta-1)*exp(pow(-((x-v)/alpha),beta)));
else
if v == 0 && alpha == 1 && x >= 0
pdf=(1/alpha)*exp(-(x/alpha));
else
pdf=0
if x >= v
cdf=1-exp(-(pow((x-v)/alpha,beta)));
else
cdf=0
End
5.6 Triangular Distribution
Write a C/C++/Excel Program to find Probability Distribution Function (pdf) and Cumulative Distribution Function (cdf) for Triangular Distribution Accept parameters a,b,c where a ( b ( c from the user.
Theory: A random variable X has a triangular distribution if its pdf is given by
The mode occurs at x = b. The parameters ( a, b, c) can be related. The cdf is given by
The mean
5.7 Lognormal Distribution
Write a C/C++/Excel Program to find Probability Distribution Function (pdf) and Cumulative Distribution Function (cdf) for Lognormal Distribution Accept parameters mean ( and variance (2 from the user.
Theory: A random variable X has a Lognormal Distribution if its pdf is given by
Where > 0. The mean and variance of lognormal random variable are
The parameters come from the fact that when Y has N () distribution, then X = e Y has a lognormal distribution with parametes. If the mean & variance of the lognormal are know to be , respectively, then the parameters are given by
Code:#include
#include
#include
#include
void uniform_distribution();
void exponential_distribution();
void weibull_distribution();
void erlang_distribution();
void normal_distribution();
void triangular_distribution();
void lognormal_distribution();
long fact(int);
void main()
{
int choice,flag=1;
clrscr();
while(flag==1)
{
printf("\n\t\t\t Continuous Distribution.");
printf("\n\n1. Uniform Distribution.");
printf("\n2. Exponential Distribution.");
printf("\n3. Erlang Distribution.");
printf("\n4. Normal Distribution.");
printf("\n5. Weibull Distribution.");
printf("\n6. Triangular Distribution.");
printf("\n7. Lognormal Distribution.");
printf("\n\n\nSelect Any One Of The Options : ");
scanf("%d",&choice);
flag=0;
}
switch(choice)
{
case 1:
clrscr();
uniform_distribution();
break;
case 2:
clrscr();
exponential_distribution();
break;
case 3:
clrscr();
erlang_distribution();
break;
case 4:
clrscr();
normal_distribution();
break;
case 5:
clrscr();
weibull_distribution();
break;
case 6:
clrscr();
triangular_distribution();
break;
case 7:
clrscr();
lognormal_distribution();
break;
default:
break;
}
getch();
}
void uniform_distribution()
{
float a,b,x,pdf,cdf,mean,variance;
float f[10];
printf("\t\t\t CONTINIOUS DISTRIBUTION");
printf("\n\n\t\t\t Uniform Distribution ");
printf("\nEnter a = ");
scanf("%f",&a);
printf("\nEnter b = ");
scanf("%f",&b);
printf("\nEnter Random Variable(x) = ");
scanf("%f",&x);
if(a=v || v==0)
{
ans1=(x-v)/alpha;
pdf=(beta/alpha)*pow(ans1,beta-1)*exp(pow(-ans1,beta));
printf("\n\nResults : ");
printf("\nPDF is %.3f",pdf);
}
else
if(v==0 && alpha==1 && x>=0)
{
pdf=(1/alpha)*exp(-(x/alpha));
printf("\n\nResults :");
printf("\nPDF is %.3f",pdf);
}
else
printf("\nPDF is 0.");
if(x>=v)
{
cdf=1-exp(-(pow( ((x-v)/alpha),beta)));
printf("\nCDF is %.3f",cdf);
}
else
{
printf("\nCDF is 0");
}
mean=(float)v+( alpha * fact(1/beta));
ans=fact(2/beta)-pow(fact(1/beta),2);
variance=(float)pow(alpha,2)*ans;
printf("\n\nMean E(X) = %.0f",mean);
printf("\n\nThe variance V(X) = %.0f",variance);
getch();
}
void triangular_distribution()
{
float a,b,c,x,cdf,pdf,r1,mean,var,mode;
int flag=1;
printf("\t\t\t CONTINIOUS DISTRIBUTION");
printf("\n\n\t\t\t Triangular Distribution");
printf("\n\nEnter the random variable x :");
scanf("%f",&x);
printf("\nEnter the parameter values such that a 0 has pmf
N can be interpreted as the number of arrivals from the Poisson arrival process in one unit of time.
Algorithim:
Step1 : n=0, P=1Step2 : Generate a random number R
EMBED Equation.3 and replace P by P. R
Step3 : if p < e- , then accept N = n. Otherwise, reject the surrent n, increase n
by one, and retuen to step 2.
8.2 Gamma Distribution :
Algorithm :Step1 : Compute a =
Step2 : Generate R1 and R2.
Step3 : Compute X =
Step4a : if X use X as the desired variate. The generated variates
from step 4a will have mean & variance both equal to .
Step4b : if X >reject & return to step 2.
Code :
//Acceptance-rejection Technique
#include
#include
#include
#include
void poisson_distribution();
void gamma_distribution();
void main()
{
int choice;
clrscr();
x:
printf("\n\n Acceptance-Rejection Techinque");
printf("\n 1: Poisson Distribution");
printf("\n 2: Gamma Distribution");
printf("\n 3: Exit");
printf("\n Enter Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
clrscr();
poisson_distribution();
goto x;
case 2:
clrscr();
gamma_distribution();
goto x;
case 3:
exit(0);
}
getch();
}
void poisson_distribution()
{
float n=0,P=1,R[20],alpha,q;
int x,count=0,N=0;
printf("\n\n\t\t\t Poisson Distribution");
printf("\n\n Enter the number of Poisson variates : ");
scanf("%d",&x);
printf("\n\n Enter the mean alpha : ");
scanf("%f",&alpha);
//calculating e exp -alpha
q=exp(-(alpha));
randomize();
//printing column values
printf("\n n \t R[n+1] \t P \t Accept/Reject \t Result");
printf("\n--------------------------------------------------------------");
while(count