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: limit the loop where we look for possible delays #10126

Merged
merged 1 commit into from
Dec 19, 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
19 changes: 18 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,8 @@ 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.max
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,14 +31,17 @@ 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
while (java.lang.Double.isFinite(time)) {
if (time - startTime > maximumDelay) break
val availability =
getLastBlockAvailability(
infraExplorerWithNewEnvelope,
Expand All @@ -58,6 +63,18 @@ 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 max(0.0, 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.opentelemetry.instrumentation.annotations.WithSpan
import java.time.Duration
import java.time.Instant
import java.util.*
import kotlin.Double.Companion.POSITIVE_INFINITY
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -272,7 +273,7 @@ class STDCMPathfinding(
earliestReachableTime = startTime,
maxDepartureDelayingWithoutConflict = maxDepartureDelay,
departureTime = startTime,
timeOfNextConflictAtLocation = 0.0,
timeOfNextConflictAtLocation = POSITIVE_INFINITY,
totalRunningTime = 0.0,
stopTimeData = listOf(),
maxFirstDepartureDelaying = maxDepartureDelay,
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/TimeData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ data class TimeData(
var maxDepartureDelayingWithoutConflict = maxDepartureDelayingWithoutConflict
val nextEarliestReachableTime =
earliestReachableTime + extraTravelTime + (extraStopTime ?: 0.0)
var timeOfNextConflict = timeOfNextConflictAtLocation
if (maxAdditionalStopTime != null)
timeOfNextConflict = nextEarliestReachableTime + maxAdditionalStopTime
if (extraStopTime != null) {
val stopDataCopy = newStopData.toMutableList()
stopDataCopy.add(
Expand All @@ -108,6 +111,7 @@ data class TimeData(
maxDepartureDelayingWithoutConflict = maxDepartureDelayingWithoutConflict,
maxFirstDepartureDelaying =
min(maxFirstDepartureDelaying, (maxAdditionalStopTime ?: POSITIVE_INFINITY)),
timeOfNextConflictAtLocation = timeOfNextConflict,
)
}

Expand Down
Loading