Skip to content

Commit 40070b8

Browse files
committed
core: remove coastFromBeginning to avoid space search discontinuities during mareco allowance calculations
1 parent f7d8deb commit 40070b8

File tree

5 files changed

+6
-58
lines changed

5 files changed

+6
-58
lines changed

core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/mareco_impl/CoastingGenerator.java

+1-32
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,8 @@
1010
import fr.sncf.osrd.envelope.part.constraints.EnvelopeConstraint;
1111
import fr.sncf.osrd.envelope.part.constraints.SpeedConstraint;
1212
import fr.sncf.osrd.envelope_sim.*;
13-
import fr.sncf.osrd.envelope_sim.overlays.EnvelopeCoasting;
14-
import fr.sncf.osrd.reporting.exceptions.OSRDError;
15-
import fr.sncf.osrd.reporting.exceptions.ErrorType;
1613

1714
public final class CoastingGenerator {
18-
/** Generate a coasting envelope part which starts at startPos */
19-
public static EnvelopePart coastFromBeginning(
20-
Envelope envelope,
21-
EnvelopeSimContext context,
22-
double startPos
23-
) {
24-
var partBuilder = new EnvelopePartBuilder();
25-
partBuilder.setAttr(EnvelopeProfile.COASTING);
26-
var constrainedBuilder = new ConstrainedEnvelopePartBuilder(
27-
partBuilder,
28-
new SpeedConstraint(0, FLOOR),
29-
new EnvelopeConstraint(envelope, CEILING)
30-
);
31-
var speed = envelope.interpolateSpeed(startPos);
32-
EnvelopeCoasting.coast(context, startPos, speed, constrainedBuilder, 1);
33-
if (constrainedBuilder.lastIntersection == 0)
34-
throw new OSRDError(ErrorType.ImpossibleSimulationError); // We reached a stop while coasting
35-
if (partBuilder.isEmpty())
36-
return null;
37-
return partBuilder.build();
38-
}
3915

4016
/** Generate a coasting envelope part which ends at endPos and never goes below lowSpeedLimit */
4117
public static EnvelopePart coastFromEnd(
@@ -59,14 +35,12 @@ public static EnvelopePart coastFromEnd(
5935
double speed = envelope.interpolateSpeed(position);
6036
var initInter = constrainedBuilder.initEnvelopePart(position, speed, -1);
6137
assert initInter;
62-
boolean reachedLowLimit = false;
6338
while (true) {
6439
var step = TrainPhysicsIntegrator.step(context, position, speed, Action.COAST, -1);
6540
position += step.positionDelta;
6641
speed = step.endSpeed;
6742
if (speed < lowSpeedLimit) {
6843
speed = lowSpeedLimit;
69-
reachedLowLimit = true;
7044
}
7145

7246
if (!constrainedBuilder.addStep(position, speed, step.timeDelta))
@@ -78,11 +52,6 @@ public static EnvelopePart coastFromEnd(
7852

7953
assert constrainedBuilder.getLastPos() < endPos;
8054

81-
if (!reachedLowLimit && constrainedBuilder.getLastPos() != envelope.getBeginPos())
82-
return backwardPartBuilder.build();
83-
84-
var resultCoast = coastFromBeginning(envelope, context, constrainedBuilder.getLastPos());
85-
assert resultCoast == null || resultCoast.getEndPos() <= endPos + context.timeStep * speed;
86-
return resultCoast;
55+
return backwardPartBuilder.build();
8756
}
8857
}

core/envelope-sim/src/test/java/fr/sncf/osrd/envelope_sim/AllowanceTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.carrotsearch.hppc.DoubleArrayList;
1818
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1919
import fr.sncf.osrd.envelope.Envelope;
20+
import fr.sncf.osrd.envelope.EnvelopeDebug;
2021
import fr.sncf.osrd.envelope.EnvelopeShape;
2122
import fr.sncf.osrd.envelope.EnvelopeTransitions;
2223
import fr.sncf.osrd.envelope_sim.allowances.AbstractAllowanceWithRanges;
@@ -553,10 +554,11 @@ public void testMarecoAcceleratingSlopes() {
553554
// If the test fails here, plot the curves to check if the curve makes sense and adapt the shape.
554555
// It is not supposed to be an absolute shape, but at least to be triggered if MARECO doesn't take into
555556
// account the accelerating slopes
557+
EnvelopeDebug.plot(marecoEnvelope);
556558
check(marecoEnvelope, new EnvelopeShape[][]{
557559
{INCREASING}, {CONSTANT}, {DECREASING, INCREASING}, {CONSTANT}, {INCREASING}, {CONSTANT},
558560
{DECREASING, INCREASING}, {CONSTANT}, {DECREASING, INCREASING}, {CONSTANT},
559-
{DECREASING, INCREASING, DECREASING, INCREASING, DECREASING, INCREASING},
561+
{DECREASING, INCREASING, DECREASING, INCREASING, DECREASING, CONSTANT},
560562
{DECREASING}, {INCREASING}, {CONSTANT}, {INCREASING}, {INCREASING}, {CONSTANT},
561563
{DECREASING, INCREASING}, {CONSTANT}, {DECREASING, INCREASING, DECREASING},
562564
{CONSTANT}, {DECREASING, INCREASING}, {CONSTANT}, {DECREASING, INCREASING, DECREASING}, {DECREASING}

core/envelope-sim/src/test/java/fr/sncf/osrd/envelope_sim/TrainPhysicsIntegratorTest.java

-23
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
import static fr.sncf.osrd.envelope_sim.SimpleContextBuilder.makeSimpleContext;
44
import static fr.sncf.osrd.envelope_sim.TrainPhysicsIntegrator.getWeightForce;
55
import static fr.sncf.osrd.envelope_sim.TrainPhysicsIntegrator.newtonStep;
6-
import static fr.sncf.osrd.envelope_sim.allowances.mareco_impl.CoastingGenerator.coastFromBeginning;
76
import static org.junit.jupiter.api.Assertions.*;
87

9-
import fr.sncf.osrd.envelope.Envelope;
10-
import fr.sncf.osrd.envelope.part.ConstrainedEnvelopePartBuilder;
11-
import fr.sncf.osrd.envelope.part.EnvelopePartBuilder;
12-
import fr.sncf.osrd.envelope.part.constraints.EnvelopePartConstraintType;
13-
import fr.sncf.osrd.envelope.part.constraints.SpeedConstraint;
14-
import fr.sncf.osrd.envelope_sim.overlays.EnvelopeDeceleration;
158
import org.junit.jupiter.api.Test;
169

1710

@@ -112,25 +105,9 @@ public void testAccelerateAndCoast() {
112105
for (int i = 0; i < 60; i++) {
113106
step = TrainPhysicsIntegrator.step(context, position, speed, Action.COAST, +1);
114107
position += step.positionDelta;
115-
var prevSpeed = step.startSpeed;
116108
speed = step.endSpeed;
117109
}
118110
// it should be stopped
119111
assertEquals(speed, 0.0);
120112
}
121-
122-
@Test
123-
public void testEmptyCoastFromBeginning() {
124-
var context = makeSimpleContext(100000, 0, TIME_STEP);
125-
var builder = new EnvelopePartBuilder();
126-
var constrainedBuilder = new ConstrainedEnvelopePartBuilder(
127-
builder,
128-
new SpeedConstraint(0, EnvelopePartConstraintType.FLOOR)
129-
);
130-
EnvelopeDeceleration.decelerate(context, 0, 10, constrainedBuilder, 1);
131-
var acceleration = Envelope.make(builder.build());
132-
// starting a coasting phase in a braking phase must result in a null EnvelopePart
133-
var failedCoast = coastFromBeginning(acceleration, context, 0);
134-
assertNull(failedCoast);
135-
}
136113
}

core/envelope-sim/src/testFixtures/java/fr/sncf/osrd/envelope/EnvelopeShape.java

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

3+
import static fr.sncf.osrd.envelope_sim.TrainPhysicsIntegrator.areSpeedsEqual;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
45

56
import fr.sncf.osrd.envelope.part.EnvelopePart;
@@ -14,7 +15,7 @@ public enum EnvelopeShape {
1415
public static EnvelopeShape fromStep(EnvelopePart part, int stepIndex) {
1516
var beginSpeed = part.getBeginSpeed(stepIndex);
1617
var endSpeed = part.getEndSpeed(stepIndex);
17-
if (beginSpeed == endSpeed)
18+
if (areSpeedsEqual(beginSpeed, endSpeed))
1819
return CONSTANT;
1920
else if (beginSpeed < endSpeed)
2021
return INCREASING;

core/src/main/kotlin/fr/sncf/osrd/sim_infra_adapter/RawInfraAdapter.kt

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ fun adaptRawInfra(infra: SignalingInfra): SimInfraAdapter {
276276
signalsPerTrack,
277277
builder
278278
)
279-
builder
280279

281280
// check if the zone is a release zone
282281
if (releaseIndex < oldReleasePoints.size && oldEndDet.detector!! == oldReleasePoints[releaseIndex]) {

0 commit comments

Comments
 (0)