TL;DR
Improvement to the existing algorithm that would increase train throughput without breaking existing train networks.Why ?
I now have a large base and the bottleneck is train scheduling to bring ressources to bases, despite optimizing the train network as much as I could.The current train scheduling algorithm is great but I think it might be improved further.
I guess this was already discussed many times but there are my toughts:
The current algorithm is good to define train ordering with some guarantee of no deadlock if possible which is great.
However with a very large map it means a train could be waiting for ages for some other train to release a lock if the other train is at the other end of the map and could itself be waiting.
What ?
I think the current algorithm can be used as a basis to build a train schedule that would make train scheduling much more optimal without breaking existing train networks and preserving properties of the current algorithm:1. Build the Optimistic train schedule: from the rail model and from a train program/weight/length it's possible to compute very fast the optimistic schedule of the train (as if it's not blocked or slowed down).
The schedule is a simple list of times the train would optimistically take from the previous stop to enter and leave each crossed rail segment for the configured train program.
2. Add a schedule to each rail segment
Starting with the first train to ask (the highest priority train), the algorithm would insert trains in the schedule for a segment, so no more than one train can be scheduled on the segment at a given time.
The rail segment schedule would replace the current rail segment waiting queue. It could be implemented as a simple linked list of time pairs, maybe with a train reference. It could be invisible for the user.
3. When a train wants to go to its next stop, it would ask to be added to the schedule of rail segments on its path.
A newer/lower priority train would have to wait for the next available time in the schedule. This ensures an older/higher priority train would never be slowed down by a lower priority train.
However a lower priority train can be scheduled before a higher priority train if it fits in the schedule.
If rail segments are linked together (with advanced signals), a train can be scheduled only if its schedule fits for all of the linked segments. It is scheduled as soon as possible given the current segment schedules.
Performance
Optimistic train schedule only needs to be computed when the rails, the train or its program change.
Scheduling rail segments should be quite fast and happens incrementally as train add themselves to the schedule.