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: fix input to TrainScheduleV2 into 'Offset<TravelledPath>' #7532

Merged
merged 1 commit into from
May 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fr.sncf.osrd.sim_infra.impl.buildChunkPath
import fr.sncf.osrd.utils.DistanceRangeMap
import fr.sncf.osrd.utils.indexing.DirStaticIdxList
import fr.sncf.osrd.utils.indexing.StaticIdx
import fr.sncf.osrd.utils.units.Length
import fr.sncf.osrd.utils.units.Distance
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.Speed
import java.lang.RuntimeException
Expand Down Expand Up @@ -46,7 +46,7 @@ interface PathProperties {

@JvmName("getSpeedLimits") fun getSpeedLimits(trainTag: String?): DistanceRangeMap<Speed>

@JvmName("getLength") fun getLength(): Length<Path>
@JvmName("getLength") fun getLength(): Distance

@JvmName("getTrackLocationAtOffset")
fun getTrackLocationAtOffset(pathOffset: Offset<Path>): TrackLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ data class PathPropertiesImpl(
}
}

override fun getLength(): Length<Path> {
return Length(chunkPath.endOffset - chunkPath.beginOffset)
override fun getLength(): Distance {
return chunkPath.endOffset - chunkPath.beginOffset
}

override fun getTrackLocationAtOffset(pathOffset: Offset<Path>): TrackLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package fr.sncf.osrd.sim_infra.utils
import fr.sncf.osrd.geom.LineString
import fr.sncf.osrd.sim_infra.api.*
import fr.sncf.osrd.utils.DistanceRangeMap
import fr.sncf.osrd.utils.units.Length
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.Speed
import fr.sncf.osrd.utils.units.meters
import fr.sncf.osrd.utils.units.*

/**
* This class is used to create a PathProperties from a slice of an existing PathProperties.
Expand All @@ -27,7 +24,7 @@ data class PathPropertiesView(
return base
.getOperationalPointParts()
.map { IdxWithOffset(it.value, it.offset - startOffset.distance) }
.filter { it.offset >= Offset(0.meters) && it.offset <= getLength() }
.filter { it.offset >= Offset(0.meters) && it.offset.distance <= getLength() }
}

override fun getGradients(): DistanceRangeMap<Double> {
Expand All @@ -39,7 +36,7 @@ data class PathPropertiesView(
}

override fun getGeo(): LineString {
val baseLength = base.getLength().distance.meters
val baseLength = base.getLength().meters
return base
.getGeo()
.slice(startOffset.distance.meters / baseLength, endOffset.distance.meters / baseLength)
Expand All @@ -61,8 +58,8 @@ data class PathPropertiesView(
return sliceRangeMap(base.getSpeedLimits(trainTag))
}

override fun getLength(): Length<Path> {
return Length(endOffset - startOffset)
override fun getLength(): Distance {
return endOffset - startOffset
}

override fun getTrackLocationAtOffset(pathOffset: Offset<Path>): TrackLocation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.sncf.osrd.api.api_v2

import com.squareup.moshi.Json
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.sim_infra.api.TrackSection
Expand All @@ -21,7 +22,7 @@ data class UndirectedTrackRange(
)

data class RangeValues<T>(
val boundaries: List<Offset<Path>> = listOf(),
val boundaries: List<Offset<TravelledPath>> = listOf(),
val values: List<T> = listOf()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package fr.sncf.osrd.api.api_v2.path_properties
import com.google.common.collect.Range
import fr.sncf.osrd.api.api_v2.RangeValues
import fr.sncf.osrd.api.pathfinding.toRJSLineString
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.railjson.schema.geom.RJSLineString
import fr.sncf.osrd.sim_infra.api.NeutralSection
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.sim_infra.api.PathProperties
import fr.sncf.osrd.sim_infra.api.RawSignalingInfra
import fr.sncf.osrd.utils.DistanceRangeMap
Expand Down Expand Up @@ -112,7 +112,7 @@ private fun <T> makeRangeValues(distanceRangeMap: DistanceRangeMap<T>): RangeVal
}

private fun <T> makeRangeValues(entries: List<DistanceRangeMap.RangeMapEntry<T>>): RangeValues<T> {
val boundaries = mutableListOf<Offset<Path>>()
val boundaries = mutableListOf<Offset<TravelledPath>>()
val values = mutableListOf<T>()
for (entry in entries) {
boundaries.add(Offset(entry.upper))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.squareup.moshi.*
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import fr.sncf.osrd.api.api_v2.RangeValues
import fr.sncf.osrd.api.api_v2.TrackRange
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.envelope_sim.PhysicsRollingStock.GammaType
import fr.sncf.osrd.railjson.schema.rollingstock.RJSEffortCurves.RJSModeEffortCurve
import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance
Expand Down Expand Up @@ -90,7 +91,7 @@ class SimulationPath(
)

class SimulationScheduleItem(
@Json(name = "path_offset") val pathOffset: Offset<Path>,
@Json(name = "path_offset") val pathOffset: Offset<TravelledPath>,
val arrival: TimeDelta?,
@Json(name = "stop_for") val stopFor: Duration?,
@Json(name = "on_stop_signal") val onStopSignal: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import fr.sncf.osrd.api.api_v2.*
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.reporting.exceptions.OSRDError
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.utils.json.UnitAdapterFactory
Expand Down Expand Up @@ -39,7 +40,7 @@ class MRSPResponse(
)

class CompleteReportTrain(
positions: List<Offset<Path>>,
positions: List<Offset<TravelledPath>>,
times: List<TimeDelta>, // Times are compared to the departure time
speeds: List<Double>,
@Json(name = "energy_consumption") energyConsumption: Double,
Expand All @@ -50,7 +51,7 @@ class CompleteReportTrain(
) : ReportTrain(positions, times, speeds, energyConsumption)

open class ReportTrain(
val positions: List<Offset<Path>>,
val positions: List<Offset<TravelledPath>>,
val times: List<TimeDelta>, // Times are compared to the departure time
val speeds: List<Double>,
@Json(name = "energy_consumption") val energyConsumption: Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun convertPathfindingResult(
warningRecorder: DiagnosticRecorderImpl
): PathfindingResult {
val path = makePathProps(rawInfra, blockInfra, rawPath.ranges)
val result = PathfindingResult(path.getLength().distance.meters)
val result = PathfindingResult(path.getLength().meters)
result.routePaths = makeRoutePath(blockInfra, rawInfra, rawPath.ranges)
result.pathWaypoints = makePathWaypoint(path, rawPath, rawInfra, blockInfra)
result.geographic = makeGeographic(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RemainingDistanceEstimator(
): Point {
val path = makePathProps(blockInfra, rawInfra, blockIdx)
val lineString = path.getGeo()
val normalizedOffset = pointOffset.distance.meters / path.getLength().distance.meters
val normalizedOffset = pointOffset.distance.meters / path.getLength().meters
return lineString.interpolateNormalized(normalizedOffset)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.common.collect.TreeRangeMap
import fr.sncf.osrd.api.FullInfra
import fr.sncf.osrd.api.api_v2.RangeValues
import fr.sncf.osrd.api.api_v2.standalone_sim.*
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.envelope.Envelope
import fr.sncf.osrd.envelope_sim.EnvelopeSimContext
import fr.sncf.osrd.envelope_sim.allowances.LinearAllowance
Expand Down Expand Up @@ -158,7 +159,10 @@ fun makeElectricalProfiles(
}

val boundaries =
profileMap.asMapOfRanges().map { Offset<Path>(it.key.upperEndpoint().meters) }.dropLast(1)
profileMap
.asMapOfRanges()
.map { Offset<TravelledPath>(it.key.upperEndpoint().meters) }
.dropLast(1)
val values = profileMap.asMapOfRanges().map { it.value }

return RangeValues(boundaries = boundaries, values = values)
Expand Down Expand Up @@ -186,10 +190,10 @@ fun buildFinalEnvelope(
allowanceType: RJSAllowanceDistribution,
scheduledPoints: List<SimulationScheduleItem>
): Envelope {
fun getEnvelopeTimeAt(offset: Offset<Path>): Double {
fun getEnvelopeTimeAt(offset: Offset<TravelledPath>): Double {
return provisionalEnvelope.interpolateTotalTimeClamp(offset.distance.meters)
}
var prevFixedPointOffset = Offset<Path>(0.meters)
var prevFixedPointOffset = Offset<TravelledPath>(0.meters)
var prevFixedPointDepartureTime = 0.0
val marginRanges = mutableListOf<AllowanceRange>()
for (point in scheduledPoints) {
Expand Down Expand Up @@ -220,7 +224,7 @@ fun buildFinalEnvelope(
prevFixedPointOffset = point.pathOffset
prevFixedPointDepartureTime = arrivalTime + extraTime + (point.stopFor?.seconds ?: 0.0)
}
val pathEnd = Offset<Path>(maxEffortEnvelope.endPos.meters)
val pathEnd = Offset<TravelledPath>(maxEffortEnvelope.endPos.meters)
if (prevFixedPointOffset < pathEnd) {
// Because the last margin call is based on the max effort envelope,
// we still need to cover all ranges to keep the standard margin,
Expand Down Expand Up @@ -257,12 +261,12 @@ fun distributeAllowance(
provisionalEnvelope: Envelope,
extraTime: Double,
margins: RangeValues<MarginValue>,
startOffset: Offset<Path>,
endOffset: Offset<Path>
startOffset: Offset<TravelledPath>,
endOffset: Offset<TravelledPath>
): List<AllowanceRange> {
fun rangeTime(
from: Offset<Path>,
to: Offset<Path>,
from: Offset<TravelledPath>,
to: Offset<TravelledPath>,
envelope: Envelope = provisionalEnvelope
): Double {
assert(from < to)
Expand Down Expand Up @@ -304,7 +308,7 @@ fun buildProvisionalEnvelope(
): Envelope {
val marginRanges = mutableListOf<AllowanceRange>()
// Add path extremities to boundaries
val boundaries = mutableListOf<Offset<Path>>()
val boundaries = mutableListOf<Offset<TravelledPath>>()
boundaries.add(Offset(Distance.ZERO))
boundaries.addAll(rawMargins.boundaries)
boundaries.add(Offset(Distance.fromMeters(context.path.length)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import fr.sncf.osrd.utils.units.Distance
/** Builds the ElectrificationMap */
fun buildElectrificationMap(path: PathProperties): DistanceRangeMap<Electrification> {
val res: DistanceRangeMap<Electrification> = DistanceRangeMapImpl()
res.put(Distance.ZERO, path.getLength().distance, NonElectrified())
res.put(Distance.ZERO, path.getLength(), NonElectrified())
res.updateMap(path.getElectrification()) { _: Electrification?, electrificationMode: String ->
if (electrificationMode == "") NonElectrified() else Electrified(electrificationMode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class MRSPTest {
justification = "called implicitly by MethodSource"
)
private fun testComputeMRSPArgs(): Stream<Arguments> {
val pathLength = toMeters(path!!.getLength().distance)
val pathLength = toMeters(path!!.getLength())
return Stream.of(
// Multiple speed sections with correct/incorrect train tag and no rolling stock
// length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fr.sncf.osrd.graph.Pathfinding.EdgeLocation
import fr.sncf.osrd.graph.PathfindingEdgeLocationId
import fr.sncf.osrd.sim_infra.api.Block
import fr.sncf.osrd.sim_infra.api.BlockId
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.sim_infra.api.PathProperties
import fr.sncf.osrd.utils.Helpers
import fr.sncf.osrd.utils.units.Distance.Companion.fromMeters
Expand Down Expand Up @@ -73,25 +74,25 @@ class RemainingDistanceEstimatorTest {
0
), // Test with target at the end of the edge
Arguments.of(
listOf(EdgeLocation(block, path!!.getLength())),
listOf(EdgeLocation(block, Offset<Path>(path!!.getLength()))),
0,
fromMeters(points[0].distanceAsMeters(Iterables.getLast(points))).millimeters,
0
), // Test multiple targets
Arguments.of(
listOf(
EdgeLocation(block, Offset(0.meters)),
EdgeLocation(block, path!!.getLength())
EdgeLocation(block, Offset<Path>(path!!.getLength()))
),
0,
0,
0
), // Test with an offset on the block
Arguments.of(
listOf(EdgeLocation(block, path!!.getLength())),
listOf(EdgeLocation(block, Offset<Path>(path!!.getLength()))),
0,
0,
path!!.getLength().distance.millimeters
path!!.getLength().millimeters
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fr.sncf.osrd.api.api_v2.RangeValues
import fr.sncf.osrd.api.api_v2.standalone_sim.MarginValue
import fr.sncf.osrd.api.api_v2.standalone_sim.ReportTrain
import fr.sncf.osrd.api.api_v2.standalone_sim.SimulationScheduleItem
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.envelope_sim.EnvelopeSimContext
import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue.Percentage
import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue.TimePerDistance
Expand All @@ -14,7 +15,6 @@ import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath
import fr.sncf.osrd.envelope_sim_infra.MRSP
import fr.sncf.osrd.external_generated_inputs.ElectricalProfileMapping
import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.sim_infra.api.makePathProperties
import fr.sncf.osrd.train.RollingStock
import fr.sncf.osrd.train.TestTrains
Expand Down Expand Up @@ -103,9 +103,9 @@ class StandaloneSimulationTest {
*/
private fun generateTestCases(): Stream<Arguments> {
// Enumerate possible individual scheduled points
val thirdDistance = pathLength / 3.0
val halfDistance = pathLength / 2.0
val twoThirdDistance = pathLength * (2.0 / 3.0)
val thirdDistance = Offset<TravelledPath>(pathLength / 3.0)
val halfDistance = Offset<TravelledPath>(pathLength / 2.0)
val twoThirdDistance = Offset<TravelledPath>(pathLength * (2.0 / 3.0))
val possibleScheduledItem =
listOf(
SimulationScheduleItem(
Expand All @@ -124,7 +124,7 @@ class StandaloneSimulationTest {
),
SimulationScheduleItem(twoThirdDistance, null, 30.seconds, false),
SimulationScheduleItem(
pathLength,
Offset<TravelledPath>(pathLength),
maxEffortEnvelope.totalTime.seconds + 300.seconds,
0.seconds,
false
Expand All @@ -149,7 +149,7 @@ class StandaloneSimulationTest {
RangeValues(),
RangeValues(listOf(), listOf(MarginValue.Percentage(10.0))),
RangeValues(
listOf(Offset(pathLength.distance / 2.0)),
listOf(Offset(pathLength / 2.0)),
listOf(
MarginValue.Percentage(10.0),
MarginValue.MinPer100Km(5.0),
Expand All @@ -169,7 +169,7 @@ class StandaloneSimulationTest {
margins = margin,
startSpeed = startSpeed,
allowanceDistribution = distribution,
pathLength = pathLength.distance
pathLength = pathLength
)
)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ class StandaloneSimulationTest {
}

// Test margin values
val boundaries = mutableListOf<Offset<Path>>()
val boundaries = mutableListOf<Offset<TravelledPath>>()
boundaries.add(Offset(Distance.ZERO))
boundaries.addAll(testCase.margins.boundaries)
boundaries.add(Offset(testCase.pathLength))
Expand Down Expand Up @@ -260,7 +260,7 @@ class StandaloneSimulationTest {
* Returns the time at which the given offset is reached, interpolating linearly between points.
*/
private fun getTimeAt(
offset: Offset<Path>,
offset: Offset<TravelledPath>,
train: ReportTrain,
interpolateRight: Boolean
): Double {
Expand All @@ -271,8 +271,8 @@ class StandaloneSimulationTest {
* Returns the time at which the given offset is reached, interpolating linearly between points.
*/
private fun getTimeAt(
offset: Offset<Path>,
positions: List<Offset<Path>>,
offset: Offset<TravelledPath>,
positions: List<Offset<TravelledPath>>,
times: List<TimeDelta>,
interpolateRight: Boolean
): Double {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun makeRequirementsFromPath(
TestTrains.REALISTIC_FAST_TRAIN,
0.0,
ArrayList(),
listOf(TrainStop(trainPath.getLength().distance.meters, 1.0)),
listOf(TrainStop(trainPath.getLength().meters, 1.0)),
listOf(),
null,
RollingStock.Comfort.STANDARD,
Expand Down
Loading
Loading