Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Started With Traffic Simulation in JavaScript

I am going to be asking a lot of questions in the upcoming months. For my ninth grade science fair project I would like to create a traffic simulator in order to test whether or not interconnected communicating traffic lights can increase traffic flow. I have a couple of generic questions that I need help with...

  • How would I represent roads?
  • How would I make car follow a road?
  • How would I make a car switch lanes or roads?

I am not looking for specific code, just good pointers and resources to help me get started. Any help is appreciated, C.Ruhl.

PS I am only in high school so no advanced math notations please :)

like image 561
Conner Ruhl Avatar asked May 15 '11 06:05

Conner Ruhl


1 Answers

One possible approach which is taken quite often is to use a discrete model for roads and cars' positions.

Road representation

Each position on the road can either be occupied by a car (blue dot) or be empty. Cars move at discrete time steps by exactly one position (if the target position is empty) along the given arrows. Thus a car can even switch lanes if it would otherwise have to slow down or stop.

You can further improve it by using separate timesteps per car (simulating faster/slower cars) or in many other ways.

After you've defined your roads (i.e. the positions and their follow-up positions) by an appropriate data structure this model is relatively easy to simulate but already shows interesting effects.

like image 78
Howard Avatar answered Oct 20 '22 22:10

Howard