Cities: Skylines II

Cities: Skylines II

656 ratings
Practical Engineering: Efficient Grids
By me22ca
I started my first city with a 112 metre square grid, as it seemed the obvious choice. But it turns out that other sizes are actually better!

UPDATE: Now covers hexagonal, rectangular, and triangular grids too
55
19
4
24
3
8
4
6
5
2
3
2
2
   
Award
Favorite
Favorited
Unfavorite
Introduction
Which of the two square grids below do you think has more zoning cells?

Each covers the same footprint: 1008 metres for each edge, about 100 hectares.

The one on the left sure looks like the obvious choice. It leaves exactly 12 zoning cell widths between the roads, the most you can get without leaving a gap. That's one of the easiest lengths to draw with the road tool, since you just have to line up the zoning circles. It even happens to be the widest width you can get with the parallel road mode.

But if you count them all up (or as you might guess if you read my guide for the original Cities Skylines), the one on the right actually has more zoning cells despite the big holes in the middle of each block. The right is cheaper to build and maintain, too, since it has less roadway.

The left has 12²×9² = 11664 cells; the right has (16² - 4²)×7² = 11760 cells.

Can we do better? Let's calculate it! (Spoiler: Yes, we can.)
Optimal Square Grids
First, let's define some variables:
  • x is the length of the road on one side of a block, as reported by the road tool
  • z is the length of zonable frontage
  • h is the length of the side of the hole in the middle of the zoning
  • W is the width of the road being used

Pedantic math aside: the below is going to assume x > z > h ≥ 0 for simplicity. It's possible to fix that by using things like h = max(0, z - 96m), but that no longer has a contiguous derivative, which is a pain. The maximum we're looking for is in the convenient part of the parameter space anyway. That's unsurprising, since z < 96m just means a higher road-to-zoning ratio without any offsetting bonuses elsewhere.

Using this, the zonable area in each block is the space inside the block (z²) minus the part too far from the roads (h²). But both of these are directly related to the block length, as the frontage is the block size minus the road width (z = x - W), and relatedly the hole is the frontage minus how far the zoning goes (h = z - 2 × 6 x 8m = x - W - 96m).

The density, which we're trying to optimize, is thus

(z² - h²) / x²
= ((x - W)² - (x - W - 96)²) / x²
= 192×(x - W + 48) / x²

How do we maximize it? Calculus! The maximum is where the derivative is zero:

0 = d/dx 192×(x - W + 48m) / x²
0 = d/dx (x - W + 48m) / x²
0 = (2W - x + 96) / x³
0 = 2W - x + 96
x = 2W + 96m

Plugging that answer into the previous formula for the hole simplifies interestingly:

h = x - W - 96m
h = 2W + 96m - W - 96m
h = (2W - W) + (96m - 96m)
h = W

In other words, to make an optimal square grid, leave a hole in the middle the same size as the road you're using.

Let's look at how that works for a small road:

Block Size
Density
Road Needed
112m (14u)
³⁶⁄₄₉ ≈ 73.5%
²⁸⁄₉ ≈ 3.11 m/cell
128m (16u)
¾ = 75%
⁸⁄₃ ≈ 2.67 m/cell
144m (18u)
²⁰⁄₂₇ ≈ 74.1%
¹²⁄₅ = 2.40 m/cell

So with 16m roads, by using the optimal square grid you get about 2% more zoning cells in the same area yet pay about 14% less for roads (both up-front and in upkeep), compared to the square grid without the hole in the middle.

And while 2% may not sound like much, remember that density helps everything with a service area. If you place a signature building with "+4 Well-Being within 1 km", for example, more density means it can give that bonus to more

Final answer

Thus for the best square grid, use a block size of
  • 112m for tiny (8m) roads like the gravel road, giving a density of ⁶⁄₇ ≈ 85.7%
  • 128m for small (16m) roads like the two-lane road, giving a density of ¾ = 75%
  • 144m for medium (24m) roads like the four-lane road, giving a density of ⅔ ≈ 66.7%
  • 160m for large (32m) roads like the six-lane road, giving a density of ⅗ = 60%
  • 176m for extra-large (40m) roads like the eight-lane road, giving a density of ⁶⁄₁₁ = 54.6%
The Cost of Wider Roads
The previous section had lots of math. While that's great for finding the one best answer, it can be hard to get an intuition from it.

Here's a graph of the resulting densities for square grids using 8m (red), 16m (purple), 24m (green), 32m (orange), and 40m (blue) roads:


The thing that emphasizes to me the most is just how much density you lose to wider roads. A far-from-optimal block size using a narrower road will easily beat the optimal square block with a wider road.

Here are the ranges of block sizes where a square grid will give you particular target densities:
Target Density
Large Roads
Medium Roads
Small Roads
Tiny Roads
≥60%
160 metres
107 - 210 metres
71 - 231 metres
36 - 247 metres
≥65%
impossible
125 - 171 metres
83 - 201 metres
42 - 220 metres
≥70%
impossible
impossible
98 - 172 metres
49 - 195 metres
≥75%
impossible
impossible
128 metres
60 - 173 metres
≥80%
impossible
impossible
impossible
76 - 150 metres
≥85%
impossible
impossible
impossible
103 - 123 metres

To make an extreme example of that, the left grid below is actually more dense than the one at the right, because the wide roads just take up so much space:


As such, never zone on large (or even medium, let alone extra-large) roads.

If you feel a need for more lanes, consider using a grid of smaller one-way roads. For example, a 80m grid using 2-lane one-way roads (as seen at the right) has 64% density which, despite not being optimal, is better than the 60% density for the grid with large roads. And its traffic likely works better too, as there are far fewer conflict points for intersecting one-way roads compared to two-way roads.

Why wide roads exist

The purpose of medium and large roads is to be collectors and arterials, not for zoning. The higher capacity and higher speed is there for people who need to go a further distance. Such roads are best when they have
  • No driveways: The speed of traffic is high enough that people shouldn't be judging whether they have space to fit in when leaving. And you don't want people stuck between trucks slowing down to do deliveries (nor garbage trucks slowing down to collect, etc.)
  • No uncontrolled lefts: Whether from a side road or the main road, the road is busy enough that waiting for a gap in traffic is impractical. That means that any left has a light or roundabout, aka any intersection without one of those has all the left turns disabled. Similarly, straight across the wide road is only allowed with a light/roundabout. Though even better is not having straights across the wide road, only T-junctions -- perhaps even Continuous Green-T[virginiadot.org] intersections.
  • Few intersections: The small roads have lots of intersections to get you everywhere. The wide roads should have sufficient space between intersections that traffic can accelerate enough to take advantage of the higher speed limits. Just think about how annoying it is when you're driving along and hit a red light every 100 metres. The extra space is also needed to give vehicles enough space to change lanes when needed.
(If you search "stroad" on YouTube you'll find hundreds of videos complaining about zoning on wide roads IRL, too. This isn't just an in-game problem!)

