Thursday, May 19, 2022

How Traffic Works in Cities Skylines AI and Games

How Traffic Works in Cities Skylines  AI and Games


Quite often artificial intelligence is in control of so many elements of our favorite video games but we seldom take notice and take it for granted an ai tool or system can be running in plain sight providing a critical element.




Of the game that players are largely unaware of until it starts to go wrong i'm tommy thompson and in this episode of ai and games we're going to look at a fantastic example of this found in the popular city building simulator cities skylines let's take a look at the traffic and navigation systems that run in every city how citizens go about their day-to-day routine.




And how developers colossal order sought to address the traffic jams that can quite easily emerge released in 2015 published by paradox interactive cities skylines is an open-ended city building simulator where players are responsible for many aspects of modern urban planning this includes establishing city zoning utilities such as water and electricity establishing zones for residential commercial and industrial growth public services.




Such as schools fire services and law enforcement all the taxation that is required to pay for it all and critically for this episode road placement.




And establishing transportation services within the region colossal order having achieved success with the cities in motion series had sought to expand into a full city building title a sentiment that at that time paradox interactive did not share however 2013 saw a gap emerging the market courtesy of the latest entry in the beloved sim city franchise from electronic arts the game came under intense criticism at release with players posting screenshots and videos.




Of cities not behaving as expected and while the issues raised were numerous there are two critical points we are exploring in this episode first the traffic simulation in simcity was highly problematic traffic would often bottleneck creating massive jams that seemingly never resolved themselves meanwhile should the player attempt to rework junctions to enable better traffic flow or add public transportation this often proved to be more of a hindrance than a help secondly.




The citizens in sim city did not behave as expected while it was anticipated that the sims would live their predetermined lives working jobs and living happily in their homes in reality they lacked any individuality sims would leave the house in the morning find the nearest job available in the city and then after the working day they didn't necessarily go back to the house they had previously left instead they simply go to the nearest vacant property while this is undesirable it seems slightly innocuous until you realize how big an impact this would have on the already troubled traffic systems.




As well as the actual behavior and economy of the cities themselves while simcity sought to address this through numerous patches it never really collapsed at a solution that players were happy with however city skylines when released satisfied many of the features that players sought from its competitor and as we'll see in a moment it not only tracks the passage of every vehicle through your city's road system but your citizens.




Will go about their daily business as one would expect that said it still suffers from traffic congestion and a few other issues now before.




We get into the intricacies of this problem and how it is tackled in city skylines it's important to acknowledge that this isn't just an issue that plagues video games but the real world too traffic management systems in the real world are highly complex and incredibly expensive to research and develop these systems have to manage signaling traffic flow and congestion tracking and responding to accidents and other incidents on the road such as spillages damage to the road or faults emerging in signaling systems and cctv cameras.




That are used to provide oversight there are efforts to employ artificial intelligence to handle the complexities of real-world traffic management but it is far from a solved problem at this time hence it's understandable that as a city building simulation game seeks to become more and more realistic the challenges that developers face will rise accordingly first let's talk about the citizens.




How do they work and what impact are they going to have on the traffic network each citizen and city skylines has information that is used as part of the city simulation this includes their name what level of education they have their residential address their place of employment or education if they have one their overall level of happiness a reference to their current activity including any destinations that they're currently heading towards if they're traveling around the map their health their wealth and lastly it maintains references to familial relationships.




And what other citizens are related to them each of these features impacts the game in different ways levels of education influence what type of jobs they take on the performance of these businesses and the value of residential areas meanwhile happiness is shown to the player and gives a barometer for how well you're performing given there may be services these citizens require such as healthcare or utilities that they feel is lacking or the job opportunities in the region aren't up to scratch but perhaps what's most influential on citizens behavior.




As they move around the map is their age while a citizen does have a numeric age this isn't exposed to players by default but the key part is that they live their lives in five stages children where they start going to nearby schools if there is capacity teens who go to high schools if there is space young adults who either attend university or get a job if they can adults.




Who not only move out of their current home and into a new one if they can but will also settle down and start their own families and lastly seniors where citizens retire and no longer go to work but still use city services and commercial businesses this has a huge impact on the transportation network given kids are going to school adults are either at university or in a job and pensioners are running amok picking up newspapers cans of tenants super and jelly suites some of these citizens.




Will be in their own car while others use public transport and this is a very difficult balancing act given not only will your city grow if you're doing your job right but citizens age at an incredibly fast rate with the average life expectancy being around six in-game years oh man the first aion games video was in 2014 that means i just wasted my entire city skyline's life trying to sound smart on the internet oh what a waste of time so many things i've ever got to do like an episode on shadow of mordor or looking.




At the ai of dark souls or that bloody forza video i threaten on the welcome video why am i only thinking about the videos there's so much more to life than youtube and oh man my wife's gonna kill me  so given we have so many citizens moving around how does the road system work before i can get into the movement of traffic let's look.




At how roads are built given this influences how the search process takes place afterwards under the hood roads are modeled as a collection of nodes two nodes connected to one another is a segment providing both start and end points your average road in city skylines is actually multiple segments glued together given a segment has a maximum size each node in a segment is known as a control point this provides start and end positions for roads.




As well as the intersection with other roads creating junctions each segment of the road stores information about itself including what type of road it is how many lanes it has and what types of lanes these are this all becomes useful when a citizen wants to travel between locations now this information extends to sidewalks too which operate on a slightly different system given they can be elevated or tunneled to go over or under traffic and crosswalks are established when building them alongside roads to enable pedestrians.




To cross all of this information comes into play when a citizen makes the decision to travel to a destination having citizens move around in city skylines is by the developer's own admission the single greatest challenge faced during development resonating with the issues that plagued simcity given it is arguably the one system that any player who spends more than 10 minutes.




In the game will come to interact with hence ensuring a basic level of functionality and avoiding some.




Of the more gnarly edge cases was paramount to that end not only did colossal order rework this system several times over but as we'll see in a moment some elements that players might want to see were actually removed because.




It only made the problem worse when a citizen decides they want to travel.




They use all of the available information about the city's transport infrastructure including the roads sidewalks crossings public transportation routes.




And available vehicles and will find the fastest possible route to their destination hence the node system within the roads and sidewalks is searched through to find a valid path this actually factors in numerous elements based on the citizen involved and the local geography if a citizen owns a car they will attempt to drive it if they don't have a car they'll not only check for a valid path on sidewalks but also factor in whether there is any public transportation that can speed up that process in some cases there are strict rules on how this can operate pacific buildings such as hospitals and fire departments.




Will enforce the use of ambulances and fire trucks respectively rather than a firefighter taking a bus with a bucket of water as your home turns to ash meanwhile pedestrians cannot walk on highways and hence if they don't have public transportation options and sufficient sidewalks to get them to their destinations they'll resign themselves to defeat colossal order have never outright stated what the such algorithm is however given the rich data laced throughout the road network.




I would not be surprised to find a modified version of a-star or dijkstra's that achieves the desired effect the resulting system is actually quite remarkable since a character can make this level of nuanced decision-making at this scale given a pedestrian can easily walk and take multiple forms of transportation in order to get to their destination the destination they want to visit can vary and while they will prioritize going to the primary destination for their life stage such as school college or work they will.




Also go to commercial units such as shops and restaurants as well as clinics and hospitals when a citizen takes a car it utilizes not just the road network topology but the additional constraints of the road types themselves against the vehicle this includes the dedicated cycling or bus lanes as well as the speed limits the number of lanes and the current congestion level provided the system can generate a path through the road network.




Then the vehicle will begin to drive it it can also still use the public transportation system hence it is possible for a citizen to drive to a metro station and then use the train for the remainder of the journey in essence that's how city skylines.




