Created
December 10, 2020 00:31
-
-
Save gitaeks/0a9fa91094779ad7a8625f82cbbee9e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #위코드와 아래 코드 어느것을 참고해도 괜찮습니다. | |
| #윗코드는 실습시간에 했던 코드, 아래 코드는 미리 했던 코드 | |
| import random | |
| from collections import deque | |
| def is_customer_arrived(): | |
| if(random.randint(0,100)> 30): | |
| return True | |
| else: | |
| return False | |
| def insert_customer(arrival_time): | |
| global customer | |
| customer+=1 | |
| service_time=random.randint(3,5) | |
| deq.append({customer:[arrival_time,service_time]}) | |
| print('******>고객', customer,'이',arrival_time,'분에 들어옵니다.') | |
| print('예상서비스시간은', service_time, '입니다.\n') | |
| def remove_customer(): | |
| global waited_time, served_customer | |
| if len(deq)==0: | |
| return 0 | |
| pop_customer=deq.popleft() | |
| served_customer+=1 | |
| for i,j in pop_customer.items(): | |
| pass | |
| print('=====>고객', i,'이',clock,'분에 서비스를 받기 시작합니다.') | |
| print('대기시간은',clock-j[0], '분 입니다.\n') | |
| waited_time +=clock-j[0] | |
| return j[1] | |
| deq=deque([]) | |
| customer=0 #고객수 누적변수 | |
| duration = 10 #가상 시뮬레이션 10분 | |
| clock=0 #가상의 현재 시간 | |
| service_time=0 #고객이 서비스받고 있는 시간을 체크 | |
| served_customer=0 #서비스 완료된 고객수 누적변수 | |
| waited_time=0 # 서비스 완료된 고객의 대기시간 누적변수 | |
| while clock<duration: | |
| clock+=1 #1분 | |
| print('현재시간', clock, '분') | |
| if (is_customer_arrived()): # 매 분마다 고객이 왔는지를 체크 | |
| insert_customer(clock) #고객이 왔다면 queue에 삽입 | |
| if (service_time>0): # | |
| service_time-=1 | |
| else : | |
| service_time = remove_customer() | |
| service_time-=1 | |
| print('서비스완료 또는 서비스중인 고객수',served_customer) | |
| print('대기중인고객수', len(deq)) | |
| print('평균대기시간', waited_time/served_customer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment