3. Planning for Multiple Days
Setup
Our current model only simulates a single day. However, we would like to have an optimal schedule for the number of nurses to employ for an entire period, say 3 weeks. We could do this by making 21 plots using the code above, one for each day, using the number of students scheduled to arrive for that day. We could then show each of those 21 plots to management and have them pick out a point on each plot. This would be a pain, however. It is better to show them a single plot for the entire 3-week period and have them select a point. In addition, we would like to introduce the possibility that a student does not test positive immediately upon arriving and thus contacts multiple students during the time he/she goes undetected. For simplicity, we do not assume the contacted students spread the virus to other contacts. For example, a student arriving on day 0 may not test positive until day 4, and he/she may contact 6 students. We will implement this improved model below. Before we do so, note that our objective is essentially still the same as above: for a particular  𝛼  optimally choose the number of nurses to schedule to minimize the expected total cost. However, our choice of nurses to schedule is no longer a scalar, since we are considering many days as opposed to a single day. Rather, it is a vector (say,  𝑁⃗ ) whose length is the number of days in the period we are considering, and whose 𝑗 th entry is our choice of the number of nurses to employ on day  𝑗 .

For the mathematically inclined, our problem can be restated as the following optimization problem. (You may skip reading this cell, but it may help give you a better understanding of the problem at hand.) Let  (𝑁1,...,𝑁𝐷)=𝑁⃗  be a vector giving the number of nurses that will work on each day ( 1  through  𝐷 ), then, for a particular value of  𝛼 , our objective function is: Objective (𝑁⃗)  = ExpectedTotalOverage( 𝑁⃗ ) +  𝛼⋅  ExpectedTotalUnderage( 𝑁⃗ ) =  ∑𝐷𝑑=1   𝐸  (Overage for day  𝑑  +  𝛼⋅  Underage for day  𝑑  | We use  𝑁𝑑  nurses on day  𝑑 ) ≈   ∑𝐷𝑑=1   1𝑀   ∑𝑀𝑖=1  (Overage for day  𝑑   +𝛼⋅  Underage for day  𝑑  | We use  𝑁𝑑  nurses on day  𝑑  and the random outcome for simulation  𝑖  is (𝑎𝑚𝑜𝑢𝑛𝑡_𝑜𝑓_𝑤𝑜𝑟𝑘)𝑖∈ℝ≥0 ) where  𝑀  is the number of simulations. Let  𝑁∗(𝛼)  be the optimal choice of  𝑁1,...,𝑁𝐷  for a particular  𝛼  (i.e. the  𝑁⃗  that minimizes the Objective function), then we would like to ultimately plot the Pareto Frontier : ExpectedTotalOverage( 𝑁∗(𝛼) ) vs. ExpectedTotalUnderage( 𝑁∗(𝛼) ).


Simulation
Here we'll simulate scenarios, where each scenarios consists of the amount of work that needs to be done on each day during the first 3 weeks of the semester



num_days = 21
num_scenarios = 20

# This is the number of people who arrive on each day.
# It was generated using num_arrivals = np.ceil(2000*rand.uniform(size=num_days)) 
num_arrivals = [1076., 1752., 1783., 1326., 1385., 1454., 1230.,  689., 1190.,
       1853., 1716.,  405.,   70., 1097., 1504.,  634., 1407., 1222.,
       1140.,  404., 1703.]



# Create a dataframe containing all 0's where each row will be a scenario
# and each column will be a simulated day.  Once we run the code below, the
# values in the dataframe will be the number of nurses needed on each day in 
# each scenario
df_sim = pd.DataFrame(0, index=range(num_scenarios), columns=range(num_days))

for i in range(num_scenarios):
  for d in range(num_days): # Iterate over days in our simulation
    # Simulate the students who arrive on this day
    infected_no = rand.binomial(num_arrivals[d],prevalence)
    for j in range(infected_no):
      days_infectious = rand.geometric(0.3)
      day_tested_positive = d + days_infectious
      if day_tested_positive < num_days:
        contacts = 4
        df_sim.loc[i,day_tested_positive] += (30 + 20 * contacts)/(8*60)

df_sim


Question 9: Change the above code so that the number of contacts depends on the number of days the person is infectious. Let the number of contacts be 1.5 times the number of days infectious. This models the fact that a person who has been circulating in the campus population is going to have more local contacts.