diff --git a/editoast/src/core/simulation.rs b/editoast/src/core/simulation.rs index 96044f4cd9d..b9209581786 100644 --- a/editoast/src/core/simulation.rs +++ b/editoast/src/core/simulation.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; use editoast_schemas::rolling_stock::EffortCurves; use editoast_schemas::rolling_stock::Gamma; use editoast_schemas::rolling_stock::RollingResistance; -use editoast_schemas::rolling_stock::RollingStock; use editoast_schemas::rolling_stock::TowedRollingStock; use editoast_schemas::train_schedule::Comfort; use editoast_schemas::train_schedule::Distribution; @@ -18,6 +17,7 @@ use utoipa::ToSchema; use super::pathfinding::TrackRange; use crate::core::{AsCoreRequest, Json}; use crate::error::InternalError; +use crate::models::RollingStockModel; use crate::views::path::pathfinding::PathfindingFailure; use derivative::Derivative; use editoast_schemas::primitives::Identifier; @@ -78,11 +78,16 @@ pub struct PhysicsConsistParameters { /// In m/s pub max_speed: Option, pub towed_rolling_stock: Option, - pub traction_engine: RollingStock, + pub traction_engine: RollingStockModel, } impl PhysicsConsistParameters { - pub fn from_traction_engine(traction_engine: RollingStock) -> Self { + pub fn set_traction_engine(mut self, traction_engine: RollingStockModel) -> Self { + self.traction_engine = traction_engine; + self + } + + pub fn from_traction_engine(traction_engine: RollingStockModel) -> Self { PhysicsConsistParameters { max_speed: None, total_length: None, diff --git a/editoast/src/models/fixtures.rs b/editoast/src/models/fixtures.rs index da30b374a98..948e901d4c2 100644 --- a/editoast/src/models/fixtures.rs +++ b/editoast/src/models/fixtures.rs @@ -245,8 +245,10 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock { } } -pub fn create_simple_rolling_stock() -> RollingStock { - RollingStock { +pub fn create_simple_rolling_stock() -> RollingStockModel { + RollingStockModel { + id: 1, + version: 1, name: "SIMPLE_ROLLING_STOCK".to_string(), loading_gauge: LoadingGaugeType::G1, supported_signaling_systems: RollingStockSupportedSignalingSystems(vec![]), diff --git a/editoast/src/views/path/pathfinding.rs b/editoast/src/views/path/pathfinding.rs index ff892b9a171..48e630189cd 100644 --- a/editoast/src/views/path/pathfinding.rs +++ b/editoast/src/views/path/pathfinding.rs @@ -23,6 +23,7 @@ use crate::core::pathfinding::PathfindingInputError; use crate::core::pathfinding::PathfindingNotFound; use crate::core::pathfinding::PathfindingRequest; use crate::core::pathfinding::PathfindingResultSuccess; +use crate::core::simulation::PhysicsConsistParameters; use crate::core::AsCoreRequest; use crate::core::CoreClient; use crate::error::InternalError; @@ -340,7 +341,12 @@ pub async fn pathfinding_from_train( RollingStockModel::retrieve(conn, train_schedule.rolling_stock_name.clone()) .await? .into_iter() - .map(|rs| (rs.name.clone(), rs)) + .map(|rs| { + ( + rs.name.clone(), + PhysicsConsistParameters::from_traction_engine(rs), + ) + }) .collect(); Ok(pathfinding_from_train_batch( @@ -363,7 +369,7 @@ pub async fn pathfinding_from_train_batch( core: Arc, infra: &Infra, train_schedules: &[TrainSchedule], - rolling_stocks: &HashMap, + consists: &HashMap, ) -> Result> { let mut results = vec![ PathfindingResult::Failure(PathfindingFailure::PathfindingInputError( @@ -376,7 +382,7 @@ pub async fn pathfinding_from_train_batch( for (index, train_schedule) in train_schedules.iter().enumerate() { // Retrieve rolling stock let rolling_stock_name = &train_schedule.rolling_stock_name; - let Some(rolling_stock) = rolling_stocks.get(rolling_stock_name).cloned() else { + let Some(rolling_stock) = consists.get(rolling_stock_name).cloned() else { let rolling_stock_name = rolling_stock_name.clone(); results[index] = PathfindingResult::Failure(PathfindingFailure::PathfindingInputError( PathfindingInputError::RollingStockNotFound { rolling_stock_name }, @@ -384,6 +390,8 @@ pub async fn pathfinding_from_train_batch( continue; }; + let rolling_stock = rolling_stock.traction_engine; + // Create the path input let path_input = PathfindingInput { rolling_stock_loading_gauge: rolling_stock.loading_gauge, diff --git a/editoast/src/views/timetable/stdcm.rs b/editoast/src/views/timetable/stdcm.rs index ec5f718783c..d76dbc6e831 100644 --- a/editoast/src/views/timetable/stdcm.rs +++ b/editoast/src/views/timetable/stdcm.rs @@ -204,14 +204,7 @@ async fn stdcm( core_client.clone(), &infra, &train_schedules, - vec![rolling_stock.clone()] - .into_iter() - .map(|rs| (rs.name.clone(), rs.clone())) - .collect(), - vec![physics_consist_parameters.clone()] - .into_iter() - .map(|consist| (consist.traction_engine.name.clone(), consist)) - .collect(), + HashMap::from([(physics_consist_parameters.traction_engine.name.clone(), physics_consist_parameters.clone())]), stdcm_request.electrical_profile_set_id, ) .await? @@ -436,11 +429,12 @@ impl VirtualTrainRun { &[train_schedule.clone()], vec![rolling_stock] .into_iter() - .map(|rs| (rs.name.clone(), rs.clone())) - .collect(), - vec![consist_parameters.clone()] - .into_iter() - .map(|consist| (consist.traction_engine.name.clone(), consist)) + .map(|rs| { + ( + rs.name.clone(), + consist_parameters.clone().set_traction_engine(rs.clone()), + ) + }) .collect(), None, ) diff --git a/editoast/src/views/train_schedule.rs b/editoast/src/views/train_schedule.rs index df7b465d5fe..3591dd83461 100644 --- a/editoast/src/views/train_schedule.rs +++ b/editoast/src/views/train_schedule.rs @@ -423,7 +423,6 @@ pub async fn train_simulation_batch( core.clone(), infra, train_schedules, - rolling_stocks, consists, electrical_profile_set_id, ) @@ -436,7 +435,6 @@ pub async fn consist_train_simulation_batch( core: Arc, infra: &Infra, train_schedules: &[TrainSchedule], - rolling_stocks: HashMap, consists: HashMap, electrical_profile_set_id: Option, ) -> Result> { @@ -448,7 +446,7 @@ pub async fn consist_train_simulation_batch( core.clone(), infra, train_schedules, - &rolling_stocks, + &consists, ) .await?;