Hacker News new | past | comments | ask | show | jobs | submit login
Traffic Simulator (traffic-simulation.de)
542 points by eecc 9 days ago | hide | past | favorite | 140 comments






Unfortunately CS suffers from many "dumb computer tricks". The pathing algorithm is open loop, often causing huge 1 lane jams even though it would be more efficient for through traffic to use other less congested lanes. You end up needing to create crazy unrealistic spaghetti interchanges in order to trick the AI into behaving

Having watched way too many Biffa vids. The way to fix that is to create/force dedicated turning lanes. There is a plugin that lets you manage it. It should be built in. If you do not have the plugin sometimes you can fix it by changing the number of lanes on both sides of an interchange (what biffa calls lane mathematics). Basically if you have 3 lanes merging into 3 you need a 6 lane on the other side. If you have 6 and 3 dumping off you need 3 for both exits. That does not fix 4 way intersections though and usually you need the plugins to fix that.

I have tried this method, and it does indeed work (TM:PE is the mod I think you are talking about). But at some point the sims have to change lanes to get into the correct one to turn, unfortunately they wait until the last possible moment to switch, causing huge traffic issues. On top of that the sims still prefer a single lane even if you do the lane mathematics. A 6 lane freeway, splitting to a 2 lane and 4 lane doesn't help when the sims still insist on using 1 of those 2 and 4 lanes.

TM:PE allows to forbid lane switching close to the intersection forcing them to pick a lane earlier at higher speed and not break the flow.

To do so use the yellow+red circles tool, pick a road node and press Shift+S. Repeat until traffic goes smoothly.

Demo https://youtu.be/ex2PfNktryk?t=1260


This is another thing they do in Washington D.C. that really annoys me. GPS tells me that I need to turn left ahead, no problem I work my way over to the far left lane. However when I get near the intersection it turns out I needed to have turned into parallel side street a quarter mile back. Other times those side streets are really long freeway ramps or turn off before the left turn. Other times they stop traffic at the intersections and you have to turn left across multiple lanes that don’t turn left. It’s a wildcard every time.

This methods does not always work if the intersections are too close to each other in some small edge cases. You usually just need to space things out more which will in turn tear up part of your city.

Another method he uses with that mod is to sometimes not allow changes anywhere on the road. Then he forces them to pick a lane when they cross an intersection that connects to the road.

Also along main roads with lots of intersections he has all the feeder roads yield and tells all the intersections to go on through.


Oh yeah! That is usually what I end up doing, but even as you forbid lane switching on the nodes preceding the turn, the sims still will all switch lanes at the node closest to the turn which does not have lane switching forbidden. Causing the backup to happen, not at the exit, but 3-4 nodes before the exit! Lol, I don't know how to solve it

A good way to handle that is to make sure they pick their lane at the start of the road (if you can). You do that by having no lane switching except at entrance intersection. Does not always work but does sometimes. Another trick he has used sometimes is 2 lane picking. Basically you can only 1 lane at a time. The thing will sometimes get confused and try cutting across 3 lanes of traffic holding up all 3 lanes. He usually stacks 2-3 of the 1 lane switches after each other and that sometimes clears it up.

I agree, Computer Science does suffer from many dumb computer tricks.

Wait a second. Ah well, point still stands.

E: It was a joke...


about the one lane backups, one method that i employ are 3 lane roads, all only lanes and by use of TM:PE, say do not switch lanes for 5 points before intersection, forcing traffic to use all lanes.

A/B Street is much, much more ambitious as far as traffic simulation goes, but still in progress.

https://github.com/dabreegster/abstreet#ab-street

If someone is looking for interesting Rust project to contribute (also as a beginner) I really recommend it. Author is great, friendly to PRs (what includes PRs made be programmers with no Rust experience).


That looks really cool! I hope they finish it.

I don't think traffic in Cities Skylines can count as "nice". I quit playing CS because I spent 80% of the time fixing the traffic. It gets exponentially harder as your city gets bigger. I found myself using extensions to designate lane change rules, set precise traffic light time periods, etc. It was time consuming and the fun was lost.

The cars in the demo seem much much smarter.

EDIT: typos.


Hehe, traffic management is really the only challenge in that game. Otherwise its almost a sandbox city builder.

The challenge I happily took is to grow the city. I'd expect if the layout of resources is not balanced, people will move out. But it turned out people move out because of the traffic??

Check out ABstreet as well on github:

