Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: stdcm: fix post-processing when arrival time is set #9874

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
),
)
}
}
Loading