Skip to content

Commit

Permalink
core: sim: ignore overlapping scheduled points
Browse files Browse the repository at this point in the history
Update core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt

Co-authored-by: bougue-pe <150040524+bougue-pe@users.noreply.github.com>
  • Loading branch information
eckter and bougue-pe committed Jun 18, 2024
1 parent 76b4250 commit a85eb96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package fr.sncf.osrd.api.api_v2
import fr.sncf.osrd.api.api_v2.standalone_sim.SimulationScheduleItem
import fr.sncf.osrd.utils.units.TimeDelta
import java.lang.Long.min
import mu.KotlinLogging

val simulationScheduleItemParserLogger = KotlinLogging.logger {}

/**
* Merge consecutive schedule items which are at the same location, i.e. have the same path offset.
Expand Down Expand Up @@ -44,9 +47,12 @@ fun parseRawSimulationScheduleItems(
onStopSignal = onStopSignal || rawSimulationScheduleItems[i + 1].onStopSignal
i++
}
simulationScheduleItems.add(
SimulationScheduleItem(pathOffset, arrival, stopFor, onStopSignal)
)
val newItem = SimulationScheduleItem(pathOffset, arrival, stopFor, onStopSignal)
if (simulationScheduleItems.lastOrNull() == newItem) {
simulationScheduleItemParserLogger.warn { "duplicated schedule items: $newItem" }
} else {
simulationScheduleItems.add(newItem)
}
i++
}
return simulationScheduleItems.sortedBy { it.pathOffset }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import fr.sncf.osrd.utils.indexing.StaticIdxList
import fr.sncf.osrd.utils.units.Distance
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters
import org.slf4j.Logger
import org.slf4j.LoggerFactory

val standaloneSimLogger: Logger = LoggerFactory.getLogger("StandaloneSimulation")

/** Run a simulation for a single train. */
fun runStandaloneSimulation(
Expand Down Expand Up @@ -216,6 +220,7 @@ fun buildFinalEnvelope(
var extraTime = point.arrival.seconds - arrivalTime
if (extraTime < 0.0) {
// TODO: raise a warning
standaloneSimLogger.warn("impossible scheduled point")
extraTime = 0.0
}
marginRanges.addAll(
Expand Down Expand Up @@ -271,6 +276,12 @@ fun distributeAllowance(
startOffset: Offset<TravelledPath>,
endOffset: Offset<TravelledPath>
): List<AllowanceRange> {
assert(startOffset <= endOffset)
if (startOffset == endOffset) {
// TODO: raise warning (overlapping scheduled points)
standaloneSimLogger.info("Warning: different scheduled points at the same location")
return listOf()
}
fun rangeTime(
from: Offset<TravelledPath>,
to: Offset<TravelledPath>,
Expand Down

0 comments on commit a85eb96

Please sign in to comment.