And you'll notice that all these issues apply to plopped buildings too. The only buildings that make sense on wide roads are those where the traffic is very low or highly urgent, and there's very few of those. A Radio Mast would be ok (1 workplace), a Transformer Station (which doesn't even need a road), maybe a Fire House (8 workplaces, but the engine traffic is important). But a Fire Station has traffic from 60 workplaces, for example, a Police Station has low priority jail traffic, etc.

Indeed, you might consider just using the Two-way Highways (perhaps with Sound Barriers) in many of these situations. Then you can't zone on them, which also helps keep the zoning grid from getting confused by the extra road. Just make sure to remember to still provide good pedestrian connections so people aren't forced to get into their cars. The best public transit in CSⅡ, by far, is walking.
Rectangular Grids
Unfortunately, there's no One True™ rectangular grid. Using longer and longer rectangles does technically keep increasing the density (asymptotically). For example, using small roads you can get to 85% density, but it requires a 112×1920 metre grid. That's a block more than 3 tiles long, which is pretty excessive, if you ask me.

So instead, let's start by looking at which rectangular grids using small roads have a density at least as good as the best square grid (75%, in orange) or get up to 80% (in purple)

You can see the optimal square of 128×128 m on the graph where the two orange areas touch at the corner. And the graph is symmetric, so I cut off the top as unnecessary. The SW boundary of the orange region is at (x-64)(y-64)=3*32², except for the bit where neither side is ≥ 128 m.

The simple observation here is that 112 - 128 metres by anything 128 metres or more is at least as good as the optimal square grid. And 112×240 metres is the smallest size (with small roads) that gives 80% density.

Interestingly, there's much more freedom here than existed in CSⅠ, thanks to the deeper zoning grid. If one side of the grid is at least 128 metres (call it 𝑥), then anything from 64×(𝑥-16)÷(𝑥-64) metres up to 128 metres is also at least as good as the square grid.

For example 96×160 metres (aka 10×18 zonable cells) is just as good as the square grid, and so is 80×256 metres (aka 8×30 zonable cells). Especially the latter of those is probably too tight, and leaving more space between the intersections would probably be better, but it's still possible if you prefer that look.

What if, then, we instead look for the best rectangular grid with a particular aspect ratio 𝘙 ≥ 1? Then ISO paper fans can use √2, Fibonacci fans can use ϕ, and New York fans can use 3 or more.

We know that for a square (𝘙 = 1), we should get 𝑥 = 𝘙𝑥 = 128 metres. But we also know that in the limit as 𝘙 → ∞, we should get 𝑥 = 112. How do we bridge them?

Running some math ends up with 𝑥 = 256/(𝘙 + 1) I'll leave how as an exercise to the reader, this time. As a basic sanity check, that gives the previously-calculated answer for a square, so it seems plausible. But it has 𝑥 → 0 as 𝘙 → ∞, so it can't be the whole answer.

What happened? Well, it's critical to notice that the formula leading to that answer is based on an assumption: that 𝘙𝑥 ≥ 𝑥 ≥ 112.

That means the formula only holds for 1 ≤ 𝘙 ≤ ⁹⁄₇, which is really quite limiting. Restricting it further to only block sizes that are a multiple of 8 metres (aka "Snap to zoning cell length") leaves just
  • 𝘙 = 1, with a block size of 128×128 metres
  • 𝘙 = ¹⁷⁄₁₅ ≈ 1.1333, with a block size of 120×136 metres
  • 𝘙 = ⁹⁄₇ ≈ 1.2857, with a block size of 112×144 metres
That last one agrees with the 𝑥 = 112 answer we expected for large 𝘙, so we've found a continuous (albeit only piecewise differentiable) answer.

Perhaps it gives a reasonable way to pick a rectangle: 112×144 metres is the squarest possible aspect ratio where the optimal grid doesn't have a hole, when using small roads. It gives a density of ¹⁶⁄₂₁ ≈ 76.2%, slightly more than the 75% density from 128×128 metres.
Regular Polygons
Hexagons are the Bestagons. Among many other reasons, the honeycomb conjecture proved that hexagons have the least perimiter of any subdivision of the plane into equal-area regions. And while that's not exactly what we're trying to do here -- our roads aren't infinitely narrow, and it's not exactly area that we care about -- it's close enough that it sure seems like we ought to try it.

Doing calculations in terms of the side length of a hexagon is somewhat awkward. But if we think instead in terms of the in-diameter, we get the same formulæ as before:
  • density = (A(z) - A(h)) / A(x)
  • z = x - W
  • h = z - 2×D = x - W - 2×D
(where D is the zoning depth, to save writing out 6 × 8 m = 48 m so much)

Why did these work for a square too? Well, the side length of a square is equal to its in-diameter. (Think of the left side as the in-diameter between the top and the bottom.)

For a square, the area formula was easy, A(λ) = λ². How do we do this for a more complex shape? Well, the in-diameter is twice that of the in-radius, and the latter generalizes to the apothem of any regular polygon. Checking wikipedia for the formula, that gives us A(λ) = ¼Nλ²tan(π/N).

But most of that is a constant. Rearranging, it's A(λ) = (¼N×tan(π/N)) λ² = Cₙ λ².

So what does that do to the overall formula? density = (A(z) - A(h)) / A(x)
= (Cₙ z² - Cₙ h²) / (Cₙ x²)
= (Cₙ (z² - h²)) / (Cₙ x²)
= (z² - h²) / x²

Well that's convenient! It means that what we already calculated for the block size with a square is actually also the answer for the in-diameter of any regular polygon. (Well, there's only 3 regular polygons that tile the plane, so it's not that helpful, but at least we don't need to calculate equilateral triangles and hexagons separately.)

I loathe the zoning system

So are we done? Sadly no. The thing I most wanted Cities Skylines Ⅱ to fix was the zoning system, in hopes that it would be less awkward on curves or non-right angles. But no, we're stuck with the tyranny of little squares.

What does that mean here? Well, to the right you can see a hexagon I made with z = 12 cells. Math says that A₆(12) = ¼×6×tan(π/6)×12² = 72√3 ≈ 124.7 cells. But what we actually get is only 88 cells, if you count it up. We're missing about 36.7 cells compared to what the math says.

That makes some sense, though. It's a 6-sided shape, and the zoning depth is also 6 cells. If we expect to lose about half a cell (sometimes more, sometimes less) to rounding at each level on both sides of each edge, that'd lose us about 36 cells. Let's call that an area of N×DxZ cells: the number of corners times the depth of the zoning times (a new variable Z=8 for) the width of a lost zoning cell.

