The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: inkelyad on May 30, 2010, 07:24:19 PM

Title: The size of cities after map creation.
Post by: inkelyad on May 30, 2010, 07:24:19 PM
The size of cities after map creation should follow Zipf's distribution.
http://www2.econ.uu.nl/users/marrewijk/geography/zipf/index.htm (http://www2.econ.uu.nl/users/marrewijk/geography/zipf/index.htm),
http://www.nslij-genetics.org/wli/zipf/ (http://www.nslij-genetics.org/wli/zipf/)
Title: Re: The size of cities after map creation.
Post by: jamespetts on May 30, 2010, 08:29:07 PM
Inkelyad,

this looks very interesting, although I haven't had a chance to try it yet as I'm currently away from home. Looking at your patch, it doesn't seem that this is specific to Simutrans-Experimental, and could work equally well in Simutrans-Standard. I'll move the topic to the standard development and bug reports, patch releases folder so that the Standard developers can have a look at this one. I shall also have a look at it when I get the chance, if it hasn't already been slated for inclusion in Standard by then.

Edit: May I ask - how does it work for you when you test it?
Title: Re: The size of cities after map creation.
Post by: prissi on May 30, 2010, 09:43:29 PM
The current generation is already 25000*mean_number/(simrand(20000)+100) (the 100 is just to avoid too large towns). Thus this is already close to said distribution.
Title: Re: The size of cities after map creation.
Post by: jamespetts on May 30, 2010, 09:53:40 PM
Inkelyad,

do you notice a major difference in practice between the original version and your version when maps are generated?
Title: Re: The size of cities after map creation.
Post by: inkelyad on May 31, 2010, 04:04:19 PM
In current implementation there is almost 10% chance city population will
be greater then mean_number * 10. When city number is 22 that means there is
only 10% chance map will have less then 7 such cities. It is way too often.

Zipf's distribution don't do that. It creates only one big city.

Title: Re: The size of cities after map creation.
Post by: jamespetts on May 31, 2010, 04:32:28 PM
Inkelyad,

can you give some examples of the maps created with and without your patch - either in a table or with screenshots? It's hard to gauge the effect without a little more detail.

Prissi - in your opinion, is Inkelyad right about the difference in distribution between the model in this patch and that in Standard; and which do you think is closer to reality?
Title: Re: The size of cities after map creation.
Post by: inkelyad on May 31, 2010, 04:41:27 PM
Sorry, my math was wrong. But current implementation really too often makes too big cities.
Title: Re: The size of cities after map creation.
Post by: jamespetts on May 31, 2010, 06:58:51 PM
Quote from: inkelyad on May 31, 2010, 04:41:27 PM
Sorry, my math was wrong. But current implementation really too often makes too big cities.


The maths in your patch, in your explanation of the patch, or both? Does that mean that we should not use your patch?
Title: Re: The size of cities after map creation.
Post by: inkelyad on May 31, 2010, 07:14:17 PM
Math in explanation. I am wrong about "When city number is 22 that means there is
only 10% chance map will have less then 7 such cities".
Title: Re: The size of cities after map creation.
Post by: prissi on May 31, 2010, 08:30:48 PM
In you link Zipf distribution is Pn = 1/n (when alpha=1 what should be often the case, according to the text.) That is exactly the code implemented in Simutrans.

The only difference is, that Pn is limited between 25*mean_number < generated number < 0.124 * mean_number. There is a 10% chance for a city larger than 1,19 than mean_number, and a 5% chance for 2.27*mean_number, and a 1% chance for 8.333*mean_number. The probability for a city larger than 10x mean_number is actually 0,66%, i.e. you need on average more than 150 cities until one is larger than 10x mean_number.

Since those are random numbers, you milage may vary ...
Title: Re: The size of cities after map creation.
Post by: jamespetts on June 01, 2010, 10:50:32 AM
I'm still not clear on how the patch differs in practice from the current Simutrans implementation...
Title: Re: The size of cities after map creation.
Post by: prissi on June 01, 2010, 12:44:09 PM
A short glance at the algorithm would indicate, that you would always have a guranteed Zipf distribution on your map (with some small jittering) compared to the current, more random one (especially for small number of towns). As this is noticeable in practice: just patch and see.
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 01, 2010, 04:28:49 PM
Quote from: jamespetts on May 31, 2010, 04:32:28 PM
can you give some examples of the maps created with and without your patch - either in a table or with screenshots? It's hard to gauge the effect without a little more detail.
Yes. See attached OpenOffice OpenDocument Spreadsheet
Title: Re: The size of cities after map creation.
Post by: prissi on June 01, 2010, 09:25:21 PM
Actually, standard has a better Zipf distribution, the slope is exactly -1 ... The main difference between the patch and the unpatched version is, that the mean number is effectively 2.5 higher than in the patched version (well, more precisely rising from 2 to 2.8, since the slope differs a little.) All in all the effect of this patch can be achieved by dividing the mean_citicen number by 2.4 before starting creation.
Title: Re: The size of cities after map creation.
Post by: jamespetts on June 01, 2010, 10:50:50 PM
Prissi,

