Unfortunately, as far as I know, trains currently do
not detect if they are cutting another train off, even if there are multiple trains waiting. Such a detection would require track to have a "lookahead" reservation, so that a train that intends to reserve a track will notice if another train intends to use that track soon, so it can take the other train's "lookahead" reservation into account when deciding which track to take.
I'm afraid implementing "weak" and "lookahead" reservations will require a complete rewrite of the way reservations are stored, because a track segment would have to be able to contain several reservations from different trains, for example one "strong" reservation, two "weak" reservations and seven "lookahead" reservations.
Here is a short summary of the different types of reservations that I think must be implemented:
exclusive reservations:
A train making this type of reservation tells other trains:
"I currently need exclusive access to this track segment so no other trains may use it. Since I may be forced to wait in front of a red signal in this reserved segment, 'weak' reservations from other trains into this segment are currently not permitted."
This reservation type permits only additional "lookahead" reservations on this track segment. No other reservation types are permitted and only one such reservation may exist on a single track segment. An exception to this rule is that there may be two exclusive reservations on the same track segment if you explicitly force a train over a red signal (thereby risking a crash).
strong reservations:
A train making this type of reservation tells other trains:
"I am currently using this track segment, so no other trains may use it at the moment. However, I guarantee that I will be leaving this track segment soon and won't get stuck in it, so other trains may make 'weak' reservations on this segment."
This reservation type permits other trains to make a "waiting", "weak" and "lookahead" reservations on this track segment. No further "exclusive" or "strong" reservations are permitted, unless you explicitly force a train over a red signal (thereby risking a crash).
waiting reservations:
A train making this type of reservation tells other trains:
"Although I am currently not using this track, I plan to use this track segment
as my next safe waiting location. Therefore, other trains may reserve this track, as long as they guarantee that they won't get stuck inside this segment, because that could cause me getting stuck in a non-safe waiting location, i.e. in front of a signal declared as an unsafe waiting location."
This reservation type permits other trains to make "strong" and "weak" reservations, but not "exclusive" reservations or further "waiting" reservations, because these reservations do not guarantee that the other train will be able to clear the segment without getting stuck.
weak reservations:
A train making this type of reservation tells other trains:
"Although I am currently not using this track, I plan to use this track segment
as a route to my next safe waiting location.
I do not intend to actually wait inside this track segment. Therefore, other trains may reserve this track, as long as they guarantee that they won't get stuck inside this segment, because that could cause me getting stuck in a non-safe waiting location, i.e. in front of a signal declared as an unsafe waiting location."
The difference between a "weak" reservation and a "waiting" reservation is that only one "waiting" reservation is allowed per track segment, because there is only room for one train in front of every safe waiting location (i.e. standard signal, station platform). Also, a train with a "waiting" reservation must first let all other trains with a "weak" reservation past this segment, otherwise it will be blocking all trains with a "weak" reservation if it gets stuck.
lookahead reservations:
A train making this type of reservation tells other trains:
"I plan to use this track segment soon. If other trains want to use it too and there is a conflict, a train prioritization system must decide which train should be given right of way."
There is no limit in the number of "lookahead" reservations a track segment may have and they can be combined with any other reservation type. These "lookahead" reservations are simply used to detect train conflicts in advance, so they can be resolved in advance by a train prioritization system. For example, trains with a higher priority will be given right of way and trains with lower priority will have to wait.
Michi_cc wrote:The problem is that 'implement weak reservations' sounds like a nice and simple addition to YAPP. Doing it right, i.e weak reservations that actually work in all cases, is many things, but certainly not nice and simple.
Proper weak reservations imply that trains influence each other's pathfinding decision, because otherwise it's not possible to optimally choose between using the weak reservation or making another. This is something the current pathfinder framework can not do. So implement weak reservations turns into someting like do a complete pathfinder rewrite, a much bigger task than YAPP was.
Strictly speaking, it is not necessary that trains influence each other's pathfinding decision in order to implement 'weak' reservations. However, it is correct that 'weak' reservations are useless with
bi-directional double track without a good train prioritization system using 'lookahead' reservations.