Machine Problem 9

Due Apr 07, on line

Part of the homework for CS:2820, Spring 2021
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Background

Finally, it's time to start people moving. Eventually, it would be fun if schedules included days of the week and a probability of taking or not taking a particular trip, so we could write things like this:

role teacher 10
  home
  school       (8AM-5PM weekdays 0.95 15min)
  church       (10AM-12AM Sunday 0.4)
  groceryStore (10AM-11AM Saturday)
  mall         (1:30PM-3PM Saturday 0.3 30min)
  drugStore    (5:30PM-6PM weekdays 0.05);

That's a refinement we'll leave for later, although in your design, it would be useful to keep this option in mind.

For now, we will ignore days of the week, and concentrate only on time of day, and we will ignore the possibility that some trips might not always happen. Sometimes, teachers in the above role don't go to school (5% of the tie), and they frequently don't go to church (60% of the time). Our teachers always go to the grocery store, though.

For now, we'll ignore the time it takes to get places. We'll assume that all trips are instantaneous. On the average, people live about 20 minutes from their job, regardless of whether they walk, take public transit, drive on city streets, or have access to expressways. The variation is wide, but most people also shop within 20 minutes of their home, and the distribution for distances to restaurants friends is also similar. That would make a fine default value. The above schedule shows that the travel times to the school and grocery store are different from the default, but we won't do that!

Added Features for the Model Description File

This time around, we will not add anything to the model description file. All entries in the schedule are done 100% of the time, all entries are daily, and times are specified in fractional hours from midnight, with no colons dividing hours and minutes and no AM or PM designators.

We will add a constraint: The times on the schedules for each role must not overlap. A model description that includes overlapping schedules is an error.

Simulation Output

The output format should be exactly as it was in machine problems 7 and 8, except that now, people move around following their schedule, and when contageous people move, they cease to spread disease in the place they were and begin spreading disease in their new place.

In addition, when someone becomes bedridden, they don't leave home. We won't bother modeling people going home early, if they suddenly become bedridden in the middle of a work day or while commuting to work, but once a bedridden person gets home, they stay there until they recover or die.

Assignment

Extend any solution to MP8 so that:

Also in writing your code, think ahead. In future versions, possibly after the semester ends:

The usual rules and coding standards apply. Your code should conform reasonably to the Sun/Oracle rules for Java formatting: 4-space indents, appropriate use of comments, 80-character lines, etc. You should check your code for annoying problems with ~dwjones/format. This will identify overlength lines and flag other undesirable problems with your text file such as residual DOS artifacts that come from transferring files between Windows and Linux systems.

Note that, with the features we will implement this time around, the epidemic simulator will have reached the point that it could be used to compare the outcome of the epidemic with and without such measures as closing schools Just run the simulation with those places in people's schedules and then run it again with those features removed, and you can see the impact of those places on the spread of the disease. Of course, until we add weekly behavior to the schedules, we can't experiment with closing churches or other weekend attractions, and the problem of building a realistic collection of roles and schedules is far from trivial.

Submision

As usual, submit using the ~dwjones/submit utility. Your program should be in a single source file called epidemic.java.

Questions and Answers

A student asked: What if one schedule ends at 10AM and another begins at 10AM, do these overlap?

Let's consider them to be an overlap. The fact that travel time is instantaneous means that, in theory, we could consider each schedule to be a half-open interval and declare them to be non-overlapping, but this introduces problems with simultaneous events. Better, for now, to force complete non-overlap.

A student asked: Is there a bug in the posted solution to MP8? When I tried role homemaker, with just one place, it said that there was no place.

Yes, that's a bug. Needless to say, the official test data for testing the assignment won't have this case. A repaired version of the code has now been posted. 11 lines of code have been changed (excluding comments). If you get both copies on a Unix compatible system, you can use the diff utility to list the lines that differ from one copy to the other. This makes it easy to install those changes in code you may have already started editing.

A student asked: Is the travel time between places the "default travel time" of 20 minutes or zero?