https://github.com/dabreegster/abstreet


BTW the M1 Macs run Cities Skylines beautifully through Rosetta 2. I lowkey wanted to try it for years and now on the M1 Air I can and the game is just amazing.

I have a base spec 2017 iMac and it runs City: Skylines smoothly. It's not a particularly hungry game.

City Skylines traffic simulation is mediocre at best. This project is extremely impressive. I sat and watched the traffic simulation for 15 minutes before I realized it.

In the first video a bunch of cars are crowded in one lane of the double lane road (a problem that plagues much of the traffic in the game)

Things like this are cool. What I would be curious to see though, rather than setting global parameters (i.e., politeness), would be to have each agent have its own politeness score (as well as other attributes). Models like the one linked to here work as if each agent is a particle, rather than autonomous decision-maker adapting to their circumstances locked in long-term, iterated games with other anonymous drivers.

This way, agents would adapt their attributes to maximize their own local advantage, and therefore could see how large scale trends develop. I've driven in many countries and regions within countries, and it's just wild how "driving cultures" vary so much. Some places the drivers are so polite to the point it really makes things dangerous, other places the drivers are vindictive (distinct from being aggressive driver). It would be interesting to model how driving cultures emerge.

Edit: I guess the short story is I'm really curious why some places, like Bangkok driving is chaotic, dangerous, gridlocked, and no one adheres to traffic laws much or yields to pedestrians, but relatively devoid of road rage (and people will let you merge over if you need to). In DC, people carefully adhere to red lights, stop signs, pedestrians, etc but will go far, far out of their way to block you from changing lanes once they see your turn signal go on.

