TRAFFIC SIMULATOR

OVERVIEW

This was group project assigned in an upper division software design course at UCI. The assignment required that our group of 6 design a fully functional traffic simulator for use in a civil engineering course. The challenge was to design this application in the midst of changing requirements as a software developer should expect to encounter in the wild.




The simulator is required to track cars going at two different speeds, and accomodate left and right turns. It also must not allow for collisions. At any time, the student should be able to stop the simulation, and change the traffic light behavior or modify the amount of cars entering the map. Each light must also support a sensor, which modifies the timing based on whether or not cars are present. These features represent the final requirements that we eventually designed for.

APPROACH

Our approach was to represent lanes as arrays of Vehicle objects, with Cars and Trucks being to subclasses. This way, we could utilize polymorphism to store each car or truck in a vehicle array and query each one's speed when attempting to move them forward. The algorithm for movement queried each northbound lane before moving on to the southbound lanes and so on. Each northbound lane (stored as a vehicle array) would work backwords, attempting to pull a vehicle into the next spot if that spot was occupied. This approach seemed very intuitive as vehicles cannot occupy spaces which are already taken (would result in a collision).

SIGNAL STATES

RESULTS

Our simulation worked as intended and would provided immense educational value to future civics students. While this was a great learning opportunity with regard to design, it was an even better lesson in working with a team. Up until that point in my accademic career, I was very used to working alone and, quite frankly, strongly preferred it that way. However, I learned that two heads can be better than one, and six can be even better!

Just when I thought our collective minds were set on a certain decision, someone would enlighten the group with a different approach to a specific question and we would all be left wondering why we, ourselves didn't think of that! There's something really special about working with a group of diverse, motivated people, and I believe our end product was far greater for it!