Skip to content

Commit b111c8e

Browse files
committed
core: pathfinding: filter out routes without blocks
1 parent 7e5a041 commit b111c8e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

core/src/main/java/fr/sncf/osrd/api/pathfinding/PathfindingResultConverter.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection.START_TO_STOP;
44
import static fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection.STOP_TO_START;
5+
import static fr.sncf.osrd.sim_infra.utils.BlockRecoveryKt.recoverBlocks;
56
import static fr.sncf.osrd.utils.KtToJavaConverter.toIntList;
67
import static fr.sncf.osrd.utils.indexing.DirStaticIdxKt.toDirection;
78
import static fr.sncf.osrd.utils.indexing.DirStaticIdxKt.toValue;
@@ -17,13 +18,12 @@
1718
import fr.sncf.osrd.railjson.schema.infra.RJSRoutePath;
1819
import fr.sncf.osrd.railjson.schema.infra.trackranges.RJSDirectionalTrackRange;
1920
import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl;
20-
import fr.sncf.osrd.sim_infra.api.BlockInfra;
21-
import fr.sncf.osrd.sim_infra.api.PathProperties;
22-
import fr.sncf.osrd.sim_infra.api.RawSignalingInfra;
23-
import fr.sncf.osrd.sim_infra.api.RawSignalingInfraKt;
21+
import fr.sncf.osrd.sim_infra.api.*;
2422
import fr.sncf.osrd.utils.Direction;
2523
import fr.sncf.osrd.utils.DistanceRangeMap;
2624
import fr.sncf.osrd.utils.graph.Pathfinding;
25+
import fr.sncf.osrd.utils.indexing.MutableStaticIdxArrayList;
26+
2727
import java.util.ArrayList;
2828
import java.util.Collection;
2929
import java.util.Comparator;
@@ -193,7 +193,7 @@ static List<RJSRoutePath> makeRoutePath(
193193
.map(Pathfinding.EdgeRange::edge)
194194
.toList();
195195
var chunkPath = chunksOnBlocks(blockInfra, blocks);
196-
var routes = chunksToRoutes(rawInfra, chunkPath);
196+
var routes = chunksToRoutes(rawInfra, blockInfra, chunkPath);
197197
var startOffset = findStartOffset(blockInfra, rawInfra, chunkPath.get(0), routes.get(0), ranges.get(0));
198198
var endOffset = findEndOffset(blockInfra, rawInfra, Iterables.getLast(chunkPath),
199199
Iterables.getLast(routes), Iterables.getLast(ranges));
@@ -347,12 +347,13 @@ private static List<Integer> chunksOnBlocks(BlockInfra blockInfra, List<Integer>
347347
/** Converts a list of dir chunks into a list of routes */
348348
public static List<Integer> chunksToRoutes(
349349
RawSignalingInfra infra,
350+
BlockInfra blockInfra,
350351
List<Integer> pathChunks
351352
) {
352353
var chunkStartIndex = 0;
353354
var res = new ArrayList<Integer>();
354355
while (chunkStartIndex < pathChunks.size()) {
355-
var route = findRoute(infra, pathChunks, chunkStartIndex, chunkStartIndex != 0);
356+
var route = findRoute(infra, blockInfra, pathChunks, chunkStartIndex, chunkStartIndex != 0);
356357
res.add(route);
357358
var chunkSetOnRoute = new HashSet<>(toIntList(infra.getChunksOnRoute(route)));
358359
while (chunkStartIndex < pathChunks.size() && chunkSetOnRoute.contains(pathChunks.get(chunkStartIndex)))
@@ -364,6 +365,7 @@ public static List<Integer> chunksToRoutes(
364365
/** Finds a valid route that follows the given path */
365366
private static int findRoute(
366367
RawSignalingInfra infra,
368+
BlockInfra blockInfra,
367369
List<Integer> chunks,
368370
int startIndex,
369371
boolean routeMustIncludeStart
@@ -374,19 +376,22 @@ private static int findRoute(
374376
routes.sort(Comparator.comparingInt(r -> -infra.getChunksOnRoute(r).getSize()));
375377

376378
for (var routeId : routes)
377-
if (routeMatchPath(infra, chunks, startIndex, routeMustIncludeStart, routeId))
379+
if (routeMatchPath(infra, blockInfra, chunks, startIndex, routeMustIncludeStart, routeId))
378380
return routeId;
379381
throw new RuntimeException("Couldn't find a route matching the given chunk list");
380382
}
381383

382384
/** Returns false if the route differs from the path */
383385
private static boolean routeMatchPath(
384386
RawSignalingInfra infra,
387+
BlockInfra blockInfra,
385388
List<Integer> chunks,
386389
int chunkIndex,
387390
boolean routeMustIncludeStart,
388391
int routeId
389392
) {
393+
if (!routeHasBlockPath(infra, blockInfra, routeId))
394+
return false; // Filter out routes that don't have block, they would cause issues later on
390395
var firstChunk = chunks.get(chunkIndex);
391396
var routeChunks = infra.getChunksOnRoute(routeId);
392397
var routeChunkIndex = 0;
@@ -408,4 +413,18 @@ private static boolean routeMatchPath(
408413
chunkIndex++;
409414
}
410415
}
416+
417+
/** Returns true if the route contains a valid block path */
418+
private static boolean routeHasBlockPath(
419+
RawSignalingInfra infra,
420+
BlockInfra blockInfra,
421+
int routeId
422+
) {
423+
var routeIds = new MutableStaticIdxArrayList<Route>();
424+
routeIds.add(routeId);
425+
var blockPaths = recoverBlocks(
426+
infra, blockInfra, routeIds, null
427+
);
428+
return !blockPaths.isEmpty();
429+
}
411430
}

core/src/main/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fun run(envelope: Envelope, trainPath: PathProperties, chunkPath: ChunkPath, sch
7878
val simulator = fullInfra.signalingSimulator
7979

8080
// get a new generation route path
81-
val routePath = toRouteIdList(chunksToRoutes(rawInfra, toIntList(chunkPath.chunks)))
81+
val routePath = toRouteIdList(chunksToRoutes(rawInfra, fullInfra.blockInfra, toIntList(chunkPath.chunks)))
8282

8383
// recover blocks from the route paths
8484
val detailedBlockPath = recoverBlockPath(simulator, fullInfra, routePath)

0 commit comments

Comments
 (0)