Assignment 9Due Oct 22, on line
Part of
the homework for CS:2820, Fall 2020
|
private void open( double time ) { System.out.println( this.toString() + " opened at time " + time ); Simulator.schedule( time + 8 * Simulator.hour, (double t)-> this.close( t ) ); }
The time units used in this program are declared in ...
a) class Time
b) class Simulator.Time
c) class Simulator
d) class Workplace
e) each class that needs to use time units
Simulator.schedule( endTime, (double t)->System.exit( 0 ) );
This is rather stupid, it just kills the program, while really, we should
replace the call to System.exit( 0 ) with a call to
a routine to wrap up the simulation and print out a final report of the
results.
Which of the following would be the best replacement for the above line?
a) Simulator.schedule( endTime, (double t)->wrapUp( t ) );
b) Simulator.schedule( endTime, (double t)->this.wrapUp( t ) );
c) Simulator.schedule( endTime, (double t)->Simulator.wrapUp( t ) );
d) Simulator.schedule( endTime, (double t)->wrapUp() );
e) Simulator.schedule( endTime, (double t)->this.wrapUp() );
a) Add class MyRandom to to your epidemic simulator, and fix all use of randomness in the simulator to properly use it. This includes moving the generation of log-normal distributions into MyRandom.
b) Make places keep track of their occupants, with methods arrive(p) and depart(p) to signal the arrival and departure of person p at that place.
c) Add a method travelTo(p, t) for each person that that causes that person to leave their current place and arrive at place p at time t at that time.
d) For each employee, make them travel to their workplace in the morning leaving home 25 minutes before the workplace opening time. Note that all workplaces currently have the same opening time, but this could change in the future, so each workplace should have its own opening time attribute. Travel times to work should be log-normally distributed, with a median travel time of 20 minutes and a scatter of 3 minutes (yes, a fraction of the workers will be late for work).
e) For each workplace, when that workplace closes, all employees should be sent home. The travel time home will follow the same rules as the travel time to work.
f) Cut out all unnecessary debugging output, except, for each employee, make the simulation report all arrivals and departures of people from places and the times at which they occur.
A student asked: The place.arrive(person) and place.depart(person) methods do not have a time parameter, so they cannot be called from Simulator.schedule().
This is correc. Not all methods are scheduled at future times; arrive and depart make immediate changes to the state of the model. They are designed to be called from methods of class Person (or anywhere else) that are scheduled.
A student asked: Do you want us to use arrive and depart to ...
As I said in lecture, I have deliberately left many design decisions to you in this assignment.
A student asked: What should the output look like.
The assignment said to delete extraneous output, so all we need to see is the employees commuting to and from work. Remember, all the output you are producing up to this point is just debugging output so you can convince yourself and us that the simulator is working, at least as far as it goes. Nobody wants to wade through reams of extraneous debug output.
It even makes sense to simplify the to-string methods of people and places to their default form. I simply commented out about 4 lines of code in my solution so I could focus on the output that told me about commuters.
A student asked: Can we change arrive(p) and depart(p) to arrive(p,t) and depart(p,t) where p is the person arriving or departing this place and t is the time at which this happens?
Yes. This makes sense, particularly in light of the output required in item f) above.