Skip to content

Instantly share code, notes, and snippets.

@gitaeks
Created December 10, 2020 00:30
Show Gist options
  • Select an option

  • Save gitaeks/d87d048db2e4a091aa4b8f83e49b7034 to your computer and use it in GitHub Desktop.

Select an option

Save gitaeks/d87d048db2e4a091aa4b8f83e49b7034 to your computer and use it in GitHub Desktop.
from collections import deque
import random
def customer_in(clock):
global customer
customer += 1
print('고객',customer,'님이', clock, '분 에 들어왔습니다.')
service_time=random.randint(2, 5)
print('서비스시간은',service_time, '분이 예상됩니다.\n')
cus = {customer:[clock, service_time] } #딕셔너리
deq.append(cus)
def customer_out():
global waited_time, count
if len(deq):
cus=deq.popleft()
for i,j in cus.items():
service_time = j[1]
waited_time += clock-j[0] #clock :현재 시간 - 고객이 들어온 시간을 빼줌
count+=1
print(i,'번째 고객님이',clock,'분에 서비스를 받기 시작합니다.\n')
return service_time
else:
print("None")
return 0
def arrived_customer(): # 단위시간당 사람이 은행에 들어올 확률
if random.randint(1,10)>3:
return True
else:
return False
customer = 0
service_time = 0
duration = 10
clock = 0
deq=deque([])
waited_time = 0
count=0
while clock < duration:
clock+= 1
if (arrived_customer()): # 고객이 들어올 확률
customer_in(clock) # 고객을 큐에 추가하는 함수
if service_time > 1:
service_time -= 1
else:
service_time = customer_out()
print ("서비스가 완료됬거나, 서비스중인고객수 ",count)
print ("평균대기시간", waited_time/count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment