10 ms·
Abstreet: Traffic simulation game written in Rust
- pmontra 7y agoThe next step would be writing a program to modify intersections, monitor how long cars take to get a journey done and optimize the streets for total transit time, or emissions, or whatever. That's probably faster than letting people discover optima along their usual routes.
- bluGill 7y agoI'm pretty sure that is a NP-complete problem (or worse). Which means on the scale of a city all the computers in the world couldn't solve it in a human lifetime. A small town is easy, but in a large city is out of control. Ignoring that, cities change. You can come up with an optimal system, but people get new jobs, move to new houses, have kids, die, just to name a few obvious things that affect traffic - it might seem minor but they all add up to your optimal system today being wrong for tomorrow. Even ignoring that, budgets are finite. The ideal solution probably is to tear down all buildings, move the mountain a few dozen miles east, re-reoute the river, change the shoreline, and then rebuild. Any one of them is possible on a small scale, but not on the whole thing all at once (you wouldn't move a whole mountain, but we have created passes). Really the best we can do is come up with ideas that are affordable and then test them. One thing this can do well (if the simulation is good!) is let us see if fixing one are makes a different area worse - which helps as talk about the trade offs in the projects we can afford to do.
- dabreegster 7y agoI've brainstormed with some people about trying reinforcement learning. It's not a direction I'm prioritizing anytime soon, but if you're interested in this, I'm happy to adjust the sim and analysis layer to make this as easy as possible.
- arjie 7y agoThis is really fucking cool. And I love your ultimate objective: to allow informed public participation in transport planning. Nice developer info, too. Looking forward to playing with this.
- w0utert 7y agoYes it's awesome! Calling it just a 'traffic simulation game' is probably a disservice to the potential applications of something like this. Very inspiring!
- leppr 7y agoNice work. I'm wondering since this project seems to use its own nicely modularized GUI library, what motivated you in particular to write your own instead of using an existing Rust GUI library/game engine ? And would you make the same decision if you started now (vs 2 years ago) ?
- erlend_sh 7y agoIced has emerged as a strong favorite for game GUIs: https://github.com/hecrj/iced https://github.com/hecrj/iced
- Waterluvian 7y agoLooks promising. But I don't see any sort of XML-like component layout/config so I assume it's all done by calling methods? That sounds kind of kludgy. Or am I missing an example?
- setr 7y agoWhat makes you think xml isn't kludgy
- Waterluvian 7y agoOh it is. And I don't want the XML-style solution. But I don't see any configuration option in the examples other than chaining method calls to set each config option. Is there something else?
- dabreegster 7y agoI wouldn't call the GUI library "nicely modularized" at all. :) I regret rolling my own; the best choice when I started probably would have been https://github.com/Gekkio/imgui-rs https://github.com/Gekkio/imgui-rs. Recently iced has appeared and looks like the most promising.
- noobermin 7y agoIs this is a one person show? If so bravo! It looks like there's a mirror at google though, is this like a mini-google project?
- seeekr 7y agoNot a mirror, it was forked initially from that repo 2 years or so ago when the codebase had just roughly 20 commits, and it the contributor graph shows it is indeed basically just Dustin working on this.
- dabreegster 7y agoI started the project while I was working at Google, went through the open source process, and then left a short while after to work on it full-time. There's no affiliation with Google.
- Tempest1981 7y agoI'm super-curious to hear more about this, in that it's hard to imagine walking away from a significant stable money-stream like Google.
- dabreegster 7y agoIt's a bit more of a story to tell offline. In short, the stable money stream quickly leads to a comfortable savings, giving me time to try an experiment like this. Right now I'm motivated by technically interesting projects that might lead towards good things in the real world, and once I was in a position to realize that, there was no way I wouldn't be working on A/B St.
- deleted 7y ago[deleted]
- farhanhubble 7y agoI swear I was discussing exactly this sort of simulation with my brother as both of us wondered how many city planners model the changes they are making to the road networks before pumping millions into projects that dump traffic from one point to another. Additionally, it'd be interesting to simulate the cascading effect of traffic violations like bad parkings, straddling lanes. Kudos to Dustin for working on this.
- Deutscher 7y agoThere are commercial traffic micro-simulation applications[0] for exactly this purpose. [0] https://en.wikipedia.org/wiki/Microsimulation#Traffic_microsimulation https://en.wikipedia.org/wiki/Microsimulation#Traffic_micros...
- natestemen 7y agoin nyc it's quite common (maybe even required) to run simulations of changes of infrastructure before making them to see how they will effect traffic. source: my partner helps run these simulations as part of their job/their company gets contract work from the city all the time to check changes of bus routes/etc.
- dabreegster 7y agoI've had some trouble getting in touch with the engineers who did this around Seattle. Any details they can share about the software they use, what metrics they base decisions on, where they pull demand data? Any thoughts on making the input and results of these simulations public so anybody can reproduce the analysis, experiment on their own, etc?
- gchp 7y agoCame here to write almost exactly this! I've been thinking for a while now about building a system like this. There is one particular set of traffic lights on my commute which causes 45-60 minute delays at peak times. I've wondered how some small changes to timings of the light might reduce some of that, and was thinking about building something to simulate it and test my theory. The other thing that is interesting about traffic patterns is how truly connected the entire network of roads are. You can have a collision on a major road which has a big impact on roads several miles away. I've always thought it would be fun to visualize that somehow, to determine not just the immediate effects of a change to a road system, but how it effects other commuter routes. Definitely going to play around with this. Kudos to the author.
- chme 7y agoVery cool! That reminds me of Sumo[1] a open source traffic simulator I used at university to import a OSM map of town, populate it with activity based traffic and simulated the traffic under different conditions. While that isn't quite as 'gameified' as this, it was fun! [1] https://sumo.dlr.de/index.html https://sumo.dlr.de/index.html
- BelleOfTheBall 7y agoWhile I'm not overly optimistic about his goal of getting solutions from the game to be enacted in real life Seattle, it's a really admirable idea and an impressive execution to boot. I'm wondering if, with a big enough budget and a team of skilled devs like Dustin here, the local government could create more refined simulations to tackle these planning issues. Or would that inevitably run into the problem mentioned in his Project Mission: 'People are local experts on the small slice of the city they interact with daily -- the one left turn lane that always backs up or a certain set of poorly timed walk signals'? Perhaps, with a large enough data pool, even these small quirks could be worked out via simulation?
- ken 7y ago> Project Mission: 'People are local experts on the small slice of the city they interact with daily -- the one left turn lane that always backs up or a certain set of poorly timed walk signals' 100% of the intersections I see that get backed up are backed up because someone blocks the box. Can we get more enforcement for that? They don't even need a patrol car. Just have an officer stand at the corner of Mercer and Westlake from 4pm to 7pm, and each time the light changes, walk out into the intersection and ticket the guy who's blocking it. You could write $1000 in tickets an hour, every night of the week. Many intersections have threatening signs to this effect, but they don't do any good. I've never seen or heard of anyone getting ticketed for that.
- throwawaysea 7y agoI would be supportive of this as long as it is done with some degree of discretion. On every traffic light cycle each side must release at least one car for the system to work out (traffic light timing must accommodate this). Sometimes that first car has to get into the intersection. I don’t really fault that driver for doing so.
- jeffbarr 7y agoSeconded! I would also like to see some pedestrian bridges or tunnels that would allow walking commuters like me to cross our major streets (Mercer, Denny, Westlake, and Dexters) at any time. This, I strongly believe, could reduce traffic, make residential neighborhoods effectively closer to commercial areas (due to reduced walking time), and improve both vehicle and pedestrian safety. Bridges should be far less expensive than roads, and could be built very quickly.
- pjc50 7y agoAmazing! This is basically a live action more detailed version of Cities:Skylines. That game taught me how much of a blocker traffic turning across other traffic is, and the benefits of one-way systems in avoiding that.
- ken 7y agoThis is pretty cool! One thing that bothers me about every traffic simulation I've ever seen, though: all of the vehicles and pedestrians here seem to be obeying the law. That's just not realistic -- especially on Mercer, which is blocked (both directions) every few minutes in rush hour by some jerk trying to make an illegal turn onto a packed street. I'd say the main causes of traffic blockages that I encounter during rush hour are drivers blocking the box, and pedestrians entering the crosswalk against a red hand. I also see a lot of lane sweeping, too, which I assume is from the influx of drivers from California (where it's legal). I hope traffic engineers aren't making real-world decisions based on simulations that follow all state laws perfectly, but I fear they are.
- blincoln 7y agoI agree with you. However, this may be obvious, but some of that could be due to people trying to follow Google Maps, Waze, or other similar navigation system directions where the routes are generated based on what other users have done. I drove in downtown Seattle rush "hour" traffic for the first time in almost a year earlier this week, and Maps was giving me all kinds of dangerous, traffic-jam-causing directions. Things like "make a left turn at an uncontrolled intersection, from a side street onto an arterial that's gridlocked for about a kilometer in either direction". Apparently it had been happening for awhile, because the city had installed a barrier across the median, and I couldn't have followed the directions even if I'd wanted to. IOW, it's not just drivers ignoring the law, it's tech companies explicitly instructing drivers to break the law and cause traffic problems that the simulations need to account for now.
- nkrisc 7y ago> it's not just drivers ignoring the law It is. If a driver comes across the situation you described, any action other than a right-hand turn means they should probably take a driver's ed course again. Regardless of what a robotic voice on their phone is telling them. Google maps once instructed my wife to do a U-turn on Lakeshore Drive. Nope.
- 7y ago
- brylie 7y agoA/B Street would fit really well into the Citybound project, as they are both striving to produce realistic simulations. https://github.com/citybound/citybound https://github.com/citybound/citybound I really hope A/B Street and Citybound developers will work together. https://github.com/dabreegster/abstreet/issues/20 https://github.com/dabreegster/abstreet/issues/20 https://github.com/citybound/citybound/issues/361 https://github.com/citybound/citybound/issues/361
- gtycomb 7y agoLink to a slide set in this distribution -- the overall approach. https://docs.google.com/presentation/d/1cF7qFtjAzkXL_r62CjxBvgQnLvuQ9I2WTE2iX_5tMCY/edit#slide=id.g6201f22714_0_144 https://docs.google.com/presentation/d/1cF7qFtjAzkXL_r62CjxB... A beautiful piece of work. What else to say.
- jmpman 7y agoI have a theory that restricting an on-ramp/off-ramp for one street during peak rush hour will significantly improve traffic flow on my freeway commute. I’ve taken the time to propose the change to my department of transportation, suggesting they simulate the change. Expect that suggestion went straight into the trash can. Realistically, modeling this section of the freeway would be difficult, and proving there would be a net benefit - even harder, because there are accidents due to this on-ramp merge which cause the delays. The simulation has to model accidents to be valid. If anyone knows of a way to simulate traffic, including changing accident probability based upon traffic flow (quick stops caused by merging traffic likely increase the accident probability), I’d like to model my commute and provide that to the department of transportation.
- dabreegster 7y agoHi, author here! Didn't intend for this to wind up on HN quite yet, but I'm excited to answer the good questions coming up here.
- proxybop 7y agoyou’re the hero we (commuters) need. We certainly don’t deserve you though, you’ve seen how we drive
- malpighien 7y agoQuestion from a completely clueless perspective. The points you mention I always have and I have been wondering where to simulate it and get numerical answers to all those behaviors that can be infuriating. In your seattle full map you say you heuristically got the time for the lights, but where is that coming from exactly, like would it be possible to infer that for another city from some kind of public data. Is it in the domain of science fiction, there are so many parameters to take in account so it probably is impossible, that you could model the usual behavior of commuters in a city and then simulate whether the current traffic lights are set for the right length of time. I suppose some are updated live to react to traffic jams but in these circumstances there could also be way to simulate how shifting times would be the best to refluidify the traffic, instead of just going with brute force and empirical intuition which I assume is how it works most of the time.
- dabreegster 7y agoI don't have real traffic signal timing for Seattle. I'm waiting on a reply from some folks at SDOT and King County GIS. In the meantime, I have heuristics like https://github.com/dabreegster/abstreet/blob/ed2f703e859d57d9333738d3fd97942fce725ae7/map_model/src/traffic_signals.rs#L200 https://github.com/dabreegster/abstreet/blob/ed2f703e859d57d.... They're not great at all. If you're interested in improving these, https://github.com/dabreegster/abstreet/issues/8 https://github.com/dabreegster/abstreet/issues/8 is a great bug. ;) Some traffic signals are adaptive (they'll switch phases sooner/later based on real-time vehicle detection, bus priority, etc) or even centrally controllable. I'm not modeling that yet.
- crimsonalucard 7y agoLooking to learn rust. Anybody know how/what library was used to build those graphics? I'm looking for 3D or 2D graphics libraries that are good for prototyping stuff in Rust.
- mastax 7y agoLooking at the Cargo.toml for ezgui this uses glium which is an attempt at making OpenGL safe using the typesystem. I don't think it's worth the hassle. For 2D I'd recommend ggez, it's easily the simplest and most polished rust game toolkit. There's a good wrapper for SDL2, but I forget which one it is. wgpu-rs is a really cool next-gen-but-easier-to-use cross platform graphics API. It's early days though so you have to be willing to do some legwork. Amethyst is taking a shot at a Godot or Unity style modern integrated game engine. It'll be a while before they get to that level but it's still useful and reasonably well documented.
- brimstedt 7y agoNice work! How would I go about to use it for my own city?
- dabreegster 7y agoIn theory, https://github.com/dabreegster/abstreet/blob/master/docs/new_city.md https://github.com/dabreegster/abstreet/blob/master/docs/new.... There are a bunch of unsolved problems -- for example, most places in OSM don't map on-street parking, so there won't be any. For Seattle, I'm inferring from an extra shapefile. Have to figure out how to generalize that.
- jackhack 7y agoVery impressive simulation! For others unfamiliar with the term "lane sweeping", it means crossing/changing a lane during a turn. You must turn into the lane closest to you. https://cherinlawfirm.com/2018/01/what-is-lane-sweeping-and-is-it-illegal/ https://cherinlawfirm.com/2018/01/what-is-lane-sweeping-and-... (It's scary thinking a half-mile traffic jam starts at 4am... and I can't help but wonder what it looks like at more sane hours such as 8:30am or 5:15pm. Is everything just red for miles around?)
- dabreegster 7y agoThe jam is probably not realistic. Because that area is a divided set of one-way roads, there are a few intersections each tagged with a traffic signal in OpenStreetMap. I'm simulating each signal independently right now. In reality, it's one signal with more reasonable timing. (Also sorry for the slow replies, HN is rate-limiting comments because this is a new account.)