This is the post explaining the traffic simulator implementation that I promised. I will be going through the traffic simulator exemplar and explaining where the properties of my simulator differ from those of Simulators A and/or B, and why I made the decisions to change them to what they are. As there are many changes, this is going to be a long post, so I'm going to add to it in stages. In the interests of coherence, the additions will simply be edits to the original post. Originally, I thought I might add a post to this thread notifying people when I had made an addition to the implementation description, but due to the lack of response to this thread so far, I think that may be excessive, and so for now I plan only to announce when the entire description is finished. If people think I should add notification posts at each stage instead, please let me know.
I have based my implementation and the following description on my knowledge of the traffic simulator. I have both read extensively what others have written in these forums and others, and performed numerous experiments myself. Nevertheless, I may have gotten some things wrong. If you see such an instance, please let me know.
Now on to the description...
Customers/Traffic Noise Coefficient - This number controls both the number of customers businesses receive due to traffic, measured as a function of traffic noise (a good thing), as well as the amount of traffic noise experienced by residences (a bad thing). More customers means increased desirability for a commercial lot, while more noise means reduced desirability for a residential lot. So the goal here is to balance this number to the point where businesses receive enough customers, but residential areas aren't too noisy. Maxis set this number at .128, where it remains in Simulator A, while in Simulator B, it was reduced to .096. Since my simulator increases the amount of cars significantly, and therefore the amount of traffic noise, I have found that a value of .04 works well here.
Network Speeds - Before getting into the actual speeds themselves, I would like to address the question of what units the speeds are in. Some people have said that they are have no units associated with them, but various factors make it clear that these speeds are in kph. Fortunately, the current simulators are all assuming speeds of kph, so it's not necessary to debate that issue here. Instead, I'll just move on directly to the speeds themselves. I have found that small changes in these speeds typically do not make much difference in the game, so what has been done here should not be weighted too heavily. I started with the speeds from the CAM simulator and modified them where I felt appropriate. As for the speeds themselves:
Walking - 15 kph on all networks where walking is allowed.
Driving - Roads: 50, Highways, 150, Streets: 30, Avenues: 50, One-Ways: 75, RHW: 150, Ground highway: 150.
Bus - Roads: 45, Highways, 150, Streets: 25, Avenues: 45, One-Ways: 65, RHW: 150, Ground highway: 150.
Passenger Train - 140.
Freight Truck - Roads: 40, Highways, 130, Streets: 25, Avenues: 45, One-Ways: 60, RHW: 130, Ground highway: 130.
Freight Train - 105.
Subway - 105.
El Train & GLR - 105.
Monorail, HSR, & BTM - 225.
In general, these speeds are fairly close to those in Simulators A and B, which differ slightly between each other. I made bus speeds lower than car speeds to take into account intermediate bus stops, which are otherwise invisible to Sims. I left bus speeds for highways the same as for cars because there are no bus stops on highways. (RHW may be an exception, but I think any bus stops there are far enough apart not to matter. I also decided to ignore the fact that if you put a bus stop next to a highway, some Sims will walk into the bus stop, climb up onto the highway, and jump onto the next passing bus.)
Many of the CAM simulator speeds are somewhat higher than the speeds in Simulators A and B, and even the corresponding speeds in real life, yet I left them unchanged. There are two reasons for this. First, I wanted to compensate at least somewhat for the limitations in the underlying traffic simulator algorithms. Since these algorithms don't take speed adequately into account when determining a Sim's path, on average the paths will take longer than optimal. Increasing speeds by a slight amount offsets this a bit. Second, I discovered that all other things being equal, a network's speed plays a big role in the probability that Sims will use that network for inter-city travel; in fact, it plays even a bigger role than the math would suggest. (I'll go more into this in the section on Commute Trip Max Time.) So the slightly higher CAM speeds are quite useful. I also felt that the proportion of the various network speeds to each other in the CAM simulator was rather realistic.
As for the other changes I made here, I knocked down the CAM avenue driving speed from 80 to 70. This is still a little high, but it encourages Sims to use the avenues, which adds somewhat to both the realism and the workability of the simulator. The other change I made along these lines has to do with elevated train speeds. Once again, this comes down to the limitation of the traffic simulator algorithms that I just mentioned. One thing people do to get around this limitation is to use a large network of subway lines beneath their cities, which tends to work very well. But there are inevitably relatively few elevated rail lines above ground, and with all those intersecting subway lines available, the elevated rail lines don't tend to get used much. By giving them a slight speed advantage, they get more realistic usage.
Travel strategy percent - This is where the changes were made to increase car usage. The first of the four entries here is "Travel strategy percent WealthNone." I'm not sure what that is - background traffic, maybe? If anyone knows for sure, please post. In any case, I left it alone.
The next three entries actually control normal commuting traffic choices. They are described in detail on page 250 of the Prima guide. Each entry has three numbers, which are the percent probability the Sim of that wealth category will use mass transit for his or her commute, the percent probability the Sim will use a car, and the percent probability that the Sim will choose the best route. The manual says "fastest route," but of course it isn't necessarily the fastest, nor is it necessarily the shortest; it's simply the best route the simulator knows how to calculate.
The manual also implies that the simulator sticks to these percentages strictly, although it does mention that the Commuter Shuttle Service ordinance alters the numbers more in favor of mass transit. It doesn't say how much, but my experience is that the difference is fairly small, maybe a few percent for each travel type. But the implication that with this ordinance turned off, the simulator sticks to the specified percentages exactly is completely wrong. The simulator treats these numbers as purely advisory. It pays attention to them, but only to the extent it thinks is best. Specifically, it will follow the recommendation if and only if that method can get the Sim to work within the Commute Trip Max Time. Otherwise, it will use the other method, and add a penalty specified by by the Trip Starting Cost by Travel Type properties, which are described below. The Pathfinding Heuristic also indirectly affects these probabilities by affecting how successful different travel strategies are. It is also described below.
So here are the standard Maxis probabilities, which are present in all the simulators I have seen. Each triplet of numbers represent percentage preference for mass transit, car, or best route:
R$ 80,20,0
R$$ 30,0,70
R$$$ 10,80,10
And here are my set of numbers:
R$ 70,30,0
R$$ 20,70,10
R$$$ 10,80,10
For one thing, I thought that these were much more realistic numbers, though still far below the typical percentages I mentioned in my first post. Also, I noticed no deleterious effects on my cities from switching from the first set of numbers to the second one. Notice that the numbers for R$$$ remain the same; I experimented with changing them to 5,90,5, but this did have a small negative effect in that my R$$$ population immediately dropped slightly. As my other populations had not suffered from their changes, I thought I should leave the R$$$ numbers alone.
Although car usage did jump in my cities by a factor ranging from 2.5 to 6, what's interesting to note is how far the final traffic volume numbers were from the percentages above. Using strictly those numbers, you would have expected to see about twice the car usage that I saw. It is possible to enforce these numbers strictly using the abovementioned Trip Starting Cost by Travel Type properties, but as I discuss in their section below, it's not a good idea. So for now, these seem like good numbers that produce a reasonable balance of traffic.
Pathfinding Heuristic - This is by far one of the most important numbers in the traffic simulator. Basically, it's a measure of the accuracy of the pathfinding algorithm, which is what is used to determine a Sim's path to and from work. The lower this number, the more accurate the algorithm. Still, the accuracy of pathfinding in the game is limited by the nature of the algorithm used. The one used in the traffic simulator primarily looks at distance, and tries to find the shortest path. Speed is only a secondary consideration, although it does figure into the calculations. So does traffic congestion, which of course has an effect on speed.
Instead of going through all the implications of this, along with the principles of heuristic pathfinding, I would refer the interested reader to mott's excellent dissertation on this topic, which can be found
here (mostly in the large post). In terms of principles of operation, there's really nothing I can add that he hasn't already written.
Now that you are all experts on heuristic pathfinding, how does this apply to the game? Well, we want the best pathfinding possible, which means the lowest number we can use for this paramater. In the vanilla versions of the game, this parameter is set to 0.09, which results in very mediocre pathfinding at best. With this number, Sims often do not find an optimal path from home to work, and as a result, the simulator may decide that commute time is too long and abandon a building, even if there are jobs within commuting range. As mott pointed out, one big reason that Maxis chose such a relatively high number was that when this game was released in 2003, computers could not be guaranteed to have the processing power to handle lower numbers. (More accurate pathfinding tends to take more CPU time, as you would expect.)
Once the NAM came out, lower numbers were tried for this parameter. For example, the traffic simulator packaged with the CAM uses a value of 0.0465, which while still relatively high, is a big improvement over 0.09. Then we come to the current simulators, A and B, which use values of 0.009 and 0.025, respectively. (Since mott built Simulator B, and he also showed that a value of 0.003 resulted in essentially perfect pathfinding, I'm somewhat puzzled by why he chose such a relatively large value for his simulator. Especially when he said, "Stick with the 0.003 heuristic for now, I'd say." Does anyone know why? Mott?) Originally, I chose a value of 0.009 for my simulator, the same as is used in Simulator A. Moving from CAM's 0.465 to 0.009 had immediate and dramatic results. In one city, a traffic jam that had been present for literally centuries disappeared overnight. Why? What appears to have happened is that the simulator now spent more time finding the best individual route for each Sim, and this tended to spread traffic over a wider area. In a similar vein, the simulator appeared to become smarter at avoiding congestion, again by spreading out traffic. While doing so, it would find faster routes, and the speed of the routes became more significant. Highways started becoming used more. So traffic patterns as a whole became more realistic.
What about mott's magic number of 0.003? As mott points out, for reasons which he details, CPU usage does not grow exponentially as this number declines. In fact, it doesn't necessarily decline even linearly. So I tried it out. As expected, pathfinding became even more realistic. So did commuting patterns as Sims started heading downtown from other tiles, even nonadjacent tiles. I found one development to be particularly noteworthy. I had already made the change to increase car usage in all my cities quite a while ago, but in my Downtown city, when I dropped the pathfinding heuristic to 0.003, car usage increased immediately even more, along with increased road congestion. I found this rather puzzling, so I asked, "Why, O Perfect Pathfinding Algorithm, why is this happening?" And it responded, "Look at the commute times, dummy." Ignoring the insult from the algorithm, I looked at the commute times, and sure enough, they had dropped. So the traffic simulator was now smart enough to figure out that by moving more Sims into cars, even at the expense of creating more traffic congestion, it could get them to work faster than by using my extensive mass transit system. I was impressed.
As for performance, I found that in some cities, this value resulted in performance no worse than, and perhaps even a little better than, a value of 0.009. I'm sure that mott would not be surprised. Unfortunately, in other cities, performance took a big hit, so big, in fact, that the game spent almost all its time running the traffic simulator. When this happens, Sim time does not move forward, and so this was unacceptable.
I went back to mott's posts and read through them again. This time I noticed the part where he mentioned that having many steps in the congestion vs. speed curve (see below) could speed up the algorithm greatly. So I added a number of more steps to my congestion vs. speed curve, without changing the shape of the curve. Bingo! I could now run with a pathfinding heuristic of 0.003 in my cities with quite acceptable performance. Subjectively, it seems no worse anywhere than when I was using 0.009, and in some places it seems better. So my present simulator uses the value of 0.003, which according to mott, results in the "perfect" version of the pathfinder.
I noticed that one city runs a fair amount slower than the others using a value of 0.003. Depending on the results of wider testing, it may be wise to create two versions of the simulator (at least from the perspective of pathfinding), with one version using "better" pathfinding with a heuristic of 0.009, and the other using "best" pathfinding with a heuristic of 0.003. There is certainly ample precedent for this.
Congestion to Accident Probability - I spent quite a bit of time researching this issue at the Google Institute of Traffic Engineering. The final result I found was: It depends. It depends on what country you're in, which region of the country, whether it's rural or urban, what type of neighborhood if it's urban, what the weather is, what kinds of roads you're talking about, etc. As you might expect, with all of these factors involved, there's a wide variation of plausible numbers. Both the Maxis numbers and the numbers in Simulators A and B fall within the range of plausible numbers. For simplicity's sake, I chose to stick with the Maxis numbers.
Network Traffic Capacity - This property is one of the most important in any traffic simulator, and this simulator is no exception. The proper values for these capacities are dependent on many other properties in the simulator, though, so network capacities for one traffic simulator are not necessarily comparable to those of a different simulator. This is especially true in the case of this simulator. The capacities I have chosen here are all based on real-world capacities, yet they are much higher than for most traffic simulators in use. This does not mean that this is a "super-easy" simulator. To the contrary, I have verified that all network types can get congested beyond 100% capacity in a realistic city environment.
Essentially, higher capacities are required because this simulator, by being more realistic, produces more traffic. For example, the Commute Trip Max Time is much larger in this simulator than in most others, leading to trips that are longer on average for most Sims. Since the Sims are traveling longer times on all networks, this factor alone results in higher network traffic at any given time. Furthermore, the higher Commute Trip Max Time makes it possible for more Sims to get to more jobs, further increasing traffic. A third factor, which has been mentioned above, is that the change in the Travel Strategy Percent results in their being 2.5 to 6 times as many car trips as there would be in other simulators. This number has a multiplicative effect on the previous number. A fourth factor is that the intersection capacity effect is strengthened in this simulator, further slowing down traffic, and adding to the number of cars and buses on the road at any given time. Finally, inter-city traffic is much more common, meaning that networks have to handle not only traffic from their cities, but sometimes significant amounts from neighboring cities as well. All of these factors are designed to make the game more realistic, and they all result in network capacities that are more realistic as well.
With this in mind, here are the network capacities currently in use for all versions of this simulator. As is customary, all capacities are expressed per tile.
[tabular type=2]
[row] [head]Network[/head] [head]Classic[/head] [head]Low[/head] [head]Medium[/head] [head]High[/head] [head]Ultra[/head] [/row]
[row] [data]Street[/data] [data]100[/data] [data]1500[/data] [data]2400[/data] [data]3600[/data] [data]7200[/data] [/row]
[row] [data]Road[/data] [data]1200[/data] [data]2400[/data] [data]4000[/data] [data]6000[/data] [data]12,000[/data] [/row]
[row] [data]Avenue[/data] [data]1400[/data] [data]2400[/data] [data]4000[/data] [data]6000[/data] [data]12,000[/data] [/row]
[row] [data]One-way Road[/data] [data]1800[/data] [data]3600[/data] [data]6000[/data] [data]9000[/data] [data]18,000[/data] [/row]
[row] [data]Rail[/data] [data]3000[/data] [data]10,000[/data] [data]16,000[/data] [data]30,000[/data] [data]65,200[/data] [/row]
[row] [data]Subway[/data] [data]3000[/data] [data]10,000[/data] [data]16,000[/data] [data]30,000[/data] [data]65,200[/data] [/row]
[row] [data]Elevated Rail[/data] [data]3000[/data] [data]10,000[/data] [data]16,000[/data] [data]30,000[/data] [data]65,200[/data] [/row]
[row] [data]Monorail[/data] [data]3000[/data] [data]10,000[/data] [data]16,000[/data] [data]30,000[/data] [data]65,200[/data] [/row]
[row] [data]RHW[/data] [data]2700[/data] [data]6000[/data] [data]10,000[/data] [data]15,000[/data] [data]30,000[/data] [/row]
[row] [data]Highway[/data] [data]4000[/data] [data]9000[/data] [data]15,000[/data] [data]22,500[/data] [data]45,000[/data] [/row]
[row] [data]Ground Highway[/data] [data]4000[/data] [data]9000[/data] [data]15,000[/data] [data]22,500[/data] [data]45,000[/data] [/row]
[/tabular]
Some of these figures may seem to be high, especially the rails. But if you look at real-life rail lines they're actually quite reasonable. For example, the new Second Avenue Subway in New York is designed to carry 600,000 passengers per day. So if you were trying to simulate a real New York City, you couldn't do it, even with these capacities. Fortunately, most people aren't building New York City, and the game doesn't require such high capacities. But the capacities in this simulator do seem to fit in with actual game usage quite well.