Repository navigation
Expand file tree
/
Copy pathMMck.c
More file actions
executable file
·114 lines (105 loc) · 2.96 KB
/
Copy pathMMck.c
File metadata and controls
executable file
·114 lines (105 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Module: MMck
*
* Author: Rob Jones
*
* Last Updated: 3/5/97
*
* Description: CSci 726 Homework Exercise 9.3.10
* Computes the state occumpancy probabilities in steady-state
* for M/M/c/k service node using Algorithm (9.3.2).
*/
#include <math.h>
#include <stdio.h>
#define lambda 8.0 /* arrival rate */
#define nu 2.0 /* single server service rate */
#define c 4 /* max number of servers */
#define k 10 /* max number allowed in service node */
int main(void)
{
long l; /* state identifier */
double pi[k+1]; /* state probability */
double alpha; /* normalization coefficient */
double rho; /* traffic intensity */
double fact; /* factorial */
/* initialization */
pi[0] = 1.0; /* initial condition */
alpha = 1.0; /* add pi[0] to alpha */
/*
* Compute unnormalized state occupancy probabilities f'(l) = pi
* using Algorithm 9.3.2
*/
for (l = 1; l <= k; l++) {
if (l < c) {
pi[l] = pi[l-1]*lambda/(l*nu);
} else {
pi[l] = pi[l-1]*lambda/(c*nu);
}
alpha += pi[l];
}
printf("\nDistribution of jobs in M/M/%d/%d service node, f(l)\n",c,k);
for (l = 0; l <= k; l++) {
pi[l] /= alpha;
printf("f(%ld)\t = %f\n",l,pi[l]);
}
printf("\n");
/*
* Perform analytical calculations from Exercise 9.3.9
*/
rho = lambda/(c*nu);
alpha = 1.0;
fact = 1.0;
for (l = 1; l < c; l++) {
fact *= l;
alpha += pow(c*rho,l)/fact;
}
fact *= c;
for (l = c; l <= k; l++) {
alpha += pow(c*rho,c)*pow(rho,l-c)/fact;
}
printf("\nAnalytical calculation of f(l)\n");
pi[0] = 1/alpha;
fact = 1.0;
printf("f(%ld)\t = %f\n",0L,pi[0]);
for (l = 1; l < c; l++) {
fact *= l;
pi[l] = pow(c*rho,l)/(alpha*fact);
printf("f(%ld)\t = %f\n",l,pi[l]);
}
fact *= c;
for (l = c; l <= k; l++) {
pi[l] = pow(c*rho,c)*pow(rho,l-c)/(alpha*fact);
printf("f(%ld)\t = %f\n",l,pi[l]);
}
printf("\n");
}
/*
=====================================================================================
OUTPUT OF PROGRAM
=====================================================================================
Distribution of jobs in M/M/4/10 service node, f(l)
f(0) = 0.010169
f(1) = 0.040678
f(2) = 0.081356
f(3) = 0.108475
f(4) = 0.108475
f(5) = 0.108475
f(6) = 0.108475
f(7) = 0.108475
f(8) = 0.108475
f(9) = 0.108475
f(10) = 0.108475
Analytical calculation of f(l)
f(0) = 0.010169
f(1) = 0.040678
f(2) = 0.081356
f(3) = 0.108475
f(4) = 0.108475
f(5) = 0.108475
f(6) = 0.108475
f(7) = 0.108475
f(8) = 0.108475
f(9) = 0.108475
f(10) = 0.108475
=====================================================================================
*/