I'm currently trying to simulate a scheduling problem. Each day a number of arrivals call a hospital to request an appointment. At the end of each day the arrivals are assigned a time slot. Initially I constructed an array with the arrivals each day and an array representing the number of time slots per day. Looping through the arrivals of each day, arrivals are assigned to the nearest time slot. However, when the number of arrivals is relative high the code will try to assign an arrival to a time slot beyond the end of the server array, i.e. it is referencing to an index larger than the server array. Is there any way to automatically append the array whenever the model tries to assign an arrival to a time slot further in the future then the server array currently contains?
So far I've first generated an arrival array (a) and set the server array (s) equal to twice the size of the arrival rate. While this works fine as long as no extreme values (high labda or low mu) are chosen, but I would like to have a little more robust creation of s. Personally I think the easiest would be by appending s.
def simple_model_test():
labda, mu, Days = 10, 4, 10
a = poisson(labda).rvs(Days) # Generate array with number of arrivals each day
s = np.ones_like(a) * mu # Generate equal sizes array with time slots
s = np.append(s, np.ones_like(a) * mu) # Add some additional days at the end of time horizon
for i in range(0, len(a)): # Cycle through all days of time horizon
j = i + 1 # Patients cannot be served at day of arrival
# if s[j] is empty: # I was trying to do something like this, but this does not work
# s = np.append(s, mu)
while a[i] > 0: # Assign all patients that arrived to a time slot
if s[j] > 0: # Check if time slots are available at day j
a[i] -= 1 # To indicate that a patient is assigned
s[j] -= 1 # To indicate that a time slot is filled at day j
else:
j += 1 # Check for free time slots next day
print(s)
simple_model_test()
So currently it is giving the error: "IndexError: index 20 is out of bounds for axis 0 with size 20". So I would like to append s whenever s[j] did not yet exist.