Skip to content

Commit

Permalink
core: move block offset to next signal if flag
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Dec 27, 2024
1 parent dc7b257 commit 03bbd62
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PathfindingBlockRequest(
val rollingStockSupportedSignalingSystems: List<String>,
@Json(name = "rolling_stock_maximum_speed") val rollingStockMaximumSpeed: Double,
@Json(name = "rolling_stock_length") val rollingStockLength: Double,
@Json(name = "stop_at_next_signal") val stopAtNextSignal: Boolean,
val timeout: Double?,
val infra: String,
@Json(name = "expected_version") val expectedVersion: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ fun runPathfinding(
): PathfindingBlockResponse {
// Parse the waypoints
val waypoints = ArrayList<Collection<PathfindingEdgeLocationId<Block>>>()
for (step in request.pathItems) {
request.pathItems.forEachIndexed { stepIndex, step ->
val allStarts = HashSet<PathfindingEdgeLocationId<Block>>()
for (direction in Direction.entries) {
for (waypoint in step) allStarts.addAll(findWaypointBlocks(infra, waypoint, direction))
for (waypoint in step) {
val waypointBlocks = findWaypointBlocks(infra, waypoint, direction)
if (request.stopAtNextSignal && stepIndex != 0 && stepIndex != request.pathItems.lastIndex) {
allStarts.addAll(waypointBlocks.map { findWaypointBlockNextSignalBlock(request, it, infra) })
} else {
allStarts.addAll(waypointBlocks)
}
}
}
waypoints.add(allStarts)
}
Expand Down Expand Up @@ -369,3 +376,27 @@ private fun getBlockOffset(
String.format("getBlockOffset: Track chunk %s not in block %s", trackChunkId, blockId)
)
}

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

private fun getNextSignalOffset(blockId: BlockId, blockOffset: Offset<Block>, infra: FullInfra, rollingStockLength: Double): Offset<Block> {
val signalsPositions = infra.blockInfra.getSignalsPositions(blockId)
val blockLength = infra.blockInfra.getBlockLength(blockId).distance
val nextSignalPosition = signalsPositions.firstOrNull { it.distance > blockOffset.distance }

val maxHeadOffset = (nextSignalPosition?.distance ?: blockLength) - 1.meters
// println("signalsPositions: $signalsPositions, blockLength: $blockLength, blockOffset: $blockOffset, nextSignalPosition: $nextSignalPosition, maxHeadOffset: $maxHeadOffset")

// TODO: pour garder la queue sur le PR
// val minTailOffset = blockOffset.distance + rollingStockLength.meters
// val finalOffset = if (minTailOffset <= maxHeadOffset) minTailOffset else maxHeadOffset
val finalOffset = maxHeadOffset
return Offset(finalOffset)
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ class SimulationPowerRestrictionItem(
)

class TrainScheduleOptions(
@Json(name = "use_electrical_profiles") val useElectricalProfiles: Boolean
@Json(name = "use_electrical_profiles") val useElectricalProfiles: Boolean,
// @Json(name = "stop_at_next_signal") val stopAtNextSignal: Boolean // TODO: not sure it is used still
)
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private fun parseSteps(
return pathItems
.map {
STDCMStep(
findWaypointBlocks(infra, it.locations),
findWaypointBlocks(infra, it.locations), // TODO: use moveWaypointBlockToNextSignal()
it.stopDuration?.seconds,
it.stopDuration != null,
if (it.stepTimingData != null)
Expand Down Expand Up @@ -362,7 +362,7 @@ private fun checkForConflicts(

private fun findWaypointBlocks(
infra: FullInfra,
waypoints: Collection<TrackLocation>
waypoints: Collection<TrackLocation>,
): Set<PathfindingEdgeLocationId<Block>> {
val waypointBlocks = HashSet<PathfindingEdgeLocationId<Block>>()
for (waypoint in waypoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class STDCMRequestV2(
@Json(name = "rolling_stock_supported_signaling_systems")
val rollingStockSupportedSignalingSystems: List<String>,
@Json(name = "trains_requirements") val trainsRequirements: Map<Long, TrainRequirementsRequest>,
@Json(name = "stop_at_next_signal") val stopAtNextSignal: Boolean,

// Simulation inputs
val comfort: Comfort,
Expand Down

0 comments on commit 03bbd62

Please sign in to comment.