The International Simutrans Forum

 

Author Topic: Pull request: Smoother industry retirement algorithm  (Read 156 times)

0 Members and 1 Guest are viewing this topic.

Offline freddyhayward

  • Devotee
  • *
  • Posts: 456
  • Languages: EN
Pull request: Smoother industry retirement algorithm
« on: November 21, 2020, 03:42:27 AM »
https://github.com/jamespetts/simutrans-extended/pull/300
This patch affects the chance over time of an industry having to close down or upgrade after it has retired.

It works on the same general principle as the current algorithm, which is to gradually increase the chance every month until a final month, given by a number of years (32 by default) past the industry's retire month. All industries are guaranteed to close/upgrade on or before that month.

The problem with the current algorithm is that a large number of industries remain open by the time the final month is reached (see Fig 1), resulting in a large 'death spike' of mass closures (see Fig. 2).

This effect was harshly felt on bridgewater-brunel. On one occasion, almost all coal-fired power stations closed in a single month, leaving most of the world suddenly without power. On another occasion, nearly 600 industries closed down in a single month, which froze the server for several minutes.

My patch addresses this problem by closing down industries at a roughly uniform rate between the retire month and the final month. The actual chance per month still increases every month, but an industry has a roughly equal chance of closing at any point within this period. Remaining industries are still guaranteed to close/upgrade on the final month, but the rate of closure means that only a very small number of industries actually remain by then.


Offline Matthew

  • *
  • Posts: 439
    • Japan Railway Journal
  • Languages: EN, some ZH, DE & SQ
Re: Pull request: Smoother industry retirement algorithm
« Reply #1 on: November 21, 2020, 07:45:40 AM »
From the point of view of a player, this appears to simply be a better implementation of James' successful feature design, and therefore an unqualified improvement.

It's also really encouraging to see the patch has been tested and has produced good results.

I wonder whether it would be worth testing it on an offline B-B save just to check for any transitional effects?

I am not qualified to comment on the quality of the code, but otherwise I would like to see this implemented soon.

Offline freddyhayward

  • Devotee
  • *
  • Posts: 456
  • Languages: EN
Re: Pull request: Smoother industry retirement algorithm
« Reply #2 on: November 21, 2020, 08:33:17 AM »
I wonder whether it would be worth testing it on an offline B-B save just to check for any transitional effects?
Thanks for suggesting this - I have just tested B-B from October to November 1943, and didn't find anything out of the ordinary. Two industries did close at the beginning of November. Do you know how many closed at the same time online?

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20342
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Pull request: Smoother industry retirement algorithm
« Reply #3 on: November 21, 2020, 11:57:00 AM »
Excellent, thank you very much for this. If Freddy's tests are correct (and I trust that they are), the new algorithm is indeed a better implementation of what I had always intended than my old algorithm: the large numbers of industries closing down at once was evidently disruptive and unrealistic.

I have now incorporated Freddy's patch; I very much appreciate the large amount of work that has gone into writing and testing this. It is a definite improvement.