|
本帖最后由 紅塵市長 于 2013-12-25 15:52 编辑
Under the Hood of SimCity's Traffic.....那个英文好的帮忙翻译一下
译文:
http://www.simcity.cn/forum.php?mod=redirect&goto=findpost&ptid=117303&pid=1756410&fromuid=501441
http://www.simcity.com/en_US/blog/article/under-the-hood-of-simcitys-traffic
Mar 23, 2013
Software Engineer Alexander Harkness
Hello, I’m Alexander Harkness, and I’m a Software Engineer working in the transportation team of SimCity. I’ve primarily been working on implementing the behaviors for the vehicles, rail, boats, and helicopters during my amazing time here at Maxis. I wanted to take some time out of my usual duties to explain to you all how the traffic system works and how you can make the most of it.
Vehicle Behaviors
Basic Information
Every vehicle in the game has a basic set of performance characteristics such as top speed, acceleration, and deceleration. The values assigned to each vehicle vary on the type of vehicle (scooter, car, and truck), the wealth value of the vehicle, or where the weight has changed after a delivery is made.
Lane Changing
Vehicles will always try and get into the correct lane for the next turn they are required to make. So when turning right, they will attempt to get into the right lane. And when turning left, they will attempt to be in the left lane. Vehicles travelling straight through an intersection can be in any lane. Vehicles will also overtake vehicles in front using the lane to the left if the vehicle in front is travelling slower and there is space for them to do so. Emergency vehicles can undertake and overtake using any available lane. When the vehicle is expecting to enter a building on the current section of road, the vehicle will always try and be in the right most lanes, they will only move out of that lane if there is an obstruction such as a stationary fire truck.
Limitations
We tend to be quite strict in cases such as U-turning where we found very early on that letting vehicles U-turn wherever they thought was best caused so many traffic problems that we had to restrict them to U-turns at intersections only. Other limitations imposed are vehicles not being allowed to cross the median to enter buildings on avenues and emergency/service vehicles stopping outside of building only. This means vehicles must travel much farther when their destination is on the opposite side of the road, since they will need to U-turn at the next available intersection. Of course, from this you can see that it is not always wise to immediately upgrade all your roads to avenues in an attempt to solve congestion.
Emergency Vehicles
Driving to emergency
All emergency vehicles have the ability to change the traffic lights in their path to green. This is so by the time they reach those lights, they should have changed, and any traffic at the set of lights should have started to flow. During periods of heavy traffic, it could be that there is some gridlock where traffic is not moving, even after the emergency vehicle has changed the light to green. In this case, it will remove the lock on the green light, as this can potentially be the cause of the gridlock.
Stopping outside buildings
All emergency vehicles will stop outside their destination while they are attending to the situation at hand. This causes a temporary blockage on the lane immediately outside the building and can last a variable amount of time depending on the emergency. On two lane roads, this causes an issue with traffic being permanently blocked until the emergency is over, however, on four or six lane roads, the vehicles should flow around unless they are interested in entering the building that the emergency is at.
New additions
In a recent update, we added some new functionality that prioritizes emergency vehicles over all other vehicles. The first change was to ensure that these vehicles could exit their garages and get onto the road as quickly as possible and deal with the emergency. This means that they will immediately reserve a spot on the lane outside the garage and drive straight onto it. Previously they would have to wait for a spot to open up which may never have happened during times of congestion. The second change was allowing them to use any lane on the road regardless of whether they were required to turn left/right at the next intersection, which as previously mentioned, would normally force the vehicle to attempt to get into that lane.
Intersections
All way stops
At these types of intersections, vehicles obey the rules of first to arrive is the first to move. This rule is broken for two different scenarios. The first is where we can improve traffic flow by allowing multiple vehicles that will not cross paths to move at the same time. And the second is where the vehicle is unable to move because the road is blocked. In the latter case, the next vehicle to arrive is promoted to the top of the queue and the blocked vehicle is moved to the back.
Traffic lights
Traffic lights can be used to improve the flow of traffic at intersections dramatically over all way stops. During testing, it was seen that there was a 4-5x improvement in the amount of traffic travelling through the intersection. Traffic lights also have knowledge of traffic whether it is vehicles or pedestrians that are waiting at the lights. In the case where there is zero traffic waiting or approaching, the intersection light will switch to allow traffic from the opposite set of lights to proceed. The traffic light will then stay green in that direction until traffic from the crossing direction approaches/arrives at the intersection. When there is traffic from both crossing directions, the lights work on a timer countdown. This countdown is differs in length depending on the combination of the joining roads at the intersection, but the length the light stays green is longer the wider and higher density the road is.
Side street stops
This setup can be incredibly useful to create corridors through the city where traffic can flow freely without interruption from stop signs or traffic lights (vehicles will only stop to let pedestrians cross). These can be created by using any four lane road or greater in combination with a two lane street or dirt road as the side roads.
Creating intersections
To achieve better flow through the city it is much better to use T-Junctions than four way intersections. This is simply because there will be fewer vehicles trying to cross the path of oncoming traffic for which they have to wait until it passed. You may have noticed that often queues will form where traffic is waiting to turn left across the path of traffic. Intersections that are too close together are another thing to avoid. This is because the flow of traffic during the green phase of one of the intersections towards the next intersection will be very small due to the area available for the vehicles to wait and most of the green phase will have been wasted as no cars are moving.
Routing
Overview
To understand how the routing system works, I’ll talk a bit about how roads are created, how routing propagates values through it, and how you can influence these values.
Roads
Roads are constructed from many paths and paths are constructed from one or more segments. A path is the road between two intersections. Each path is made from segments and the number of these can vary depending on the curvature of the path or the terrain the path is crossing. So flat areas paths will tend to be only one single segment.
Assigning weights
Where there is any capacity on a segment, we assign a value to that segment based on the capacity. In this example, the work place has ten open jobs so we assign a base value of ten at each point on the ends of segment four. This value then propagates out through the network adding on the length of the segment that the vehicle will have to traverse. So in this case we say that segment two and three are fifty meters in length, and segment one is two hundred meters long.
In addition to this, we also add on congestion values that are calculated continuously. These values are only applied to the network when they reach certain thresholds that we have set at 25%, 50%, and 75% of road capacity. We do this to avoid the overhead in continually updating the complete network of paths. You have to know that we have many hundreds of these networks to update to cover the many different destinations vehicles have. As an example, say that segment 2 becomes 50% congested. We would then take the length of that segment and multiply it by a set amount, say 10 times. This would mean that the values would then become 10, 10, 510, 560 and 760.
Influencing the values
Let us look at the scenario below which has been seen in a video posted on YouTube. I marked each of the segments and the values at each end of the segment as before. With this layout, the vehicles will all initially exit their houses and use segments 5, 6, 2, and 1 to get to their jobs. As segment 6 becomes congested due to the traffic, the additional congestion weight will be applied to influence the value so that vehicles will route around using segments 4 and 3. However, in this case, because there is only one segment on the path where segment 6 is, and the value at the end is shared between segment 2, 3, and 6, the value will not actually change from its current value of 60 since the distance from segment 3 to segment 2 is still only an additional 50 meters and during the propagation the lowest value is always applied.
You can however influence the network by forcing a path to split into multiple segments. The cheapest way to do this is by drawing a dirt road midway along the path and then bulldozing this path. This then changes how the values are applied and would make the vehicles take the alternative longer but less congested route.
Obviously, this is not an ideal solution for you as a player since you can’t see how the paths are split up, so we are of course working hard at improving the routing.
Final Tips
Mass Transit
Traffic should generally be at an absolute minimum around an hour before the shift changes start at 6am and 6pm. When I start to see the congestion building up and lasting closer to this point I start to plan ahead and think about my mass transit options. Remember, when picking stops, the green overlays show you how far Sims are willing to walk to the bus stop, which can be a handy guide to helping space them out. This is important when strategically placing bus stops. Since busses don’t follow set routes, it’s a good idea to place them closely spaced in lines on the same side of the road to encourage the busses to go to the next stop in the line. This way, they won’t have to make a U-turn to reach the next stop. In addition to busses, you can also upgrade your avenues to allow for street cars. Street cars are always my preference as it can’t get stuck in traffic jams like the buses can, however don’t go crazy with lots of avenues as this can cause extra traffic itself as I mentioned before. Plan out a route that will cover your highest density population areas and places of work then place rail stops that will allow those Sims to get out of their car and walk to the nearest stop instead.
Thanks for listening everyone. I really hope these tips help you out in designing your perfect city and getting that traffic flowing. Just remember, avenues won’t solve all your traffic woes. And look out for those telltale signs your road network can no longer cope with current volume of vehicles.
|
|