Java - Traffic Simulation

 

This is a project of CS699 at George Mason University in Fall 1997. It is a good example of using multi-thread programming technics.

The project tried to implement a Traffic Simulation. There is a narrow light-duty bridge on a public highway. Traffic may only cross the bridge in one direction at a time, and if there are ever more than 3 vehicles on the bridge at one time, it will collapse under their weight. It takes 4s for a vehicle to cross the bridge.

"Fair" traffic control policy imposes a limit (say 4) on the number of vehicles that can cross the bridge in one direction, while vehicles traveling in the opposite direction are waiting to get on the bridge. If there are no vehicles waiting to get on the bridge in the opposite direction, the policy should not switch the directions. On the other hand, "Exhaustive" policy means, once vehicles in one direction get on the bridges, the policy will not switch directions until all vehicles pass the bridge in the same direction.

Total 20 vehicles arrive in three schedules:

  • 5*4 (10)
  • 10*2 (10)
  • 20

The first number indicates the number of vehicles arriving simultaneously at the bridges, while the number in parentheses indicates the delay before the next arrival. The second number shows the times of arrival. Under schedule (3), all 20 vehicles arrive at the same time.

You have several choices of the control policy limit and schedules. Press "Start" button to see the simulation. Press "Pause" button to suspend the simulation temporarily. You may press "Start" button at any time to restart a new simulation.