Page 1 of 1

Performant train routing

Posted: Sun Jan 06, 2019 12:07 am
by Mike5000
The objective is to provide improved control of train routing without impacting performance and with neither the implementation complexity nor the end use complexity of LTN.

There are many existing suggestions for providing increased control of train routing. However they tend to require hooks into the A* search which would impact performance. This suggestion hooks into the preparation for the A* search without modifying the A* search itself, thus providing improved routing control without impacting performance.

The train pathfinding code is invoked with an array request.toEnds which I presume is obtained by searching the train's surface for enabled train stops whose names match the train's current schedule record. I have studed 0.16 train pathfinding code and am hopeful that this suggestion is compatible with the way that Factorio uses the train pathfinding code.

My suggestion is for an optional hook on the surface which if present would be invoked prior to train pathfinding and which would take as sole argument the train and which would return either an array of target train stops or else a string which would be displayed instead of "no path". An empty array or any other return value would result in the default "no path" message. There would be no subsequent filtering - in other words the chosen train stops would be passed to train pathfinding whether enabled or disabled and whether or not their names matched.

This would enable:
  • A mod could avoiding thundering herds by limiting the number of trains pathing to a stop.
  • A mod could match an "Iron Mine 5" train stop to an "Iron Mine" schedule record.
  • A mod could cause a train to display "Waiting for full load" instead of "no path".
  • A mod could target a train to the train stop with the most available ore (or other circuit value).
Thank you for your consideration.