diff --git a/editoast/src/core/simulation.rs b/editoast/src/core/simulation.rs index 84f6567f54a..d0bb96d0248 100644 --- a/editoast/src/core/simulation.rs +++ b/editoast/src/core/simulation.rs @@ -82,6 +82,11 @@ pub struct PhysicsConsistParameters { } impl PhysicsConsistParameters { + pub fn set_traction_engine(mut self, traction_engine: RollingStock) -> Self { + self.traction_engine = traction_engine; + self + } + pub fn with_traction_engine(traction_engine: RollingStock) -> Self { PhysicsConsistParameters { max_speed: None, diff --git a/editoast/src/views/timetable.rs b/editoast/src/views/timetable.rs index 49e49c54622..9866c515636 100644 --- a/editoast/src/views/timetable.rs +++ b/editoast/src/views/timetable.rs @@ -317,6 +317,7 @@ async fn conflicts( &trains, &infra, electrical_profile_set_id, + None, ) .await?; diff --git a/editoast/src/views/timetable/stdcm.rs b/editoast/src/views/timetable/stdcm.rs index f92a64d75b8..5a900adce63 100644 --- a/editoast/src/views/timetable/stdcm.rs +++ b/editoast/src/views/timetable/stdcm.rs @@ -234,6 +234,14 @@ async fn stdcm( None }; + let physics_consist_parameters = PhysicsConsistParameters { + max_speed: stdcm_request.max_speed, + total_length: stdcm_request.total_length, + total_mass: stdcm_request.total_mass, + towed_rolling_stock: towed_rolling_stock.map(From::from), + traction_engine: rolling_stock.clone().into(), + }; + let simulations = train_simulation_batch( conn, valkey_client.clone(), @@ -241,6 +249,7 @@ async fn stdcm( &train_schedules, &infra, stdcm_request.electrical_profile_set_id, + Some(physics_consist_parameters.clone()), ) .await?; @@ -259,6 +268,7 @@ async fn stdcm( &infra, &rolling_stock, timetable_id, + Some(physics_consist_parameters.clone()), // TODO maybe passe by ref ) .await?; let simulation_run_time = match simulation_run_time { @@ -345,14 +355,7 @@ async fn stdcm( latest_simulation_end, ), temporary_speed_limits, - rolling_stock: PhysicsConsistParameters { - max_speed: stdcm_request.max_speed, - total_length: stdcm_request.total_length, - total_mass: stdcm_request.total_mass, - towed_rolling_stock: towed_rolling_stock.map(From::from), - traction_engine: rolling_stock.into(), - } - .into(), + rolling_stock: physics_consist_parameters.into(), }; let stdcm_response = stdcm_request.fetch(core_client.as_ref()).await?; @@ -605,10 +608,11 @@ async fn simulate_train_run( db_pool: Arc, valkey_client: Arc, core_client: Arc, - data: &STDCMRequestPayload, + data: &STDCMRequestPayload, // TODO build PhysicsConsistParameters from this infra: &Infra, - rolling_stock: &RollingStockModel, + rolling_stock: &RollingStockModel, // TODO remove it (maybe remplace it with towed) timetable_id: i64, + physics_consist_parameters: Option, ) -> Result<( SimulationTimeResult, TrainSchedule, @@ -653,6 +657,7 @@ async fn simulate_train_run( train_schedule.clone(), infra, None, + physics_consist_parameters, ) .await?; diff --git a/editoast/src/views/train_schedule.rs b/editoast/src/views/train_schedule.rs index 7946ad98a81..51e766d8a73 100644 --- a/editoast/src/views/train_schedule.rs +++ b/editoast/src/views/train_schedule.rs @@ -366,6 +366,7 @@ async fn simulation( train_schedule, &infra, electrical_profile_set_id, + None, ) .await? .0, @@ -380,6 +381,7 @@ pub async fn train_simulation( train_schedule: TrainSchedule, infra: &Infra, electrical_profile_set_id: Option, + physics_consist_parameters: Option, ) -> Result<(SimulationResponse, PathfindingResult)> { Ok(train_simulation_batch( conn, @@ -388,6 +390,7 @@ pub async fn train_simulation( &[train_schedule], infra, electrical_profile_set_id, + physics_consist_parameters, ) .await? .pop() @@ -404,6 +407,7 @@ pub async fn train_simulation_batch( train_schedules: &[TrainSchedule], infra: &Infra, electrical_profile_set_id: Option, + physics_consist_parameters: Option, ) -> Result> { let mut valkey_conn = valkey_client.get_connection().await?; // Compute path @@ -459,13 +463,21 @@ pub async fn train_simulation_batch( // Build simulation request let rolling_stock = rolling_stocks[&train_schedule.rolling_stock_name].clone(); + + let physics_consist_parameters = + if let Some(physics_consist_parameters) = physics_consist_parameters.clone() { + physics_consist_parameters.set_traction_engine(rolling_stock.into()) + } else { + PhysicsConsistParameters::with_traction_engine(rolling_stock.into()) + }; + let simulation_request = build_simulation_request( infra, train_schedule, path_item_positions, path, - rolling_stock, electrical_profile_set_id, + physics_consist_parameters, ); // Compute unique hash of the simulation input @@ -529,8 +541,8 @@ fn build_simulation_request( train_schedule: &TrainSchedule, path_item_positions: &[u64], path: SimulationPath, - rolling_stock: RollingStockModel, electrical_profile_set_id: Option, + physics_consist_parameters: PhysicsConsistParameters, ) -> SimulationRequest { assert_eq!(path_item_positions.len(), train_schedule.path.len()); // Project path items to path offset @@ -590,7 +602,7 @@ fn build_simulation_request( speed_limit_tag: train_schedule.speed_limit_tag.clone(), power_restrictions, options: train_schedule.options.clone(), - rolling_stock: PhysicsConsistParameters::with_traction_engine(rolling_stock.into()).into(), + rolling_stock: physics_consist_parameters.into(), electrical_profile_set_id, } } @@ -697,6 +709,7 @@ async fn simulation_summary( &train_schedules, &infra, electrical_profile_set_id, + None, ) .await?; diff --git a/editoast/src/views/train_schedule/projection.rs b/editoast/src/views/train_schedule/projection.rs index cdae18626e9..21f6be19f46 100644 --- a/editoast/src/views/train_schedule/projection.rs +++ b/editoast/src/views/train_schedule/projection.rs @@ -190,6 +190,7 @@ async fn project_path( &trains, &infra, electrical_profile_set_id, + None, ) .await?;