forked from pdsteele/DES-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssms.py
More file actions
142 lines (112 loc) · 4.55 KB
/
ssms.py
File metadata and controls
142 lines (112 loc) · 4.55 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# # -----------------------------------------------------------------------
# * This program - an extension of program ssq2 - simulates a single-server
# * machine shop using Exponentially distributed failure times, Uniformly
# * distributed service times, and a FIFO service queue.
# *
# * Name : ssms.c (Single Server Machine Shop)
# * Authors : Steve Park & Dave Geyer
# * Language : ANSI C
# * Latest Revision : 9-28-98
# * -----------------------------------------------------------------------
# */
from rngs import random, plantSeeds, selectStream
from math import log
#include <stdio.h>
#include <math.h>
#include "rngs.h"
LAST = 100000 # number of machine failures */
START = 0.0 # initial time */
M = 60 # number of machines */
def Exponential(m):
# ---------------------------------------------------
# * generate an Exponential random variate, use m > 0.0
# * ---------------------------------------------------
# */
return (-m * log(1.0 - random()))
def Uniform(a,b):
# --------------------------------------------
# * generate a Uniform random variate, use a < b
# * --------------------------------------------
# */
return (a + (b - a) * random())
def GetFailure():
# # ------------------------------------------------
# * generate the operational time until next failure
# * ------------------------------------------------
# */
selectStream(0)
return (Exponential(100.0))
def NextFailure(failure,m):
# # -----------------------------------------------------------------
# * return the next failure time, and the index of the failed machine
# * -----------------------------------------------------------------
# */
# failure and m are lists
i = 0
t = float(failure[0])
m[0] = i
for i in range(1,M):
if (failure[i] < t):
t = failure[i]
m[0] = i
#EndFor
return (t)
def GetService():
# # ------------------------------
# * generate the next service time
# * ------------------------------
# */
selectStream(1)
return (Uniform(1.0, 2.0))
class sumOf:
wait = 0.0 #wait times
delay = 0.0 #delay times
service = 0.0 #service times
interarrival = -1.0 #interarrival times
##############################Main Program################################
index = 0 # job (machine failure) index */
arrival = START # time of arrival (failure) */
delay = -1.0 # delay in repair queue */
service = -1.0 # service (repair) time */
wait = -1.0 # delay + service */
departure = START # time of service completion */
m = 0 # machine index 0,1,...(M-1) */
failure = [] # list of next failure times */
sum = sumOf()
plantSeeds(123456789)
for m in range(0,M): # initial failures */
failure.append(START + GetFailure())
m = [m] #convert to list to become mutable when passing to NextFailure
while (index < LAST):
index += 1
arrival = NextFailure(failure,m)
if (arrival < departure):
delay = departure - arrival
else:
delay = 0.0
service = GetService()
wait = delay + service
departure = arrival + wait # completion of service */
failure[m[0]] = departure + GetFailure() # next failure, machine m */
sum.wait += wait
sum.delay += delay
sum.service += service
#EndWhile
sum.interarrival = arrival - START
print("\nfor a pool of {0:1d} machines and {1:1d} simulated failures\n".format(M,index))
print("average interarrival time .. = {0:6.2f}".format(sum.interarrival / index))
print("average wait ............... = {0:6.2f}".format(sum.wait / index))
print("average delay .............. = {0:6.2f}".format(sum.delay / index))
print("average service time ....... = {0:6.2f}".format(sum.service / index))
print("average # in the node ...... = {0:6.2f}".format(sum.wait / departure))
print("average # in the queue ..... = {0:6.2f}".format(sum.delay / departure))
print("utilization ................ = {0:6.2f}".format(sum.service / departure))
#C output:
# for a pool of 60 machines and 100000 simulated failures
# average interarrival time .. = 1.75
# average wait ............... = 5.09
# average delay .............. = 3.59
# average service time ....... = 1.50
# average # in the node ...... = 2.90
# average # in the queue ..... = 2.05
# utilization ................ = 0.86