Skip to content

Commit

Permalink
editoast: add max speed to towed rs
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <egor@berezify.fr>
  • Loading branch information
Wadjetz committed Dec 4, 2024
1 parent b789c34 commit d7136ad
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ diesel::table! {
locked -> Bool,
mass -> Float8,
length -> Float8,
max_speed -> Nullable<Float8>,
comfort_acceleration -> Float8,
startup_acceleration -> Float8,
inertia_coefficient -> Float8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ pub struct TowedRollingStock {
/// The constant gamma braking coefficient used when NOT circulating
/// under ETCS/ERTMS signaling system in m/s^2
pub const_gamma: f64,
pub max_speed: Option<f64>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE towed_rolling_stock
DROP max_speed;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE towed_rolling_stock
ADD max_speed FLOAT8;
36 changes: 19 additions & 17 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ impl PhysicsConsistParameters {
}

pub fn compute_max_speed(&self) -> f64 {
match self.max_speed {
Some(0.0) => self.traction_engine.max_speed,
Some(max_speed_parameter) => {
f64::min(self.traction_engine.max_speed, max_speed_parameter)
}
None => self.traction_engine.max_speed,
}
let max_speeds = [
self.max_speed,
self.towed_rolling_stock
.as_ref()
.and_then(|towed| towed.max_speed),
Some(self.traction_engine.max_speed),
];
max_speeds
.into_iter()
.flatten()
.reduce(f64::min)
.unwrap_or_else(|| self.traction_engine.max_speed)
}

pub fn compute_startup_acceleration(&self) -> f64 {
Expand Down Expand Up @@ -557,6 +562,7 @@ mod tests {

#[test]
fn physics_consist_max_speed() {
// Towed max speed 35
let mut physics_consist = create_physics_consist();
physics_consist.max_speed = Some(20.0); // m/s
physics_consist.traction_engine.max_speed = 22.0; // m/s
Expand All @@ -571,6 +577,12 @@ mod tests {

physics_consist.max_speed = None;
assert_eq!(physics_consist.compute_max_speed(), 24.0);

physics_consist.traction_engine.max_speed = 40.0; // m/s
assert_eq!(physics_consist.compute_max_speed(), 35.0);

physics_consist.towed_rolling_stock = None;
assert_eq!(physics_consist.compute_max_speed(), 40.0);
}

#[test]
Expand Down Expand Up @@ -625,14 +637,4 @@ mod tests {
physics_consist.traction_engine.rolling_resistance,
);
}

#[test]
fn physics_consist_max_speed_is_not_zero() {
let mut physics_consist = create_physics_consist();
physics_consist.max_speed = None;
assert_ne!(physics_consist.compute_max_speed(), 0.0);

physics_consist.max_speed = Some(0.0);
assert_ne!(physics_consist.compute_max_speed(), 0.0);
}
}
1 change: 1 addition & 0 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock {
C: 0.0002, // In N/(m/s)²
},
const_gamma: 1.0,
max_speed: Some(35.0),
railjson_version: "3.4".to_string(),
}
}
Expand Down
3 changes: 3 additions & 0 deletions editoast/src/models/towed_rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct TowedRollingStockModel {
pub mass: f64,
/// In m
pub length: f64,
/// In km/h
pub max_speed: Option<f64>,
pub comfort_acceleration: f64,
pub startup_acceleration: f64,
pub inertia_coefficient: f64,
Expand All @@ -48,6 +50,7 @@ impl From<TowedRollingStockModel> for TowedRollingStock {
inertia_coefficient: model.inertia_coefficient,
rolling_resistance: model.rolling_resistance,
const_gamma: model.const_gamma,
max_speed: model.max_speed,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/views/rolling_stock/towed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct TowedRollingStockForm {
pub inertia_coefficient: f64,
pub rolling_resistance: RollingResistancePerWeight,
pub const_gamma: f64,
pub max_speed: Option<f64>,
}

impl From<TowedRollingStockForm> for Changeset<TowedRollingStockModel> {
Expand All @@ -121,6 +122,7 @@ impl From<TowedRollingStockForm> for Changeset<TowedRollingStockModel> {
.inertia_coefficient(towed_rolling_stock_form.inertia_coefficient)
.rolling_resistance(towed_rolling_stock_form.rolling_resistance)
.const_gamma(towed_rolling_stock_form.const_gamma)
.max_speed(towed_rolling_stock_form.max_speed)
}
}

Expand Down
6 changes: 5 additions & 1 deletion editoast/src/views/timetable/stdcm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
use validator::Validate;

use crate::core::pathfinding::PathfindingInputError;
use crate::error::Result;
Expand Down Expand Up @@ -65,7 +66,7 @@ struct StepTimingData {
}

/// An STDCM request
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Validate, ToSchema)]
pub(super) struct Request {
/// Deprecated, first step arrival time should be used instead
pub(super) start_time: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -102,10 +103,13 @@ pub(super) struct Request {
#[schema(value_type = Option<String>, example = json!(["5%", "2min/100km"]))]
pub(super) margin: Option<MarginValue>,
/// Total mass of the consist in kg
#[validate(range(exclusive_min = 0.0))]
pub(super) total_mass: Option<f64>,
/// Total length of the consist in meters
#[validate(range(exclusive_min = 0.0))]
pub(super) total_length: Option<f64>,
/// Maximum speed of the consist in km/h
#[validate(range(exclusive_min = 0.0))]
pub(super) max_speed: Option<f64>,
pub(super) loading_gauge_type: Option<LoadingGaugeType>,
}
Expand Down

0 comments on commit d7136ad

Please sign in to comment.