Works but there are several edge cases revolving around traffic the number of citizens in the city and more and we're going to get into that now but before i do there are two really important caveats i want to cover first things first not all citizens are rendered in the city at any point in time there is a hard limit on how many citizens and vehicles can be simulated on the streets of your city at any given moment now you might think this is just a rendering issue and that the game is still simulating all citizens under the hood and you just don't see it no no no no city skylines outright caps.




How many citizens can be traveling within the city at any given time there is a separate system that monitors whether there are available slots for travelling citizens and then allows them to travel once there is space while the movement of citizens is important for maintaining the economy and their own personal health and education you the player are not penalized for a citizen being unable to travel due to the simulation cap the system that oversees this ensures that players are not punished because a citizen is due to compute limitations unable to travel to their desired destination.




The second caveat is that the traffic you see on the streets is a separate simulation from the citizen management when you watch traffic it's a collection of thousands of small physics objects that read information from the road network to simulate how the citizen is moving through it so for the remainder of this episode let's look at two things first how the traffic simulation systems work and secondly.




What happens when traffic jams start to occur in the game world traffic is handled in a separate simulation system that is actively calculating how to follow the chosen path the velocity that the vehicle should be going at and also preventing collisions while traffic looks like this smooth and constantly updating process it's only rendered that way the traffic simulation is actually only updated four times a second and the rendering system takes two of these simulation updates to derive the movement of the objects currently on screen when traffic is simulated a vehicle knows the path that it's been told to go on and they know where on a given road they can drive hence they won't drive the wrong way down a runway paths through the roads are calculated on a spline using the nodes of each road segment this allows for tight corners and intersections to be handled as gracefully as possible these simulation.




Steps allow for vehicles to calculate whether collisions are going to occur at intersections or from traffic slowing down vehicles do recognize traffic lights and will slow down and stop if the lights dictate they can't travel into the intersection meanwhile to minimize crashes vehicles check ahead of themselves during the simulation for whether a collision between two vehicles is imminent this annotates a segment of the road as liable to cause a crash at which point.




The distance to the segment is used to decide which vehicle should go first and they move through it on a first come first serve basis each adapting speed accordingly but of course despite all of this effort there are still.




Issues with traffic jams in part this is to be expected if the player does not build the network sufficiently but there are other issues that impact the system so let's wrap up by talking about what the simulation does and does not do in order to keep it manageable first of all unless something happens that causes a given path to no longer be valid or has been extensively modified a citizen or vehicle will not change their pre-calculated routes.




You may think there would be some opportunistic behavior going on here where a character may re-evaluate their options on the fly but nope only in the event something happens that negates the original path plus you'll note that while in some larger segments of road with multiple lanes that could spread the traffic out you'll notice they don't change lane again after moving into the one they originally decided upon even if that would make sense to do so having vehicles change lanes midway through a segment of road was actually something that colossal order experimented.




With only to later remove because during internal testing it actually made everything worse when traffic builds up you may see cars sitting idle at junctions and not moving forward despite having room to do so and that's.




Often because their simulation has determined further issues up ahead and as a result they opt to simply stand idle rather than continue forward on their pre-chosen path last but not least city skylines has a fallback option for when traffic jams are overwhelming if a vehicle has found itself in gridlock and unable to move it will actually teleport back to its origin and the previously mentioned worker system may well stop that citizen from trying to travel again and avoid punishing.




The player any further this was a decision made by colossal order in order to make the transportation challenge more manageable given even some relatively small cities can begin to be impacted by this issue this decision has actually proven to be contentious among some players who prefer the challenge it presents and use mods to actively remove the teleport feature building a city simulation game.


https://bit.ly/3G3pZjz

No comments:

Post a Comment

YT Explosion Code Review" Week 1 Results

Hi guys Kelita and I wanted to come and give you a YouTube explosion code review and this review is really from my first week of being invol...