Traffic Simulator

The traffic simulator is a great exercise in software engineering while using programming patterns. The purpose was to take an idea and then create a complete software product.

In this simulation there is a traffic grid with a variable number of north/south and east/west roads. All roads are uni-directional and a single lane of traffic. Cars do not turn, but stay on the same road in a constant direction.

There are two traffic patterns that the controller can chose from:

cog0 Simple : All roads go in the same direction from source to sink
cog0 Alternating : Roads alternate the direction from source to sink


Each car has multiple properties which are within a random range of preset values:

cog0 Max Velocity : Meters/second
cog0 Brake Distance : If the distance of the next car is less than the brake distance, the car will slow down
cog0 Stop Distance : If the distance of the next car is less than the stop distance, the car will stop


Road intersections contain a traffic controller with individual light durations:

cog0 North/South yellow : Duration of light phase in seconds
cog0 North/South green : Duration of light phase in seconds
cog0 East/West yellow : Duration of light phase in seconds
cog0 East/West green : Duration of light phase in seconds


Many of the parameters are configurable in the simulation:

cog0 Simulation time step (seconds)
cog0 Silulation run time (seconds)
cog0 Grid size (number of roads)
cog0 Traffic pattern
cog0 Car generation delay (seconds/car)
cog0 Many more!


Patterns were used thoughtout the simulation:

cog0 Observer is used for realtime graphic updates
cog0 Null object is used for the end of a road and red lights
cog0 Proxy is used for the light road segment
cog0 Singleton is used for the simulation settings
cog0 Composite is used for roads and all the segments of the road
cog0 Factory is used to build the cars for the road segment
cog0 State is used for the intersection lights


JUnit tests were written for each subsystem.


Specifications:

cog0 Programmed in Java
cog0 Swing interface
cog0 Code by Patrick Levoshko
cog0 Many different patterns used
cog0 All major objects have JUnit tests
cog0 Some UML class diagrams
cog0 Code available by request