The time is zero!

A student asked: When a schedule does not place a person somewhere else, do they always go home?

Yes. Even if one place's schedule ends at 10.0 and the next place's schedule begins at 10.001, the person goes home and spends 0.001 of an hour there (that's 36 seconds).

A student asked: When a bedridden person recovers, what happens?

The bedridden person resumes all activities. They resume following their schedule, visiting locations, and (potentially) adding to congestion. This has no impact on anything in the MP9 model, but in later extensions to the model, where immunity doesn't last forever, or where congestion is taken into account, it could matter.

A student asked: How should we handle the fact that bedridden people cancel all their activities and stay home?

As is typical in programming problems, there are a huge number of potential solutions. For example, bedirdden people could simply ignore their schedule and stay home, or bedridden people could swap turn off their schedule or replace it with an empty schedule until they recover.

A student asked: Just to clarify, is a person's home constrained to have any special name or is the home just the place with no schedule?

The home has no special name. For role collegeStudent you might call home dorm while for role cityDweller you might call home apartment. The only thing that sets the home apart from other places associated with a role is that it has no schedule attached to it. In the posted solution to MP8, the home field of class Person holds that person's home place, and the emplace method uses the fact of a null Schedule to set that field.

A student asked: Can you give an example of input and the expected output?

Here is an interesting input:

population 100;
infected 1;
place earth 100 0 0.001;
place moon  100 0 .0001;
place mars  100 0 0.001;
role human   50 earth  moon (10-12.1);
role martian 50 mars   moon (12-15);
end 30;

latent       2.0 0;
asymptomatic 3   0;
symptomatic  5   1   0.9;
bedridden    8   2   0.9;

The reason the above input is interesting is because the one infected person ends up either on the earth or mars, and the disease spreads rathe rapidly there. Since both humans and martians visit the moon, where their schedules briefly overlap, there is a chance that the disease will be transmitted between them.

The probability of interplanetary infection is small enough that, in some simulation runs, all the residents of the uninfected planet remain uninfected while everyone on the other planet gets the disease. Here's the tail end of the output from a run where one planet dodged the bullet:

21.0,50,1,2,22,2,23,0
22.0,50,0,1,19,2,28,0
23.0,50,0,1,17,2,30,0
24.0,50,0,1,10,1,38,0
25.0,50,0,0,6,1,43,0
26.0,50,0,0,3,0,47,0
27.0,50,0,0,1,0,49,0
28.0,50,0,0,1,0,49,0
29.0,50,0,0,0,0,50,0
30.0,50,0,0,0,0,50,0

Here's the tail end of the output from a run where the disease jumped from planet to planet.

21.0,0,4,19,38,5,34,0
22.0,0,0,16,36,10,38,0
23.0,0,0,7,36,10,47,0
24.0,0,0,4,33,12,51,0
25.0,0,0,0,33,10,57,0
26.0,0,0,0,29,11,60,0
27.0,0,0,0,19,11,69,1
28.0,0,0,0,9,10,80,1
29.0,0,0,0,3,9,87,1
30.0,0,0,0,1,6,92,1

No change was made to the simulation input between the above two runs. The only difference is a matter of the random number seed from one run to the next.

Here is another interesting model where the disease runs rather quickly. With this disease, if you juat have one place (home) large enough to hold the entire population, and one role (homebody), the disease runs its course in under 15 days. If you run it with the following parameters, though, small homes and small workplaces, the epidemic takes 25 days with the peak number of symptomatic people occurring around day 15-17.

population 100;
infected 1;
place home  10  0 0.01;
place work  10  0 0.01;
role homebody 60 home;
role worker   40 home work (9-17);
end 30;

latent       2.0 0;
asymptomatic 2   0;
symptomatic  2   0   0.9;
bedridden    2   0   0.9;

If you change the home and workplace sizes given above from 10 to 8, the peak population in the symptomatic category is delayed from days 15-17 to days 21-14 because the disease has to diffuse through a larger number of smaller households and workplaces to reach the whole population.