Adding a correction factor gives this:
density = (A(z) - A(h) - NDZ) / A(x)
= (Cₙ z² - Cₙ h² - NDZ) / (Cₙ x²)
= (z² - h² - NDZ/Cₙ) / x²
= (z² - h² - NDZ/(¼N×tan(π/N))) / x²
= (z² - h² - 4DZ/tan(π/N)) / x²
= (4Dx - 4D² - 4DW - 4DZ/tan(π/N)) / x²
= 4D (x - D - W - Zcot(π/N)) / x^2

The maximum for that is at x = 2(W + D + Zcot(π/N)): The same as the previous answer, plus the extra correction factor that increases the more sides there are.

For a hexagon with small roads, that gives x ≈ 155.7, or a side length of about 89.9 metres. The horrible zoning grid means that, rather than being the best, the hexagon fell to a density of only about 61.65%, worse even than a square grid with medium roads.

An equilateral triangle with small roads fares better thanks to having fewer corners. It works out to x ≈ 137.2, with a density of about 69.95%. But x here is unhelpful for drawing the triangle, since N is odd. More helpful is that the in-radius is 64+8/√3 ≈ 68.6, the side length is about 237.7, and the height -- also the distance between parallel lines in a triangular grid -- is 192 + 8√3 ≈ 205.9.
Rounding up the side length and height slightly gives a practical way to draw such a grid consistently. 26-by-15 is a remarkably good approximation: arctan(26/15) ≈ 60.018°, so it's at least 10× better than can reasonably done by eye-balling the angle measurement on your screen. Thus if you draw a base of 30 cells (240 m), then a height of 26 cells (208 m) in the middle of that base, you'll have a practical and nearly-optimal triangular grid.

The hypotenuse ends up being √( (120m)² + (208m)² ) = √(240² + 8²) m ≈ 240.133 m. That's close enough to show as just 240m in-game, and I don't think I'd notice a block being 13 cm off IRL either -- 0.056% error is completely fine.
Postscript
Thanks for coming to check out my guide! I was happy that people liked the one I wrote for the first game, so when the new one came out with a different zoning depth, I knew it was time to revisit it. If you found it interesting, please give it a 👍 to help others see it as well.

Let me know in the comments what else you'd like to see. I'm excited to experiment more with rectangular grids, with other patterns like herringbone layouts, and to see how the new alleys work in practice. Hopefully that'll turn into more sections here once I make a few more cities.

And don't feel like you have to use the highest-possible density. Optimized layouts are fun, but so are organic ones that follow the natural terrain features. Use what you like best for the map; it's your city.

Hallowe'en Edit: Thanks for making this the first ⭐⭐⭐⭐⭐ guide for CSⅡ!
88 Comments
sketch Apr 22 @ 2:19am 
Who would have thought you'll find a traffic analysis on steam. Brilliant work.
Talon Mar 8 @ 11:04pm 
Nice guide for Anti-utopian city
pr3da Feb 7 @ 5:29am 
Man you are fkn crazy. Wow, dat is awesome.
joshwiz23 Jan 27 @ 12:21pm 
math headache lol
adventurerneil Jan 14 @ 5:40am 
So satisfying for me as a non-math density-maximizer. Thank you.
Vulpsune Oct 14, 2024 @ 5:33pm 
based author
me22ca  [author] Sep 15, 2024 @ 1:59pm 
@setta3733 Forced creativity is an oxymoron.

As I said in the postscript, play how you like. Don't let anyone bully you into doing something else, and don't gatekeep how others have fun. It's a single-player game.

If you have fun seeing how dense you can get, go for it.
If you have fun following topo lines, go for it.
If you have fun starting from a 1-mile grid like the American west, go for it.
If you have fun making a Radburn-inspired garden city, go for it.
If you have fun building a planned city like DC, go for it.

Personally, I think the best cities are those that mix things. The best places to show creativity are where different philosophies meet.
Toby from HR Sep 8, 2024 @ 6:06am 
I completely agree with caseyas435943. City's should not be endless grids they should force creativity and respect topography and look nice to.
caseyas435943 Aug 14, 2024 @ 11:48pm 
TaloN.

You are building a city. Not a money crunching city. If building sterile looking cites are your thing great. I build them to look good. Having endless grinds all the same size looks terrible and boring and takes zero imagination.

If to make the game work I have to build them I'd delete the game.

I maybe have 2 blocks of 8x8. Then a few of 4x4. Then some curved blocks. Long teardrop blocks. But to have 40 8x8s. My God why?

I hardly have 4-way intersections in any town I build. This help break that horrible grind (lazy) building style.
⚔️やiͥzzͣaͫkiller⚔ Jul 12, 2024 @ 5:30pm 
thanks for the headach now i need to see a math teacher to be able to even understand this as i am not a architect XD