Skip to content

Commit

Permalink
core: move block offset to next signal in stdcm
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Jan 8, 2025
1 parent 88422de commit 4effe83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -377,12 +377,12 @@ private fun getBlockOffset(
)
}

private fun findNextSignalBlockOnWaypointBlock(
request: PathfindingBlockRequest,
public fun findNextSignalBlockOnWaypointBlock(
waypointBlock: PathfindingEdgeLocationId<Block>,
infra: FullInfra
infra: FullInfra,
rollingStockLength: Double
): PathfindingEdgeLocationId<Block> {
val nextSignalOffset = getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, request.rollingStockLength)
val nextSignalOffset = getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, rollingStockLength)
return PathfindingEdgeLocationId(waypointBlock.edge, nextSignalOffset)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -281,7 +282,8 @@ fun buildTemporarySpeedLimitManager(
private fun parseSteps(
infra: FullInfra,
pathItems: List<STDCMPathItem>,
startTime: ZonedDateTime
startTime: ZonedDateTime,
rollingStockLength: Double
): List<STDCMStep> {
if (pathItems.last().stopDuration == null) {
throw OSRDError(ErrorType.MissingLastSTDCMStop)
Expand All @@ -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)
Expand Down

0 comments on commit 4effe83

Please sign in to comment.