The Poisson function, r -C P(r) = C * e / r! where C = the distribution average,
ID: 3759276 • Letter: T
Question
The Poisson function,
r -C
P(r) = C * e / r! where C = the distribution average, is useful for modeling a distribution when the probability of any one occurrence of P(r) is extremely small and r is the number of occurrences of the event. Applying this average to message volumes and interarrival rates, C = * T where = message volume and T = interarrival rate, would imply:
r (- T)
P(r) = ( T) * e / r!
Assume the special case r = 0 (no messages arrive for a specific length of time) -- ie
0 (- T) (- T)
(T) * e / 0! = e
t=T
Let us say that f(t)dt represents the probability of "one arrival within T units of
t=0
time after prior arrival." Therefore the probability of no messages
(- T) t=T t=T (- T)
e = 1 - f(f)dt and f(t)dt = 1 - e
t=0 t=0
For purposes of simulation let the integral be represented by a random number RN such that 0 <= RN < 1.
(- T) (-T)
Thus 1 - e = RN, (1 - RN) = e , LN(1 - RN) = - T and
-1/ * LN(1 - RN) = T = interarrival time.
Develop a simulation program to accomplish the following:
1) Ask for and accept message volume per hour, Lambda.
2) Convert this volume to message volume per second, Lambda/3600.
3) Ask for and accept the number of simulations desired.
4) Ask for and accept a random number generator seed.
5) Perform the simulation loop to determine and print interarrival
times for Lambda where RN is determined by a random number
generator function.
6. Compute the average message interarrival time = sum of all interarrival times / count.
Use volumes of 3600 and 7200 with 100 simulations each.
Explanation / Answer
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <math.h> /* log */
/*-1/ L * LN(1 - RN) = T = interarrival time.
Develop a simulation program to accomplish the following:
1) Ask for and accept message volume per hour, Lambda.
2) Convert this volume to message volume per second, Lambda/3600.
3) Ask for and accept the number of simulations desired.
4) Ask for and accept a random number generator seed.
5) Perform the simulation loop to determine and print interarrival
times for Lambda where RN is determined by a random number
generator function.
6. Compute the average message interarrival time = sum of all interarrival times / count.
Use volumes of 3600 and 7200 with 100 simulations each.
*/
int main(int argc, char** argv) {
//*****************************************************
// Declaration of variables
int Lambda, simulation, seed,i;
float lambda_per_second, T, RN, avg=0;
//******************************************************
// 1) Ask for and accept message volume per hour, Lambda.
printf ("Please insert the number of message volume per hour, Lambda ");
scanf ("%d",&Lambda);
//*******************************************************
//2) Convert this volume to message volume per second, Lambda/3600.
lambda_per_second=Lambda/3600.00;
// printf ("%f", lambda_per_second);
//*******************************************************
// 3) Ask for and accept the number of simulations desired.
printf (" Please insert the number of simulations desired, simulation ");
scanf ("%d",&simulation);
//********************************************************
// 4) Ask for and accept a random number generator seed.
printf (" Please insert a random number generator seed, seed ");
scanf ("%d",&seed);
srand(seed);
//********************************************************
/* 5) Perform the simulation loop to determine and print interarrival
times for Lambda where RN is determined by a random number
generator function.
-1/ L * LN(1 - RN) = T = interarrival time
*******************************************************/
for(i=1; i<=simulation; i++)
{
RN=rand() % 10000 + 0;
RN=RN/10000;
// printf("random number is %f ",RN);
T=-log(1-RN)/lambda_per_second;
printf ("interarrival time for Lambda %d is %f ",i,T);
/***********************************************************
6. Compute the average message interarrival time = sum of all interarrival times / count.
***********************************************************/
avg=T+avg;
}
avg=avg/simulation;
printf("The average time is %f",avg);
return 0;
}
/*********************************************************************************************
********************************************************************************************
with 3600 The average time is 1.082516
with 7200 The average time is 0.590793
if you have any question about it please leave me a comment
*************************************************************************/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.