Skip to content

Commit 630fdc7

Browse files
committed
core: spacing-requirements: add tests
1 parent e182e96 commit 630fdc7

File tree

4 files changed

+302
-24
lines changed

4 files changed

+302
-24
lines changed

core/src/main/java/fr/sncf/osrd/conflicts/IncrementalRequirementEnvelopeAdapter.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package fr.sncf.osrd.conflicts
22

3-
import fr.sncf.osrd.standalone_sim.EnvelopeStopWrapper
4-
import fr.sncf.osrd.train.RollingStock
3+
import fr.sncf.osrd.envelope.EnvelopeTimeInterpolate
4+
import fr.sncf.osrd.envelope_sim.PhysicsRollingStock
55
import fr.sncf.osrd.utils.units.Offset
66
import fr.sncf.osrd.utils.units.meters
77
import kotlin.math.max
88
import kotlin.math.min
99

1010
class IncrementalRequirementEnvelopeAdapter(
11-
private val rollingStock: RollingStock,
12-
private val envelopeWithStops: EnvelopeStopWrapper,
11+
private val rollingStock: PhysicsRollingStock,
12+
private val envelopeWithStops: EnvelopeTimeInterpolate,
1313
override var simulationComplete: Boolean,
1414
) : IncrementalRequirementCallbacks {
1515
override fun arrivalTimeInRange(
@@ -41,9 +41,6 @@ class IncrementalRequirementEnvelopeAdapter(
4141
if (criticalPoint >= 0.0 && criticalPoint <= envelopeWithStops.endPos)
4242
return envelopeWithStops.interpolateTotalTime(criticalPoint)
4343

44-
if (arrivalTimeInRange(pathBeginOff, pathEndOff).isFinite())
45-
return envelopeWithStops.totalTime
46-
4744
return Double.POSITIVE_INFINITY
4845
}
4946

core/src/main/java/fr/sncf/osrd/conflicts/SpacingResourceGenerator.kt

+6-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fr.sncf.osrd.conflicts
33
import fr.sncf.osrd.signaling.SignalingSimulator
44
import fr.sncf.osrd.signaling.ZoneStatus
55
import fr.sncf.osrd.sim_infra.api.*
6-
import fr.sncf.osrd.sim_infra_adapter.SimInfraAdapter
76
import fr.sncf.osrd.standalone_sim.result.ResultTrain.SpacingRequirement
87
import fr.sncf.osrd.utils.indexing.mutableStaticIdxArrayListOf
98
import fr.sncf.osrd.utils.units.Offset
@@ -36,11 +35,11 @@ data class PendingSpacingRequirement(
3635

3736
class SpacingRequirementAutomaton(
3837
// context
39-
val rawInfra: SimInfraAdapter,
38+
val rawInfra: RawInfra,
4039
val loadedSignalInfra: LoadedSignalInfra,
4140
val blockInfra: BlockInfra,
4241
val simulator: SignalingSimulator,
43-
val callbacks: IncrementalRequirementCallbacks,
42+
var callbacks: IncrementalRequirementCallbacks,
4443
val incrementalPath: IncrementalPath,
4544
) {
4645
private var nextProcessedBlock = 0
@@ -188,8 +187,8 @@ class SpacingRequirementAutomaton(
188187
// there may be more zone states than what's contained in the path's blocks, which shouldn't
189188
// matter
190189
val zoneStartIndex = incrementalPath.getBlockStartZone(incrementalPath.beginBlockIndex)
191-
val zoneCount =
192-
incrementalPath.getBlockEndZone(incrementalPath.endBlockIndex - 1) - zoneStartIndex
190+
val zoneEndIndex = incrementalPath.getBlockEndZone(incrementalPath.endBlockIndex - 1)
191+
val zoneCount = zoneEndIndex - zoneStartIndex
193192
val zoneStates = MutableList(zoneCount) { ZoneStatus.CLEAR }
194193

195194
// for all signals, update zone requirement times until a signal is found for which
@@ -215,10 +214,9 @@ class SpacingRequirementAutomaton(
215214

216215
// find the first zone after the signal which can be occupied without disturbing the
217216
// train
218-
var lastConstrainingZone = -1
219217
zoneProbingLoop@ while (true) {
220218
// if we reached the last zone, just quit
221-
if (nextProbedZoneForSignal == incrementalPath.endZonePathIndex) {
219+
if (nextProbedZoneForSignal == zoneEndIndex) {
222220
if (incrementalPath.pathComplete) break@zoneProbingLoop
223221
return NotEnoughPath
224222
}
@@ -249,13 +247,6 @@ class SpacingRequirementAutomaton(
249247
// FIXME: Have a better way to check if the signal is constraining
250248
if (signalState.getEnum("aspect") == "VL") break
251249
addSignalRequirements(signalProtectedZone, zoneIndex, sightTime)
252-
lastConstrainingZone = zoneIndex
253-
}
254-
255-
if (lastConstrainingZone == -1) {
256-
logger.error {
257-
"signal ${rawInfra.getLogicalSignalName(pathSignal.signal)} does not react to zone occupation"
258-
}
259250
}
260251
pendingSignals.removeFirst()
261252
nextProbedZoneForSignal = -1
@@ -318,6 +309,6 @@ class SpacingRequirementAutomaton(
318309

319310
sealed interface SpacingResourceUpdate
320311

321-
class SpacingRequirements(val requirements: List<SpacingRequirement>) : SpacingResourceUpdate
312+
data class SpacingRequirements(val requirements: List<SpacingRequirement>) : SpacingResourceUpdate
322313

323314
data object NotEnoughPath : SpacingResourceUpdate

core/src/main/java/fr/sncf/osrd/standalone_sim/result/ResultTrain.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
910
public class ResultTrain {
@@ -78,8 +79,7 @@ public static final class SpacingRequirement {
7879
public double endTime;
7980

8081
// whether the requirement end_time is final. it's metadata, and **shouldn't be used for conflict detection**
81-
@Json(name = "is_complete")
82-
public boolean isComplete;
82+
public transient boolean isComplete;
8383

8484
public SpacingRequirement(String zone, double beginTime, double endTime, boolean isComplete) {
8585
this.zone = zone;
@@ -95,6 +95,28 @@ public SpacingRequirement(String zone, double beginTime, double endTime, boolean
9595
public SpacingRequirement withAddedTime(double timeToAdd) {
9696
return new SpacingRequirement(zone, beginTime + timeToAdd, endTime + timeToAdd, isComplete);
9797
}
98+
99+
@Override
100+
public String toString() {
101+
return "SpacingRequirement{" + "zone='" + zone + '\'' + ", beginTime=" + beginTime + ", endTime=" + endTime
102+
+ '}';
103+
}
104+
105+
@Override
106+
public boolean equals(Object o) {
107+
if (this == o) return true;
108+
if (o == null || getClass() != o.getClass()) return false;
109+
final SpacingRequirement that = (SpacingRequirement) o;
110+
return Double.compare(beginTime, that.beginTime) == 0
111+
&& Double.compare(endTime, that.endTime) == 0
112+
&& isComplete == that.isComplete
113+
&& Objects.equals(zone, that.zone);
114+
}
115+
116+
@Override
117+
public int hashCode() {
118+
return Objects.hash(zone, beginTime, endTime, isComplete);
119+
}
98120
}
99121

100122
@Json(name = "spacing_requirements")

0 commit comments

Comments
 (0)