Skip to content

Commit

Permalink
core: changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahBellaha authored and anisometropie committed Feb 7, 2024
1 parent 27e6627 commit 88843d9
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ public enum ErrorType {
),
PathfindingGaugeError(
"no_path_found:gauge",
"No path could be found that meets loading Gauge constraints",
"No path could be found with compatible Gauge",
ErrorCause.USER
),
PathfindingElectrificationError(
"no_path_found:electrification",
"No path could be found that meets Electrification constraints",
"No path could be found with compatible electrification",
ErrorCause.USER
),
PathfindingSignalisationSystemError(
"no_path_found:signalisation_system",
"No path could be found, signaling system",
"No path could be found with a compatible signaling system",
ErrorCause.USER
),
PathfindingTimeoutError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import fr.sncf.osrd.api.InfraManager
import fr.sncf.osrd.api.pathfinding.constraints.ElectrificationConstraints
import fr.sncf.osrd.api.pathfinding.constraints.LoadingGaugeConstraints
import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraints
import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraintsFactory
import fr.sncf.osrd.api.pathfinding.request.PathfindingRequest
import fr.sncf.osrd.api.pathfinding.request.PathfindingWaypoint
import fr.sncf.osrd.api.pathfinding.response.PathWaypointResult
import fr.sncf.osrd.api.pathfinding.response.PathfindingResult
import fr.sncf.osrd.envelope_sim.TrainPhysicsIntegrator
import fr.sncf.osrd.graph.*
import fr.sncf.osrd.graph.Pathfinding.EdgeLocation
import fr.sncf.osrd.infra.api.Direction
Expand Down Expand Up @@ -206,8 +205,9 @@ fun runPathfinding(
infra.blockInfra, infra.rawInfra,
rollingStocks
)
val signalisationSystemConstraints = SignalingSystemConstraints(
infra.blockInfra, infra.signalingSimulator,
val signalisationSystemConstraints = SignalingSystemConstraintsFactory().create(
infra.blockInfra,
infra.signalingSimulator,
rollingStocks
)
val constraints = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import fr.sncf.osrd.utils.units.Distance
import fr.sncf.osrd.utils.units.Offset
import java.util.stream.Collectors

@JvmRecord
data class ElectrificationConstraints(
val blockInfra: BlockInfra,
val rawInfra: RawSignalingInfra,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import fr.sncf.osrd.utils.DistanceRangeMap
import fr.sncf.osrd.utils.units.Offset
import java.util.stream.Collectors

@JvmRecord
data class LoadingGaugeConstraints(
val blockInfra: BlockInfra,
val infra: RawSignalingInfra,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,58 @@ 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,
val rollingStocks: Collection<RollingStock>
val rollingStocksSupportedSigSystems: List<List<SignalingSystemId>>
) : EdgeToRangesId<Block> {
override fun apply(edge: BlockId): MutableCollection<Pathfinding.Range<Block>> {
val res = HashSet<Pathfinding.Range<Block>>()
for (rs in rollingStocks) {
res.addAll(getBlockedRanges(rs, edge, blockInfra, signalingSimulator))
for (rollingStocksigSystems in rollingStocksSupportedSigSystems) {
val edgeBlockedRanges = getBlockedRanges(edge, blockInfra, rollingStocksigSystems)
if (edgeBlockedRanges.isNotEmpty()) {
res.addAll(edgeBlockedRanges)
break // if this edge is blocked for 2 RS, we will have the same exact range (the full edge range) twice
}
}
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(
edge: BlockId,
blockInfra: BlockInfra,
rollingStockSigSystems: List<SignalingSystemId>
): Set<Pathfinding.Range<Block>> {
val blockSigSystem = blockInfra.getBlockSignalingSystem(edge)
val isRSCompatibleWithBlock = rollingStockSigSystems.contains(blockSigSystem)
if (isRSCompatibleWithBlock) {
return setOf()
}
return setOf(Pathfinding.Range(
Offset(0.meters),
blockInfra.getBlockLength(edge))
)
}
}

class SignalingSystemConstraintsFactory {
fun create(
blockInfra: BlockInfra,
signalingSimulator: SignalingSimulator,
rollingStocks: Collection<RollingStock>,
): SignalingSystemConstraints {
val rsSupportedSigSystems = rollingStocks.map { stock ->
stock.supportedSignalingSystems.mapNotNull { s -> try {
signalingSimulator.sigModuleManager.findSignalingSystem(s)
} catch (e: Exception) {
null
} }
}
return SignalingSystemConstraints(
blockInfra,
rsSupportedSigSystems
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.sncf.osrd.stdcm.graph
import fr.sncf.osrd.api.FullInfra
import fr.sncf.osrd.api.pathfinding.constraints.ElectrificationConstraints
import fr.sncf.osrd.api.pathfinding.constraints.LoadingGaugeConstraints
import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraints
import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraintsFactory
import fr.sncf.osrd.api.pathfinding.makeHeuristics
import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue
import fr.sncf.osrd.graph.*
Expand Down Expand Up @@ -59,7 +59,7 @@ fun findPath(
fullInfra.blockInfra, fullInfra.rawInfra,
listOf(rollingStock)
)
val signalingSystemConstraints = SignalingSystemConstraints(
val signalingSystemConstraints = SignalingSystemConstraintsFactory().create(
fullInfra.blockInfra, fullInfra.signalingSimulator,
listOf(rollingStock)
)
Expand Down
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
@@ -1,6 +1,6 @@
package fr.sncf.osrd.pathfinding.constraints

import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraints
import fr.sncf.osrd.api.pathfinding.constraints.SignalingSystemConstraintsFactory
import fr.sncf.osrd.graph.Pathfinding
import fr.sncf.osrd.sim_infra.api.Block
import fr.sncf.osrd.sim_infra.api.BlockId
Expand All @@ -11,58 +11,41 @@ import fr.sncf.osrd.utils.DummyInfra
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.io.IOException
import java.net.URISyntaxException
import java.util.stream.Stream

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

@BeforeAll
@Throws(IOException::class, URISyntaxException::class)
fun setUp() {
/* c1
^ \
/ v
a --> b d --> e
\ ^
v /
c2
*/
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")
}

@ParameterizedTest
@MethodSource("testSignalingSystemArgs")
fun testSignalingSystemBlockedRanges(blockId: BlockId, rollingStock: RollingStock, expectedBlockedRanges: Collection<Pathfinding.Range<Block>>) {
val fullInfra = infra?.fullInfra();
signalingSystemConstraints = SignalingSystemConstraints(
fullInfra!!.blockInfra, fullInfra.signalingSimulator,
/*
a --> b --> c
*/
val infra = DummyInfra()
infra.addBlock("a", "b", signalingSystemName = "BAL")
infra.addBlock("b", "c", signalingSystemName = "TVM430")
val fullInfra = infra.fullInfra()
val signalingSystemConstraints = SignalingSystemConstraintsFactory().create(
fullInfra.blockInfra,
fullInfra.signalingSimulator,
listOf(rollingStock)
)
val blockedRanges = signalingSystemConstraints!!.apply(blockId)
val blockedRanges = signalingSystemConstraints.apply(blockId)
Assertions.assertThat(blockedRanges).isEqualTo(expectedBlockedRanges)
}

private fun testSignalingSystemArgs(): Stream<Arguments> {
return Stream.of(
Arguments.of(1, TestTrains.TRAIN_WITHOUT_TVM, HashSet<Any>()),
Arguments.of(2, TestTrains.TRAIN_WITHOUT_TVM, setOf(Pathfinding.Range<TrackChunk>(Offset(0.meters), Offset(100.meters)))),
Arguments.of(0, TestTrains.TRAIN_WITHOUT_TVM, HashSet<Any>()),
Arguments.of(1, TestTrains.TRAIN_WITHOUT_TVM, setOf(Pathfinding.Range<TrackChunk>(Offset(0.meters), Offset(100.meters)))),
Arguments.of(0, TestTrains.FAST_ELECTRIC_TRAIN, HashSet<Any>()),
Arguments.of(1, TestTrains.FAST_ELECTRIC_TRAIN, HashSet<Any>()),
Arguments.of(2, TestTrains.FAST_ELECTRIC_TRAIN, HashSet<Any>()),
)
}
}
Loading

0 comments on commit 88843d9

Please sign in to comment.