Designing Software  «Prev  Next»

Traffic Flow System - Exercise

Objective: Finish your traffic flow system.

The traffic simulation is designed to run with no input from the user. Since we are deliberately avoiding the complexities of coding a graphical user interface, we will hard-code the length of time (number of seconds) the simulation runs as well as the relative percentages of cars, buses, trucks, bicycles, and pedestrians in all directions.
  1. Set the simulation to run for 600 seconds (ten minutes). You will need to construct a SignalMediator, the four vehicle queues and the four vehicle factories that go with them.
  2. Make 10% of the vehicles in north and south bicycles, and the rest pedestrians. Use the default frequencies of cars, buses, and bicycles for the east and west roads.
  3. Assume that a "vehicle" enters from the north approximately once every one hundred seconds, from the south once every fifty seconds, from the east once every twenty seconds, and from the west once every thirty seconds. Note that these are only average times.
  4. For output, every second (simulation seconds, not real seconds) list the current time, and the length and number of vehicles in the east and west queues and the combined number of pedestrians and bicycles in the north and south queues. (Since pedestrians tend to bunch up, their queue length will almost always be effectively zero.)
In the text area below, type in or paste your answer and click the Submit button.