From 4effe831bf44728cf946bbb07f69c53d1202d235 Mon Sep 17 00:00:00 2001 From: Louis Greiner Date: Tue, 7 Jan 2025 12:02:52 +0100 Subject: [PATCH] core: move block offset to next signal in stdcm Signed-off-by: Louis Greiner --- .../pathfinding/PathfindingBlocksEndpointV2.kt | 10 +++++----- .../osrd/api/api_v2/stdcm/STDCMEndpointV2.kt | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) 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 e38dcaeef20..a750736b1d8 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 @@ -86,7 +86,7 @@ fun runPathfinding( for (waypoint in step) { val waypointBlocks = findWaypointBlocks(infra, waypoint, direction) if (request.stopAtNextSignal && stepIndex != 0) { - allStarts.addAll(waypointBlocks.map { findNextSignalBlockOnWaypointBlock(request, it, infra) }) + allStarts.addAll(waypointBlocks.map { findNextSignalBlockOnWaypointBlock(it, infra, request.rollingStockLength) }) } else { allStarts.addAll(waypointBlocks) } @@ -377,12 +377,12 @@ private fun getBlockOffset( ) } -private fun findNextSignalBlockOnWaypointBlock( - request: PathfindingBlockRequest, +public fun findNextSignalBlockOnWaypointBlock( waypointBlock: PathfindingEdgeLocationId, - infra: FullInfra + infra: FullInfra, + rollingStockLength: Double ): PathfindingEdgeLocationId { - val nextSignalOffset = getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, request.rollingStockLength) + val nextSignalOffset = getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, rollingStockLength) return PathfindingEdgeLocationId(waypointBlock.edge, nextSignalOffset) } 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 0f09c35e1c5..0b7efc880cc 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 @@ -5,6 +5,7 @@ import fr.sncf.osrd.api.ExceptionHandler import fr.sncf.osrd.api.FullInfra import fr.sncf.osrd.api.InfraManager import fr.sncf.osrd.api.api_v2.* +import fr.sncf.osrd.api.api_v2.pathfinding.findNextSignalBlockOnWaypointBlock import fr.sncf.osrd.api.api_v2.pathfinding.findWaypointBlocks import fr.sncf.osrd.api.api_v2.pathfinding.runPathfindingBlockPostProcessing import fr.sncf.osrd.api.api_v2.standalone_sim.* @@ -97,7 +98,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { convertWorkScheduleCollection(infra.rawInfra, request.workSchedules) trainsRequirements.add(convertedWorkSchedules) val spacingRequirements = trainsRequirements.flatMap { it.spacingRequirements } - val steps = parseSteps(infra, request.pathItems, request.startTime) + val steps = parseSteps(infra, request.pathItems, request.startTime, request.rollingStock.length.distance.meters) // Run the STDCM pathfinding val path = @@ -281,7 +282,8 @@ fun buildTemporarySpeedLimitManager( private fun parseSteps( infra: FullInfra, pathItems: List, - startTime: ZonedDateTime + startTime: ZonedDateTime, + rollingStockLength: Double ): List { if (pathItems.last().stopDuration == null) { throw OSRDError(ErrorType.MissingLastSTDCMStop) @@ -296,9 +298,15 @@ private fun parseSteps( pathItems.first().stopDuration = null return pathItems - .map { + .mapIndexed { index, it -> STDCMStep( - findWaypointBlocks(infra, it.locations), // TODO: use moveWaypointBlockToNextSignal() + if (index != 0) { + findWaypointBlocks(infra, it.locations).map { waypointBlock -> + findNextSignalBlockOnWaypointBlock(waypointBlock, infra, rollingStockLength) + } + } else { + findWaypointBlocks(infra, it.locations) + }, it.stopDuration?.seconds, it.stopDuration != null, if (it.stepTimingData != null)