Skip to content

Commit

Permalink
core: stdcm: fix post-processing when arrival time is set
Browse files Browse the repository at this point in the history
We'd add too much delay to the departure time,
resulting in inconsistencies

Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Nov 28, 2024
1 parent ab6cdbb commit a41cfd2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,26 @@ data class STDCMNode(
return relativeMaxTimeDiff
}

/** Returns true if there's no stop between the start and this node (excluded). */
private fun isBeforeFirstStop(): Boolean {
var edge = previousEdge
while (true) {
if (edge == null) return true
val node = edge.previousNode
if (node.stopDuration != null) return false
edge = node.previousEdge
}
}

/**
* Compute how much delay we can add to the current node, given some elements about what happens
* further down the path. The tricky part is identifying how stop durations may be adjusted to
* locally change passage times without conflict.
*/
private fun computeMaxAddedDelay(updatedTimeData: TimeData): Double {
if (isBeforeFirstStop()) {
return updatedTimeData.maxFirstDepartureDelaying
}
var maxAddedDelay = Double.POSITIVE_INFINITY

// List of stops that haven't been reached on this node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class STDCMPostProcessing(private val graph: STDCMGraph) {
node,
nodes.subList(firstPlannedNodeIndex + 1, nodes.size),
mutableStopData,
timeData,
)
var actualStopAddedTime = min(maxAddedTime, timeDiff)

Expand Down Expand Up @@ -231,7 +232,9 @@ class STDCMPostProcessing(private val graph: STDCMGraph) {
node: STDCMNode,
nextNodes: List<STDCMNode>,
mutableStopData: MutableList<StopTimeData>,
lastTimeData: TimeData,
): Double {
if (lastStopIndexBeforeNode == 0) return lastTimeData.maxFirstDepartureDelaying
var maxTimeDiff = Double.POSITIVE_INFINITY
var nextStopIndex = lastStopIndexBeforeNode
if (node.stopDuration != null) nextStopIndex++
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/kotlin/fr/sncf/osrd/stdcm/FullSTDCMTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class FullSTDCMTests {
} else {
assertEquals(expectedPassageTime, res.departureTime + res.envelope.totalTime, timeStep)
}
assertTrue(res.departureTime <= 12_000.0) // Max departure delay
}

/** Check that the result we find doesn't cause a conflict */
Expand Down Expand Up @@ -381,6 +382,14 @@ class FullSTDCMTests {
10_000.0,
true,
),
Arguments.of(
start,
end,
null,
PlannedTimingData(20_000.seconds, 1_000.seconds, 1_000.seconds),
19_000.0, // We'd need more than max departure delay to reach 20_000
true,
),
)
}
}

0 comments on commit a41cfd2

Please sign in to comment.