From e3a3b092ebcdc36c42f95084012a1b1a269733a2 Mon Sep 17 00:00:00 2001 From: Loup Federico <16464925+Sh099078@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:08:00 +0100 Subject: [PATCH] use gradlew splotlessapply --- .../kotlin/fr/sncf/osrd/RawInfraRJSParser.kt | 6 +- .../osrd/sim_infra/impl/PathPropertiesImpl.kt | 15 +- .../osrd/sim_infra/impl/RawInfraBuilder.kt | 3 +- .../impl/TemporarySpeedLimitManager.kt | 13 +- .../sim_infra/utils/PathPropertiesView.kt | 1 - .../fr/sncf/osrd/utils/DistanceRangeMap.kt | 4 +- .../sncf/osrd/utils/TestDistanceRangeMap.kt | 6 +- .../fr/sncf/osrd/api/api_v2/CommonSchemas.kt | 1 - .../PathfindingBlocksEndpointV2.kt | 10 +- .../osrd/api/api_v2/stdcm/STDCMEndpointV2.kt | 68 +++--- .../osrd/api/api_v2/stdcm/STDCMRequestV2.kt | 4 +- .../fr/sncf/osrd/envelope_sim_infra/MRSP.kt | 4 +- .../fr/sncf/osrd/stdcm/STDCMHeuristic.kt | 7 +- .../sncf/osrd/stdcm/graph/STDCMPathfinding.kt | 9 +- .../stdcm/infra_exploration/InfraExplorer.kt | 8 +- .../sncf/osrd/utils/CachedBlockMRSPBuilder.kt | 10 +- .../standalone_sim/ConflictDetectionTest.java | 1 - .../StandaloneSimulationTest.kt | 52 ++--- .../osrd/stdcm/STDCMPathfindingBuilder.kt | 8 +- .../osrd/stdcm/TemporarySpeedLimitTests.kt | 207 ++++++++++-------- 20 files changed, 242 insertions(+), 195 deletions(-) diff --git a/core/kt-osrd-rjs-parser/src/main/kotlin/fr/sncf/osrd/RawInfraRJSParser.kt b/core/kt-osrd-rjs-parser/src/main/kotlin/fr/sncf/osrd/RawInfraRJSParser.kt index 0b65208e4d4..4391ecec06e 100644 --- a/core/kt-osrd-rjs-parser/src/main/kotlin/fr/sncf/osrd/RawInfraRJSParser.kt +++ b/core/kt-osrd-rjs-parser/src/main/kotlin/fr/sncf/osrd/RawInfraRJSParser.kt @@ -53,7 +53,8 @@ private fun parseLineString(rjsLineString: RJSLineString?): LineString? { private fun getSlopes(rjsTrackSection: RJSTrackSection): DistanceRangeMap { val slopes = distanceRangeMapOf( - *listOf(DistanceRangeMap.RangeMapEntry(0.meters, rjsTrackSection.length.meters, 0.0)).toTypedArray() + *listOf(DistanceRangeMap.RangeMapEntry(0.meters, rjsTrackSection.length.meters, 0.0)) + .toTypedArray() ) if (rjsTrackSection.slopes != null) { for (rjsSlope in rjsTrackSection.slopes) { @@ -75,7 +76,8 @@ private fun getSlopes(rjsTrackSection: RJSTrackSection): DistanceRangeMap { val curves = distanceRangeMapOf( - *listOf(DistanceRangeMap.RangeMapEntry(0.meters, rjsTrackSection.length.meters, 0.0)).toTypedArray() + *listOf(DistanceRangeMap.RangeMapEntry(0.meters, rjsTrackSection.length.meters, 0.0)) + .toTypedArray() ) if (rjsTrackSection.curves != null) { for (rjsCurve in rjsTrackSection.curves) { diff --git a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt index 417e60e04d7..a64d16e13d0 100644 --- a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt +++ b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt @@ -104,9 +104,11 @@ data class PathPropertiesImpl( // \ // - start - - - commonChunk - -> val route = routeOnChunk.firstOrNull()?.let { routeId -> infra.getRouteName(routeId) } - val permanentSpeedLimits = infra.getTrackChunkSpeedLimitProperties(dirChunkId, trainTag, route) + val permanentSpeedLimits = + infra.getTrackChunkSpeedLimitProperties(dirChunkId, trainTag, route) if (temporarySpeedLimitManager != null) { - val temporarySpeedLimits = temporarySpeedLimitManager.getTrackChunkTemporarySpeedLimits(dirChunkId); + val temporarySpeedLimits = + temporarySpeedLimitManager.getTrackChunkTemporarySpeedLimits(dirChunkId) permanentSpeedLimits.updateMap(temporarySpeedLimits) { s1, s2 -> if (s1.speed < s2.speed) { s1 @@ -125,7 +127,8 @@ data class PathPropertiesImpl( if (zoneId != null) { val chunkLength = infra.getTrackChunkLength(chunkId).distance distanceRangeMapOf( - *listOf(DistanceRangeMap.RangeMapEntry(Distance.ZERO, chunkLength, zoneId)).toTypedArray() + *listOf(DistanceRangeMap.RangeMapEntry(Distance.ZERO, chunkLength, zoneId)) + .toTypedArray() ) } else { distanceRangeMapOf() @@ -294,8 +297,8 @@ data class PathPropertiesImpl( res: List> ): List> { return res.filter { element -> - element.offset >= chunkPath.beginOffset && element.offset <= chunkPath.endOffset - } + element.offset >= chunkPath.beginOffset && element.offset <= chunkPath.endOffset + } .map { element -> IdxWithOffset(element.value, element.offset - chunkPath.beginOffset.distance) } @@ -315,7 +318,7 @@ fun getOffsetOfTrackLocationOnChunks( val chunkOffset = infra.getTrackChunkOffset(dirChunk.value) if ( chunkOffset <= location.offset && - location.offset <= (chunkOffset + chunkLength.distance) + location.offset <= (chunkOffset + chunkLength.distance) ) { val distanceToChunkStart = if (dirChunk.direction == Direction.INCREASING) location.offset - chunkOffset diff --git a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/RawInfraBuilder.kt b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/RawInfraBuilder.kt index b531b9feb82..c0aa977710d 100644 --- a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/RawInfraBuilder.kt +++ b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/RawInfraBuilder.kt @@ -497,7 +497,8 @@ class RawInfraBuilder { loadingGaugeConstraints, // Electrifications will be filled later on distanceRangeMapOf( - *listOf(DistanceRangeMap.RangeMapEntry(0.meters, length.distance, "")).toTypedArray() + *listOf(DistanceRangeMap.RangeMapEntry(0.meters, length.distance, "")) + .toTypedArray() ), // NeutralSections will be filled later on DirectionalMap(distanceRangeMapOf(), distanceRangeMapOf()), diff --git a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/TemporarySpeedLimitManager.kt b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/TemporarySpeedLimitManager.kt index 8acc01158e8..0bc8a1661e5 100644 --- a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/TemporarySpeedLimitManager.kt +++ b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/TemporarySpeedLimitManager.kt @@ -1,7 +1,6 @@ package fr.sncf.osrd.sim_infra.impl import fr.sncf.osrd.sim_infra.api.DirTrackChunkId -import fr.sncf.osrd.sim_infra.api.RawInfra import fr.sncf.osrd.sim_infra.api.SpeedLimitProperty import fr.sncf.osrd.sim_infra.api.TrackChunk import fr.sncf.osrd.utils.Direction @@ -9,7 +8,6 @@ import fr.sncf.osrd.utils.DistanceRangeMap import fr.sncf.osrd.utils.DistanceRangeMap.RangeMapEntry import fr.sncf.osrd.utils.distanceRangeMapOf import fr.sncf.osrd.utils.indexing.DirStaticIdxList -import fr.sncf.osrd.utils.indexing.StaticIdxList import fr.sncf.osrd.utils.units.OffsetList import fr.sncf.osrd.utils.units.Speed @@ -24,9 +22,11 @@ data class TemporarySpeedLimit( class TemporarySpeedLimitManager( val speedLimits: MutableMap>, ) { - constructor(): this(speedLimits = mutableMapOf()) { } + constructor() : this(speedLimits = mutableMapOf()) {} - fun getTrackChunkTemporarySpeedLimits(trackChunkId: DirTrackChunkId): DistanceRangeMap { + fun getTrackChunkTemporarySpeedLimits( + trackChunkId: DirTrackChunkId + ): DistanceRangeMap { val res = distanceRangeMapOf() if (!speedLimits.containsKey(trackChunkId)) { @@ -39,8 +39,9 @@ class TemporarySpeedLimitManager( val startOffset = speedLimit.startOffsets[chunkIdx].distance val endOffset = speedLimit.endOffsets[chunkIdx].distance val speedLimitProperty = SpeedLimitProperty(speedLimit.speedLimit, null) - val speedLimitMap = distanceRangeMapOf(RangeMapEntry(startOffset, endOffset, speedLimitProperty)) - res.updateMap(speedLimitMap) {s1, s2: SpeedLimitProperty -> minOf(s1, s2)} + val speedLimitMap = + distanceRangeMapOf(RangeMapEntry(startOffset, endOffset, speedLimitProperty)) + res.updateMap(speedLimitMap) { s1, s2: SpeedLimitProperty -> minOf(s1, s2) } } return res } diff --git a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/utils/PathPropertiesView.kt b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/utils/PathPropertiesView.kt index e03ebb86ab1..01587afeb6e 100644 --- a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/utils/PathPropertiesView.kt +++ b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/utils/PathPropertiesView.kt @@ -2,7 +2,6 @@ package fr.sncf.osrd.sim_infra.utils import fr.sncf.osrd.geom.LineString import fr.sncf.osrd.sim_infra.api.* -import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager import fr.sncf.osrd.utils.DistanceRangeMap import fr.sncf.osrd.utils.units.Distance import fr.sncf.osrd.utils.units.Offset diff --git a/core/kt-osrd-utils/src/main/kotlin/fr/sncf/osrd/utils/DistanceRangeMap.kt b/core/kt-osrd-utils/src/main/kotlin/fr/sncf/osrd/utils/DistanceRangeMap.kt index c922a66ff8e..028362a17bc 100644 --- a/core/kt-osrd-utils/src/main/kotlin/fr/sncf/osrd/utils/DistanceRangeMap.kt +++ b/core/kt-osrd-utils/src/main/kotlin/fr/sncf/osrd/utils/DistanceRangeMap.kt @@ -69,9 +69,7 @@ interface DistanceRangeMap : Iterable> { fun clear() } -fun distanceRangeMapOf( - vararg entries: DistanceRangeMap.RangeMapEntry -): DistanceRangeMap { +fun distanceRangeMapOf(vararg entries: DistanceRangeMap.RangeMapEntry): DistanceRangeMap { return DistanceRangeMapImpl(entries.asList()) } diff --git a/core/kt-osrd-utils/src/test/kotlin/fr/sncf/osrd/utils/TestDistanceRangeMap.kt b/core/kt-osrd-utils/src/test/kotlin/fr/sncf/osrd/utils/TestDistanceRangeMap.kt index f2100912316..2e6b7fcbd28 100644 --- a/core/kt-osrd-utils/src/test/kotlin/fr/sncf/osrd/utils/TestDistanceRangeMap.kt +++ b/core/kt-osrd-utils/src/test/kotlin/fr/sncf/osrd/utils/TestDistanceRangeMap.kt @@ -261,10 +261,8 @@ class TestDistanceRangeMap { fun testMergeDistanceRangeMapsSimple() { val inputMap = distanceRangeMapOf( - - DistanceRangeMap.RangeMapEntry(Distance(0), Distance(50), 1), - DistanceRangeMap.RangeMapEntry(Distance(50), Distance(100), 2), - + DistanceRangeMap.RangeMapEntry(Distance(0), Distance(50), 1), + DistanceRangeMap.RangeMapEntry(Distance(50), Distance(100), 2), ) val distances = listOf(Distance(100)) diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/CommonSchemas.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/CommonSchemas.kt index e74d83ba5c8..ce7cc3aa234 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/CommonSchemas.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/CommonSchemas.kt @@ -3,7 +3,6 @@ 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.SpeedLimit import fr.sncf.osrd.sim_infra.api.TrackSection import fr.sncf.osrd.utils.units.Offset import fr.sncf.osrd.utils.units.TimeDelta diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt index bcf18a09690..e8ff1d325c3 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt @@ -14,7 +14,6 @@ import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl import fr.sncf.osrd.sim_infra.api.* -import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager import fr.sncf.osrd.stdcm.graph.extendLookaheadUntil import fr.sncf.osrd.stdcm.infra_exploration.initInfraExplorer import fr.sncf.osrd.utils.* @@ -199,7 +198,14 @@ private fun getStartLocations( val firstStep = waypoints[0] val stops = listOf(waypoints.last()) for (location in firstStep) { - val infraExplorers = initInfraExplorer(rawInfra, blockInfra, location, stops = stops, constraints = constraints) + val infraExplorers = + initInfraExplorer( + rawInfra, + blockInfra, + location, + stops = stops, + constraints = constraints + ) val extended = infraExplorers.flatMap { extendLookaheadUntil(it, 1) } for (explorer in extended) { val edge = PathfindingEdge(explorer) diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt index 388008bf68c..a03f4940f1a 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt @@ -1,7 +1,6 @@ package fr.sncf.osrd.api.api_v2.stdcm import com.google.common.collect.ImmutableRangeMap -import com.squareup.moshi.Json import fr.sncf.osrd.api.ExceptionHandler import fr.sncf.osrd.api.FullInfra import fr.sncf.osrd.api.InfraManager @@ -18,7 +17,6 @@ import fr.sncf.osrd.envelope_sim_infra.computeMRSP import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingEdgeLocationId import fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection -import fr.sncf.osrd.railjson.schema.infra.trackranges.RJSDirectionalTrackRange import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError @@ -26,7 +24,6 @@ import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.sim_infra.api.DirTrackChunkId import fr.sncf.osrd.sim_infra.api.TrackChunk -import fr.sncf.osrd.sim_infra.api.TrackChunkId import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimit import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager import fr.sncf.osrd.sim_infra.utils.chunksToRoutes @@ -43,16 +40,21 @@ import fr.sncf.osrd.stdcm.preprocessing.implementation.makeBlockAvailability import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TrainStop import fr.sncf.osrd.utils.Direction -import fr.sncf.osrd.utils.indexing.DirStaticIdxList import fr.sncf.osrd.utils.indexing.MutableDirStaticIdxArrayList import fr.sncf.osrd.utils.units.Distance import fr.sncf.osrd.utils.units.MutableOffsetArrayList import fr.sncf.osrd.utils.units.Offset -import fr.sncf.osrd.utils.units.OffsetList import fr.sncf.osrd.utils.units.Speed import fr.sncf.osrd.utils.units.TimeDelta import fr.sncf.osrd.utils.units.meters import fr.sncf.osrd.utils.units.seconds +import java.io.File +import java.time.Duration.between +import java.time.Duration.ofMillis +import java.time.LocalDateTime +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import kotlin.math.max import org.takes.Request import org.takes.Response import org.takes.Take @@ -61,13 +63,6 @@ import org.takes.rs.RsJson import org.takes.rs.RsText import org.takes.rs.RsWithBody import org.takes.rs.RsWithStatus -import java.io.File -import java.time.Duration.between -import java.time.Duration.ofMillis -import java.time.LocalDateTime -import java.time.ZonedDateTime -import java.time.format.DateTimeFormatter -import kotlin.math.max class STDCMEndpointV2(private val infraManager: InfraManager) : Take { @Throws(OSRDError::class) @@ -93,7 +88,8 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { } // parse input data val infra = infraManager.getInfra(request.infra, request.expectedVersion, recorder) - val temporarySpeedLimitManager = buildTemporarySpeedLimitManager(infra, request.temporarySpeedLimits) + val temporarySpeedLimitManager = + buildTemporarySpeedLimitManager(infra, request.temporarySpeedLimits) val rollingStock = parseRawRollingStock( request.rollingStock, @@ -132,7 +128,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { Pathfinding.TIMEOUT, temporarySpeedLimitManager, ) - if (path == null) { + if (path == null) { val response = PathNotFound() return RsJson(RsWithBody(stdcmResponseAdapter.toJson(response))) } @@ -220,7 +216,8 @@ fun buildTemporarySpeedLimitManager( infra: FullInfra, speedLimits: Collection ): TemporarySpeedLimitManager { - var outputSpeedLimits: MutableMap> = mutableMapOf() + var outputSpeedLimits: MutableMap> = + mutableMapOf() for (speedLimit in speedLimits) { var chunkIds = MutableDirStaticIdxArrayList() var startOffsets = MutableOffsetArrayList() @@ -237,12 +234,19 @@ fun buildTemporarySpeedLimitManager( if (chunkEndOffset < trackRange.begin || trackRange.end < chunkStartOffset) { continue } - var startOffset = Offset(Distance.max(0.meters, trackRange.begin - chunkStartOffset)) - var endOffset = Offset(Distance.min(trackChunkLength, trackRange.end - chunkStartOffset)) - var direction = when (trackRange.direction) { - EdgeDirection.START_TO_STOP -> Direction.INCREASING - EdgeDirection.STOP_TO_START -> Direction.DECREASING - } + var startOffset = + Offset( + Distance.max(0.meters, trackRange.begin - chunkStartOffset) + ) + var endOffset = + Offset( + Distance.min(trackChunkLength, trackRange.end - chunkStartOffset) + ) + var direction = + when (trackRange.direction) { + EdgeDirection.START_TO_STOP -> Direction.INCREASING + EdgeDirection.STOP_TO_START -> Direction.DECREASING + } val dirTrackChunkId = DirTrackChunkId(trackChunkId, direction) chunkIds.add(dirTrackChunkId) @@ -252,17 +256,17 @@ fun buildTemporarySpeedLimitManager( } } } - val speedLimit: TemporarySpeedLimit = TemporarySpeedLimit( - Speed.fromMetersPerSecond(speedLimit.speedLimit), - chunkIds, - startOffsets, - endOffsets, - directions - ) + val speedLimit: TemporarySpeedLimit = + TemporarySpeedLimit( + Speed.fromMetersPerSecond(speedLimit.speedLimit), + chunkIds, + startOffsets, + endOffsets, + directions + ) for (chunkId in chunkIds) { - outputSpeedLimits.get(chunkId)?.let { speedLimits -> - speedLimits.add(speedLimit) - } ?: outputSpeedLimits.put(chunkId, mutableListOf(speedLimit)) + outputSpeedLimits.get(chunkId)?.let { speedLimits -> speedLimits.add(speedLimit) } + ?: outputSpeedLimits.put(chunkId, mutableListOf(speedLimit)) } } return TemporarySpeedLimitManager(outputSpeedLimits) @@ -308,11 +312,9 @@ private fun parseMarginValue(margin: MarginValue): AllowanceValue? { is MarginValue.MinPer100Km -> { TimePerDistance(margin.value) } - is MarginValue.Percentage -> { Percentage(margin.percentage) } - is MarginValue.None -> { null } diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt index 82cfb9dbed3..20119098384 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt @@ -6,7 +6,6 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import fr.sncf.osrd.api.api_v2.DirectionalTrackRange import fr.sncf.osrd.api.api_v2.TrackLocation -import fr.sncf.osrd.api.api_v2.TrackRange import fr.sncf.osrd.api.api_v2.WorkSchedule import fr.sncf.osrd.api.api_v2.conflicts.TrainRequirementsRequest import fr.sncf.osrd.api.api_v2.standalone_sim.MarginValue @@ -56,7 +55,8 @@ class STDCMRequestV2( val margin: MarginValue, @Json(name = "work_schedules") val workSchedules: Collection = listOf(), /// Temporary speed limits which are active between the train departure and arrival. - @Json(name = "temporary_speed_limits") val temporarySpeedLimits: Collection, + @Json(name = "temporary_speed_limits") + val temporarySpeedLimits: Collection, ) data class STDCMTemporarySpeedLimit( diff --git a/core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt b/core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt index 7853d7b3d96..5da321bc9a7 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt @@ -166,7 +166,9 @@ fun makeSpeedLimitAttributes( baseAttrs: List, ): DistanceRangeMap> { val result: DistanceRangeMap> = - distanceRangeMapOf(*listOf(DistanceRangeMap.RangeMapEntry(lower, upper, baseAttrs)).toTypedArray()) + distanceRangeMapOf( + *listOf(DistanceRangeMap.RangeMapEntry(lower, upper, baseAttrs)).toTypedArray() + ) // Add important attributes from the old speed ranges val attrsWithMissingRange = baseAttrs.toMutableList() diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/STDCMHeuristic.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/STDCMHeuristic.kt index 31198813368..7cfd481eef8 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/STDCMHeuristic.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/STDCMHeuristic.kt @@ -5,7 +5,6 @@ import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.sim_infra.api.BlockId import fr.sncf.osrd.sim_infra.api.BlockInfra import fr.sncf.osrd.sim_infra.api.RawInfra -import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimit import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager import fr.sncf.osrd.sim_infra.utils.getBlockEntry import fr.sncf.osrd.stdcm.graph.STDCMEdge @@ -43,10 +42,12 @@ class STDCMHeuristicBuilder( private val steps: List, private val maxRunningTime: Double, private val rollingStock: PhysicsRollingStock, - private val temporarySpeedLimitManager: TemporarySpeedLimitManager = TemporarySpeedLimitManager() + private val temporarySpeedLimitManager: TemporarySpeedLimitManager = + TemporarySpeedLimitManager() ) { private val logger: Logger = LoggerFactory.getLogger("STDCMHeuristic") - private val mrspBuilder = CachedBlockMRSPBuilder(rawInfra, blockInfra, rollingStock, temporarySpeedLimitManager) + private val mrspBuilder = + CachedBlockMRSPBuilder(rawInfra, blockInfra, rollingStock, temporarySpeedLimitManager) /** Runs all the pre-processing and initialize the STDCM A* heuristic. */ @WithSpan(value = "Initializing STDCM heuristic", kind = SpanKind.SERVER) diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt index e47e8562df2..3cb00076416 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt @@ -257,7 +257,14 @@ class STDCMPathfinding( assert(!firstStep.stop) for (location in firstStep.locations) { val infraExplorers = - initInfraExplorerWithEnvelope(fullInfra, location, rollingStock, stops, constraints, temporarySpeedLimitManager) + initInfraExplorerWithEnvelope( + fullInfra, + location, + rollingStock, + stops, + constraints, + temporarySpeedLimitManager + ) val extended = infraExplorers.flatMap { extendLookaheadUntil(it, 3) } for (explorer in extended) { val node = diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/infra_exploration/InfraExplorer.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/infra_exploration/InfraExplorer.kt index fc27846f5a1..ca693cc13b7 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/infra_exploration/InfraExplorer.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/infra_exploration/InfraExplorer.kt @@ -185,7 +185,13 @@ private class InfraExplorerImpl( ) } if (path.temporarySpeedLimitManager != this.temporarySpeedLimitManager) { - path = makePathProps(blockInfra, rawInfra, getCurrentBlock(), temporarySpeedLimitManager = this.temporarySpeedLimitManager) + path = + makePathProps( + blockInfra, + rawInfra, + getCurrentBlock(), + temporarySpeedLimitManager = this.temporarySpeedLimitManager + ) } val route = blockRoutes[getCurrentBlock()]!! val blockPathProperties = path.withRoutes(listOf(route)) diff --git a/core/src/main/kotlin/fr/sncf/osrd/utils/CachedBlockMRSPBuilder.kt b/core/src/main/kotlin/fr/sncf/osrd/utils/CachedBlockMRSPBuilder.kt index 6f398197394..b38bb65723a 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/utils/CachedBlockMRSPBuilder.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/utils/CachedBlockMRSPBuilder.kt @@ -8,7 +8,6 @@ import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.sim_infra.api.BlockId import fr.sncf.osrd.sim_infra.api.BlockInfra import fr.sncf.osrd.sim_infra.api.RawInfra -import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimit import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager import fr.sncf.osrd.utils.units.Offset import fr.sncf.osrd.utils.units.meters @@ -39,7 +38,14 @@ data class CachedBlockMRSPBuilder( /** Returns the speed limits for the given block (cached). */ fun getMRSP(block: BlockId): Envelope { return mrspCache.computeIfAbsent(block) { - val pathProps = makePathProps(blockInfra, rawInfra, block, routes = listOf(), temporarySpeedLimitManager = temporarySpeedLimitManager) + val pathProps = + makePathProps( + blockInfra, + rawInfra, + block, + routes = listOf(), + temporarySpeedLimitManager = temporarySpeedLimitManager + ) computeMRSP(pathProps, rsMaxSpeed, rsLength, false, null) } } diff --git a/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java b/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java index 68720e34d97..68a12d14bc0 100644 --- a/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java +++ b/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java @@ -27,7 +27,6 @@ import fr.sncf.osrd.railjson.schema.schedule.RJSTrainStop.RJSReceptionSignal; import fr.sncf.osrd.sim_infra.api.PathProperties; import fr.sncf.osrd.sim_infra.impl.ChunkPath; -import fr.sncf.osrd.sim_infra.impl.TemporarySpeedLimitManager; import fr.sncf.osrd.standalone_sim.result.ResultTrain; import fr.sncf.osrd.train.StandaloneTrainSchedule; import fr.sncf.osrd.train.TestTrains; diff --git a/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt b/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt index 1b625bd2457..197e99c0a02 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt @@ -166,18 +166,19 @@ class StandaloneSimulationTest { distanceRangeMapOf(), distanceRangeMapOf( *listOf( - DistanceRangeMap.RangeMapEntry(0.meters, pathLength / 3.0, "Restrict1"), - DistanceRangeMap.RangeMapEntry( - pathLength / 3.0, - pathLength * 2.0 / 3.0, - "Restrict2" - ), - DistanceRangeMap.RangeMapEntry( - pathLength * 2.0 / 3.0, - pathLength, - "Restrict1" + DistanceRangeMap.RangeMapEntry(0.meters, pathLength / 3.0, "Restrict1"), + DistanceRangeMap.RangeMapEntry( + pathLength / 3.0, + pathLength * 2.0 / 3.0, + "Restrict2" + ), + DistanceRangeMap.RangeMapEntry( + pathLength * 2.0 / 3.0, + pathLength, + "Restrict1" + ) ) - ).toTypedArray() + .toTypedArray() ) ) @@ -320,20 +321,21 @@ class StandaloneSimulationTest { val expected = distanceRangeMapOf( *listOf( - DistanceRangeMap.RangeMapEntry(0.meters, 50.meters, 30.kilometersPerHour), - DistanceRangeMap.RangeMapEntry(50.meters, 150.meters, 10.kilometersPerHour), - DistanceRangeMap.RangeMapEntry( - 10_200.meters, - 10_300.meters, - 30.kilometersPerHour - ), - // Last buffer stop short slip range - DistanceRangeMap.RangeMapEntry( - 10_300.meters, - 10_400.meters, - 10.kilometersPerHour - ), - ).toTypedArray(), + DistanceRangeMap.RangeMapEntry(0.meters, 50.meters, 30.kilometersPerHour), + DistanceRangeMap.RangeMapEntry(50.meters, 150.meters, 10.kilometersPerHour), + DistanceRangeMap.RangeMapEntry( + 10_200.meters, + 10_300.meters, + 30.kilometersPerHour + ), + // Last buffer stop short slip range + DistanceRangeMap.RangeMapEntry( + 10_300.meters, + 10_400.meters, + 10.kilometersPerHour + ), + ) + .toTypedArray(), ) assertEquals(expected, safetySpeedRanges) } diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt index 9509f3195cd..94cc82b039d 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt @@ -145,10 +145,10 @@ data class STDCMPathfindingBuilder( return this } - /** - * Sets the temporary speed limit manager to be used. - */ - fun setTemporarySpeedLimitManager(temporarySpeedLimitManager: TemporarySpeedLimitManager): STDCMPathfindingBuilder { + /** Sets the temporary speed limit manager to be used. */ + fun setTemporarySpeedLimitManager( + temporarySpeedLimitManager: TemporarySpeedLimitManager + ): STDCMPathfindingBuilder { this.temporarySpeedLimitManager = temporarySpeedLimitManager return this } diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/TemporarySpeedLimitTests.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/TemporarySpeedLimitTests.kt index b3b30f876dd..4ba2b7f887d 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/TemporarySpeedLimitTests.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/TemporarySpeedLimitTests.kt @@ -23,26 +23,25 @@ class TemporarySpeedLimitTests { beginDetector: String, endDetector: String ): STDCMResult { - val temporarySpeedLimitManager = buildTemporarySpeedLimitManager(infra, temporarySpeedLimits) + val temporarySpeedLimitManager = + buildTemporarySpeedLimitManager(infra, temporarySpeedLimits) val startDetectorId = infra.rawInfra.findDetector(beginDetector)!! - val blocksOnStart = infra.blockInfra().getBlocksStartingAtDetector( - DirDetectorId( - startDetectorId, - Direction.INCREASING - ) - ) + val blocksOnStart = + infra + .blockInfra() + .getBlocksStartingAtDetector(DirDetectorId(startDetectorId, Direction.INCREASING)) val endDetectorId = infra.rawInfra.findDetector(endDetector)!! - val blocksOnEnd = infra.blockInfra().getBlocksStartingAtDetector( - DirDetectorId( - endDetectorId, - Direction.INCREASING - ) - ) - val startBlock = blocksOnStart[0]; - val endBlock = blocksOnEnd[0]; + val blocksOnEnd = + infra + .blockInfra() + .getBlocksStartingAtDetector(DirDetectorId(endDetectorId, Direction.INCREASING)) + val startBlock = blocksOnStart[0] + val endBlock = blocksOnEnd[0] return STDCMPathfindingBuilder() .setInfra(infra) - .setStartLocations(setOf(Pathfinding.EdgeLocation(startBlock, Offset(Distance(0L))))) + .setStartLocations( + setOf(Pathfinding.EdgeLocation(startBlock, Offset(Distance(0L)))) + ) .setEndLocations(setOf(Pathfinding.EdgeLocation(endBlock, Offset(Distance(0L))))) .setTemporarySpeedLimitManager(temporarySpeedLimitManager) .run()!! @@ -52,31 +51,38 @@ class TemporarySpeedLimitTests { fun temporarySpeedLimitIsUsedIfSmallerThanOtherSpeedLimits() { val speedLimit = Speed.fromMetersPerSecond(20.0) // Add a temporary speed limit to a track - val temporarySpeedLimits = listOf( - STDCMTemporarySpeedLimit( - speedLimit.metersPerSecond, - listOf( - DirectionalTrackRange( - trackSection = "TF1", - begin = Offset(Distance.fromMeters(500.0)), - end = Offset(Distance.fromMeters(1000.0)), - direction = EdgeDirection.START_TO_STOP + val temporarySpeedLimits = + listOf( + STDCMTemporarySpeedLimit( + speedLimit.metersPerSecond, + listOf( + DirectionalTrackRange( + trackSection = "TF1", + begin = Offset(Distance.fromMeters(500.0)), + end = Offset(Distance.fromMeters(1000.0)), + direction = EdgeDirection.START_TO_STOP + ) ) ) ) - ) - val res = sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") + val res = + sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") val resultSpeedLimits = res.trainPath.getSpeedLimitProperties("") // Check that the temporary speed limit applies on the correct range in the STDCM result // Distance between DE3 and the LTV begin on TF1 on the path TE2 -> TE0 -> TF0 -> TF1 - val expectedSpeedLimitBeginOffset = Distance.fromMeters(2183.0); + val expectedSpeedLimitBeginOffset = Distance.fromMeters(2183.0) // Same distance as above plus the LTV length - val expectedSpeedLimitEndOffset = Distance.fromMeters(2683.0); - val expectedSpeedLimitProperty = SpeedLimitProperty(Speed.fromMetersPerSecond(speedLimit.metersPerSecond), null) + val expectedSpeedLimitEndOffset = Distance.fromMeters(2683.0) + val expectedSpeedLimitProperty = + SpeedLimitProperty(Speed.fromMetersPerSecond(speedLimit.metersPerSecond), null) val expectedSpeedLimitRangeMap = - RangeMapEntry(expectedSpeedLimitBeginOffset, expectedSpeedLimitEndOffset, expectedSpeedLimitProperty) + RangeMapEntry( + expectedSpeedLimitBeginOffset, + expectedSpeedLimitEndOffset, + expectedSpeedLimitProperty + ) assert(resultSpeedLimits.contains(expectedSpeedLimitRangeMap)) } @@ -84,72 +90,78 @@ class TemporarySpeedLimitTests { fun temporarySpeedLimitHigherThanPermanentSpeedLimitIsIgnored() { val speedLimit = Speed.fromMetersPerSecond(20.0) // Add a temporary speed limit to a track - val temporarySpeedLimits = listOf( - STDCMTemporarySpeedLimit( - 100.0, - listOf( - DirectionalTrackRange( - trackSection = "TF1", - begin = Offset(Distance.fromMeters(500.0)), - end = Offset(Distance.fromMeters(1000.0)), - direction = EdgeDirection.START_TO_STOP + val temporarySpeedLimits = + listOf( + STDCMTemporarySpeedLimit( + 100.0, + listOf( + DirectionalTrackRange( + trackSection = "TF1", + begin = Offset(Distance.fromMeters(500.0)), + end = Offset(Distance.fromMeters(1000.0)), + direction = EdgeDirection.START_TO_STOP + ) ) ) ) - ) - val res = sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") + val res = + sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") val resultSpeedLimits = res.trainPath.getSpeedLimitProperties("") - val expectedRangeMap = RangeMapEntry( - Distance.fromMeters(0.0), - Distance.fromMeters(3933.0), - SpeedLimitProperty(Speed(83333U), SpeedLimitSource.UnknownTag()) - ) + val expectedRangeMap = + RangeMapEntry( + Distance.fromMeters(0.0), + Distance.fromMeters(3933.0), + SpeedLimitProperty(Speed(83333U), SpeedLimitSource.UnknownTag()) + ) assert(resultSpeedLimits.contains(expectedRangeMap)) } @Test fun smallestTemporarySpeedLimitOnTrackRangeIsKept() { // Add a temporary speed limit to a track - val temporarySpeedLimits = listOf( - STDCMTemporarySpeedLimit( - 30.0, - listOf( - DirectionalTrackRange( - trackSection = "TF1", - begin = Offset(Distance.fromMeters(500.0)), - end = Offset(Distance.fromMeters(1000.0)), - direction = EdgeDirection.START_TO_STOP + val temporarySpeedLimits = + listOf( + STDCMTemporarySpeedLimit( + 30.0, + listOf( + DirectionalTrackRange( + trackSection = "TF1", + begin = Offset(Distance.fromMeters(500.0)), + end = Offset(Distance.fromMeters(1000.0)), + direction = EdgeDirection.START_TO_STOP + ) ) - ) - ), - STDCMTemporarySpeedLimit( - 20.0, - listOf( - DirectionalTrackRange( - trackSection = "TF1", - begin = Offset(Distance.fromMeters(800.0)), - end = Offset(Distance.fromMeters(1100.0)), - direction = EdgeDirection.START_TO_STOP + ), + STDCMTemporarySpeedLimit( + 20.0, + listOf( + DirectionalTrackRange( + trackSection = "TF1", + begin = Offset(Distance.fromMeters(800.0)), + end = Offset(Distance.fromMeters(1100.0)), + direction = EdgeDirection.START_TO_STOP + ) ) ) ) - ) - val res = sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") + val res = + sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") val resultSpeedLimits = res.trainPath.getSpeedLimitProperties("") - val expectedSpeedLimitRangeMaps = listOf( - RangeMapEntry( - Distance.fromMeters(2183.0), - Distance.fromMeters(2483.0), - SpeedLimitProperty(Speed.fromMetersPerSecond(30.0), null) - ), - RangeMapEntry( - Distance.fromMeters(2483.0), - Distance.fromMeters(2783.0), - SpeedLimitProperty(Speed.fromMetersPerSecond(20.0), null) - ), - ) + val expectedSpeedLimitRangeMaps = + listOf( + RangeMapEntry( + Distance.fromMeters(2183.0), + Distance.fromMeters(2483.0), + SpeedLimitProperty(Speed.fromMetersPerSecond(30.0), null) + ), + RangeMapEntry( + Distance.fromMeters(2483.0), + Distance.fromMeters(2783.0), + SpeedLimitProperty(Speed.fromMetersPerSecond(20.0), null) + ), + ) for (speedLimitRangeMap in expectedSpeedLimitRangeMaps) { assert(resultSpeedLimits.contains(speedLimitRangeMap)) } @@ -159,27 +171,30 @@ class TemporarySpeedLimitTests { fun temporarySpeedLimitsInOppositeDirectionAreIgnored() { val speedLimit = Speed.fromMetersPerSecond(20.0) // Add a temporary speed limit to a track - val temporarySpeedLimits = listOf( - STDCMTemporarySpeedLimit( - 20.0, - listOf( - DirectionalTrackRange( - trackSection = "TF1", - begin = Offset(Distance.fromMeters(800.0)), - end = Offset(Distance.fromMeters(1100.0)), - direction = EdgeDirection.STOP_TO_START + val temporarySpeedLimits = + listOf( + STDCMTemporarySpeedLimit( + 20.0, + listOf( + DirectionalTrackRange( + trackSection = "TF1", + begin = Offset(Distance.fromMeters(800.0)), + end = Offset(Distance.fromMeters(1100.0)), + direction = EdgeDirection.STOP_TO_START + ) ) ) ) - ) - val res = sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") + val res = + sendSTDCMWithTemporarySpeedLimits(smallInfra, temporarySpeedLimits, "DE3", "DF1_1") val resultSpeedLimits = res.trainPath.getSpeedLimitProperties("") - val expectedRangeMap = RangeMapEntry( - Distance.fromMeters(0.0), - Distance.fromMeters(3933.0), - SpeedLimitProperty(Speed(83333U), SpeedLimitSource.UnknownTag()) - ) + val expectedRangeMap = + RangeMapEntry( + Distance.fromMeters(0.0), + Distance.fromMeters(3933.0), + SpeedLimitProperty(Speed(83333U), SpeedLimitSource.UnknownTag()) + ) assert(resultSpeedLimits.contains(expectedRangeMap)) } }