2
2
3
3
import static fr .sncf .osrd .railjson .schema .common .graph .EdgeDirection .START_TO_STOP ;
4
4
import static fr .sncf .osrd .railjson .schema .common .graph .EdgeDirection .STOP_TO_START ;
5
+ import static fr .sncf .osrd .sim_infra .utils .BlockRecoveryKt .recoverBlocks ;
5
6
import static fr .sncf .osrd .utils .KtToJavaConverter .toIntList ;
6
7
import static fr .sncf .osrd .utils .indexing .DirStaticIdxKt .toDirection ;
7
8
import static fr .sncf .osrd .utils .indexing .DirStaticIdxKt .toValue ;
17
18
import fr .sncf .osrd .railjson .schema .infra .RJSRoutePath ;
18
19
import fr .sncf .osrd .railjson .schema .infra .trackranges .RJSDirectionalTrackRange ;
19
20
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 .*;
24
22
import fr .sncf .osrd .utils .Direction ;
25
23
import fr .sncf .osrd .utils .DistanceRangeMap ;
26
24
import fr .sncf .osrd .utils .graph .Pathfinding ;
25
+ import fr .sncf .osrd .utils .indexing .MutableStaticIdxArrayList ;
26
+
27
27
import java .util .ArrayList ;
28
28
import java .util .Collection ;
29
29
import java .util .Comparator ;
@@ -193,7 +193,7 @@ static List<RJSRoutePath> makeRoutePath(
193
193
.map (Pathfinding .EdgeRange ::edge )
194
194
.toList ();
195
195
var chunkPath = chunksOnBlocks (blockInfra , blocks );
196
- var routes = chunksToRoutes (rawInfra , chunkPath );
196
+ var routes = chunksToRoutes (rawInfra , blockInfra , chunkPath );
197
197
var startOffset = findStartOffset (blockInfra , rawInfra , chunkPath .get (0 ), routes .get (0 ), ranges .get (0 ));
198
198
var endOffset = findEndOffset (blockInfra , rawInfra , Iterables .getLast (chunkPath ),
199
199
Iterables .getLast (routes ), Iterables .getLast (ranges ));
@@ -347,12 +347,13 @@ private static List<Integer> chunksOnBlocks(BlockInfra blockInfra, List<Integer>
347
347
/** Converts a list of dir chunks into a list of routes */
348
348
public static List <Integer > chunksToRoutes (
349
349
RawSignalingInfra infra ,
350
+ BlockInfra blockInfra ,
350
351
List <Integer > pathChunks
351
352
) {
352
353
var chunkStartIndex = 0 ;
353
354
var res = new ArrayList <Integer >();
354
355
while (chunkStartIndex < pathChunks .size ()) {
355
- var route = findRoute (infra , pathChunks , chunkStartIndex , chunkStartIndex != 0 );
356
+ var route = findRoute (infra , blockInfra , pathChunks , chunkStartIndex , chunkStartIndex != 0 );
356
357
res .add (route );
357
358
var chunkSetOnRoute = new HashSet <>(toIntList (infra .getChunksOnRoute (route )));
358
359
while (chunkStartIndex < pathChunks .size () && chunkSetOnRoute .contains (pathChunks .get (chunkStartIndex )))
@@ -364,6 +365,7 @@ public static List<Integer> chunksToRoutes(
364
365
/** Finds a valid route that follows the given path */
365
366
private static int findRoute (
366
367
RawSignalingInfra infra ,
368
+ BlockInfra blockInfra ,
367
369
List <Integer > chunks ,
368
370
int startIndex ,
369
371
boolean routeMustIncludeStart
@@ -374,19 +376,22 @@ private static int findRoute(
374
376
routes .sort (Comparator .comparingInt (r -> -infra .getChunksOnRoute (r ).getSize ()));
375
377
376
378
for (var routeId : routes )
377
- if (routeMatchPath (infra , chunks , startIndex , routeMustIncludeStart , routeId ))
379
+ if (routeMatchPath (infra , blockInfra , chunks , startIndex , routeMustIncludeStart , routeId ))
378
380
return routeId ;
379
381
throw new RuntimeException ("Couldn't find a route matching the given chunk list" );
380
382
}
381
383
382
384
/** Returns false if the route differs from the path */
383
385
private static boolean routeMatchPath (
384
386
RawSignalingInfra infra ,
387
+ BlockInfra blockInfra ,
385
388
List <Integer > chunks ,
386
389
int chunkIndex ,
387
390
boolean routeMustIncludeStart ,
388
391
int routeId
389
392
) {
393
+ if (!routeHasBlockPath (infra , blockInfra , routeId ))
394
+ return false ; // Filter out routes that don't have block, they would cause issues later on
390
395
var firstChunk = chunks .get (chunkIndex );
391
396
var routeChunks = infra .getChunksOnRoute (routeId );
392
397
var routeChunkIndex = 0 ;
@@ -408,4 +413,18 @@ private static boolean routeMatchPath(
408
413
chunkIndex ++;
409
414
}
410
415
}
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
+ }
411
430
}
0 commit comments