Also, exploring the game theoretic (probably prisoner's dilemma?) aspects of tailgating and how that seriously depends on the driving culture. When someone tailgates, the tailgatee can slow down (everyone loses), speed up or move out of the way (tailgater wins/tailgatee loses), etc. If everyone slowed down when tailgated, there would be no benefit of tailgating; if enough people give in when tailgated, that keeps rewarding the behavior. Anyway, that would be something fun to explore in one of these traffic simulations.


> In DC, people carefully adhere to red lights, stop signs, pedestrians, etc but will go far, far out of their way to block you from changing lanes once they see your turn signal go on.

The last part, yes, but the first half has very much not been my experience here in DC. I usually see at least one driver blow a stop sign, red light, or one-way street before I make it 2 blocks from my house. The other thing I found amazing is that it's totally normed that you can just park in the traffic lane whenever you want — not just FedEx/Amazon but I've seen people park downtown at rush hour, get their dry cleaning, and get back in their car as if it was normal.

I think the main cause here is that we have a bunch of poorly-trained commuters from suburbs where they're used to high speed limits and wide, less used roads but the traffic means they're lucky to average 5mph on their commute into the city and a certain fraction of people cut any corner they can because they think they're owed a higher average speed. They're “running late” every day because they don't want to admit that their “30 minute commute” is off by a factor of 2-3. I'm curious whether the pandemic will lead to people trying to stay at 100% telework after realizing how much better life is without spending a couple hours a day stuck in traffic.


This would be a neat reinforcement learning project.

> Some places the drivers are so polite to the point it really makes things dangerous

I've known people like this, who will approach a 4-way intersection and stop even when they don't have a stop sign and the perpendicular street does.


Places where I've seen it, people who have the right of way take that to mean they get to play "traffic cop". E.g., at a 4-way stop the "extra polite" person who gets there first, instead of going through the intersection first, waits and waves the person who does not have the right of way to go through first, which makes that person (and everyone else) confused, and then causes a lot of slowdown, frustration, etc. Of course only happens in certain locales, where it's part of the local driving culture.

Or they slam on the brakes at the end of what should be a merging ramp or lane because the fore and aft distances to the other traffic that were good enough for the prior N people would be too close for them.

Well to be fair the distance most people feel fine with is not near what is safe.

this has always bothered me.

if you have the right of way, and you do not take the right of way, in most cases you are effectively disobeying traffic rules and disrupting the flow of traffic.


In rural areas where this is common there isn't traffic. Thus the politeness doesn't cost you anything. Also in those rural areas it is somewhat common for someone with the right away to have a reason to drive much slower than the speed limit and so giving up your right away makes things better for everyone - the other person doesn't have to try to pass you latter.

When there is traffic you giving up the right away is impolite to the person behind you and shouldn't be done. unless traffic is so heavy that you won't be able to move, and so you should give you your right away to someone who can go.


> Also in those rural areas it is somewhat common for someone with the right away to have a reason to drive much slower than the speed limit

Why does living in a rural area make someone more likely to have a reason to drive below the speed limit?


Because they often are farmers with equipment in tow that is instable at speed. 20mph (40kmh ?) Is too fast for a hay wagon.

> who will approach a 4-way intersection and stop even when they don't have a stop sign and the perpendicular street does

Not the main point but I never liked how traffic signs aren't affirmative sometimes. In the case of the 4-way usually the stopping direction have a stop sign with a missing "All Way" sign below it. But thats not required in all jurisdictions. Nor is the non-stopping direction 100% sure their stop sign is still visible (shrubs, weather, etc) and can proceed at regular speed.

I'm sure there are a ton of reasons for the way things are, I just think the outcome is you can't really ever be 100% sure what the correct thing to do is without slowing down and observing.


Speaking as someone who recently blew through a 4-way stop with other cars waiting, because the setting sun made it hard to see the stop sign, yeah, there are no shortage of human factors at play.

Stop signs are the shape they are so you can recognize them from the reverse for this purpose

Hard to recognize them from the reverse when they're hidden behind a bush!

Participating in traffic all comes down to being as predictable as possible, I think.

Yep. I prefer the driving rule, "Don't be nice, be predictable."

That is, don't deliberately be mean, but don't extend any courtesy where doing so would come at the cost of being predictable.


Yes, but in a way that's obvious to other drivers.

Driving decisively is more important to overall safety than driving defensively.


*and people on foot or bicycles

> Some places the drivers are so polite to the point it really makes things dangerous

I live in a small town that has extra polite drivers. It was really confusing for a while. Eventually I realized that it was a practical response to the overall street layout, with a limited number of main streets, and different areas of town not being well connected. Stopping to let others cross improves the overall traffic flow - if no one did it, traffic would just be backed up for miles.


> I'm really curious why some places...

Based on my experience of living in different countries, differences in behaviour and car culture are often underlined by hidden aspects of legislation which support those differences. I'm thinking more in terms of who is liable in the event of a crash, rather than the actual traffic rules.

>Some places the drivers are so polite to the point it really makes things dangerous

I think the danger you are talking about generally comes from the lack of anticipation and lack of meeting expectations, rather than the politeness.

If you shock a driver's expectations, that will at least appear dangerous, because they have to consciously react (or crash). A Bangkok-style driver in DC is dangerous, just as a DC-style driver in Bangkok is the dangerous one.


It would be cool to study things like politeness, top speed, acceleration, etc in different cities and then create traffic profiles that represent these cities and see what kind of tweaks can improve each one.

I love these little simulators because while they purport to show that slower more polite driving is more efficient, more often than not they show the exact opposite. Want to shove the most cars through per hour? Remove the speed limit. Accelerate and brake like every intersection is a drag race. Leave absolutely no distance between cars. And dump any notion of polite lane changes. NASCAR was right: Minimize unused pavement. The most efficient way to move large numbers of cars down a road is at 200mph with only inches between each car.

That's because these simulations don't include inattentive drivers. They assume everyone behaves ideally.

Normally all those things you said would result in accidents. If the simulators randomly added delays for cars braking or starting up, and then kept a death count, it would be more accurate...


Hell screw the death count, just a graph of average commuting time becoming unbounded would be enough to get people on board.

A pet peeve of mine when I still drove was when drivers would leave 1-3 car length's in front of their car when stopped at a stoplight. And then after the car in front starts moving, it'd take them a solid second to start inching forward also.

The bigger problem was that this type of behavior was the norm to the point where at slow speed intersections with stoplights (e.g. city streets around college campuses), only a single digit number of cars would be able to go through per green light.


Or worse yet, they leave so much space that they don't trigger the sensors. That can mess with the traffic management scheme, sometimes preventing a light from ever changing.

> And then after the car in front starts moving, it'd take them a solid second to start inching forward also.

Indeed, the most influential slider in the simulation seems to be the “max acceleration” one... if people accelerate quickly up to their max speed it seems to prevent traffic waves from propagating backwards. It meshes well with my observations 213929387 years ago when I used to drive in traffic.


Putting more people through per stoplight doesn't really change much. You just get more people at the next stop light. The light is by far the limiting factor, not the drivers. That's why polite driving actually helps, because you get less people blocking each other and less mishaps, the things that actually slow everything down.

You've never been stopped at a light where the queue was many multiples of the number of cars that could get through in one cycle?

Or more infuriating, when you want to make a left turn, but the dedicated lane for that is unreachable until the queue in front of you moves through the intersection. And some inattentive driver ahead misses the light and leaves you with an opening that is exactly 1 foot narrower than your car.

That still doesn't mean someone leaving a bit of space or a few seconds time between you and the light changes anything. You're still just going on to another stop light afterwards, which is a much larger limiting factor and the de facto limiting factor in traffic design. Too many people misunderstand this, leading to unnecessary aggressive driving. Understanding the basics of traffic mechanics should really be part of the exam in getting your licence.

One solution might be to characterize individual drivers (agents) by running an RL experiment that mimics the interactions of individual car drivers. If the reward function is made to compare traffic patterns of the simulation vs real life, then eventually the RL model (a combination of agents) should converge to how humans drive.

So you would have various transition probabilities of a car driver moving from an attentive state into various inattentive states, with drivers having different reactions in each state.

It would also help to have a level of "variance" in individual drivers. So instead of having a bunch of drivers who are just as likely to make mistakes, you have some who transition far more easily into inattentiveness and some whose likelihood of damage/nuisance is higher than the standard driver when inattentive.

It seems entirely doable. (famous last words)


These type of models are done to death in traffic and other social models. Just look up “agent based modeling” and read to your heart’s content

> they purport to show that slower more polite driving is more efficient

Where are you seeing this?


In this instance, upping the politeness bar seems to reduce traffic ...

Adjusting it in either direction seems detrimental.

hmm. it could be an interaction with some of the other settings I was fiddling with, i.e. could make it better in some conditions but not others.

The comment I was responding to indicated the opposite.

Looks like maxing out acceleration solves all other problems. I guess we should require a minimum power-to-weight ratio for cars from now on.

I've made the same observation. But I don't believe human drivers could reasonably take advantage of high acceleration, at least not as well as the simulated cars here. This is a great showcase of the usefulness of autonomous cars, though. Take humans out of the equation and traffic will flow.

The other thing that really seems to make the biggest difference (in combination with better acceleration) is following distance, which is another thing that presumably gets less important with autonomous cars because you don't really have to account for a relatively slow reaction time or poor braking.

The observation on acceleration does make me wonder whether teaching proper merging etiquette better (reach freeway speeds before you're at the merge junction) would make a significant difference if properly followed.


How do autonomous cars deal with cheap or worn tyres? Is there still a lot of allowance for braking distance?

Or weather/road conditions. Reaction time is irrelevant if you happen to be driving over an irregular/wet/oily/sandy/etc section of roadway at the moment maximum braking force is demanded.

A burnout at the beginning of every drive cycle would do wonders for calibration.

Autonomous cars still need to have adequate following distance. Without that one small problem turns into a 10+ car pileup.

Autonomous cars would be in contact with the cars ahead so it would react to car 1 braking, not number 9. IMO we will see this years before we see actual autonomous cars, no matter what fever dreams Elon Musk have.

This would actually be possible to implement with the general switch to electric cars...

What about electric trucks? I set the veh/hr to max and then when I changed truck percentage to 14% I almost immediately stopped traffic at the onramp as the trucks inevitably don't have enough space to accelerate from the meter point. Especially if one of the cars cuts the truck off.

Maxing out 'politeness', 'acceleration', and 'inflow' I could achieve nearly 7000veh/hr.

Probably impossible, since it would cause heaps of rear ending accidents. Maybe if driver assist features both prevent lane changes and optimize avg. speed.


In practice that would mean a lot more head/tail accidents, I've seen that happen plenty of times in traffic jams from over-eager drivers, sudden stops (either people trying to go too fast or not paying attention), etc.

Easier to do with self driving cars, and can probably be attained with Level 3 autonomy.

Yeah, and there would be no reason to increase acceleration -- increasing the acceleration only aids in this project because it shortens the time when the car behind the stopped car in front of it can get up to speed. If the cars are all talking to each other -- they can all start accelerating at the exact same time and rate as soon as the light turns green etc.

There's also the frequent problem of split attention when you're accelerating like that. Often you may be trying to change lanes, and checking a mirror for an opening. Even without that kind of better communication, computers are just better at tracking multiple data points at once.

That's true only when every car is a self driving car. In the interim, if only a subset of cars is running Level 3 autonomy, then including a quick acceleration into the adaptive cruise control is a good way to minimize these phantom traffic jams.

Not to mention killing a lot more non-car road users who don't have access to the same acceleration.

Turning the politeness down to zero really messes things up for everyone. There's a lesson in there somewhere...

I found that changing the politeness in either directions causes traffic jams. But I feel it happens faster if you decrease the value (but I'm not sure). Also it's best to set "timewrap" to 20 times to see the effects quickly.

Perhaps these questions are appropriate for this post.

I'm beginning to delve into this space and I've not managed to get any satisfactory answers to these questions, despite my month(s) long search.

1) How does one build a traffic (i.e state-space system), forgetting the visualization aspect of things ? Just generating sparse matrices, and adding elements to interact (add/subtract) from these matrices would be a great start! Any way to do this in a compiled language ?

2) Are there any libraries out there that help you simulate traffic in an existing network of roads, extracted from OpenStreetMaps perhaps?


1) There are different choices you can make about simulating individual agents or aggregate flows along roads. Assuming you're interested in the former, you can advance the simulation in discrete time-steps using approaches like the intelligent driver model mentioned in another thread. Chapter 4 of https://apps.cs.utexas.edu/tech_reports/reports/tr/TR-2157.p... is a different approach to the discrete time system that tries to handle complications that come up when applying to OpenStreetMap, like having a vehicle cross multiple roads and intersections in a single 0.1 second timestep, due to really short roads. If you're willing to throw away detailed movement (including acceleration and lane-changing), you can try a discrete-event approach, where you say "this vehicle enters one end of a road at time t, don't calculate anything for it until t + best_case_time_to_cross". https://dabreegster.github.io/abstreet/trafficsim/index.html has some ideas there.

