Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing conflict detection #4628

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface EnvelopeTimeInterpolate {
* clamping the position to [0, envelope length] first */
double interpolateTotalTimeClamp(double position);

/** Returns the start position of the envelope */
double getBeginPos();

/** Returns the end position of the envelope */
double getEndPos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class MaxEffortEnvelopeBuilder {
/** Builds max effort envelope with the specified stops, on a flat MRSP */
public static Envelope makeSimpleMaxEffortEnvelope(
EnvelopeSimContext context,
double speed,
double maxSpeed,
double[] stops
) {
var flatMRSP = makeSimpleMRSP(context, speed);
var flatMRSP = makeSimpleMRSP(context, maxSpeed);
var maxSpeedEnvelope = MaxSpeedEnvelope.from(context, stops, flatMRSP);
return MaxEffortEnvelope.from(context, 0, maxSpeedEnvelope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class BlockBuilderTest {
// \
// w x \ y z
// I---B---I---C---I---D---I
//
// S
// <-- reverse normal -->

// region build the test infrastructure
val builder = RawInfraBuilder()
// region switches
val switch = builder.movableElement(delay = 10L.milliseconds) {
val switch = builder.movableElement("S", delay = 10L.milliseconds) {
config("xy", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("vy", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ interface TrackNetworkInfra {
/** Returns the time it takes for the node to change configuration */
fun getTrackNodeDelay(trackNode: TrackNodeId): Duration
fun getTrackNodeConfigName(trackNode: TrackNodeId, config: TrackNodeConfigId): String
fun getTrackNodeName(trackNode: TrackNodeId): String


val trackNodes: StaticIdxSpace<TrackNode>
val trackSections: StaticIdxSpace<TrackSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ interface MovableElementDescriptorBuilder {
}

class MovableElementDescriptorBuilderImpl(
private val name: String,
private val delay: Duration,
private val ports: StaticPool<TrackNodePort, EndpointTrackSectionId>,
private val configs: StaticPool<TrackNodeConfig, MovableElementConfigDescriptor>,
private val configs: StaticPool<TrackNodeConfig, TrackNodeConfigDescriptor>,
) : MovableElementDescriptorBuilder {
override fun port(endpoint: EndpointTrackSectionId): TrackNodePortId {
return ports.add(endpoint)
}

override fun config(name: String, portLink: Pair<TrackNodePortId, TrackNodePortId>): TrackNodeConfigId {
return configs.add(MovableElementConfigDescriptor(name, portLink))
return configs.add(TrackNodeConfigDescriptor(name, portLink))
}

fun build(): MovableElementDescriptor {
return MovableElementDescriptor(delay, ports, configs)
fun build(): TrackNodeDescriptor {
return TrackNodeDescriptor(name, delay, ports, configs)
}
}

Expand Down Expand Up @@ -163,7 +164,7 @@ class RouteDescriptorImpl(
) : RouteDescriptor

interface RestrictedRawInfraBuilder {
fun movableElement(delay: Duration, init: MovableElementDescriptorBuilder.() -> Unit): TrackNodeId
fun movableElement(name: String, delay: Duration, init: MovableElementDescriptorBuilder.() -> Unit): TrackNodeId
fun detector(name: String?): DetectorId
fun linkZones(zoneA: ZoneId, zoneB: ZoneId): DetectorId
fun linkZones(detector: DetectorId, zoneA: ZoneId, zoneB: ZoneId)
Expand Down Expand Up @@ -232,7 +233,7 @@ interface RawInfraBuilder : RestrictedRawInfraBuilder {
}

class RawInfraBuilderImpl : RawInfraBuilder {
private val trackNodePool = StaticPool<TrackNode, MovableElementDescriptor>()
private val trackNodePool = StaticPool<TrackNode, TrackNodeDescriptor>()
private val trackSectionPool = StaticPool<TrackSection, TrackSectionDescriptor>()
private val trackChunkPool = StaticPool<TrackChunk, TrackChunkDescriptor>()
private val nextNode = IdxMap<DirTrackSectionId, TrackNodeId>()
Expand All @@ -246,8 +247,8 @@ class RawInfraBuilderImpl : RawInfraBuilder {
private val zonePathMap = mutableMapOf<ZonePathSpec, ZonePathId>()
private val operationalPointPartPool = StaticPool<OperationalPointPart, OperationalPointPartDescriptor>()

override fun movableElement(delay: Duration, init: MovableElementDescriptorBuilder.() -> Unit): TrackNodeId {
val movableElementBuilder = MovableElementDescriptorBuilderImpl(delay, StaticPool(), StaticPool())
override fun movableElement(name: String, delay: Duration, init: MovableElementDescriptorBuilder.() -> Unit): TrackNodeId {
val movableElementBuilder = MovableElementDescriptorBuilderImpl(name, delay, StaticPool(), StaticPool())
movableElementBuilder.init()
val movableElement = movableElementBuilder.build()
return trackNodePool.add(movableElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import fr.sncf.osrd.utils.units.*
import kotlin.time.Duration


class MovableElementConfigDescriptor(
class TrackNodeConfigDescriptor(
val name: String,
val portLink: Pair<TrackNodePortId, TrackNodePortId>,
)

class MovableElementDescriptor(
class TrackNodeDescriptor(
val name: String,
val delay: Duration,
val ports: StaticPool<TrackNodePort, EndpointTrackSectionId>,
val configs: StaticPool<TrackNodeConfig, MovableElementConfigDescriptor>,
val configs: StaticPool<TrackNodeConfig, TrackNodeConfigDescriptor>,
)

class TrackSectionDescriptor(
Expand Down Expand Up @@ -117,7 +118,7 @@ class NeutralSection(


class RawInfraImpl(
val trackNodePool: StaticPool<TrackNode, MovableElementDescriptor>,
val trackNodePool: StaticPool<TrackNode, TrackNodeDescriptor>,
val trackSectionPool: StaticPool<TrackSection, TrackSectionDescriptor>,
val trackChunkPool: StaticPool<TrackChunk, TrackChunkDescriptor>,
val nextNode: IdxMap<DirTrackSectionId, TrackNodeId>,
Expand Down Expand Up @@ -273,6 +274,10 @@ class RawInfraImpl(
return trackNodePool[trackNode].configs[config].name
}

override fun getTrackNodeName(trackNode: TrackNodeId): String {
return trackNodePool[trackNode].name
}

override val zones: StaticIdxSpace<Zone>
get() = zonePool.space()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestLocation {
// setup test data
val infra = rawInfra {
// create a test switch
val switchA = movableElement(delay = 42L.milliseconds) {
val switchA = movableElement("A", delay = 42L.milliseconds) {
config("a", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("b", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestMovableElements {
fun lockMoveTest() = runTest {
// setup test data
val infra = rawInfra {
movableElement(delay = 42L.milliseconds) {
movableElement("A", delay = 42L.milliseconds) {
config("a", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("b", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestReservation {

// region build the test infrastructure
val builder = RawInfraBuilder()
val switch = builder.movableElement(delay = 42L.milliseconds) {
val switch = builder.movableElement("A", delay = 42L.milliseconds) {
config("a", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("b", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class TestRouting {
// \
// w x \ y z
// I---B---I---C---I---D---I
//
// S
// <-- reverse normal -->

// region build the test infrastructure
val builder = RawInfraBuilder()
// region switches
val switch = builder.movableElement(delay = 10L.milliseconds) {
val switch = builder.movableElement("S", delay = 10L.milliseconds) {
config("xy", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("vy", Pair(TrackNodePortId(0u), TrackNodePortId(2u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class TestBALtoBAL {
// \
// w x \ y z
// I---B---I---C---I---D---I
//
// S
// <-- reverse normal -->

// region build the test infrastructure
val builder = RawInfraBuilder()
// region switches
val switch = builder.movableElement(delay = 10L.milliseconds) {
val switch = builder.movableElement("S", delay = 10L.milliseconds) {
config("xy", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
config("vy", Pair(TrackNodePortId(0u), TrackNodePortId(1u)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public static class Conflict {
public enum ConflictType {
@Json(name = "Spacing")
SPACING,
@Json(name = "Routing")
ROUTING,
}

@Json(name = "conflict_type")
Expand Down
Loading