CSC 270 Assignment 3

Due Wednesday, March 25 at beginning of class.

Start NOW.  You have 19 days.  This assignment will take longer than
you expect.  Note that csc354 has a large assignment due on March 24,
so you should finish early.

Check the newsgroup periodically for bug fixes.  Bugs are guaranteed
to appear in the code that I've provided, which is quite large.  When
I find one, I'll post a fix.  It is very unlikely that these fixes
will be in parts of the code that you're modifying (since that's
restricted to a few functions), so it should be easy for you to
incorporate the fixes that I post.


Scheduler
---------
 
Your task is to implement part of an subway simulation and to gather
some statistics about it.  The simulation has the following events: a
passenger appears, an train advances, and a train departs a station.
A working simulation is provided, which you will modify.  

The simulation draws the subway system on the screen.  Trains move
along the tracks; the tracks change colour based on their status;
subway platforms are coloured to indicate how full they are, and
trains are likewise coloured.

A. Add some trains

Modify the network configuration file, network1, to add two more
trains to the Bloor-Danforth line.  The network1 file has lots of
comments that describe how to do this.  One train should start at the
yongeE platform and head east; the other should start at yongeW and
head west.  Optional: Can you determine why it isn't possible to add a
second train to the north/south Yonge line?  Try it to see what
happens.

B. Passenger Appearances

You must model the interval between appearance times at each station
with an exponential distribution.  See the Readings on how to generate
the next appearance time.  Note that each station stores an array of
means where, for station xyz, the variable xyz.mean[i] is the mean
appearance time of passengers who start at xyz and end up at the
destination station with index i, which is stored in the global
variable allStations[i].

B.1 Modify the function Station::scheduleNextAppearance() to do this.  
    Make sure that your mean appearance time is equal to the value of
    stored in mean[i], for the appropriate i.  You can find i by
    looking at the Station class in station.h.

B.2 Collect statistics about the interval between appearance times at each
    station (regardless of destination) and about the frequency that
    each destination station is chosen (regardless of source station).
    To do this, add a function and variables to the Statistics class.  
    Call that statistics function from Station::scheduleNextAppearance()
    whenever you schedule the next person appearance.  The 
    Statistics::finalReport() function should be modified to output
    the mean appearance time for each station and the fraction of passengers that
    choose each destination station (as a number in [0,1]).  Calculate 
    these by hand from the data in the network configuration file, network1.

C. Accidents

Develop a new event, AccidentEvent.  The mean time between accidents
is 1000 seconds and has an exponential distribution.  An accident
occurs at a platform (NOT a station) that is chosen uniformly
randomly.  The mean accident duration is 300 seconds and also has an
exponential distribution.  When an accident occurs, you must set the
status of the track section (which is adjacent to the accident
platform) to RED only if it is not occupied by a train.  (If it's
occupied, no accident occurs.)  When the accident is over, set the
status to YELLOW (again, only if that section is unoccupied).  You'll
have to set and clear the frozenStatus flag of the track section
appropriately.  You'll have to schedule ANOTHER event that occurs when
the accident is over.

D. Contest

After completing the whole assignment and writing your report, you may
participate in a contest.  There will be two prizes.  One prize will
be given for the most interesting network configuration.  Submit a
file called 'neatNetwork' with the rest of your code.  Another prize
will be given for set of train routes that results in the minimum
average trip on the network described in 'network1'.  You may use as
many trains as you wish.  You may split track sections into many
sections.  You may add switches between main lines.  Submit a file
called 'fastNetwork' with the rest of your code.  I'll show both
winners in class.

Your Assignment
---------------

1. Copy the C code into your directory:

     % cd
     % cp -r /u/jstewart/270/hwk3 ttc

2. Go into that directory and compile the files:

     % cd ttc
     % make

   If you want to make the program without OpenGL graphics, do this
   instead:

     % make -f Makefile.nogl

3. Run the working program that I've provided:

     % ttc
     % ttc --          gives a list of program options
     % ttc -r 5        report interval (larger = faster animation)

   If you get a error that looks like

       ld.so.1:   ....   can't open file: errno=2

   add the following line to your ~/.login file:

       setenv LD_LIBRARY_PATH /u/jstewart/Mesa/lib:/usr/openwin/lib

   and log in again.

4. Read and understand the network1 configuration file.  Do Part A.

5. Look at the following *.C and *.h files: main, section, controller,
   defs, xy, events, passenger, station, platform, statistics, scheduler,
   train.  Read ALL the comments at the tops of the functions and in the
   class definitions.

6. Think about how you're going to do Parts B.1, B.2, and C.  Think lots.
   Time spent thinking will make subsequent programming much easier!

7. Implement Parts B.1, B.2, and C.  Do these one at a time, from
   the easiest task to the hardest, and test each thoroughly before
   proceeding to the next.

8. Write the report.

Testing
-------

Run tests of your modified code with the original network1 file, as
follows:

  % ttc -e -t

Record your statistical output.  Do the same for some modified network
file that you make.
 
Report
------

Use clear and concise English in your report.  Poor or obscure English
will be penalized.

R.1. Describe, without pseudocode, how you generate random appearance times
     that satisfy the constraints above.  One paragraph only.

R.2. Include your statistical output and discuss it.  Include the modified
     network file from which you gathered the second set of statistics.  
     Discuss the conditions under which the subway system will become
     overwhelmed.  One paragraph only.

R.3. Describe and discuss your accident generation method.  One paragraph only.


What to hand in
---------------

Hand in on paper:

1. Your reports described above.
2. The modified network configuration file that has two additional
   Bloor-Danforth trains (Part A).
2. Listings of ALL the source files that you modified, and ONLY those 
   files (Parts B.1, B.2, and C). Highlight by drawing a line on the
   left edge ALL the parts that you modified.
3. Printed output of your statistical output, and the modified network 
   file that you used for the second statistical test.
4. Tape the sheet below to an envelope put your assignment inside the
   envelope.

Hand in with the `submit' command:

5. All the files necessary to compile and run your programs.  This
   includes the Makefile, since the tutor will execute

     % make

   with the files that you submit.  If the compilation fails, you lose marks.

To submit, go into the ttc directory.  All the necessary files must
be in that directory (including a README file, if you wish).  Execute

  % make clean

which removes all *.o and *~ files.  Then execute

  % submit -N a3 csc270h *

Contest
-------

Only consider the contest after you've completed the assignment and
submitted it electronically and written the report and put it in the
envelope!  If you enter the contest, submit one or both of the files:
neatNetwork and fastNetwork.


CSC 270, Assignment 3 Cover Page: due Wednesday, March 25 at beginning of class

 
Surname _______________________________ Given Names _______________________

 
Student Number ________________________ CDF Login -------------------------
 

TA's name _____________________________ Tutorial location _________________
 
 
I declare that this assignment is my own work and is done in
accordance with the University of Toronto Code of Behavior on Academic
Matters, the Code of Student Conduct, and the guidelines for avoiding
plagiarism described in the course policies.
 
I discussed this assignment with the following people:

 
______________________________________________________


______________________________________________________


______________________________________________________
 
 
 
Signature ____________________________________________
 
 
 
GRADING
-------


Report
------

R.1  Random appearance times                    /  5

R.2  Statistical output                         / 10

R.3  Accident generation                        / 10

     Report readability                         /  5


Correctness and Efficiency of Program Code
------------------------------------------

A    Two additional trains                      /  5

B.1  Passenger appearances                      / 10

B.2  Statistics collection                      / 15

C    Accident events                            / 20

     Program style, including comments          /  5

     

     Total                                      / 85