2) Another option with much less detailed traffic simulation, but much more UI focus, is abstreet.org


This doesn't exactly answer your question, but what I settled on during my dissertation (granted, that was a few years ago now) was SUMO: https://www.eclipse.org/sumo/

IIRC you could import maps from from open street map, but I'm not sure if it has a "headless" mode, without all the visualisation.


having your route to office simulated with this would be super cool on osm

On 2) there's Matsim and AequilibraE off the top of my head.

For 2, Eclipse Sumo allows import of a road network from openstreetmap.

Needs an American mode where people don’t know they should stick to the right-most lane, unless passing.

Other uniquely American things:

- Passing on the right

- Taking an exit from the passing lane (cutting everyone off)

- Couch in the middle of the highway


Unfortunately not uniquely American. Experience all of these semi regularly on Australian roads (mirrored of course).

Those are pretty much omnipresent, certainly not uniquely American.

And a Connecticut mode where nobody uses the right lane to pass people who do that.

Just set 'Politeness', to zero: don't touch anything else.....Italy.

*Things have got better year on year, though. I have f+r dashcams - rarely needed, nowadays. If anything, they do ensure I drive better.


Unless you are approaching a red light with a right turn, and intend to go straight. I wanted to turn, now you're in the way damnit!!

To simulate my neighborhood, it needs some parked cars and trees that appear out of nowhere.

