From dc7b25725642544fefa62c6447de397ac482a485 Mon Sep 17 00:00:00 2001 From: Louis Greiner Date: Mon, 23 Dec 2024 17:55:16 +0100 Subject: [PATCH] editoast, python: add ts.config 'stop_at_next_signal' new field Signed-off-by: Louis Greiner --- .../src/train_schedule/train_schedule_options.rs | 14 ++++++++++++++ editoast/openapi.yaml | 7 +++++++ editoast/src/core/pathfinding.rs | 3 +++ editoast/src/views/path/pathfinding.rs | 10 ++++++++++ python/osrd_schemas/osrd_schemas/train_schedule.py | 9 ++++++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/editoast/editoast_schemas/src/train_schedule/train_schedule_options.rs b/editoast/editoast_schemas/src/train_schedule/train_schedule_options.rs index 693553e87b0..e9277fe788d 100644 --- a/editoast/editoast_schemas/src/train_schedule/train_schedule_options.rs +++ b/editoast/editoast_schemas/src/train_schedule/train_schedule_options.rs @@ -14,8 +14,22 @@ pub struct TrainScheduleOptions { #[derivative(Default(value = "true"))] #[serde(default = "default_use_electrical_profiles")] use_electrical_profiles: bool, + + #[derivative(Default(value = "true"))] + #[serde(default = "default_stop_at_next_signal")] // TODO: try to set default value only at 1 location (struct) + stop_at_next_signal: bool, } fn default_use_electrical_profiles() -> bool { true } + +fn default_stop_at_next_signal() -> bool { + true +} + +impl TrainScheduleOptions { + pub fn stops_at_next_signal(&self) -> bool { + self.stop_at_next_signal + } +} diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index df21a9065db..feeecc175b9 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -8160,6 +8160,9 @@ components: items: type: string description: List of supported signaling systems + stop_at_next_signal: + type: boolean + description: Stops the train at next signal instead of on path item PathfindingInputError: oneOf: - type: object @@ -11346,6 +11349,8 @@ components: options: type: object properties: + stop_at_next_signal: + type: boolean use_electrical_profiles: type: boolean additionalProperties: false @@ -11441,6 +11446,8 @@ components: TrainScheduleOptions: type: object properties: + stop_at_next_signal: + type: boolean use_electrical_profiles: type: boolean additionalProperties: false diff --git a/editoast/src/core/pathfinding.rs b/editoast/src/core/pathfinding.rs index 74c5ba738fd..3094664c9c9 100644 --- a/editoast/src/core/pathfinding.rs +++ b/editoast/src/core/pathfinding.rs @@ -42,6 +42,9 @@ pub struct PathfindingRequest { pub rolling_stock_maximum_speed: f64, /// Rolling stock length in meters: pub rolling_stock_length: f64, + /// If the train should stop on the next signal instead of on the operational point + // TODO: test if this field is really used + pub stop_at_next_signal: bool, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)] diff --git a/editoast/src/views/path/pathfinding.rs b/editoast/src/views/path/pathfinding.rs index ddef64d7edc..92a98396d9d 100644 --- a/editoast/src/views/path/pathfinding.rs +++ b/editoast/src/views/path/pathfinding.rs @@ -71,6 +71,14 @@ struct PathfindingInput { /// Rolling stock length #[schema(value_type = f64)] rolling_stock_length: OrderedFloat, + /// Stops the train at next signal instead of on path item + // TODO: try to set default value only at 1 location (struct) + #[serde(default = "default_stop_at_next_signal")] + stop_at_next_signal: bool, +} + +fn default_stop_at_next_signal() -> bool { + true } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)] @@ -325,6 +333,7 @@ fn build_pathfinding_request( .clone(), rolling_stock_maximum_speed: pathfinding_input.rolling_stock_maximum_speed.0, rolling_stock_length: pathfinding_input.rolling_stock_length.0, + stop_at_next_signal: pathfinding_input.stop_at_next_signal, }) } @@ -398,6 +407,7 @@ pub async fn pathfinding_from_train_batch( .into_iter() .map(|item| item.location) .collect(), + stop_at_next_signal: train_schedule.options.stops_at_next_signal(), }; to_compute.push(path_input); to_compute_index.push(index); diff --git a/python/osrd_schemas/osrd_schemas/train_schedule.py b/python/osrd_schemas/osrd_schemas/train_schedule.py index bccd563f95d..fe20b7c5311 100644 --- a/python/osrd_schemas/osrd_schemas/train_schedule.py +++ b/python/osrd_schemas/osrd_schemas/train_schedule.py @@ -170,12 +170,19 @@ class PowerRestrictionRanges(RootModel): class TrainScheduleOptions(BaseModel): - """Optional arguments for the standalone simulation.""" + """Optional arguments : + - `ignore_electrical_profiles` : for the standalone simulation + - `stop_at_next_signal` : for dealing with stopped trains that overflow on switches during imports + """ ignore_electrical_profiles: bool = Field( default=False, description="If true, the electrical profiles are ignored in the standalone simulation", ) + stop_at_next_signal: bool = Field( + default=False, + description="If true, the train will stop at the next signal instead of at the operational point", + ) if __name__ == "__main__":