Skip to content

Commit

Permalink
core: add a RailJSON builder and remove the old builder
Browse files Browse the repository at this point in the history
  • Loading branch information
multun committed Apr 19, 2024
1 parent 445fd69 commit e67fe5f
Show file tree
Hide file tree
Showing 18 changed files with 753 additions and 1,718 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
// PLEASE ADD AND UPDATE DEPENDENCIES USING libs.versions.toml

implementation project(':osrd-railjson')
implementation project(':kt-railjson-builder')
implementation project(':osrd-reporting')
implementation project(':envelope-sim')
implementation project(':osrd-geom')
Expand Down
1 change: 1 addition & 0 deletions core/kt-osrd-signaling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
// PLEASE ADD AND UPDATE DEPENDENCIES USING libs.versions.toml
api project(":kt-osrd-utils")
api project(':kt-osrd-sim-infra')
api project(':kt-railjson-builder')
api project(":osrd-railjson")
api project(":osrd-reporting")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package fr.sncf.osrd.signaling

import fr.sncf.osrd.railjson.builder.begin
import fr.sncf.osrd.railjson.builder.buildParseRJSInfra
import fr.sncf.osrd.railjson.builder.end
import fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection.STOP_TO_START
import fr.sncf.osrd.signaling.impl.MockSigSystemManager
import fr.sncf.osrd.signaling.impl.SignalingSimulatorImpl
import fr.sncf.osrd.sim_infra.api.*
import fr.sncf.osrd.sim_infra.impl.RawInfraBuilder
import fr.sncf.osrd.sim_infra.impl.blockInfraBuilder
import fr.sncf.osrd.utils.indexing.StaticIdx
import fr.sncf.osrd.utils.indexing.StaticIdxList
import fr.sncf.osrd.utils.indexing.mutableStaticIdxArrayListOf
import fr.sncf.osrd.utils.units.*
import kotlin.test.Test
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.milliseconds

