I-35: Texas Parking Lot¶

Sitting in traffic a while back, on my way through downtown on my way to Highland Mall to teach this class, I thought of an interesting simulation we can do as a group project. How about simulating a bunch of cars driving through downtown Austin at “Rush Hour”, with a bunch of on-ramps and off-ramps in the mix. We only need to simulate one lane, since both would be similar.

Note

In Austin on I-35, rush hour runs from midnight to 11:59pm! Don’t believe me? Ask any trucker trying to get through downtown!

Where are the Objects¶

Start thinking about the different kinds of object involved in this simulation.

• I-35: Simple, just a straight line all the cars move along
• On-ramps: Where are they located?
• Off-ramps: Where are they located?
• Cars: Do we need different types?
• Drivers: We definitely need different drivers!

Simulating Traffic¶

We have a fixed length of road to simulate. A car is “active” as long as its current position is between the starting and ending point of our simulation. It moves as time progresses. Perhaps the car will take an off ramp, perhaps not. Cars will enter the road at randon intervals, and exit the road when they reach the end or take a ramp. Some cars will enter the road from the on-ramps.

Drivers behave differently, don’t they. Some are aggressive, some are wimpy. Some drive close to others, some hold back. Some drivers will allow cars from on on-ramp to merge by slowing down for them, others speed up to get ahead. You decide what characteristices we want to model.

We should measure something in our simulation. How about cars per hour that make it out the exits, or net movement per hour. What about accidents, can we model them?

This is as much a thinking problem, as it is a programming problem. We can do this without graphics, or add graphics in as part of the program. Be creative in how you think about this.

Modeling Behavior¶

Many of the “variables” in this simulation need to be modeled with values the range from one level to another. For example, some drivers accelerate aggressively, and brake the same way. Others accellerate more slowly. All drivers have some kind of reaction time to deal with. We can use random number generator to set values for each car to simulate the random nature of real traffic. It will be fun to watch the action when we turn it on (even if we have to do this mentally, if you do not use graphics).

Getting Started¶

To get you started thinking about the design, here is an active project you can look at. This is a heavyweight program, far more complex than we need to consider here, but it will give you some idea on how they went about setting things up. * A Traffic Simulation (ATS)