-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_channel.py
More file actions
133 lines (99 loc) · 3.89 KB
/
Copy pathsingle_channel.py
File metadata and controls
133 lines (99 loc) · 3.89 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
# -*- coding: utf-8 -*-
"""Single Channel.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1SSZ0dQ-q3L_tEbe1VRSbqfq4CgOwJoDo
"""
# Commented out IPython magic to ensure Python compatibility.
from scipy.stats import *
print("Enter Number of Customer: ", end=" ")
n = int(input())
print("Do you Want to generate (Inter Arrival & Service Time) Randomly?? <'y = yes'> or <'n = no'>: ", end=" ")
optn = str(input().lower())
print()
intArrivalTime = []
arrivalTime = []
serviceTime = []
SBT = []
waitingTime = []
SET = []
customerSpendInSystem = []
idleTime = []
int_arrivalT = 0
wait_count = 0
idel_count = 0
if optn[0] == 'n':
# inter arrival Time 'User Choosen' input
for i in range(n):
if i == 0:
intArrivalTime.append(0)
print("Inter Arrival Time for customer 1: 0")
else:
intArrivalTime.append(int(input("Inter Arrival Time for Customer %i: " % (i + 1))))
#service Time 'User Choosen' input
print()
for i in range(n):
serviceTime.append(int(input("Service Time for Customer %i: " % (i + 1))))
if optn[0] == 'y':
print(" Random \n\t Distribution " "\n\n POISON")
intArrivalTime.append(0)
data_poisson = str(poisson.rvs(mu=5.6, size=(n - 1))) # μ = 5.6 customer/min (for n-1 customer) when n = 0, None of customer Inter Arrives Times
for i in range(data_poisson.__len__()):
if data_poisson[i].isnumeric():
intArrivalTime.append(int(data_poisson[i]))
for i in range(n):
print("Inter Arrival Time Customer %i: %i" % (i + 1, intArrivalTime[i]))
print("\n EXPONENTIAL")
data_expon = str(expon.rvs(scale=1, size=n)) # and λ= 1 customer/min (for n customer)
data_expon = data_expon.replace("[", "")
data_expon = data_expon.replace("]", "")
serviceTime = list(map(float, data_expon.split()))
for i in range(n):
print("Service Time Customer %i: %f" % (i + 1, serviceTime[i]))
for i in range(n):
if i == 0:
arrivalTime.append(0)
else:
int_arrivalT = int_arrivalT + intArrivalTime[i]
arrivalTime.append(int_arrivalT)
if i == 0:
SBT.append(0)
else:
if float(arrivalTime[i]) > float(SET[i - 1]):
SBT.append(float(arrivalTime[i]))
else:
SBT.append(float(SET[i - 1]))
if i == 0:
waitingTime.append(0)
else:
if SBT[i] - arrivalTime[i] > 0:
waitingTime.append(float(SBT[i] - arrivalTime[i]))
wait_count += 1
else:
waitingTime.append(0)
if i == 0:
SET.append(float(serviceTime[i] + arrivalTime[i]))
else:
SET.append(float(serviceTime[i] + SBT[i]))
customerSpendInSystem.append(float(waitingTime[i] + serviceTime[i]))
# server idle time
if i == 0:
idleTime.append(0)
else:
if float(arrivalTime[i]) > float(SET[i - 1]):
idleTime.append(float(arrivalTime[i] - SET[i - 1]))
idel_count += 1
else:
idleTime.append(0)
print(" Cust. | Inter Arrival | Arrival | Service | Service T. | Waiting T. | Service T. | C. Spend T. | Server ")
print(" No. | Time | Time | Time | Begin | in Queue | End | in System | Idle T. ")
for i in range(n):
if i == 0:
print(
" %3i - %3i %1f %1.2f %1.4f %5.3f %5.3f - "
# % (i + 1, arrivalTime[i], serviceTime[i], SBT[i], waitingTime[i], SET[i], customerSpendInSystem[i]))
else:
print(
" %3i %3i %3i %1f %1.2f %1.4f %5.3f %5.3f %5.3f "
# % (i + 1, intArrivalTime[i], arrivalTime[i], serviceTime[i], SBT[i], waitingTime[i], SET[i],
customerSpendInSystem[i], idleTime[i]))