diff --git a/editoast/core_task/src/envs/pathfinding.rs b/editoast/core_task/src/envs/pathfinding.rs index 61494a68468..cae6e3f2385 100644 --- a/editoast/core_task/src/envs/pathfinding.rs +++ b/editoast/core_task/src/envs/pathfinding.rs @@ -78,7 +78,7 @@ where }| { if let Some(tx) = ready_trains_tx.as_ref() { let trains = runner - .input_train_set(&input) + .train_set(&input) .expect("input provided by the Runner should be valid"); tx.unbounded_send(trains).ok(); } @@ -112,7 +112,7 @@ where data: path, }| { let trains = runner - .input_train_set(&input) + .train_set(&input) .expect("input provided by the Runner should be valid"); Correlated::new(trains, path) }, @@ -176,7 +176,7 @@ pub struct PathfindingConsist { #[cfg_attr(test, derive(Clone))] pub struct PathfindingConstraints { /// An ordered list of waypoints the resulting path must pass through - pub path_items: Vec, + pub path_items: Vec, } /// A set of [TrackOffset] @@ -184,15 +184,15 @@ pub struct PathfindingConstraints { /// The resulting path can cross any of these. #[derive(Debug, Hash, PartialEq, Eq)] #[cfg_attr(test, derive(Clone))] -pub struct PathWaypointAlternatives(Vec); +pub struct PathItemAlternatives(Vec); -impl FromIterator for PathWaypointAlternatives { +impl FromIterator for PathItemAlternatives { fn from_iter>(iter: T) -> Self { Self(iter.into_iter().collect()) } } -impl IntoIterator for PathWaypointAlternatives { +impl IntoIterator for PathItemAlternatives { type Item = TrackOffset; type IntoIter = as IntoIterator>::IntoIter; @@ -230,7 +230,7 @@ impl PathfindingEnvInputs where Train: TrainKey + 'static, { - fn iter(&self) -> impl Iterator> { + fn iter(&self) -> impl Iterator> { self.consists.keys().map(|train| { let pf_key = self .train_input(train) @@ -239,10 +239,10 @@ where }) } - pub(in crate::envs) fn train_input(&self, train: &Train) -> Option { + pub(in crate::envs) fn train_input(&self, train: &Train) -> Option { let consist = self.consists.get(train)?; let constraints = self.constraints.get(train)?; - Some(Input(consist.clone(), constraints.clone())) + Some(PathfindingKey(consist.clone(), constraints.clone())) } } @@ -258,11 +258,11 @@ where { core_env: CoreEnv, pub(in crate::envs) pathfinding_inputs: Arc>, - input_index: DashMap>, + rev: DashMap>, } #[derive(Debug, Clone, Hash, PartialEq, Eq)] -pub(in crate::envs) struct Input( +pub(in crate::envs) struct PathfindingKey( pub(in crate::envs) Arc, pub(in crate::envs) Arc, ); @@ -272,27 +272,27 @@ where Train: TrainKey + 'static, { pub(in crate::envs) fn new(PathfindingEnv { core_env, inputs }: PathfindingEnv) -> Self { - let input_index = DashMap::>::new(); + let rev = DashMap::>::new(); for Correlated { correlation_key: train, data: input, } in inputs.iter() { - input_index.entry(input).or_default().insert(train); + rev.entry(input).or_default().insert(train); } Self { core_env: core_env.clone(), pathfinding_inputs: Arc::new(inputs), - input_index, + rev, } } - pub(in crate::envs) fn input_train_set(&self, input: &Input) -> Option> { - self.input_index.get(input).as_deref().cloned() + pub(in crate::envs) fn train_set(&self, input: &PathfindingKey) -> Option> { + self.rev.get(input).as_deref().cloned() } - fn iter_inputs(&self) -> impl Iterator { - self.input_index.iter().map(|set| set.key().clone()) + fn iter_keys(&self) -> impl Iterator { + self.rev.iter().map(|set| set.key().clone()) } pub(in crate::envs) fn stream( @@ -300,14 +300,14 @@ where vkconn: Arc>, ) -> impl stream::Stream< Item = Correlated< - Input, + PathfindingKey, Result, >, > { use crate::TaskStreamExt as _; let requests = self - .iter_inputs() + .iter_keys() .map(|input| { let request = build_request(&self.core_env, &input); Correlated::new(input, request) @@ -334,7 +334,7 @@ where { inputs: Arc>, // optionally deduplicate similar outputs of different inputs - paths: Arc>, + paths: Arc>, } /// Ready when the pathfinding result is available and stored in [PathfindingRun], pending if the task is not yet completed @@ -348,7 +348,7 @@ where fn new(runner: &Runner) -> Self { let paths = DashMap::from_iter( runner - .iter_inputs() + .iter_keys() .zip(std::iter::repeat_with(|| Poll::Pending)), ); Self { @@ -375,7 +375,7 @@ where fn build_request( core_env: &CoreEnv, - Input(consist, constraints): &Input, + PathfindingKey(consist, constraints): &PathfindingKey, ) -> core_client::pathfinding::PathfindingRequest { core_client::pathfinding::PathfindingRequest { infra: core_env.infra_id as i64, @@ -383,7 +383,7 @@ fn build_request( path_items: constraints .path_items .iter() - .map(|PathWaypointAlternatives(track_alternatives)| { + .map(|PathItemAlternatives(track_alternatives)| { track_alternatives.clone().into_iter().collect() }) .collect(), @@ -442,12 +442,12 @@ pub(crate) mod test_data { pub(crate) fn constraints(id: usize) -> PathfindingConstraints { PathfindingConstraints { path_items: vec![ - PathWaypointAlternatives::from_iter([TrackOffset::new("id", id as u64)]), - PathWaypointAlternatives::from_iter([ + PathItemAlternatives::from_iter([TrackOffset::new("id", id as u64)]), + PathItemAlternatives::from_iter([ TrackOffset::new("tr1", 100), TrackOffset::new("tr1bis", 100), ]), - PathWaypointAlternatives::from_iter([TrackOffset::new("tr2", 200)]), + PathItemAlternatives::from_iter([TrackOffset::new("tr2", 200)]), ], } } diff --git a/editoast/core_task/src/envs/simulation.rs b/editoast/core_task/src/envs/simulation.rs index 17abfaa2aa8..4bb43a31bf0 100644 --- a/editoast/core_task/src/envs/simulation.rs +++ b/editoast/core_task/src/envs/simulation.rs @@ -135,7 +135,7 @@ where pub(in crate::envs) struct SimulationKey( Arc, Arc, - pathfinding::Input, + pathfinding::PathfindingKey, ); impl Runner @@ -178,10 +178,10 @@ where /// do not necessarily share the same simulation key (simulation inputs differ). fn simulation_keys_of_pathfinding_key( &self, - pathfinding_key: &pathfinding::Input, + pathfinding_key: &pathfinding::PathfindingKey, ) -> impl Iterator { self.pathfinding_runner - .input_train_set(pathfinding_key) + .train_set(pathfinding_key) .into_iter() .flatten() .filter_map(|train| { @@ -213,7 +213,7 @@ where correlation_key: pf_key, data: Ok(core_client::pathfinding::PathfindingCoreResult::Success(path)), } => { - let trains = runner.pathfinding_runner.input_train_set(&pf_key).expect("input provided by the runner should be valid"); + let trains = runner.pathfinding_runner.train_set(&pf_key).expect("input provided by the runner should be valid"); (trains, path) } Correlated { @@ -429,12 +429,12 @@ pub(crate) mod test_data { ), ); builder.push_waypoint( - pathfinding::PathWaypointAlternatives::from_iter([TrackOffset::new("id", id as u64)]), + pathfinding::PathItemAlternatives::from_iter([TrackOffset::new("id", id as u64)]), NonBlankString::from("start"), SimulationWaypoint::PathItem, ); builder.push_waypoint( - pathfinding::PathWaypointAlternatives::from_iter([TrackOffset::new("a", 42)]), + pathfinding::PathItemAlternatives::from_iter([TrackOffset::new("a", 42)]), NonBlankString::from("a"), SimulationWaypoint::ScheduleItem { arrival_at: Some(1200), @@ -443,7 +443,7 @@ pub(crate) mod test_data { }, ); builder.push_waypoint( - pathfinding::PathWaypointAlternatives::from_iter([ + pathfinding::PathItemAlternatives::from_iter([ TrackOffset::new("b", 43), TrackOffset::new("bis", 34), ]), @@ -455,7 +455,7 @@ pub(crate) mod test_data { }, ); builder.push_waypoint( - pathfinding::PathWaypointAlternatives::from_iter([TrackOffset::new("finish", 44)]), + pathfinding::PathItemAlternatives::from_iter([TrackOffset::new("finish", 44)]), NonBlankString::from("finish"), SimulationWaypoint::ScheduleItem { arrival_at: Some(2400), diff --git a/editoast/core_task/src/envs/simulation/inputs.rs b/editoast/core_task/src/envs/simulation/inputs.rs index 9ec7701f7db..a7581b7459a 100644 --- a/editoast/core_task/src/envs/simulation/inputs.rs +++ b/editoast/core_task/src/envs/simulation/inputs.rs @@ -18,7 +18,7 @@ use crate::PathfindingConsist; use crate::PathfindingConstraints; use crate::PathfindingTrain; use crate::TrainKey; -use crate::envs::pathfinding::PathWaypointAlternatives; +use crate::envs::pathfinding::PathItemAlternatives; #[derive(Debug)] pub(crate) struct SimulationInputs @@ -42,9 +42,9 @@ pub struct SimulationConsist(pub PhysicsConsist); #[derive(Debug, educe::Educe)] #[educe(Hash, PartialEq, Eq)] pub struct SimulationTrainParameters { - path_items: Vec, - power_restrictions: rangemap::RangeMap, - margins: rangemap::RangeMap, + waypoints: Vec, + power_restrictions: rangemap::RangeMap, + margins: rangemap::RangeMap, #[educe(Hash(method(common::units::meter_per_second::hash)))] #[educe(Eq(method(common::units::meter_per_second::eq)))] @@ -77,7 +77,7 @@ impl SimulationTrainParameters { options: TrainScheduleOptions, ) -> Self { Self { - path_items: Default::default(), + waypoints: Default::default(), power_restrictions: Default::default(), margins: Default::default(), initial_speed, @@ -88,15 +88,15 @@ impl SimulationTrainParameters { } } - pub fn schedule(&self) -> &[SimulationWaypoint] { - &self.path_items + pub fn waypoints(&self) -> &[SimulationWaypoint] { + &self.waypoints } - pub fn power_restrictions(&self) -> &rangemap::RangeMap { + pub fn power_restrictions(&self) -> &rangemap::RangeMap { &self.power_restrictions } - pub fn margins(&self) -> &rangemap::RangeMap { + pub fn margins(&self) -> &rangemap::RangeMap { &self.margins } @@ -121,7 +121,7 @@ impl SimulationTrainParameters { } fn is_empty(&self) -> bool { - self.path_items.is_empty() && self.power_restrictions.is_empty() && self.margins.is_empty() + self.waypoints.is_empty() && self.power_restrictions.is_empty() && self.margins.is_empty() } } @@ -146,11 +146,11 @@ where ) -> Option { let consist = self.consists.get(train)?; let params = self.parameters.get(train)?; - let pf_input = pathfinding_inputs.train_input(train)?; + let pf_key = pathfinding_inputs.train_input(train)?; Some(super::SimulationKey( consist.clone(), params.clone(), - pf_input, + pf_key, )) } } @@ -158,7 +158,7 @@ where /// The way to provide simulation and pathfinding inputs to a [SimulationEnv] /// /// This builder is useful to ensure the following things are consistent: -/// - pathfinding waypoints and schedule information ([SimulationWaypointSchedule]) +/// - pathfinding path items and simulation waypoint information ([SimulationWaypoint]) /// - power restrictions ranges /// - margin ranges /// @@ -169,10 +169,10 @@ pub struct SimulationTrain { pub(super) pathfinding_consist: PathfindingConsist, pub(super) parameters: SimulationTrainParameters, pub(super) path_constraints: PathfindingConstraints, - path_item_to_index: HashMap, + waypoint_to_index: HashMap, } -type PathWaypointIndex = usize; +type WaypointIndex = usize; impl SimulationTrain { pub fn new( @@ -191,13 +191,13 @@ impl SimulationTrain { path_constraints: PathfindingConstraints { path_items: Vec::new(), }, - path_item_to_index: HashMap::default(), + waypoint_to_index: HashMap::default(), } } fn waypoints(&self) -> usize { let n = self.path_constraints.path_items.len(); - debug_assert_eq!(n, self.parameters.path_items.len()); + debug_assert_eq!(n, self.parameters.waypoints.len()); debug_assert!( self.parameters .power_restrictions @@ -215,14 +215,14 @@ impl SimulationTrain { /// The label can be reused for [Self::set_power_restriction] and [Self::set_margin]. pub fn push_waypoint( &mut self, - path_constraint: PathWaypointAlternatives, + path_constraint: PathItemAlternatives, label: NonBlankString, point: SimulationWaypoint, ) { - let index = self.parameters.path_items.len(); - self.parameters.path_items.push(point); + let index = self.parameters.waypoints.len(); + self.parameters.waypoints.push(point); self.path_constraints.path_items.push(path_constraint); - self.path_item_to_index.insert(label, index); + self.waypoint_to_index.insert(label, index); } /// Sets a power restriction for a range of waypoints. @@ -238,12 +238,12 @@ impl SimulationTrain { Q: Hash + Eq + ?Sized, { let begin_index = self - .path_item_to_index + .waypoint_to_index .get(begin_label) .copied() .expect("only names already inserted through “push_waypoint” can be used"); let end_index = self - .path_item_to_index + .waypoint_to_index .get(end_label) .copied() .expect("only names already inserted through “push_waypoint” can be used"); @@ -276,12 +276,12 @@ impl SimulationTrain { Q: Hash + Eq + ?Sized, { let begin_index = self - .path_item_to_index + .waypoint_to_index .get(begin_label) .copied() .expect("only names already inserted through “push_waypoint” can be used"); let end_index = self - .path_item_to_index + .waypoint_to_index .get(end_label) .copied() .expect("only names already inserted through “push_waypoint” can be used"); @@ -317,7 +317,7 @@ where pathfinding_consist, parameters, path_constraints, - path_item_to_index: _, + waypoint_to_index: _, }, )| { ( diff --git a/editoast/core_task/src/envs/simulation/request.rs b/editoast/core_task/src/envs/simulation/request.rs index 6fe9bdfbd3e..000be0be84a 100644 --- a/editoast/core_task/src/envs/simulation/request.rs +++ b/editoast/core_task/src/envs/simulation/request.rs @@ -15,7 +15,7 @@ use super::SimulationWaypoint; pub(super) fn build_request( core_env: &CoreEnv, electrical_profile_set_id: Option, - SimulationKey(sim_consist, params, pathfinding::Input(pf_consist, constraints)): &SimulationKey, + SimulationKey(sim_consist, params, pathfinding::PathfindingKey(pf_consist, constraints)): &SimulationKey, core_client::pathfinding::PathfindingResultSuccess { path, path_item_positions, @@ -69,7 +69,7 @@ pub(super) fn build_request( ); let mut schedule = Vec::new(); - for (i, point) in params.schedule().iter().enumerate() { + for (i, point) in params.waypoints().iter().enumerate() { if let SimulationWaypoint::ScheduleItem { arrival_at, stop_for, @@ -150,7 +150,7 @@ mod tests { use super::*; use crate::envs::pathfinding; - use crate::envs::pathfinding::PathWaypointAlternatives; + use crate::envs::pathfinding::PathItemAlternatives; use crate::envs::simulation; use crate::envs::simulation::SimulationTrain; use crate::envs::simulation::SimulationTrainParameters; @@ -173,10 +173,10 @@ mod tests { let core_env = CoreEnv::new_mock(MockingClient::new()); let path_items = vec![ - PathWaypointAlternatives::from_iter([]), - PathWaypointAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), ]; - let pf_input = pathfinding::Input( + let pf_input = pathfinding::PathfindingKey( Arc::new(pathfinding::test_data::consist(1)), Arc::new(crate::PathfindingConstraints { path_items: path_items.clone(), @@ -263,13 +263,13 @@ mod tests { let core_env = CoreEnv::new_mock(MockingClient::new()); let path_items = vec![ - PathWaypointAlternatives::from_iter([]), - PathWaypointAlternatives::from_iter([]), - PathWaypointAlternatives::from_iter([]), - PathWaypointAlternatives::from_iter([]), - PathWaypointAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), ]; - let pf_input = pathfinding::Input( + let pf_input = pathfinding::PathfindingKey( Arc::new(pathfinding::test_data::consist(1)), Arc::new(crate::PathfindingConstraints { path_items: path_items.clone(), @@ -407,7 +407,7 @@ mod tests { }; let core_env = CoreEnv::new_mock(MockingClient::new()); - let pf_input = pathfinding::Input( + let pf_input = pathfinding::PathfindingKey( Arc::new(pathfinding::test_data::consist(1)), Arc::new(crate::PathfindingConstraints { path_items: vec![] }), ); @@ -424,12 +424,12 @@ mod tests { ), ); builder.push_waypoint( - PathWaypointAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), NonBlankString::from("a"), SimulationWaypoint::PathItem, ); builder.push_waypoint( - PathWaypointAlternatives::from_iter([]), + PathItemAlternatives::from_iter([]), NonBlankString::from("b"), SimulationWaypoint::ScheduleItem { arrival_at: Some(300), diff --git a/editoast/core_task/src/lib.rs b/editoast/core_task/src/lib.rs index e0987b5fe8f..7bc9ce1af3d 100644 --- a/editoast/core_task/src/lib.rs +++ b/editoast/core_task/src/lib.rs @@ -7,7 +7,7 @@ use std::sync::Arc; // Crate-level exports pub use envs::TrainSet; pub use envs::core::CoreEnv; -pub use envs::pathfinding::PathWaypointAlternatives; +pub use envs::pathfinding::PathItemAlternatives; pub use envs::pathfinding::PathfindingConsist; pub use envs::pathfinding::PathfindingConstraints; pub use envs::pathfinding::PathfindingEnv; diff --git a/editoast/src/views/timetable.rs b/editoast/src/views/timetable.rs index b026b077e52..6d925845ebb 100644 --- a/editoast/src/views/timetable.rs +++ b/editoast/src/views/timetable.rs @@ -41,10 +41,11 @@ use editoast_models::timetable::Timetable; use editoast_models::timetable::TimetableWithTrains; use itertools::Itertools; use itertools::izip; +use schemas::rolling_stock::EtcsBrakeParams; +use schemas::rolling_stock::LoadingGaugeType; use schemas::rolling_stock::RollingResistance; use schemas::rolling_stock::RollingStock; use schemas::rolling_stock::TowedRollingStock; -use schemas::rolling_stock::{EtcsBrakeParams, LoadingGaugeType}; use schemas::train_schedule::TrainScheduleLike; use serde::Deserialize; use serde::Serialize;