The more lanes you add, the more cars you get. Adding more lanes doesn't solve traffic issues.

https://en.wikipedia.org/wiki/Induced_demand#Induced_traffic...


"Induced demand" is just a backhanded way of complaining that more people can be served by expansion of a particular piece of infrastructure that you don't like. Nobody ever complains about induced demand on the subway from more frequent service causing more people to decide that's the best option for them.

Rush hour is like pouring a 5gal bucket into a sink. You can't reasonably handle that all at once will have some water in it until it all makes its way through the pipe. But you have to be insane to use that as an argument against making the pipe bigger. Increasing the max capacity of the pipe (so more lanes, in the case of highways) means that it can have normal flow before it starts backing up. The "induces" demand because at the margins some people who were voluntarily changing their usage times to avoid the peak hours will commute at peak hours.

I am intentionally trying to use generic language here because this isn't a unique phenomenon to highways.


The issue with widening highways is that traffic doesn't exist in a vacuum. You aren't widening the surface roads that back up into the highway or the interchanges to other highways, that is the crux of traffic. You widen one pipe but it feeds into the same set of narrow straws anyway, and your sink is just as backed up.

Still, this is an argument for upgrading all "pipes", not one for attempting to control demand on the supply/capacity side.

But even absent that, you want surface, collector, and feeder streets to be the natural "rate-limiting" parts of the network (in that order).

