generated from github/welcome-to-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMM1 System
69 lines (51 loc) · 1.6 KB
/
MM1 System
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
#### Generating the time between customer arrivals ####
it =c(rep(0,1000)) # create space to put the trials
lambda = 1/15 # fix the parameter of exponential
it =rexp(1000,lambda) # draw random numbers from exponential
head(it)
hist(it, freq=F, main="Exp(1/15) Inter arrival times" )
s= c(rep(0,1000))
s=runif(1000,5,15)
head(s) # View first numbers in s
hist(s, freq=F, main = "Histogram of service times")
at= c(rep(0,1000)) # create space to put the cumulative numbers.
at=cumsum(it) # Cumulative sum of the numbers in it
head(at) # View the first few numbers created
qt = c(rep(0,1000)) # open space to put the numbers
exit = c(rep(0,1000)) # open space to put the numbers
for(i in 1:999) {
if(at[i] +s[i] + qt[i] <= at[i+1]){
qt[i+1]=0
exit[i]= at[i]+s[i]+qt[i]
}
else if(at[i] + s[i]+qt[i] > at[i+1]){
exit[i]=at[i]+s[i]+qt[i]
qt[i+1] = at[i]+s[i]+qt[i] -at[i+1]
}
}
exit[1000]=at[1000]+qt[1000]+s[1000]
tts = c(rep(0,1000))
tts = exit - at # total time= exit time-arrival time.
hist(tts, freq=F, main = "Histogram of total time in the system")
mean(tts)
sd(tts)
summary(tts)
at=matrix(at) # convert at to matrix object
exit = matrix(exit) #convert exit to matrix object
atexit = cbind(at,exit) # combine the two in one matrix
tatexit = t(atexit) # transpose the matrix.
realtime=matrix(tatexit,2000,1,byrow=T) # create the real time.
head(realtime)
customer = matrix(rep(1,2000),2000,1)
realtime=cbind(realtime,customer)
for(i in 1:1000) {
realtime[2*i,2]=-1
}
oo = order(realtime[,1])
trace = realtime[oo,]
head(trace)
tracecum= cumsum(trace[,2])
mean(tracecum)
sd(tracecum)
summary(tracecum)
plot( tracecum,type="l")