jeudi 16 février 2017

Please help me use the += operator correctly

I am trying to use the += operator but I keep getting incorrect results. So we have a hair dresser in a saloon who provides a service to her customers. During each day, she has 6 slots to book appointments, the intervals between each appointment are spaced equally. If she manages to book an appointment for a slot, we denote this with the variable 1, if she can't find a customer for that slot then we denote this with the variable 0.

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, 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:
             patient_service = 0
             waiting_time_last = 0
             y += waiting_time_present
             print('waiting time =', y)
             print('service time =', patient_service)

My += is not doing what I want it to do, firstly I want the waiting time of the first customer to ALWAYS be 0 because this customer does not wait simply because there is no other customer before him/her. Secondly the results are different for the other customers as well, for example, my output was:

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

What am I doing wrong with the += operator, or maybe I am doing something else wrong.




Aucun commentaire:

Enregistrer un commentaire