It's why it's especially egregious to wave-in people from a driveway or parking lot into traffic on an already congested street. It breaks the natural rate limiting.

The right-of-way rules are surprisingly well-thought out, from a systems perspective.


most of the surface streets you would want to widen can't be. you would have to take over property or (gasp!) remove parking.

Improving capacity and traffic flow doesn't always have to mean widen.

But the point is that you increase capacities where you can, and that it's better to start large with freeways, etc and work your way down, even if freeway capacity then exceeds feeder capacity (which then exceeds collector capacity, exceeds surface capacity).


More frequent service on the subway doesn't require vast amounts of land to be removed from productive activity. At most it might require a small expansion of stabling facilities for extra carriages and engines.

Induced demand means that when you make the drain pipe bigger, the bucket gets bigger as well, so the sink gets even more full. This is not sustainable.


Why is more utilization a problem? It means more people are being served by infrastructure. Imagine complaining that more people are going to parks because the city turned a bunch of vacant lots into parks.

In the case of things like roads, rails and bus stops more utilization means more economic activity which is a good thing.


More time spent on roads does not mean more economic activity occurs. Time spent in traffic is unproductive.

Also, land used for roads cannot be used for other economic activities.


No, Induced Demand describes the phenomenon whereby the roads eat considerably into the surrounding neighborhoods and get louder and more dangerous while the amount of traffic remains the same.

The problem with individual cars is that they are less efficient than public transport. If you make a city car friendly you are going to see more inefficient cars fill up the existing road. The problem isn't some induced demand meme. It's that some forms of transportation are inherently more inefficient than others. You can solve traffic problems by increasing lanes if you dedicate those additional lanes to public transport.

Here’s a more useful concept than induced demand:

Ever since cities were invented, people have refused to have commutes longer than ~30 minutes each way, on average.

The utility of the city increases with the number of people in the city.

The purpose of the transit system (roads, trains, buses, bike lanes, side walks, ferries, etc., etc) is to increase the usefulness of the city by increasing the number of people that can commute to the city.

If adding more roads, trains, etc leads to more commuters, that means the city is bottlenecked on the transit system, and you need to expand it even more.

The core argument of induced demand is that more roads won’t make your commute shorter. This observation shouldn’t be surprising, since commute times are a function of humans tolerance for long commutes, and have been mostly constant for > 3000 years.


Traffic isn't the primary problem. It is a side effect of mobility, which is desirable.

If Traffic was the primary problem then the solution would be to eliminate roads.


Any idea why the max Accel figure is set so low by default? 0.3 m/s/s requires over a minute and a half to accelerate to 60 mph/100kph.

I'd expect something more like 2 m/s/s (0-100 kph in 14 seconds) if it's a safety-related threshold and at least 1 m/s/s if it's a general operation setting.

That it's set so far away from that makes me wonder if I don't understand what it's used for.


it is odd, especially since the "info" section on the same page lists reasonable figures as being in the range of 0.8-2.5 m/s/s. even 0.8 makes a big difference over 0.3. I can only assume they set the initial conditions to actually result in a traffic jam.

This was first posted without https and with www in 2013. https://news.ycombinator.com/item?id=6756360

I saw a comment about this site earlier on a different thread, so I think someone dug it up because of that.

It seems that decreasing politeness increases lane changing behavior. The effect of reducing politeness is that people in the on ramp get in the highway quicker but the whole highway slows down.

You don't need AI based non linear simulations to see what's going on. The simulation shows that traffic can be described in much simpler terms.

You'll notice that traffic is actually a longitudinal wave that travels through the system. The cars are particles and traffic is crests in the wave.

The wave usually travels backwards against the direction of the cars. The worst type of traffic is when you get a standing wave where the crest of the wave just stays in the same place.

Take a look at the simulation with this knowledge in mind. Then you will actually see the wave.

An elegant solution to alleviating traffic would be to then take techniques that dampen waves in materials and translate them into techniques that work for traffic.


One way to dampen the wave is to leave a lot of space between you and the car in front of you to keep a constant speed.

I do this in tunnels with heavy traffic where I know someone can merge in front of me. I keep a large space so I can prevent breaking and keep a constant speed. I get to the other end at the same time but everyone behind me gets a benefit from my constant speed instead of speeding up and breaking (wave).


