Skip to content

Commit

Permalink
core: stdcm: limit the loop where we look for possible delays
Browse files Browse the repository at this point in the history
We would keep looking for different "openings" even very far in the
future. This limits both conflict detection calls and the early steps of
edge building.

Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Dec 18, 2024
1 parent 5d127e0 commit b53af39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/DelayManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fr.sncf.osrd.utils.units.Distance.Companion.fromMeters
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters
import java.util.*
import kotlin.math.min

/**
* This class contains all the methods used to handle delays (how much we can add, how much we need
Expand All @@ -29,10 +30,12 @@ internal constructor(
*/
fun minimumDelaysPerOpening(
infraExplorerWithNewEnvelope: InfraExplorerWithEnvelope,
startTime: Double,
timeData: TimeData,
envelope: Envelope,
startOffset: Offset<Block>,
): NavigableSet<Double> {
val startTime = timeData.earliestReachableTime
val maximumDelay = computeMaximumDelay(timeData)
val res = TreeSet<Double>()
val endOffset = startOffset + fromMeters(envelope.endPos)
var time = startTime
Expand All @@ -44,6 +47,7 @@ internal constructor(
endOffset,
time,
)
if (time - startTime > maximumDelay) break
time +=
when (availability) {
is BlockAvailabilityInterface.Available -> {
Expand All @@ -58,6 +62,17 @@ internal constructor(
return res
}

/**
* Compute how much delay we may add here. Prevents the generation of edges very far in the
* future that would necessarily be discarded.
*/
private fun computeMaximumDelay(data: TimeData): Double {
val maxExtraRunTime = maxRunTime - data.totalRunningTime
val maxDelayForMaxRunTime = data.maxDepartureDelayingWithoutConflict + maxExtraRunTime
val maxDelayWithLocalConflict = data.timeOfNextConflictAtLocation - data.earliestReachableTime
return min(maxDelayForMaxRunTime, maxDelayWithLocalConflict)
}

/** Returns the start time of the next occupancy for the block */
fun findNextOccupancy(
infraExplorer: InfraExplorerWithEnvelope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal constructor(
private fun getDelaysPerOpening(): Set<Double> {
return graph.delayManager.minimumDelaysPerOpening(
getExplorerWithNewEnvelope()!!,
prevNode.timeData.earliestReachableTime,
prevNode.timeData,
envelope!!,
startOffset,
)
Expand Down

0 comments on commit b53af39

Please sign in to comment.