-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueing_sys.js
More file actions
86 lines (69 loc) · 2.3 KB
/
queueing_sys.js
File metadata and controls
86 lines (69 loc) · 2.3 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
class QueueingSys{
constructor(arrival_rate, service_rate ){
this.arrival_rate = arrival_rate;
this.service_rate = service_rate;
}
findTrafficIntensity(){
return this.arrival_rate / this.service_rate;
}
testIfPoissonDistribution(){}
avgNumOfItemInSys(){
return (this.findTrafficIntensity()/(1 - this.findTrafficIntensity()));
}
/**
* Average number of elements in the queue when there is queue
* @return number
*/
avgNumOfElementsQueueExists(){
return (1/(1 - this.findTrafficIntensity()));
}
/**
* Average number of elements in the queue including when there's queue or no queue
* @return number
*/
avgNumOfElementsQueueNotExist(){
var p = this.findTrafficIntensity();
return (Math.power(p, 2)/(1 - p));
}
avgTimeInQueue(){
var avg_num_in_sys = this.avgNumOfItemInSys();
return (avg_num_in_sys / this.service_rate );
}
avgTimeInSys(){
var avg_num_in_queue = this.avgNumOfElementsQueueExists();
return (avg_num_in_queue / this.service_rate);
}
/**
* Note: probability of queueing on arrival equals traffic intensity
*/
probOfNotQueueingOnArrival(){
return (1 - this.findTrafficIntensity());
}
findProbOfNEelementsInSysAnyTime(n){
var p = this.findTrafficIntensity();
return (1 - p)* Math.pow(p, n);
}
findProbOfNOrMoreElementsInSys(n){
return Math.pow(p, n);
}
/**
* For Simple queues, service rate must be greater than arrival rate
*/
checkQueueData(){
return this.service_rate > this.arrival_rate;
}
sysHandler(){
const MSG = [
'The Queue is not a simple queue',
'One of Parameters are missing. Try again',
'Everything looks fine',
'Blah blah'
]
}
}
var test = new QueueingSys(15, 20);
console.log("Traffic Intensity: " + test.findTrafficIntensity());
console.log("Average Queue Length: " + test.avgNumOfElementsQueueExists());
console.log("Average Time Spent in Queue: " + test.avgTimeInQueue());
console.log("Average Time Spent in System: " + test.avgTimeInSys());
console.log("Probabilty that new arrival will not be on Queue: " + test.probOfNotQueueingOnArrival());