Skip to content

Commit

Permalink
core, editoast: add flag to ignore speed limits
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Rolland <[email protected]>
Signed-off-by: Jean SIMARD <[email protected]>
  • Loading branch information
Alex Rolland authored and woshilapin committed Feb 7, 2025
1 parent 9210d41 commit 97d078c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .osrd-compose-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
host
sw
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static StandaloneSimResult run(
var rollingStock = trainSchedule.rollingStock;

// MRSP & SpeedLimits
var mrsp = computeMRSP(trainPath, rollingStock, true, trainSchedule.tag, null, null);
var speedLimits = computeMRSP(trainPath, rollingStock, false, trainSchedule.tag, null, null);
var mrsp = computeMRSP(trainPath, rollingStock, true, trainSchedule.tag, null, null, true);
var speedLimits = computeMRSP(trainPath, rollingStock, false, trainSchedule.tag, null, null, true);
mrsp = driverBehaviour.applyToMRSP(mrsp);
cacheSpeedLimits.put(trainSchedule, ResultEnvelopePoint.from(speedLimits));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SimulationEndpoint(
request.speedLimitTag,
parsePowerRestrictions(request.powerRestrictions),
request.options.useElectricalProfiles,
request.options.useInfraSpeedLimits ?: true,
2.0,
parseRawSimulationScheduleItems(request.schedule),
request.initialSpeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ class SimulationPowerRestrictionItem(
)

class TrainScheduleOptions(
@Json(name = "use_electrical_profiles") val useElectricalProfiles: Boolean
@Json(name = "use_electrical_profiles") val useElectricalProfiles: Boolean,
@Json(name = "use_infra_speed_limits_for_simulation") val useInfraSpeedLimits: Boolean?
)
13 changes: 11 additions & 2 deletions core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import kotlin.math.min
* @param addRollingStockLength whether the rolling stock length should be taken into account in the
* computation.
* @param trainTag corresponding train.
* @param useInfraSpeedLimits whether the speed limits coming from the infrastructure should be
* taken into account in the computation
* @return the corresponding MRSP as an Envelope.
*/
fun computeMRSP(
Expand All @@ -39,6 +41,7 @@ fun computeMRSP(
trainTag: String?,
temporarySpeedLimitManager: TemporarySpeedLimitManager?,
safetySpeedRanges: DistanceRangeMap<Speed>? = null,
useInfraSpeedLimits: Boolean = true,
): Envelope {
return computeMRSP(
path,
Expand All @@ -48,6 +51,7 @@ fun computeMRSP(
trainTag,
temporarySpeedLimitManager,
safetySpeedRanges,
useInfraSpeedLimits,
)
}

Expand All @@ -62,6 +66,8 @@ fun computeMRSP(
* @param trainTag corresponding train.
* @param safetySpeedRanges Extra speed ranges, used for safety speeds. Note: rolling stock length
* is *not* added at the end of these ranges.
* @param useInfraSpeedLimits whether the speed limits coming from the infrastructure should be
* taken into account in the computation
* @return the corresponding MRSP as an Envelope.
*/
fun computeMRSP(
Expand All @@ -72,12 +78,15 @@ fun computeMRSP(
trainTag: String?,
temporarySpeedLimitManager: TemporarySpeedLimitManager?,
safetySpeedRanges: DistanceRangeMap<Speed>? = null,
useInfraSpeedLimits: Boolean = true,
): Envelope {
val builder = MRSPEnvelopeBuilder()
val pathLength = toMeters(path.getLength())

val offset = if (addRollingStockLength) rsLength else 0.0
val speedLimitProperties = path.getSpeedLimitProperties(trainTag, temporarySpeedLimitManager)
val speedLimitProperties =
if (useInfraSpeedLimits) path.getSpeedLimitProperties(trainTag, temporarySpeedLimitManager)
else distanceRangeMapOf<SpeedLimitProperty>()
for (speedLimitPropertyRange in speedLimitProperties) {
// Compute where this limit is active from and to
val start = toMeters(speedLimitPropertyRange.lower)
Expand Down Expand Up @@ -117,7 +126,7 @@ fun computeMRSP(
)

// Add safety speeds
if (safetySpeedRanges != null) {
if (useInfraSpeedLimits && safetySpeedRanges != null) {
for (range in safetySpeedRanges) {
val speed = range.value
val newAttrs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fun runStandaloneSimulation(
speedLimitTag: String?,
powerRestrictions: DistanceRangeMap<String>,
useElectricalProfiles: Boolean,
useInfraSpeedLimits: Boolean,
timeStep: Double,
schedule: List<SimulationScheduleItem>,
initialSpeed: Double,
Expand All @@ -68,7 +69,16 @@ fun runStandaloneSimulation(
): SimulationSuccess {
// MRSP & SpeedLimits
val safetySpeedRanges = makeSafetySpeedRanges(infra, chunkPath, routes, schedule)
var mrsp = computeMRSP(pathProps, rollingStock, true, speedLimitTag, null, safetySpeedRanges)
var mrsp =
computeMRSP(
pathProps,
rollingStock,
true,
speedLimitTag,
null,
safetySpeedRanges,
useInfraSpeedLimits
)
mrsp = driverBehaviour.applyToMRSP(mrsp)
// We don't use speed safety ranges in the MRSP displayed in the front
// (just like we don't add the train length)
Expand All @@ -79,6 +89,8 @@ fun runStandaloneSimulation(
false,
speedLimitTag,
null,
null,
useInfraSpeedLimits,
)

// Build paths and contexts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class StandaloneSimulationTest {
null,
distanceRangeMapOf(),
false,
true,
2.0,
listOf(),
0.0,
Expand Down Expand Up @@ -236,6 +237,7 @@ class StandaloneSimulationTest {
null,
testCase.powerRestrictions,
false,
true,
2.0,
testCase.schedule,
testCase.startSpeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ pub struct TrainScheduleOptions {
#[derivative(Default(value = "true"))]
#[serde(default = "default_use_electrical_profiles")]
use_electrical_profiles: bool,
#[derivative(Default(value = "true"))]
#[serde(default = "default_use_speed_limits_for_simulation")]
use_speed_limits_for_simulation: bool,
}

fn default_use_electrical_profiles() -> bool {
true
}

fn default_use_speed_limits_for_simulation() -> bool {
true
}
4 changes: 4 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11886,6 +11886,8 @@ components:
properties:
use_electrical_profiles:
type: boolean
use_speed_limits_for_simulation:
type: boolean
additionalProperties: false
path:
type: array
Expand Down Expand Up @@ -11981,6 +11983,8 @@ components:
properties:
use_electrical_profiles:
type: boolean
use_speed_limits_for_simulation:
type: boolean
additionalProperties: false
TrainScheduleResult:
allOf:
Expand Down
2 changes: 2 additions & 0 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3302,6 +3302,7 @@ export type Margins = {
};
export type TrainScheduleOptions = {
use_electrical_profiles?: boolean;
use_speed_limits_for_simulation?: boolean;
};
export type PathItem = PathItemLocation & {
/** Metadata given to mark a point as wishing to be deleted by the user.
Expand Down Expand Up @@ -3660,6 +3661,7 @@ export type TrainScheduleBase = {
};
options?: {
use_electrical_profiles?: boolean;
use_speed_limits_for_simulation?: boolean;
};
path: (PathItemLocation & {
/** Metadata given to mark a point as wishing to be deleted by the user.
Expand Down
14 changes: 11 additions & 3 deletions python/osrd_schemas/osrd_schemas/train_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,19 @@ class PowerRestrictionRanges(RootModel):


class TrainScheduleOptions(BaseModel):
"""Optional arguments for the standalone simulation."""
"""Optional arguments :
- `use_electrical_profiles` : use the electrical profiles for the standalone simulation
- `use_infra_speed_limits_for_simulation` : use the speed limits coming from the infrastructure for
the standalone simulation
"""

ignore_electrical_profiles: bool = Field(
use_electrical_profiles: bool = Field(
default=False,
description="If true, the electrical profiles are ignored in the standalone simulation",
description="If true, the electrical profiles are used in the standalone simulation",
)
use_infra_speed_limits_for_simulation: bool = Field(
default=True,
description="If false, the speed limits of the infrastructure are ignored in the standalone simulation",
)


Expand Down

0 comments on commit 97d078c

Please sign in to comment.