반응형
Python에서의 실제 콜센터 프로세스 시뮬레이션
Simulating Real-Life Call Center Processes in Python
Simpy
SimPy는 표준 Python을 기반으로 하는 프로세스 기반 이산 이벤트 시뮬레이션 프레임워크입니다. 이벤트 디스패처는 Python의 제너레이터를 기반으로 하며 비동기 네트워킹이나 멀티 에이전트 시스템 구현에도 사용할 수 있습니다.
라이브러리
1
2
3
4
5
6
7
|
# pip install simpy
# pip install numpy
import random
import simpy
import numpy as np
|
cs |
1. Environment 클래스 선언
1
2
3
|
import numpy
env = simpy.Environment()
|
cs |
2. Process Interaction
1
2
3
4
5
|
import numpy
env = simpy.Environment()
env.process(setup(env, NUM_EMPLOYEES, AVG_SUPPORT_TIME, CUSTOMER_INTERVAL))
env.run(until = SIM_TIME)
|
cs |
1
2
3
4
5
6
7
8
9
10
11
|
class CallCenter:
def __init__(self, env, num_employees, support_time):
self.env = env
self.staff = simpy.Resource(env, num_employees)
self.support_time = support_time
def support(self, customer):
random_time = max(1, np.random.normal(self.support_time, 4))
yield self.env.timeout(random_time)
print(f"Support finished for {customer} at {self.env.now:.2f}")
|
cs |
3. Resources
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
def customer(env, name, call_center):
global customers_handled
print(f"Custoemr {name} enters waiting queue at {env.now:.2f}!")
with call_center.staff.request() as request:
yield request
print(f"Customer {name} enters call at {env.now:.2f}")
yield env.process(call_center.support(name))
print(f"Customer {name} left call at {env.now:.2f}")
customers_handled += 1
def setup(env, num_employees, support_time, customer_interval):
call_center = CallCenter(env, num_employees, support_time)
for i in range(1, 6):
env.process(customer(env, num_employees, call_center))
while True:
yield env.timeout(random.randint(customer_interval - 1, customer_interval + 1))
i += 1
env.process(customer(env, num_employees, call_center))
|
cs |
Full Code
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
|
# pip install simpy
# pip install numpy
import random
import simpy
import numpy as np
NUM_EMPLOYEES = 2
AVG_SUPPORT_TIME = 5
CUSTOMER_INTERVAL = 2
SIM_TIME = 120
customers_handled = 0
class CallCenter:
def __init__(self, env, num_employees, support_time):
self.env = env
self.staff = simpy.Resource(env, num_employees)
self.support_time = support_time
def support(self, customer):
random_time = max(1, np.random.normal(self.support_time, 4))
yield self.env.timeout(random_time)
print(f"Support finished for {customer} at {self.env.now:.2f}")
def customer(env, name, call_center):
global customers_handled
print(f"Custoemr {name} enters waiting queue at {env.now:.2f}!")
with call_center.staff.request() as request:
yield request
print(f"Customer {name} enters call at {env.now:.2f}")
yield env.process(call_center.support(name))
print(f"Customer {name} left call at {env.now:.2f}")
customers_handled += 1
def setup(env, num_employees, support_time, customer_interval):
call_center = CallCenter(env, num_employees, support_time)
for i in range(1, 6):
env.process(customer(env, num_employees, call_center))
while True:
yield env.timeout(random.randint(customer_interval - 1, customer_interval + 1))
i += 1
env.process(customer(env, num_employees, call_center))
print("Starting Call Center Simulation")
env = simpy.Environment()
env.process(setup(env, NUM_EMPLOYEES, AVG_SUPPORT_TIME, CUSTOMER_INTERVAL))
env.run(until = SIM_TIME)
print("Customers handled: " + str(customers_handled))
|
cs |
RESULT
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
### RESULT ###
Starting Call Center Simulation
Custoemr 2 enters waiting queue at 0.00!
Custoemr 2 enters waiting queue at 0.00!
Custoemr 2 enters waiting queue at 0.00!
Custoemr 2 enters waiting queue at 0.00!
Custoemr 2 enters waiting queue at 0.00!
Customer 2 enters call at 0.00
Customer 2 enters call at 0.00
Support finished for 2 at 1.00
Support finished for 2 at 1.00
Customer 2 left call at 1.00
Customer 2 left call at 1.00
Customer 2 enters call at 1.00
Customer 2 enters call at 1.00
Custoemr 2 enters waiting queue at 2.00!
Support finished for 2 at 2.53
Customer 2 left call at 2.53
Customer 2 enters call at 2.53
Support finished for 2 at 3.24
Customer 2 left call at 3.24
Customer 2 enters call at 3.24
Custoemr 2 enters waiting queue at 4.00!
Custoemr 2 enters waiting queue at 5.00!
Custoemr 2 enters waiting queue at 7.00!
Custoemr 2 enters waiting queue at 8.00!
Custoemr 2 enters waiting queue at 10.00!
Support finished for 2 at 10.14
Customer 2 left call at 10.14
Customer 2 enters call at 10.14
Custoemr 2 enters waiting queue at 11.00!
Support finished for 2 at 11.14
Customer 2 left call at 11.14
Customer 2 enters call at 11.14
Custoemr 2 enters waiting queue at 14.00!
Support finished for 2 at 15.44
Customer 2 left call at 15.44
Customer 2 enters call at 15.44
Custoemr 2 enters waiting queue at 17.00!
Custoemr 2 enters waiting queue at 19.00!
Custoemr 2 enters waiting queue at 22.00!
Support finished for 2 at 22.35
Customer 2 left call at 22.35
Customer 2 enters call at 22.35
Support finished for 2 at 22.62
Customer 2 left call at 22.62
Customer 2 enters call at 22.62
Custoemr 2 enters waiting queue at 23.00!
Custoemr 2 enters waiting queue at 25.00!
Support finished for 2 at 25.19
Customer 2 left call at 25.19
Customer 2 enters call at 25.19
Support finished for 2 at 25.90
Customer 2 left call at 25.90
Customer 2 enters call at 25.90
Custoemr 2 enters waiting queue at 27.00!
Custoemr 2 enters waiting queue at 28.00!
Custoemr 2 enters waiting queue at 31.00!
Support finished for 2 at 32.98
Customer 2 left call at 32.98
Customer 2 enters call at 32.98
Custoemr 2 enters waiting queue at 33.00!
Support finished for 2 at 34.39
Customer 2 left call at 34.39
Customer 2 enters call at 34.39
Support finished for 2 at 35.64
Customer 2 left call at 35.64
Customer 2 enters call at 35.64
Custoemr 2 enters waiting queue at 36.00!
Custoemr 2 enters waiting queue at 38.00!
Support finished for 2 at 38.93
Customer 2 left call at 38.93
Customer 2 enters call at 38.93
Custoemr 2 enters waiting queue at 41.00!
Custoemr 2 enters waiting queue at 43.00!
Support finished for 2 at 43.37
Customer 2 left call at 43.37
Customer 2 enters call at 43.37
Custoemr 2 enters waiting queue at 44.00!
Support finished for 2 at 44.69
Customer 2 left call at 44.69
Customer 2 enters call at 44.69
Custoemr 2 enters waiting queue at 45.00!
Support finished for 2 at 46.85
Customer 2 left call at 46.85
Customer 2 enters call at 46.85
Custoemr 2 enters waiting queue at 48.00!
Custoemr 2 enters waiting queue at 49.00!
Support finished for 2 at 50.97
Customer 2 left call at 50.97
Customer 2 enters call at 50.97
Custoemr 2 enters waiting queue at 51.00!
Custoemr 2 enters waiting queue at 54.00!
Support finished for 2 at 55.08
Customer 2 left call at 55.08
Customer 2 enters call at 55.08
Custoemr 2 enters waiting queue at 56.00!
Custoemr 2 enters waiting queue at 57.00!
Support finished for 2 at 57.20
Customer 2 left call at 57.20
Customer 2 enters call at 57.20
Custoemr 2 enters waiting queue at 59.00!
Custoemr 2 enters waiting queue at 61.00!
Custoemr 2 enters waiting queue at 63.00!
Support finished for 2 at 64.59
Customer 2 left call at 64.59
Customer 2 enters call at 64.59
Custoemr 2 enters waiting queue at 65.00!
Support finished for 2 at 65.68
Customer 2 left call at 65.68
Customer 2 enters call at 65.68
Custoemr 2 enters waiting queue at 66.00!
Support finished for 2 at 68.03
Customer 2 left call at 68.03
Customer 2 enters call at 68.03
Custoemr 2 enters waiting queue at 69.00!
Support finished for 2 at 69.83
Customer 2 left call at 69.83
Customer 2 enters call at 69.83
Custoemr 2 enters waiting queue at 70.00!
Support finished for 2 at 70.64
Customer 2 left call at 70.64
Customer 2 enters call at 70.64
Custoemr 2 enters waiting queue at 72.00!
Custoemr 2 enters waiting queue at 74.00!
Support finished for 2 at 75.40
Customer 2 left call at 75.40
Customer 2 enters call at 75.40
Custoemr 2 enters waiting queue at 76.00!
Support finished for 2 at 78.88
Customer 2 left call at 78.88
Customer 2 enters call at 78.88
Custoemr 2 enters waiting queue at 79.00!
Custoemr 2 enters waiting queue at 80.00!
Custoemr 2 enters waiting queue at 83.00!
Support finished for 2 at 83.60
Customer 2 left call at 83.60
Customer 2 enters call at 83.60
Support finished for 2 at 84.47
Customer 2 left call at 84.47
Customer 2 enters call at 84.47
Custoemr 2 enters waiting queue at 85.00!
Support finished for 2 at 85.47
Customer 2 left call at 85.47
Customer 2 enters call at 85.47
Custoemr 2 enters waiting queue at 86.00!
Support finished for 2 at 86.47
Customer 2 left call at 86.47
Customer 2 enters call at 86.47
Custoemr 2 enters waiting queue at 88.00!
Custoemr 2 enters waiting queue at 90.00!
Support finished for 2 at 90.32
Customer 2 left call at 90.32
Customer 2 enters call at 90.32
Support finished for 2 at 91.20
Customer 2 left call at 91.20
Customer 2 enters call at 91.20
Custoemr 2 enters waiting queue at 93.00!
Support finished for 2 at 94.59
Customer 2 left call at 94.59
Customer 2 enters call at 94.59
Custoemr 2 enters waiting queue at 96.00!
Support finished for 2 at 96.85
Customer 2 left call at 96.85
Customer 2 enters call at 96.85
Custoemr 2 enters waiting queue at 97.00!
Custoemr 2 enters waiting queue at 99.00!
Support finished for 2 at 99.51
Customer 2 left call at 99.51
Customer 2 enters call at 99.51
Custoemr 2 enters waiting queue at 102.00!
Custoemr 2 enters waiting queue at 105.00!
Support finished for 2 at 105.28
Customer 2 left call at 105.28
Customer 2 enters call at 105.28
Support finished for 2 at 106.28
Customer 2 left call at 106.28
Customer 2 enters call at 106.28
Custoemr 2 enters waiting queue at 107.00!
Support finished for 2 at 107.28
Customer 2 left call at 107.28
Customer 2 enters call at 107.28
Custoemr 2 enters waiting queue at 109.00!
Support finished for 2 at 110.44
Customer 2 left call at 110.44
Customer 2 enters call at 110.44
Custoemr 2 enters waiting queue at 111.00!
Custoemr 2 enters waiting queue at 112.00!
Custoemr 2 enters waiting queue at 114.00!
Support finished for 2 at 114.25
Customer 2 left call at 114.25
Customer 2 enters call at 114.25
Custoemr 2 enters waiting queue at 116.00!
Support finished for 2 at 116.22
Customer 2 left call at 116.22
Customer 2 enters call at 116.22
Custoemr 2 enters waiting queue at 117.00!
Custoemr 2 enters waiting queue at 118.00!
Customers handled: 43
|
cs |
반응형
'공부 > 파이썬 Python' 카테고리의 다른 글
간단한 파이썬 멀티쓰레딩 예제들 (0) | 2022.03.25 |
---|---|
Python을 사용한 유방암 검출 튜토리얼 (Breast Cancer Detection with Python) (1) | 2022.03.23 |
Python으로 전처리 파이프라인 설계하기 (3) | 2022.03.22 |
카운터와 딕셔너리의 차이 in Python (0) | 2022.03.20 |
다항식 회귀 (Polynomial Regression)이란 (0) | 2022.03.19 |
댓글