From 11f49d47518f365e58502038aa7026601cfc66d8 Mon Sep 17 00:00:00 2001 From: Eloi Charpentier Date: Tue, 14 May 2024 10:50:00 +0200 Subject: [PATCH] core: stdcm: ignore paths that use the same block several times --- .../osrd/stdcm/infra_exploration/InfraExplorer.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 32d06cd9b8c..a07e01feda3 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 @@ -141,7 +141,7 @@ private class InfraExplorerImpl( private val blockInfra: BlockInfra, private var blocks: AppendOnlyLinkedList, private var routes: AppendOnlyLinkedList, - private var blockRoutes: MutableMap>, + private var blockRoutes: MutableMap, private var incrementalPath: IncrementalPath, private var pathPropertiesCache: MutableMap, private var currentIndex: Int = 0, @@ -172,8 +172,7 @@ private class InfraExplorerImpl( getCurrentBlock(), ) } - val nonOverlappingRoutesOnBlock = - blockRoutes[getCurrentBlock()]!!.intersect(routes.toSet()).toList() + val nonOverlappingRoutesOnBlock = listOf(blockRoutes[getCurrentBlock()]!!) val blockPathProperties = path.withRoutes(nonOverlappingRoutesOnBlock) pathPropertiesCache[getCurrentBlock()] = blockPathProperties @@ -275,6 +274,7 @@ private class InfraExplorerImpl( val addedBlocks = mutableListOf() for (block in routeBlocks) { + if (blockRoutes.containsKey(block)) return false // We already passed by this block addedBlocks.add(block) if (block == firstLocation?.edge) { seenFirstBlock = true @@ -308,7 +308,10 @@ private class InfraExplorerImpl( assert(seenFirstBlock) blocks.addAll(addedBlocks) routes.add(route) - for (block in addedBlocks) blockRoutes.getOrPut(block) { mutableSetOf() }.add(route) + for (block in addedBlocks) { + assert(!blockRoutes.containsKey(block)) + blockRoutes[block] = route + } for (i in 0 ..< nBlocksToSkip) moveForward() for (pathFragment in pathFragments) incrementalPath.extend(pathFragment)