Skip to content

Commit

Permalink
core: changes after review (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahBellaha authored and anisometropie committed Feb 2, 2024
1 parent 27e6627 commit 60cd402
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import fr.sncf.osrd.train.RollingStock
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters

@JvmRecord
data class SignalingSystemConstraints(
val blockInfra: BlockInfra,
val signalingSimulator: SignalingSimulator,
Expand All @@ -22,26 +21,24 @@ data class SignalingSystemConstraints(
return res
}

companion object {
/**
* Returns the sections of the given block that can't be used by the given rolling stock
*/
private fun getBlockedRanges(
stock: RollingStock,
edge: BlockId,
blockInfra: BlockInfra,
signalingSimulator: SignalingSimulator
): Set<Pathfinding.Range<Block>> {
val blockSigSystem = blockInfra.getBlockSignalingSystem(edge)
val rsSupportedSigSystems = stock.SupportedSignalingSystems.map { s -> signalingSimulator.sigModuleManager.findSignalingSystem(s) }
val isRSCompatibleWithBlock = rsSupportedSigSystems.any { s -> s == blockSigSystem }
if (isRSCompatibleWithBlock) {
return setOf()
}
return setOf(Pathfinding.Range(
Offset(0.meters),
blockInfra.getBlockLength(edge))
)
private fun getBlockedRanges(
stock: RollingStock,
edge: BlockId,
blockInfra: BlockInfra,
signalingSimulator: SignalingSimulator
): Set<Pathfinding.Range<Block>> {
val blockSigSystem = blockInfra.getBlockSignalingSystem(edge)
val rsSupportedSigSystems = stock.supportedSignalingSystems.map { s -> signalingSimulator.sigModuleManager.findSignalingSystem(s) }
val isRSCompatibleWithBlock = rsSupportedSigSystems.contains(blockSigSystem)
if (isRSCompatibleWithBlock) {
return setOf()
}
return setOf(Pathfinding.Range(
Offset(0.meters),
blockInfra.getBlockLength(edge))
)
}
}
2 changes: 1 addition & 1 deletion core/src/test/java/fr/sncf/osrd/train/TestTrains.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static Map<String, RollingStock.ModeEffortCurves> createModeEffortCurves
Map.of("thermal", new RollingStock.EffortCurveConditions[0])),
"thermal",
"1",
new String[]{"BAL","BAPR"}
new String[]{"BAL", "BAPR"}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import org.junit.jupiter.api.BeforeEach

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PathfindingSignalingTest {
private var infra: DummyInfra? = null
private var infra: DummyInfra = DummyInfra()

private fun setSigSystemIds(list: List<BlockId>, signalingSystemName: String) {
val id = infra!!.fullInfra().signalingSimulator.sigModuleManager.findSignalingSystem(signalingSystemName)
val id = infra.fullInfra().signalingSimulator.sigModuleManager.findSignalingSystem(signalingSystemName)
list.forEach {
infra!!.blockPool[it.index.toInt()].signalingSystemId = id
infra.blockPool[it.index.toInt()].signalingSystemId = id
}
}
@BeforeEach
Expand All @@ -39,12 +39,12 @@ class PathfindingSignalingTest {
c2
*/
infra = DummyInfra()
infra?.addBlock("a", "b")
infra?.addBlock("b", "c1")
infra?.addBlock("b", "c2")
infra?.addBlock("c1", "d")
infra?.addBlock("c2", "d")
infra?.addBlock("d", "e")
infra.addBlock("a", "b")
infra.addBlock("b", "c1")
infra.addBlock("b", "c2")
infra.addBlock("c1", "d")
infra.addBlock("c2", "d")
infra.addBlock("d", "e")
}

@Test
Expand All @@ -66,7 +66,7 @@ class PathfindingSignalingTest {
// Run a pathfinding with a non TVM train, expecting not to find any path
AssertionsForClassTypes.assertThatThrownBy {
runPathfinding(
infra!!.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
infra.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
)
}
.isExactlyInstanceOf(OSRDError::class.java)
Expand Down Expand Up @@ -94,7 +94,7 @@ class PathfindingSignalingTest {
waypoints[1][0] = waypointEnd

val pathfindingResult = runPathfinding(
infra!!.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
infra.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
)

AssertionsForClassTypes.assertThat(pathfindingResult.ranges).isEqualTo(arrayListOf(
Expand Down Expand Up @@ -122,7 +122,7 @@ class PathfindingSignalingTest {
waypoints[1][0] = waypointEnd

val pathfindingResult = runPathfinding(
infra!!.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
infra.fullInfra(), waypoints, listOf(TestTrains.TRAIN_WITHOUT_TVM)
)

AssertionsForClassTypes.assertThat(pathfindingResult.ranges).isEqualTo(arrayListOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fr.sncf.osrd.graph.Pathfinding
import fr.sncf.osrd.sim_infra.api.Block
import fr.sncf.osrd.sim_infra.api.BlockId
import fr.sncf.osrd.sim_infra.api.TrackChunk
import fr.sncf.osrd.sim_infra.api.getLogicalSignalName
import fr.sncf.osrd.train.RollingStock
import fr.sncf.osrd.train.TestTrains
import fr.sncf.osrd.utils.DummyInfra
Expand All @@ -23,34 +24,28 @@ import java.util.stream.Stream
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SignalingSystemConstraintsTest {
private var signalingSystemConstraints: SignalingSystemConstraints? = null
private var infra: DummyInfra? = null
private var infra: DummyInfra = DummyInfra()

@BeforeAll
@Throws(IOException::class, URISyntaxException::class)
fun setUp() {
/* c1
^ \
/ v
a --> b d --> e
\ ^
v /
c2
/*
a --> b --> c
*/
infra = DummyInfra()
infra?.addBlock("a", "b", signalingSystemName = "BAL")
infra?.addBlock("b", "c1", signalingSystemName = "BAL")
infra?.addBlock("b", "c2", signalingSystemName = "TVM430")
infra?.addBlock("c1", "d", signalingSystemName = "TVM430")
infra?.addBlock("c2", "d", signalingSystemName = "BAL")
infra?.addBlock("d", "e", signalingSystemName = "BAL")
infra.addBlock("a", "b", signalingSystemName = "BAL")
infra.addBlock("b", "c", signalingSystemName = "TVM430")
}

@ParameterizedTest
@MethodSource("testSignalingSystemArgs")
fun testSignalingSystemBlockedRanges(blockId: BlockId, rollingStock: RollingStock, expectedBlockedRanges: Collection<Pathfinding.Range<Block>>) {
val fullInfra = infra?.fullInfra();
val fullInfra = infra.fullInfra();
val test = fullInfra.rawInfra
signalingSystemConstraints = SignalingSystemConstraints(
fullInfra!!.blockInfra, fullInfra.signalingSimulator,
fullInfra.blockInfra, fullInfra.signalingSimulator,
listOf(rollingStock)
)
val blockedRanges = signalingSystemConstraints!!.apply(blockId)
Expand Down
10 changes: 8 additions & 2 deletions core/src/test/kotlin/fr/sncf/osrd/utils/DummyInfra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DummyInfra : RawInfra, BlockInfra {
exitId,
allowedSpeed,
0.0,
signalingSystemName,
signalingSystemId,
)
)
Expand All @@ -74,6 +75,7 @@ class DummyInfra : RawInfra, BlockInfra {
val exit: DirDetectorId,
val allowedSpeed: Double,
var gradient: Double,
var sigSystemName: String,
var signalingSystemId: SignalingSystemId,
var voltage: String = "",
var neutralSectionForward: NeutralSection? = null,
Expand Down Expand Up @@ -124,15 +126,19 @@ class DummyInfra : RawInfra, BlockInfra {
}

override fun getSignalingSystemId(signal: LogicalSignalId): String {
return "BAL"
return this.fullInfra().rawInfra.getLogicalSignalName(signal) ?: "BAL"
}

fun getSignalingSystemName(block: BlockId): String {
return blockPool[block.index].sigSystemName
}

override fun getRawSettings(signal: LogicalSignalId): Map<String, String> {
return mapOf("Nf" to "false")
}

override fun getNextSignalingSystemIds(signal: LogicalSignalId): List<String> {
return listOf("BAL")
return this.fullInfra().rawInfra.getNextSignalingSystemIds(signal)
}

override val routes: StaticIdxSpace<Route>
Expand Down

0 comments on commit 60cd402

Please sign in to comment.