thank you very much for the graphs - most useful!

Inkelyad,

did you intend for your patch to have the effect that Prissi describes?
Title: Re: The size of cities after map creation.
Post by: prissi on June 02, 2010, 02:52:34 PM
I just plotted Inkelyads data; so the credit should go to him ...
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 05, 2010, 02:10:18 AM
Quote from: prissi on May 31, 2010, 08:30:48 PM
The probability for a city larger than 10x mean_number is actually 0,66%, i.e. you need on average more than 150 cities until one is larger than 10x mean_number.
There is something wrong here. See attached data(100 rows 50 cities each). Rank 1 cities larger then 10*mean_number are too common in "Standard".
Quote from: prissi on June 01, 2010, 09:25:21 PM
The main difference between the patch and the unpatched version is, that the mean number is effectively 2.5 higher than in the patched version (well, more precisely rising from 2 to 2.8, since the slope differs a little.)
I beliveve main difference is Rank 1 distributions (see images)
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 05, 2010, 02:11:30 AM
Quote from: jamespetts on June 01, 2010, 10:50:50 PM
did you intend for your patch to have the effect that Prissi describes?
No.
It is hard to get proper "city and satellite towns/villages" map in current implementation. Rank 1 sizes are "too random".

The goal was to correct it.

But it seems to me I was too successful. Now randomness is too small.
Title: Re: The size of cities after map creation.
Post by: jamespetts on June 05, 2010, 12:04:52 PM
Quote from: inkelyad on June 05, 2010, 02:11:30 AM
No.
It is hard to get proper "city and satellite towns/villages" map in current implementation. Rank 1 sizes are "too random".

The goal was to correct it.

But it seems to me I was too successful. Now randomness is too small.

Hmm - perhaps a happy medium is to be sought...?
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 06, 2010, 05:18:22 PM
Quote from: jamespetts on June 05, 2010, 12:04:52 PM
Hmm - perhaps a happy medium is to be sought...?
Ok. New version. Now number of 'big cities' is player configurable.
Option is not persistent yet. I don't want break option savefile compatibility.
Title: Re: The size of cities after map creation.
Post by: jamespetts on June 06, 2010, 05:23:46 PM
Interesting... can you give some worked examples with map generation with various options?
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 06, 2010, 07:24:46 PM
Map size: 512x512
Median population: 5000
Number of cities: 50
Number of big cities: 1, 5 and 30
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 06, 2010, 07:26:17 PM
Map size: 512x512
Median population: 3000, 8000 and 16000
Number of cities: 50
Number of big cities: 3
Title: Re: The size of cities after map creation.
Post by: inkelyad on June 06, 2010, 07:27:58 PM
Map size: 128x128
Median population: 1600
Number of cities: 30
Number of big cities: 1, 5 and 20
Title: Re: The size of cities after map creation.
Post by: jamespetts on June 06, 2010, 08:32:34 PM
That's very interesting indeed. I do like the customisability of the new system (which adds something to the existing model). I'd be very interested in people's views on whether this is a good idea, as I'm considering incorporating it into Simutrans-Experimental, if it hasn't already been put into Standard.
Title: Re: The size of cities after map creation.
Post by: vilvoh on June 06, 2010, 08:54:23 PM
I like the idea. Taking a look at the graphics, for me it's clear that standard Simutrans tends to create much more small cities than large ones. It has sense if you want to power the possibilities of the map. Small cities means less developed areas and more margin for the player to expand the game (put more effort into making cities grow). On the other side, Zipfs customizable maps may add some pepper to the initial conditions of the sceneario. The variety that zipfs generates is flexible but also balanced enough to make the initial conditions interesting.

Imho, you should include it at STExp and if players like it, I would estimate the inclusion in ST, too.
Title: Re: The size of cities after map creation.
Post by: prissi on February 02, 2012, 10:46:28 PM
As it is in experimental and adding another rather difficult parameter to the city creation, I move this to incoporated.