Skip to content

Commit

Permalink
all: handle volt unit for electrification in data only
Browse files Browse the repository at this point in the history
Front does not add 'V' as unit anymore (but some hard-coded front
processing is not tackled and just migrated).

The responsibility for unit is on the data side (rolling stock,
catenaries, electrical profiles). Railjson generation from OSM
is updated accordingly.

Hand-tested (cards, edit and curves on rolling-stock, legend and
catenaries on map, traction on study's speed-space graph):
- OK to load a dump, migrate and use
- OK to load a dump and use without migration (front crashes on speed-space
  graph as expected for traction)
  • Loading branch information
bougue-pe committed Jan 12, 2024
1 parent bf6da3d commit cad1fdf
Show file tree
Hide file tree
Showing 52 changed files with 605 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ void findHighGradePosition() {
void getElectrificationModeAndProfileOnlyModes() {
var modes = TreeRangeMap.<Double, Electrification>create();
modes.put(Range.closed(0.0, 10.0), new NonElectrified());
modes.put(Range.closed(3.0, 7.0), new Electrified("1500"));
modes.put(Range.closed(7.1, 10.0), new Electrified("25000"));
modes.put(Range.closed(3.0, 7.0), new Electrified("1500V"));
modes.put(Range.closed(7.1, 10.0), new Electrified("25000V"));
var path = new EnvelopeSimPath(10, new double[] { 0, 10 }, new double[] { 0 }, ImmutableRangeMap.copyOf(modes),
new HashMap<>());
var modeAndProfileMap = path.getElectrificationMap(null, null, null, true);

assertTrue(fullyCovers(modeAndProfileMap, 10));

assertEquals(modeAndProfileMap.get(0.), new NonElectrified());
assertEquals(modeAndProfileMap.get(4.), new Electrified("1500"));
assertEquals(modeAndProfileMap.get(4.), new Electrified("1500V"));
assertEquals(modeAndProfileMap.get(7.05), new NonElectrified());
assertEquals(modeAndProfileMap.get(7.2), new Electrified("25000"));
assertEquals(modeAndProfileMap.get(7.2), new Electrified("25000V"));
}

@ParameterizedTest
Expand All @@ -72,10 +72,10 @@ void getElectrificationModeAndProfile(boolean withEmptyPowerRestrictionMap) {

assertEquals(9, modeAndProfileMap.asMapOfRanges().size());

assertEquals(modeAndProfileMap.get(2.0), new Electrified("1500", null, null));
assertEquals(modeAndProfileMap.get(3.5), new Electrified("1500", "A", null));
assertEquals(modeAndProfileMap.get(5.5), new Electrified("1500", "C", null));
assertEquals(modeAndProfileMap.get(6.5), new Electrified("1500", "B", null));
assertEquals(modeAndProfileMap.get(2.0), new Electrified("1500V", null, null));
assertEquals(modeAndProfileMap.get(3.5), new Electrified("1500V", "A", null));
assertEquals(modeAndProfileMap.get(5.5), new Electrified("1500V", "C", null));
assertEquals(modeAndProfileMap.get(6.5), new Electrified("1500V", "B", null));
}

@Test
Expand All @@ -92,12 +92,12 @@ void getElectrificationModeAndProfileWithPowerRestrictions() {
assertEquals(10, modeAndProfileMap.asMapOfRanges().size());

assertEquals(modeAndProfileMap.get(0.5), new NonElectrified());
assertEquals(modeAndProfileMap.get(2.75), new Electrified("1500", null, "Restrict2"));
assertEquals(modeAndProfileMap.get(3.25), new Electrified("1500", "A", "Restrict2"));
assertEquals(modeAndProfileMap.get(4.5), new Electrified("1500", "B", "Restrict2"));
assertEquals(modeAndProfileMap.get(5.5), new Electrified("1500", "C", "Restrict2"));
assertEquals(modeAndProfileMap.get(6.25), new Electrified("1500", "B", "Restrict2"));
assertEquals(modeAndProfileMap.get(6.75), new Electrified("1500", "A", null));
assertEquals(modeAndProfileMap.get(2.75), new Electrified("1500V", null, "Restrict2"));
assertEquals(modeAndProfileMap.get(3.25), new Electrified("1500V", "A", "Restrict2"));
assertEquals(modeAndProfileMap.get(4.5), new Electrified("1500V", "B", "Restrict2"));
assertEquals(modeAndProfileMap.get(5.5), new Electrified("1500V", "C", "Restrict2"));
assertEquals(modeAndProfileMap.get(6.25), new Electrified("1500V", "B", "Restrict2"));
assertEquals(modeAndProfileMap.get(6.75), new Electrified("1500V", "A", null));
}

@Test
Expand All @@ -111,12 +111,12 @@ void getElectrificationModeAndProfileWithPowerRestrictionsWithoutElectricalProfi

assertEquals(6, modeAndProfileMap.asMapOfRanges().size());

assertEquals(modeAndProfileMap.get(2.0), new Electrified("1500", null, null));
assertEquals(modeAndProfileMap.get(2.0), new Electrified("1500V", null, null));
assertEquals(modeAndProfileMap.get(4.5),
new Electrified("1500", null, "Restrict2"));
new Electrified("1500V", null, "Restrict2"));
assertSame(modeAndProfileMap.get(4.5), modeAndProfileMap.get(5.5));
assertSame(modeAndProfileMap.get(5.5), modeAndProfileMap.get(6.25));
assertEquals(modeAndProfileMap.get(6.75), new Electrified("1500", null, null));
assertEquals(modeAndProfileMap.get(9.0), new Electrified("25000", null, null));
assertEquals(modeAndProfileMap.get(6.75), new Electrified("1500V", null, null));
assertEquals(modeAndProfileMap.get(9.0), new Electrified("25000V", null, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class EnvelopeSimPathBuilder {
private static RangeMap<Double, Electrification> getModeMap(double length) {
var electrificationMap = TreeRangeMap.<Double, Electrification>create();
electrificationMap.put(Range.closed(0.0, length), new NonElectrified());
electrificationMap.put(Range.closed(1.0, 8.0), new Electrified("1500"));
electrificationMap.put(Range.closed(8.1, 20.), new Electrified("25000"));
electrificationMap.put(Range.closed(1.0, 8.0), new Electrified("1500V"));
electrificationMap.put(Range.closed(8.1, 20.), new Electrified("25000V"));
electrificationMap.put(Range.closed(30., 50.), new Electrified("unhandled"));
return electrificationMap.subRangeMap(Range.closed(0.0, length));
}
Expand Down Expand Up @@ -52,15 +52,15 @@ public static EnvelopeSimPath withModes(double length) {
public static EnvelopeSimPath withElectricalProfiles1500() {
RangeMap<Double, String> profiles1 = TreeRangeMap.create();
profiles1.put(Range.closed(3.0, 8.0), "A");
profiles1.put(Range.closed(8.1, 10.5), "25000");
profiles1.put(Range.closed(8.1, 10.5), "25000V");

RangeMap<Double, String> profiles2 = TreeRangeMap.create();
profiles2.put(Range.closedOpen(3.0, 4.0), "A");
profiles2.put(Range.closedOpen(4.0, 5.0), "B");
profiles2.put(Range.closedOpen(5.0, 6.0), "C");
profiles2.put(Range.closedOpen(6.0, 7.0), "B");
profiles2.put(Range.closed(7.0, 8.0), "A");
profiles2.put(Range.closed(8.1, 10.5), "25000");
profiles2.put(Range.closed(8.1, 10.5), "25000V");

var defaultElectrificationMap = getModeMap(10.);
var byPowerClass = new HashMap<String, ImmutableRangeMap<Double, Electrification>>();
Expand All @@ -79,21 +79,21 @@ public static EnvelopeSimPath withElectricalProfiles25000(double length) {

HashMap<String, ImmutableRangeMap<Double, String>> electricalProfiles = new HashMap<>();
electricalProfiles.put("5", new ImmutableRangeMap.Builder<Double, String>()
.put(Range.closedOpen(10., 12.), "25000")
.put(Range.closedOpen(12., 14.), "22500")
.put(Range.closedOpen(14., 16.), "20000")
.put(Range.closedOpen(16., 18.), "22500")
.put(Range.closed(18., 20.), "25000")
.put(Range.closedOpen(10., 12.), "25000V")
.put(Range.closedOpen(12., 14.), "22500V")
.put(Range.closedOpen(14., 16.), "20000V")
.put(Range.closedOpen(16., 18.), "22500V")
.put(Range.closed(18., 20.), "25000V")
.build());

electricalProfiles.put("4", new ImmutableRangeMap.Builder<Double, String>()
.put(Range.closedOpen(10., 13.), "25000")
.put(Range.closedOpen(13., 17.), "22500")
.put(Range.closedOpen(17., 20.), "25000")
.put(Range.closedOpen(10., 13.), "25000V")
.put(Range.closedOpen(13., 17.), "22500V")
.put(Range.closedOpen(17., 20.), "25000V")
.build());

electricalProfiles.put("3", new ImmutableRangeMap.Builder<Double, String>()
.put(Range.closedOpen(10., 20.), "25000")
.put(Range.closedOpen(10., 20.), "25000V")
.build());

var byPowerClass = new HashMap<String, ImmutableRangeMap<Double, Electrification>>();
Expand Down
32 changes: 16 additions & 16 deletions core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ public void testElectrificationRangesInResult() throws IOException {
var electrificationRanges = simResult.electrificationRanges.get(0);

ElectrificationUsage[] expected = {
new ElectrifiedUsage("1500", true, "O", false),
new ElectrifiedUsage("1500V", true, "O", false),
new NeutralUsage(true),
new ElectrifiedUsage("25000", true, "25000", true),
new ElectrifiedUsage("25000", true, "22500", true),
new ElectrifiedUsage("25000", true, "20000", true),
new ElectrifiedUsage("25000", true, "22500", true),
new ElectrifiedUsage("25000V", true, "25000V", true),
new ElectrifiedUsage("25000V", true, "22500V", true),
new ElectrifiedUsage("25000V", true, "20000V", true),
new ElectrifiedUsage("25000V", true, "22500V", true),
new NeutralUsage(false),
new ElectrifiedUsage("25000", true, "22500", true),
new ElectrifiedUsage("25000", true, "25000", true),
new ElectrifiedUsage("25000V", true, "22500V", true),
new ElectrifiedUsage("25000V", true, "25000V", true),
};

assertArrayEquals(expected, electrificationRanges.stream().map(r -> r.electrificationUsage).toArray());
Expand Down Expand Up @@ -664,14 +664,14 @@ public void testElectrificationRangesInResultWithPowerRestriction() throws IOExc
var electrificationRanges = simResult.electrificationRanges.get(0);

ElectrificationUsage[] expected = {
new ElectrifiedUsage("1500", true, "O", false),
new ElectrifiedUsage("1500V", true, "O", false),
new NeutralUsage(true),
new ElectrifiedUsage("25000", true, "25000", true),
new ElectrifiedUsage("25000", true, "20000", true),
new ElectrifiedUsage("25000", true, "22500", true),
new ElectrifiedUsage("25000V", true, "25000V", true),
new ElectrifiedUsage("25000V", true, "20000V", true),
new ElectrifiedUsage("25000V", true, "22500V", true),
new NeutralUsage(false),
new ElectrifiedUsage("25000", true, "22500", true),
new ElectrifiedUsage("25000", true, "25000", true),
new ElectrifiedUsage("25000V", true, "22500V", true),
new ElectrifiedUsage("25000V", true, "25000V", true),
};

assertArrayEquals(expected, electrificationRanges.stream().map(r -> r.electrificationUsage).toArray());
Expand Down Expand Up @@ -736,11 +736,11 @@ public void testElectrificationRangesThermalElectrified() throws IOException {
var electrificationRanges = simResult.electrificationRanges.get(0);

ElectrificationUsage[] expected = {
new ElectrifiedUsage("1500", false, null, true),
new ElectrifiedUsage("1500V", false, null, true),
new NeutralUsage(true),
new ElectrifiedUsage("25000", false, null, true),
new ElectrifiedUsage("25000V", false, null, true),
new NeutralUsage(false),
new ElectrifiedUsage("25000", false, null, true),
new ElectrifiedUsage("25000V", false, null, true),
};

assertArrayEquals(expected, electrificationRanges.stream().map(r -> r.electrificationUsage).toArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class ExternalGeneratedInputsHelpers {
* Return a short list of electrical profiles
*/
public static RJSElectricalProfileSet getRjsElectricalProfileSet() {
return new RJSElectricalProfileSet(asList(new RJSElectricalProfileSet.RJSElectricalProfile("25000", "1",
return new RJSElectricalProfileSet(asList(new RJSElectricalProfileSet.RJSElectricalProfile("25000V", "1",
asList(new RJSTrackRange("track", 0, 10), new RJSTrackRange("track", 90, 100))),
new RJSElectricalProfileSet.RJSElectricalProfile("22500", "1",
new RJSElectricalProfileSet.RJSElectricalProfile("22500V", "1",
asList(new RJSTrackRange("track", 10, 30), new RJSTrackRange("track", 70, 90))),
new RJSElectricalProfileSet.RJSElectricalProfile("20000", "1",
new RJSElectricalProfileSet.RJSElectricalProfile("20000V", "1",
singletonList(new RJSTrackRange("track", 30, 70)))));
}
}
20 changes: 10 additions & 10 deletions core/src/test/java/fr/sncf/osrd/train/TestRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ void testMapTractiveEffortCurveWithProfiles() {
// Check that the conditions are correct
assertArrayEquals(new InfraConditions[] {
new InfraConditions("thermal", null, null), // 0
new InfraConditions("1500", null, null), // 1
new InfraConditions("1500", null, null), // 5 "Restrict1" invalid for 1500
new InfraConditions("1500V", null, null), // 1
new InfraConditions("1500V", null, null), // 5 "Restrict1" invalid for 1500V
new InfraConditions("thermal", null, null), // 8
new InfraConditions("25000", null, "Restrict2"), // 8.1
new InfraConditions("25000", "25000", "Restrict2"), // 10
new InfraConditions("25000", "25000", null), // 11
new InfraConditions("25000", "22500", null), // 12
new InfraConditions("25000", "20000", null), // 14
new InfraConditions("25000", "22500", "Restrict1"), // 15
new InfraConditions("25000", "25000", "Restrict1"), // 17
new InfraConditions("25000", "25000", null), // 18 "UnknownRestrict" invalid for 25000
new InfraConditions("25000V", null, "Restrict2"), // 8.1
new InfraConditions("25000V", "25000V", "Restrict2"), // 10
new InfraConditions("25000V", "25000V", null), // 11
new InfraConditions("25000V", "22500V", null), // 12
new InfraConditions("25000V", "20000V", null), // 14
new InfraConditions("25000V", "22500V", "Restrict1"), // 15
new InfraConditions("25000V", "25000V", "Restrict1"), // 17
new InfraConditions("25000V", "25000V", null), // 18 "UnknownRestrict" invalid for 25000V
new InfraConditions("thermal", null, null), // 20 No mode given
new InfraConditions("thermal", null, null) // 30 Invalid mode
},
Expand Down
16 changes: 8 additions & 8 deletions core/src/test/java/fr/sncf/osrd/train/TestTrains.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static Map<String, RollingStock.ModeEffortCurves> createModeEffortCurves
var modeSpeed = maxSpeed;
switch (mode) {
case "thermal" -> modeSpeed *= 0.92;
case "1500" -> modeSpeed *= 0.82;
case "1500V" -> modeSpeed *= 0.82;
default -> { }
}
var conditions = entry.getValue();
Expand All @@ -49,8 +49,8 @@ private static Map<String, RollingStock.ModeEffortCurves> createModeEffortCurves
}
if (condition.electricalProfile() != null)
switch (condition.electricalProfile()) {
case "22500" -> speed *= 0.9;
case "20000" -> speed *= .8;
case "22500V" -> speed *= 0.9;
case "20000V" -> speed *= .8;
default -> { }
}
if (condition.powerRestriction() != null)
Expand Down Expand Up @@ -81,11 +81,11 @@ private static Map<String, RollingStock.ModeEffortCurves> createModeEffortCurves
new RollingStock.EffortCurveConditions[] {
new RollingStock.EffortCurveConditions(Comfort.AC, null, null),
new RollingStock.EffortCurveConditions(Comfort.HEATING, null, null) },
"1500", new RollingStock.EffortCurveConditions[0],
"25000",
"1500V", new RollingStock.EffortCurveConditions[0],
"25000V",
Lists.cartesianProduct(
List.of(Comfort.STANDARD, Comfort.AC, Comfort.HEATING),
List.of("25000", "22500", "20000", "null"),
List.of("25000V", "22500V", "20000V", "null"),
List.of("Restrict1", "Restrict2", "null")
).stream()
.map(triple -> new RollingStock.EffortCurveConditions(
Expand Down Expand Up @@ -194,8 +194,8 @@ private static Map<String, RollingStock.ModeEffortCurves> createModeEffortCurves
PhysicsRollingStock.GammaType.CONST,
RJSLoadingGaugeType.G1,
createModeEffortCurves(MAX_SPEED, CurveShape.LINEAR,
Map.of("25000", new RollingStock.EffortCurveConditions[0])),
"25000",
Map.of("25000V", new RollingStock.EffortCurveConditions[0])),
"25000V",
"1"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class PathfindingElectrificationTest : ApiTest() {
infra.fullInfra(), waypoints, listOf(TestTrains.REALISTIC_FAST_TRAIN)
)
Assertions.assertNotNull(normalPath)
assert(TestTrains.FAST_ELECTRIC_TRAIN.modeNames.contains("25000"))
assert(TestTrains.FAST_ELECTRIC_TRAIN.modeNames.contains("25000V"))
for (block in infra.blockPool)
block.voltage = "25000"
block.voltage = "25000V"

// Removes electrification in the section used by the normal train
for (range in normalPath.ranges) {
Expand Down Expand Up @@ -130,9 +130,9 @@ class PathfindingElectrificationTest : ApiTest() {
infra.fullInfra(), waypoints, listOf(TestTrains.REALISTIC_FAST_TRAIN)
)
Assertions.assertNotNull(normalPath)
assert(TestTrains.FAST_ELECTRIC_TRAIN.modeNames.contains("25000"))
assert(TestTrains.FAST_ELECTRIC_TRAIN.modeNames.contains("25000V"))
for (block in infra.blockPool)
block.voltage = "25000"
block.voltage = "25000V"
if (!withElectrification) {
// Remove electrification in the middle of the path
infra.blockPool[secondBlock.index.toInt()].voltage = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class PathfindingTest : ApiTest() {
)

// Replace with custom electrifications
// Set voltage to 25000 everywhere except for trackSectionToBlock
// Set voltage to 25000V everywhere except for trackSectionToBlock
val trackSectionToBlock = normalPath.ranges
.map { range -> range.edge }
.flatMap { block ->
Expand All @@ -315,7 +315,7 @@ class PathfindingTest : ApiTest() {
)
}
.collect(Collectors.toList())
val voltageElectrification = RJSElectrification("25000", voltageTrackRanges)
val voltageElectrification = RJSElectrification("25000V", voltageTrackRanges)
val noVoltageElectrification = RJSElectrification("",
listOf(RJSApplicableDirectionsTrackRange(trackSectionToBlock, ApplicableDirection.BOTH, 0.0,
rjsInfra.trackSections.stream()
Expand Down
Loading

0 comments on commit cad1fdf

Please sign in to comment.