On the ring map, with default settings, just stopping traffic with the traffic light for a second produces the dreaded rubber-band effect propagating forever around the circle. Fun simulator!

That behaviour is mesmerising to observe in the simulation.

I've always wanted to program something like this. What are good references to simulation programming to handle this kind of use case?

If you want to build a large scale, real-time simulation with many participants, you might want to check out some paradigms being used in the game development arena. Particularly concepts like Unity's DOTS/ECS approach.

Ultimately, the task is producing a good model of your domain and then organizing the data in such a way that you can quickly mutate a very large number of instances with each tick (if you are seeking real-time).

If you are not seeking real-time, you could probably do whatever the hell you want.


I was also looking to learn more about this. Discrete Event Simulation books may be of some help.

What is the source of the logic for these mechanics? Meaning, how did you model the results of these inputs? Traffic phenomena is really interesting to me. This is a great way to present these inputs and visually present the outcomes.

The author used the "intelligent driver model" (IDM): https://traffic-simulation.de/info/info_IDM.html

It's a system of ODEs that describes the dynamics of each driver. So the inputs are: the parameters of the model and the inflow of cars in the section of road


To model these types of processes people usually use stochastic processes (https://en.wikipedia.org/wiki/Stochastic_process). I don't know what the author used, but seems inaccurate.

Regardless of how I change the map layout, traffic in/out flow or truck/car ratio I seem to get the best results when I crank accel, speed and right bias for trucks to the max and lane-change threshold and following distance to the minimum.

Which makes sense since those are basically the ideal conditions for reducing the number of obstructions low speed (merging, exiting, trucks on grade) traffic poses to higher speed traffic and reduces the effective road area of the obstruction.


You can almost always fix the traffic by maxing out acceleration. Sadly, this vindicates my real world aggressive driving behavior.

Probably you need to add the factor of accidents. Not only do they kill people, they are also the major reason for blocking traffic.

Why is it sad if it turns out a subset of people are already behaving in a way that analysis indicates promotes better flow?

Because aggressive driving is dangerous? Perhaps aggressive driving also contributes negatively to the overall flow in the real world when not everyone drives equally aggressive (i.e. through extra lane switches caused). But I don't know much about traffic analysis so idk.

I don't know if "right bias" is enough to simulate my experience in traffic which includes trying to get in the fastest lane and also trying to get over to the exit for my exit. As well as when my exit is backed up a couple of miles but the lane I'm in is moving faster such that I have to block my lane to wait for an opening into the lanes that will exit.

Reminded of Java simulations that show yielding control of your vehicle 100 yards before a 4-way "smart" intersection can allow the central command to get every car through safely without adjusting anyone's speed more than 5 MPH.

Wish I could find it again.


I would like to use a driving simulator to learn how to drive on the left side. Is there something like that? Good if I would rent a car on Ireland.

Euro Truck Simulator 2 is the most realistic street driving simulator I know of, and it includes roads in the U.K. I found it good driving practice when I hadn't driven for a while (as I don't own a car).

ETS2 only comes with trucks as driveable vehicles. A lot of the skills are the same as driving normal cars, but trucks have more gears, are larger, and accelerate more slowly. Truck cabs also don't have rear-view mirrors; to look backward you have to either use side mirrors or stick your head out the window.

I have seen mods that add normal cars to drive. I downloaded one of those mods but haven't tried installing it. I'm not sure if those mods unlock the cars from the start or if you have to first save up for and buy five trucks to unlock the in-game online vehicle ordering catalog (which takes many hours of gameplay).


Any games out there with good traffic simulation (IE. that doesn't break down as soon as there's a lot of traffic like Cities Skyline)?

My favorite observation is that you can move the 'politeness' slider all the way up - touch nothing else - and watch the world burn.

Love these kind of micro simulations! They really help to discover non intuitive behaviour of complex systems just by playing around. Great job!

This looks really cool! What's the tech stack?

Clearly we just need to make all cars accelerate at 4.0m/s and our traffic problems would’ve solved.

about the one lane backups, one method that i employ are 3 lane roads, all only lanes and by use of TM:PE, say do not switch lanes for 5 points before intersection, forcing traffic to use all lanes.

Okay, this made me dread returning to work and its commute. Stressballs!

This is amazing!! I'm so glad you open-sourced it!

Appears to violate divJ + rhodot = 0.

why....why is this so satisfying??

And that was fun!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: