Skip to content

Commit 991d518

Browse files
committed
core: stdcm: move "max delay" logic to edge
Signed-off-by: Eloi Charpentier <[email protected]>
1 parent 29dc885 commit 991d518

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMEdge.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ data class STDCMEdge(
9292
stopDuration,
9393
graph.delayManager.getMaxAdditionalStopDuration(
9494
infraExplorerWithNewEnvelope,
95-
timeData.earliestReachableTime + totalTime
95+
getEdgeEndTime(),
9696
)
9797
),
9898
endSpeed,
@@ -172,4 +172,23 @@ data class STDCMEdge(
172172
fun fromTravelledOffset(travelledPathOffset: Offset<TravelledPath>): Offset<BlockPath> {
173173
return infraExplorer.getIncrementalPath().fromTravelledPath(travelledPathOffset)
174174
}
175+
176+
/** Return the time at which the train quits this edge and moves on to the next. */
177+
private fun getEdgeEndTime(): Double {
178+
return timeData.earliestReachableTime + totalTime
179+
}
180+
181+
/**
182+
* Return how much delay we can add on this edge. We need to be given the time added on the next
183+
* edges (both departure delaying and allowances), as they carry over previous edges.
184+
*/
185+
fun getMaxAddedDelay(addedAllowanceOnNextEdges: Double): Double {
186+
val maxAddedDelay = timeData.timeOfNextConflictAtLocation - getEdgeEndTime()
187+
return maxAddedDelay - addedAllowanceOnNextEdges
188+
}
189+
190+
/** Return all delay added to this edge, engineering + departure delay */
191+
fun getTotalAddedDelayOnEdge(): Double {
192+
return timeData.delayAddedToLastDeparture + (engineeringAllowance?.extraDuration ?: 0.0)
193+
}
175194
}

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class STDCMGraph(
162162
while (true) {
163163
val edge = node.previousEdge ?: return maxTime
164164

165+
// TODO: this is wrong, we should use `edge.getMaxAddedDelay` instead.
166+
// But doing so can lead to infinite loops, especially in the unit test "infraWithLoop".
165167
val latestTimeWithMaxShift =
166168
edge.timeData.earliestReachableTime +
167169
edge.totalTime +

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/engineering_allowance/SimulationSegment.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ fun generatePreviousSimulationSegments(
6767
if (currentEdge.endAtStop) break
6868

6969
val envelope = currentEdge.originalEnvelope
70-
val edgeEndTime = currentEdge.timeData.earliestReachableTime + currentEdge.totalTime
71-
val maxAddedDelay =
72-
currentEdge.timeData.timeOfNextConflictAtLocation - edgeEndTime - alreadyAddedDelay
70+
val maxAddedDelay = currentEdge.getMaxAddedDelay(alreadyAddedDelay)
7371
if (maxAddedDelay <= 0.0) break
7472

7573
val backwardsPointPairs =
@@ -103,8 +101,7 @@ fun generatePreviousSimulationSegments(
103101
)
104102
)
105103
}
106-
currentEdge.engineeringAllowance?.let { alreadyAddedDelay += it.extraDuration }
107-
alreadyAddedDelay += currentEdge.timeData.delayAddedToLastDeparture
104+
alreadyAddedDelay += currentEdge.getTotalAddedDelayOnEdge()
108105
currentEdge = currentEdge.previousNode.previousEdge
109106
}
110107
}

0 commit comments

Comments
 (0)