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 ;
27
26
import java .util .ArrayList ;
28
27
import java .util .Collection ;
29
28
import java .util .Comparator ;
@@ -193,7 +192,7 @@ static List<RJSRoutePath> makeRoutePath(
193
192
.map (Pathfinding .EdgeRange ::edge )
194
193
.toList ();
195
194
var chunkPath = chunksOnBlocks (blockInfra , blocks );
196
- var routes = chunksToRoutes (rawInfra , chunkPath );
195
+ var routes = chunksToRoutes (rawInfra , blockInfra , chunkPath );
197
196
var startOffset = findStartOffset (blockInfra , rawInfra , chunkPath .get (0 ), routes .get (0 ), ranges .get (0 ));
198
197
var endOffset = findEndOffset (blockInfra , rawInfra , Iterables .getLast (chunkPath ),
199
198
Iterables .getLast (routes ), Iterables .getLast (ranges ));
@@ -347,12 +346,13 @@ private static List<Integer> chunksOnBlocks(BlockInfra blockInfra, List<Integer>
347
346
/** Converts a list of dir chunks into a list of routes */
348
347
public static List <Integer > chunksToRoutes (
349
348
RawSignalingInfra infra ,
349
+ BlockInfra blockInfra ,
350
350
List <Integer > pathChunks
351
351
) {
352
352
var chunkStartIndex = 0 ;
353
353
var res = new ArrayList <Integer >();
354
354
while (chunkStartIndex < pathChunks .size ()) {
355
- var route = findRoute (infra , pathChunks , chunkStartIndex , chunkStartIndex != 0 );
355
+ var route = findRoute (infra , blockInfra , pathChunks , chunkStartIndex , chunkStartIndex != 0 );
356
356
res .add (route );
357
357
var chunkSetOnRoute = new HashSet <>(toIntList (infra .getChunksOnRoute (route )));
358
358
while (chunkStartIndex < pathChunks .size () && chunkSetOnRoute .contains (pathChunks .get (chunkStartIndex )))
@@ -364,6 +364,7 @@ public static List<Integer> chunksToRoutes(
364
364
/** Finds a valid route that follows the given path */
365
365
private static int findRoute (
366
366
RawSignalingInfra infra ,
367
+ BlockInfra blockInfra ,
367
368
List <Integer > chunks ,
368
369
int startIndex ,
369
370
boolean routeMustIncludeStart
@@ -374,19 +375,22 @@ private static int findRoute(
374
375
routes .sort (Comparator .comparingInt (r -> -infra .getChunksOnRoute (r ).getSize ()));
375
376
376
377
for (var routeId : routes )
377
- if (routeMatchPath (infra , chunks , startIndex , routeMustIncludeStart , routeId ))
378
+ if (routeMatchPath (infra , blockInfra , chunks , startIndex , routeMustIncludeStart , routeId ))
378
379
return routeId ;
379
380
throw new RuntimeException ("Couldn't find a route matching the given chunk list" );
380
381
}
381
382
382
383
/** Returns false if the route differs from the path */
383
384
private static boolean routeMatchPath (
384
385
RawSignalingInfra infra ,
386
+ BlockInfra blockInfra ,
385
387
List <Integer > chunks ,
386
388
int chunkIndex ,
387
389
boolean routeMustIncludeStart ,
388
390
int routeId
389
391
) {
392
+ if (!routeHasBlockPath (infra , blockInfra , routeId ))
393
+ return false ; // Filter out routes that don't have block, they would cause issues later on
390
394
var firstChunk = chunks .get (chunkIndex );
391
395
var routeChunks = infra .getChunksOnRoute (routeId );
392
396
var routeChunkIndex = 0 ;
@@ -408,4 +412,18 @@ private static boolean routeMatchPath(
408
412
chunkIndex ++;
409
413
}
410
414
}
415
+
416
+ /** Returns true if the route contains a valid block path */
417
+ private static boolean routeHasBlockPath (
418
+ RawSignalingInfra infra ,
419
+ BlockInfra blockInfra ,
420
+ int routeId
421
+ ) {
422
+ var routeIds = new MutableStaticIdxArrayList <Route >();
423
+ routeIds .add (routeId );
424
+ var blockPaths = recoverBlocks (
425
+ infra , blockInfra , routeIds , null
426
+ );
427
+ return !blockPaths .isEmpty ();
428
+ }
411
429
}
0 commit comments