class BlockBuilderTest {
@Test
Expand All @@ -26,94 +27,76 @@ class BlockBuilderTest {
// S
// <-- reverse normal -->

// region build the test infrastructure
val builder = RawInfraBuilder()
// region switches
val switch =
builder.movableElement("S", delay = 10L.milliseconds) {
config("xy", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("vy", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
// endregion

// region zones
val zoneA = builder.zone(listOf())
val zoneB = builder.zone(listOf())
val zoneC = builder.zone(listOf(switch))
val zoneD = builder.zone(listOf())
val infra = buildParseRJSInfra {
val lowerLeftTrack = trackSection("lower_left", 15.0)
val upperLeftTrack = trackSection("upper_left", 15.0)
val rightTrack = trackSection("right", 15.0)
val switch =
pointSwitch("S", rightTrack.begin, lowerLeftTrack.begin, upperLeftTrack.begin, 0.01)
val detU = bufferStop("U", upperLeftTrack.end)
detector("V", upperLeftTrack.at(5.0))
val detW = bufferStop("W", lowerLeftTrack.end)
detector("X", lowerLeftTrack.at(5.0))
val detY = detector("Y", rightTrack.at(5.0))
val detZ = bufferStop("Z", rightTrack.end)

val detectorU = builder.detector("U")
builder.setNextZone(detectorU.increasing, zoneA)
val detectorV = builder.detector("V")
builder.setNextZone(detectorV.increasing, zoneC)
builder.setNextZone(detectorV.decreasing, zoneA)
val detectorW = builder.detector("W")
builder.setNextZone(detectorW.increasing, zoneB)
val detectorX = builder.detector("X")
builder.setNextZone(detectorX.increasing, zoneC)
builder.setNextZone(detectorX.decreasing, zoneB)
val detectorY = builder.detector("Y")
builder.setNextZone(detectorY.increasing, zoneD)
builder.setNextZone(detectorY.decreasing, zoneC)
val detectorZ = builder.detector("Z")
builder.setNextZone(detectorZ.decreasing, zoneD)
// endregion
val logicalSignalTemplate =
logicalSignal("BAL") {
nextSignalingSystem("BAL")
setting("Nf", "true")
defaultParameter("jaune_cli", "false")
}

// region signals
// TODO: add actual track sections
val parameters = RawSignalParameters(mapOf(Pair("jaune_cli", "false")), mapOf())
val signalX =
builder.physicalSignal("X", 300.meters, StaticIdx(42u), Offset(42.meters)) {
logicalSignal("BAL", listOf("BAL"), mapOf(Pair("Nf", "true")), parameters)
defaultSightDistance = 300.0
physicalSignal("X", lowerLeftTrack.at(7.0), STOP_TO_START) {
logicalSignal(logicalSignalTemplate)
}
val signalV =
builder.physicalSignal("Y", 300.meters, StaticIdx(42u), Offset(42.meters)) {
logicalSignal("BAL", listOf("BAL"), mapOf(Pair("Nf", "true")), parameters)
}
// endregion

// region zone paths
val zonePathWX =
builder.zonePath(detectorW.increasing, detectorX.increasing, Length(10.meters)) {
signal(signalX, Offset(8.meters))
physicalSignal("V", upperLeftTrack.at(7.0), STOP_TO_START) {
logicalSignal(logicalSignalTemplate)
}
val zonePathXY =
builder.zonePath(detectorX.increasing, detectorY.increasing, Length(10.meters)) {
movableElement(switch, StaticIdx(0u), Offset(5.meters))
}
val zonePathYZ =
builder.zonePath(detectorY.increasing, detectorZ.increasing, Length(10.meters))
val zonePathUV =
builder.zonePath(detectorU.increasing, detectorV.increasing, Length(10.meters)) {
signal(signalV, Offset(8.meters))
}
val zonePathVY =
builder.zonePath(detectorV.increasing, detectorY.increasing, Length(10.meters)) {
movableElement(switch, StaticIdx(1u), Offset(5.meters))
}
// endregion

// region routes
// create a route from W to Z, releasing at Y and Z
builder.route("W-Z") {
zonePath(zonePathWX) // zone B
zonePath(zonePathXY) // zone C
zonePath(zonePathYZ) // zone D
// release at zone C and D
releaseZone(1)
releaseZone(2)
route("U-Z", detU, STOP_TO_START, detZ) { addSwitchDirection(switch, "A_B2") }
route("W-Z", detW, STOP_TO_START, detZ) {
addReleaseDetector(detY)
addSwitchDirection(switch, "A_B1")
}
}

builder.route("U-Z") {
zonePath(zonePathUV) // zone A
zonePath(zonePathVY) // zone C
zonePath(zonePathYZ) // zone D
// release at zone D
releaseZone(2)
}
// endregion
val infra = builder.build()
// endregion
val signals = infra.physicalSignals.associateBy { infra.getPhysicalSignalName(it) }
val signalX = signals["X"]!!
val signalV = signals["V"]!!
val switch = infra.trackNodes[0]
val switchConfigs =
infra.getTrackNodeConfigs(switch).associateBy {
infra.getTrackNodeConfigName(switch, it)
}
val switchLower = switchConfigs["A_B1"]!!
val switchUpper = switchConfigs["A_B2"]!!
val detectors = infra.detectors.associateBy { infra.getDetectorName(it) }
val detU = detectors["U"]!!
val detV = detectors["V"]!!
val detW = detectors["W"]!!
val detX = detectors["X"]!!
val detY = detectors["Y"]!!
val detZ = detectors["Z"]!!
val zonePathUV = infra.findZonePath(detU.decreasing, detV.decreasing)!!
val zonePathWX = infra.findZonePath(detW.decreasing, detX.decreasing)!!
val zonePathYZ = infra.findZonePath(detY.increasing, detZ.increasing)!!
val zonePathVY =
infra.findZonePath(
detV.decreasing,
detY.increasing,
mutableStaticIdxArrayListOf(switch),
mutableStaticIdxArrayListOf(switchUpper)
)!!
val zonePathXY =
infra.findZonePath(
detX.decreasing,
detY.increasing,
mutableStaticIdxArrayListOf(switch),
mutableStaticIdxArrayListOf(switchLower)
)!!

val simulator =
SignalingSimulatorImpl(
Expand Down
Loading

0 comments on commit e67fe5f

Please sign in to comment.