3

I want to write a simple traffic simulation with one road intersection. First I thought of a cellular automata in the model but it should not be limited by an underlying discrete grid system so the streets could be more independent to location or levels. Currently I can think of three approaches and I would like to get your thoughts on it.

  1. Street as Entity An agent is part of this entity when it's driving on it.

  2. Intersection (or Endpoint) as Entity An agent drives from endpoint A to B.

  3. Intersection and Street as Entity Merged Point 1 and 2 in one system.

This reminds me somehow about the benefit of a Moore vs Mealy machine (States vs. Transition). What do you think would be the best representation to go with. As mentioned, the entire system should be not just limited by discrete values because I would like to animate the transition of the agent from street A to B. Any ideas appreciated.

closed as too broad by kevin cline, user40980, gnat, GlenH7, Kilian Foth Jan 1 '15 at 13:32

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Road traffic has been extensively studied by hundreds of researchers for years. What makes you think a programmer is the adequate person to ask? To put it differently, do you have a model in mind and want to implement it? Or maybe you want something simpler than [article name, year] because [reasons]? – Tibo Dec 20 '14 at 22:32
  • Sorry, I don't get your comment. Why I want to ask a programmer? Because it's a programming related question? I noted down some thoughts in my question about my ideas how the model could look like and I am interested about the feedback from developers how they would implement it. – seb-mtl Dec 21 '14 at 0:08
  • I meant that it could have been a programming problem if you had a model in mind and having trouble to implement it. As such your question does not really show that you do. There is a lot of available litterature on the topic, so either you have a paper in mind (relying on "entities" and finite state machine) or you are diving too fast on implementation issues rather than looking at the big picture. In any case you need to refine your question - my 2 cents. Sorry if I sounded harsh, this wasn't my intent. – Tibo Dec 21 '14 at 17:09
5

Just some thoughts.

(Mandatory disclaimer: use of the information for purposes other than strictly personal use or entertainment, or use for purposes that may harm safety or cause loss of assets or life, is strictly forbidden.)


Since I'm not certain about what you mean by "entity", I will just list the properties (model and behavior) a person (who can code) would naturally expect from these road structures and vehicles.

Streets, a bundle of lanes

  • Streets can be one-line, multi-lane, single-direction or bi-direction.
  • For simplicity, let's discount lane-changing behaviors and all sources of obstructions:
    • Entering of vehicle from a lot into a lane.
    • Exiting of a vehicle from a lane into a lot.
    • Lane-changing in general.
      • Multiple vehicles are allowed to enter one street in one direction, being initially assigned a lane number from 1 to N.
      • Upon exiting from the other end of the street, these vehicles can be found to have magically switched lane assignments.
      • For simplicity, the simulation will not look into how that happened.
    • Lane-passing.
    • Parking on the curb, and the occasional slight traffic obstruction it causes.
    • Jaywalking pedestrians

Lane, a one-dimensional position on a curve.

  • Mathematically speaking, the (traversal) position of a vehicle on a lane is a real number between 0 and x, where x is the physical arc-length of the lane (one stretch of a street).
  • While a vehicle is on a lane, it will have an instantaneous velocity, and also an acceleration/deceleration (rate of change of velocity).
    • For simplicity, let's discount rotational mechanics, torque, turning radius, or rollover (accident).
    • The simulation will treat all lane traversals as strictly linear motion as far as the physics is concerned.

Intersection, a complicated Venn diagram of exclusive zones

  • Even with the most simplistic simulation, we must agree that we can't let north-south and east-west traffic flowing at the same time. If it is so, it would not be an at-grade intersection; it would be an overpass or underpass.
  • Below we make the typical assumption of a four-way intersection, i.e. having four ingress (incoming) and four egress (leaving) directions.
  • 4 x 4 makes 16 possible vehicle trajectories. (This includes U-turns.)
  • By using pen-and-paper, one can work out the exclusion rules that allow different combinations of these trajectories to be used at different traffic signals.
  • A vehicle entering the intersection will have a velocity
  • Each trajectory takes a certain amount of time to traverse given a velocity. Work backwards and one can get a fake "length" value.
    • It is common knowledge that a vehicle must slow down upon entering an intersection and return to normal speed upon exiting, but for sake of simplicity it will be omitted from simulation.

How do I run a simulation, with many agents, with time, and with many different lengths and velocities?

Two ideas come to my mind.

  • Finite, fixed time-steps. Say, by the second.

    • At the current timestamp, calculate where each vehicle will be (position, velocity and acceleration/deceleration), and what the vehicle's steering and gas pedal behaviors will be (based on each agent's received stimuli)
  • Event-based time simulation.

    • For each agent, one would forecast the next future timestamp at which one has to re-examine the agent's whereabouts and responses. Store this future timestamp ("event") in a priority queue.
    • After forecasting future events from all agents, the agent with the nearest timestamp will be processed. The vehicles surrounding the agent will also have their status updated. If all calculations work out to be correct (no conflicts), the global simulation timestamp is updated, and the next future timestamp will be picked from the queue and processed.
  • Great collection of ideas! Thanks! With entity I ment the elements of the model - so if streets, edges or both should be part of the class diagramm. – seb-mtl Dec 22 '14 at 12:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.