Skip to content

Commit c399fdc

Browse files
Baptiste PrevotCastavo
Baptiste Prevot
authored andcommitted
examples + core: add and use a fully electric rolling stock
1 parent 5d57b6c commit c399fdc

File tree

6 files changed

+1927
-1843
lines changed

6 files changed

+1927
-1843
lines changed

core/src/test/java/fr/sncf/osrd/Helpers.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525

2626
public class Helpers {
27-
/** Parse all serialized .json rolling stock files and add these to the given map */
28-
public static List<RJSRollingStock> parseRollingStockDir(Path dirPath) throws IOException, OSRDError {
27+
/** Parse all serialized .json rolling stock files */
28+
public static List<RJSRollingStock> getExampleRollingStocks() throws IOException, OSRDError {
2929
var jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**.json");
30-
var rollingStocksPaths = Files.list(dirPath)
30+
var rollingStocksPaths = Files.list(getResourcePath("rolling_stocks/"))
3131
.filter((path) -> path.toFile().isFile())
3232
.filter(jsonMatcher::matches)
3333
.toList();
@@ -39,10 +39,6 @@ public static List<RJSRollingStock> parseRollingStockDir(Path dirPath) throws IO
3939
return res;
4040
}
4141

42-
public static List<RJSRollingStock> getExampleRollingStocks() throws OSRDError, IOException {
43-
return parseRollingStockDir(getResourcePath("rolling_stocks/"));
44-
}
45-
4642
public static RJSRollingStock getExampleRollingStock(String fileName) throws IOException, OSRDError {
4743
return MoshiUtils.deserialize(RJSRollingStock.adapter, getResourcePath("rolling_stocks/" + fileName));
4844
}

core/src/test/java/fr/sncf/osrd/api/STDCMEndpointTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void simpleEmptyTimetable() throws Exception {
2222
var requestBody = STDCMRequest.adapter.toJson(new STDCMRequest(
2323
"tiny_infra/infra.json",
2424
"1",
25-
parseRollingStockDir(getResourcePath("rolling_stocks/")).get(0),
25+
getExampleRollingStock("fast_rolling_stock.json"),
2626
Set.of(),
2727
List.of(
2828
new STDCMRequest.STDCMStep(0, true, Set.of(new PathfindingWaypoint(

core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,15 @@ public void withElectricalProfilesAndComfort() throws IOException {
462462
var stops = new RJSTrainStop[]{RJSTrainStop.lastStop(0.1)};
463463
var trainSchedules = new ArrayList<RJSStandaloneTrainSchedule>();
464464
for (int i = 1; i <= 5; i++) {
465-
var rollingStock = getExampleRollingStock("fast_rolling_stock.json");
465+
var rollingStock = getExampleRollingStock("electric_rolling_stock.json");
466466
rollingStock.name += i;
467467
rollingStock.basePowerClass = String.valueOf(i);
468468
rollingStocks.add(rollingStock);
469469

470470
var trainSchedule = new RJSStandaloneTrainSchedule("Test." + i, rollingStock.name, 0, null, stops, null);
471471
trainSchedules.add(trainSchedule);
472472
}
473-
var trainSchedule = new RJSStandaloneTrainSchedule("Test", "fast_rolling_stock1", 0, null, stops, null,
473+
var trainSchedule = new RJSStandaloneTrainSchedule("Test", "electric_rolling_stock1", 0, null, stops, null,
474474
RJSComfortType.AC, null, null);
475475
trainSchedules.add(trainSchedule);
476476

@@ -513,9 +513,9 @@ public void testWithPowerRestrictions() throws IOException {
513513
new RJSPowerRestrictionRange(6000., 8000., "Unknown"),
514514
};
515515
var trains = new ArrayList<RJSStandaloneTrainSchedule>();
516-
trains.add(new RJSStandaloneTrainSchedule("with", "fast_rolling_stock", 0, null, stops, null,
516+
trains.add(new RJSStandaloneTrainSchedule("with", "electric_rolling_stock", 0, null, stops, null,
517517
RJSComfortType.STANDARD, null, powerRestrictionRanges));
518-
trains.add(new RJSStandaloneTrainSchedule("without", "fast_rolling_stock", 0, null, stops, null));
518+
trains.add(new RJSStandaloneTrainSchedule("without", "electric_rolling_stock", 0, null, stops, null));
519519

520520
var query = new StandaloneSimulationRequest("small_infra/infra.json", "1", 2, getExampleRollingStocks(), trains,
521521
rjsTrainPath);
@@ -524,7 +524,7 @@ public void testWithPowerRestrictions() throws IOException {
524524
var resultWith = Iterables.getLast(simResult.baseSimulations.get(0).headPositions).time;
525525
var resultWithout = Iterables.getLast(simResult.baseSimulations.get(1).headPositions).time;
526526
assertTrue(resultWith > resultWithout + 1,
527-
"With power restrictions should be a lot slower than without, but was "
527+
"With power restrictions should be a lot slower than without, but was "
528528
+ resultWith + " vs " + resultWithout);
529529
}
530530

@@ -539,9 +539,9 @@ public void testWithPowerRestrictionsAndElectricalProfiles() throws IOException
539539
new RJSPowerRestrictionRange(6000., 8000., "Unknown"),
540540
};
541541
var trains = new ArrayList<RJSStandaloneTrainSchedule>();
542-
trains.add(new RJSStandaloneTrainSchedule("with", "fast_rolling_stock", 0, null, stops, null,
542+
trains.add(new RJSStandaloneTrainSchedule("with", "electric_rolling_stock", 0, null, stops, null,
543543
RJSComfortType.STANDARD, null, powerRestrictionRanges));
544-
trains.add(new RJSStandaloneTrainSchedule("without", "fast_rolling_stock", 0, null, stops, null));
544+
trains.add(new RJSStandaloneTrainSchedule("without", "electric_rolling_stock", 0, null, stops, null));
545545

546546
var query = new StandaloneSimulationRequest("small_infra/infra.json",
547547
"small_infra/external_generated_inputs.json", "1", 2, getExampleRollingStocks(), trains, rjsTrainPath);
@@ -562,8 +562,7 @@ List<String> gather(List<ElectrificationConditionsRange> ranges,
562562
public void testElectrificationConditionsInResult() throws IOException {
563563
final var rjsTrainPath = smallInfraTrainPath();
564564

565-
var rollingStock = getExampleRollingStock("fast_rolling_stock.json");
566-
rollingStock.basePowerClass = "5";
565+
var rollingStock = getExampleRollingStock("electric_rolling_stock.json");
567566

568567
var trainSchedule = new RJSStandaloneTrainSchedule("Test", rollingStock.name, 0, new RJSAllowance[0],
569568
new RJSTrainStop[] { RJSTrainStop.lastStop(0.1) }, null, RJSComfortType.AC, null, null);
@@ -583,15 +582,15 @@ public void testElectrificationConditionsInResult() throws IOException {
583582
var simResult = runStandaloneSimulation(query);
584583
var electrificationConditionsRanges = simResult.electrificationConditions.get(0);
585584

586-
var expectedUsedModes = List.of("thermal", "25000", "25000", "25000", "25000", "25000");
585+
var expectedUsedModes = List.of("1500", "25000", "25000", "25000", "25000", "25000");
587586
var usedModes = gather(electrificationConditionsRanges, e -> e.usedMode);
588587
assertEquals(expectedUsedModes, usedModes);
589588

590589
var expectedUsedProfiles = List.of("null", "25000", "22500", "20000", "22500", "25000");
591590
var usedProfiles = gather(electrificationConditionsRanges, e -> e.usedProfile);
592591
assertEquals(expectedUsedProfiles, usedProfiles);
593592

594-
var expectedSeenModes = List.of("1500", "null", "null", "null", "null", "null");
593+
var expectedSeenModes = List.of("null", "null", "null", "null", "null", "null");
595594
var seenModes = gather(electrificationConditionsRanges, e -> e.seenMode);
596595
assertEquals(expectedSeenModes, seenModes);
597596

@@ -604,8 +603,7 @@ public void testElectrificationConditionsInResult() throws IOException {
604603
public void testElectrificationConditionsInResultWithIgnored() throws IOException {
605604
final var rjsTrainPath = smallInfraTrainPath();
606605

607-
var rollingStock = getExampleRollingStock("fast_rolling_stock.json");
608-
rollingStock.basePowerClass = "5";
606+
var rollingStock = getExampleRollingStock("electric_rolling_stock.json");
609607

610608
var trainSchedule1 = new RJSStandaloneTrainSchedule("Test", rollingStock.name, 0, new RJSAllowance[0],
611609
new RJSTrainStop[] { RJSTrainStop.lastStop(0.1) }, null, RJSComfortType.AC, null, null);
@@ -642,8 +640,7 @@ public void testElectrificationConditionsInResultWithIgnored() throws IOExceptio
642640
public void testElectrificationConditionsInResultWithPowerRestriction() throws IOException {
643641
final var rjsTrainPath = smallInfraTrainPath();
644642

645-
var rollingStock = getExampleRollingStock("fast_rolling_stock.json");
646-
rollingStock.basePowerClass = "5";
643+
var rollingStock = getExampleRollingStock("electric_rolling_stock.json");
647644

648645
var trainSchedule = new RJSStandaloneTrainSchedule("Test", rollingStock.name, 0, new RJSAllowance[0],
649646
new RJSTrainStop[] { RJSTrainStop.lastStop(0.1) }, null, RJSComfortType.AC, null,
@@ -664,7 +661,7 @@ public void testElectrificationConditionsInResultWithPowerRestriction() throws I
664661
var simResult = runStandaloneSimulation(query);
665662
var electrificationConditionsRanges = simResult.electrificationConditions.get(0);
666663

667-
var expectedUsedModes = List.of("thermal", "thermal", "25000", "25000", "25000", "25000", "25000");
664+
var expectedUsedModes = List.of("1500", "1500", "25000", "25000", "25000", "25000", "25000");
668665
var usedModes = gather(electrificationConditionsRanges, e -> e.usedMode);
669666
assertEquals(expectedUsedModes, usedModes);
670667

@@ -676,7 +673,7 @@ public void testElectrificationConditionsInResultWithPowerRestriction() throws I
676673
var usedRestrictions = gather(electrificationConditionsRanges, e -> e.usedRestriction);
677674
assertEquals(expectedUsedRestrictions, usedRestrictions);
678675

679-
var expectedSeenModes = List.of("1500", "1500", "null", "null", "null", "null", "null");
676+
var expectedSeenModes = List.of("null", "null", "null", "null", "null", "null", "null");
680677
var seenModes = gather(electrificationConditionsRanges, e -> e.seenMode);
681678
assertEquals(expectedSeenModes, seenModes);
682679

core/src/test/java/fr/sncf/osrd/stdcm/FullSTDCMTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.sncf.osrd.stdcm;
22

3-
import static fr.sncf.osrd.Helpers.getResourcePath;
4-
import static fr.sncf.osrd.Helpers.parseRollingStockDir;
3+
import static fr.sncf.osrd.Helpers.getExampleRollingStock;
54
import static org.junit.jupiter.api.Assertions.assertNotNull;
65

76
import fr.sncf.osrd.Helpers;
@@ -24,7 +23,7 @@ public void testTinyInfra() throws IOException, URISyntaxException {
2423
var res = new STDCMPathfindingBuilder()
2524
.setInfra(infra)
2625
.setRollingStock(
27-
RJSRollingStockParser.parse(parseRollingStockDir(getResourcePath("rolling_stocks/")).get(0))
26+
RJSRollingStockParser.parse(getExampleRollingStock("fast_rolling_stock.json"))
2827
)
2928
.setStartLocations(Set.of(new Pathfinding.EdgeLocation<>(firstRoute, 100)))
3029
.setEndLocations(Set.of(new Pathfinding.EdgeLocation<>(secondRoute, 10125)))

0 commit comments

Comments
 (0)