2017-02-16 1 views
-1

+ = 연산자를 사용하려고하는데 잘못된 결과가 계속 나타납니다. 우리는 고객에게 서비스를 제공하는 미용실에 헤어 드레서를 가지고 있습니다. 매일 그녀는 약속을 예약하기 위해 6 개의 슬롯을 가지고 있으며, 각 약속 사이의 간격은 똑같습니다. 그녀가 슬롯에 대한 약속을 예약 할 관리하는 경우 그녀가 슬롯에 대한 고객을 찾을 수없는 경우, 우리는 변수 1이 나타내는 우리는 python + = 연산자를 올바르게 사용하는 방법은 무엇입니까?

Appointments_Booked = [1, 0, 1, 1, 1] # Where 1 indicates an appointment booked and 0 no appointment booked. 

def service_time(): 
    service = random.normalvariate(5, 1) # The time the hair dresser takes to service her customers follows a normal distribution, the hair dresser takes around 5 minutes on average to service each customer 
    return service 

def wait_time(): 
    waiting_time_last_customer = 0 # The waiting time of the first customer is zero because there is no customer booked before him or her 
    interval_time_between_slots = 5 # This is how much time we have between each appointment 
    y = 0 
    for x in Appointments_Booked: 
     if x == 1: # If we have a customer booked for a slot 
      customer_service = service_time() #How long we will take to service a customer 
      waiting_time_present_customer = max((waiting_time_last_customer + customer_service) - interval_time_between_slots, 0) # This is the formula to compute the waiting time of the current customer. It essentially says that the waiting time of the current customer is simply the interval time (space) between appointments minus how much the previous customer had to wait for service and then get serviced. 
      y += waiting_time_present_customer # THIS IS WHERE I AM ENCOUNTERING PROBLEMS 
      print('waiting time =', y) 
      print('service time =', customer_service) 
     elif x == 0: 
      customer_service = 0 
      waiting_time_last_customer = 0 
      y += waiting_time_present_customer 
      print('waiting time =', y) 
      print('service time =', customer_service) 

0

내 + = 인 변수로이를 나타냅니다 그 고객이 기다리고있는 시간이 항상 0이되기를 바란다. 왜냐하면이 고객은 다른 고객이 없기 때문에 기다리지 않기 때문이다.

waiting time = 1.449555339084272 #This does not make any sense because the first customer is supposed to have zero waiting time because they are first in line 
service time = 4.400365861292478 
waiting time = 0 
service time = 0 # refA 
waiting time = 0 # refA 
service time = 4.42621491273674 
waiting time = 1.0771427601173116 # The waiting time of this customer is supposed to also be zero because the service time (#refA) + waiting time(#refA) of the previous customer is zero. 
service time = 6.077142760117312 
waiting time = 1.0771427601173116 # The waiting time of this customer is also wrong because its supposed to be 2.154. The waiting time (1.077) + the service time (6.077) of the previous customer is 7.154 minus the interval 5 gives 2.154 
service time = 4.166720282779419 

무엇 내가 + = 연산자를 잘못하고 있어요, 또는 어쩌면 나는 다른 뭔가 잘못하고있는 중이 야 : 두 번째 결과는, 예를 들어, 내 출력했다,뿐만 아니라 다른 고객이 다른가요?

답변

1

대기 시간에 customer_service이 추가됩니다.

arrival_time(i) = arrival_time(i-1) + interarrival_time # often exponential 
begin_service_time(i) = max(arrival_time(i), end_service_time(i-1)) 
end_service_time(i) = begin_service_time(i) + customer_service(i) 

i 고객 번호입니다 : 모델을 대기 표준 단일 서버는 말한다. 올바른 초기화를 사용하면 i을 삭제할 수 있으며 업데이트는 이전 값에만 의존하므로 루프 만 수행하면됩니다.

시간 슬롯을 이산화하도록 선택했지만 대기 시간에 현재 고객의 customer_service을 포함하여 a)의 기본 논리 결함을 변경하지 않으며 b) 대기 시간에 결과를 근거로합니다. 이전 고객이 아니라 완료 시간.

다른 결함이있을 수 있지만 표시가 멈추고 모델을 실행하기위한 실제 드라이버 코드를 제공하지 않았기 때문에 검사를 중단했습니다.

+0

안녕하세요. 저는이 시간을 내 문제에 참석할 시간을 가져 주셔서 대단히 감사하다고 말하고 싶습니다. 귀하의 의견과 시간에 진심으로 감사 드리며, 정말로 감사드립니다. 내 프로그램을 조정하기 위해 귀하의 정보를 검토하고 있습니다. –

+0

목록에서 i 및 루프를 삭제하는 방법 Customer_Numbers = [1, 2, 3, 4, 5] # 목록의 각 항목이 i를 나타내며 여기서 1 시간 이상이 운동을 시도했습니다. –

+0

아이디어는 모든 고객을 위해 모든 값에 대해 배열로 스토리지를 유지할 필요가 없다는 것입니다. 예를 들어, 고객 'i'의 'arrival_time'을 찾으면 더 이상 이전 고객의 arrival_time이 필요하지 않습니다. 따라서 인덱스없이'arrival_time + = interarrival_time'으로 값을 계산할 수 있습니다. 고객 세트를 반복해야하지만 모든 고객에게 동시에 스토리지를 할당 할 필요는 없습니다. – pjs

관련 문제