Machine Problem 10

Due Apr 12, on line

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

Background

Our program has become huge. It's time to break it into multiple source files. So, for this assignment, you will just turn in a source file holding one class, and you will change the content of that class with a small change to demonstrate that you have done something.

In the previous machine problem, we suggested an ultimate goal for schdules that looked 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 too much, but consider the following useful refinement:

role teacher 10
  home
  school       (8-13)
  drugStore    (13.5-14 0.05);
This says the teacher always goes to school, but only goes to the drugstore after school 5 percent of the time. That is to say, every schedule has a probability of being followed, and that probability defaults to 1.0.

Added Features for the Model Description File

The schedules for a place will have a probability of being followed, as outlined above. The probability, if present, must be greater than zero and less than or equal to 1.

Simulation Output

The output format should be exactly as it was in machine problems 7 to 9.

Assignment

Break the distributed solutio for MP9 into multiple source files; at the very least, you need to break off the file Schedule.java, where that file contains exactly one class, class Schedule, which must be public.

Extend any solution to MP9 so that schedules have a probability of being followed, as suggested above.

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.

Submision

You should submit just the file Schedule.java; we will test this in the context of the remainder of the pieces of MP9.

As usual, submit using the ~dwjones/submit utility.

Questions and Answers

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

Here is an interesting example model that should run identically under both MP9 and MP10; it was given in the question and answer section of the MP9 assignment:

population 100;                     latent       2.0 0;
infected 1;                         asymptomatic 2   0;
place home  10  0 0.01;             symptomatic  2   0   0.9;
place work  10  0 0.01;             bedridden    2   0   0.9;
role homebody 60 home;
role worker   40 home work (9-17);
end 30;

The following model should produce very similar output under MP10. The only change is that, instead of having 40 percent of the population being workers who spread the disease from home to home by going to work, now everybody goes to work, but only 40% of the time.

population 100;                     latent       2.0 0;
infected 1;                         asymptomatic 2   0;
place home  10  0 0.01;             symptomatic  2   0   0.9;
place work  10  0 0.01;             bedridden    2   0   0.9;
role everybody 100 home work (9-17 0.4);
end 30;

Over multiple runs, with the pseudo-random-number generator seeded differently on each runs, these produce output where there is as much variation from one run to another with the same model as there is between models. I will not post any of the output, but if you run the reference solution to MP9 on the first model given above, you can explore how it varies from run to run. You should get a similar range of variation with your solution to MP10 using either model.

A student asked: Can I add a method to MyScanner to help deal with the optional probability in each schedule?

No. The only code you are submitting is class Schedule. If you make changes to any other class, you won't be submitting that so your code will not work!

Note that class InfectionRule includes support for an optional field using existing methods, and this approach works equally well for the optionall field of a schedule.

A student asked: I have my own code, can I turn in code for my version of Schedule instead of working with your version?

We will evaluate your implementation of class Schedule in terms of how it works when compiled with the other classes from the reference solution. If the code you submit for class Schedule works in that context, that is good. If it does not, it will be judged to be non working!

Most likely, this means you are better off starting with the reference solution and abandoning (at least for what's left of this course) the code you have been working on.

A student asked: I noticed that when you broke up the source for the road-network simulator into multiple source files, the header comments on the entire file seem to have been reduced to just one line giving the file name. Should we do this on our new version of Schedule.java?

Yes. When a file contains just one class, the javadoc comments at the head of that class take over the role of the header comments on a file containing multiple classes. The fact that the import directives come before the header comments on the class pushes this comment down into the file, but usually not far enough down that there's a need for a big header comment before the list of imports.

If you look at Intersection.java, you'll see that that file still contains multiple clases -- class Intersection plus its three subclasses. Those subclasses are not used outside of class Interseciton, but perhaps a small header should have indicated that they are present. This is not an issue for this machine problem.