Skip to content

Commit

Permalink
editoast: stdcm fix train simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Nov 8, 2024
1 parent b777099 commit f0f89c1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
5 changes: 5 additions & 0 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions editoast/src/views/timetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ async fn conflicts(
&trains,
&infra,
electrical_profile_set_id,
None,
)
.await?;

Expand Down
25 changes: 15 additions & 10 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,22 @@ 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(),
core_client.clone(),
&train_schedules,
&infra,
stdcm_request.electrical_profile_set_id,
Some(physics_consist_parameters.clone()),
)
.await?;

Expand All @@ -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 {
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -605,10 +608,11 @@ async fn simulate_train_run(
db_pool: Arc<DbConnectionPoolV2>,
valkey_client: Arc<ValkeyClient>,
core_client: Arc<CoreClient>,
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<PhysicsConsistParameters>,
) -> Result<(
SimulationTimeResult,
TrainSchedule,
Expand Down Expand Up @@ -653,6 +657,7 @@ async fn simulate_train_run(
train_schedule.clone(),
infra,
None,
physics_consist_parameters,
)
.await?;

Expand Down
19 changes: 16 additions & 3 deletions editoast/src/views/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ async fn simulation(
train_schedule,
&infra,
electrical_profile_set_id,
None,
)
.await?
.0,
Expand All @@ -380,6 +381,7 @@ pub async fn train_simulation(
train_schedule: TrainSchedule,
infra: &Infra,
electrical_profile_set_id: Option<i64>,
physics_consist_parameters: Option<PhysicsConsistParameters>,
) -> Result<(SimulationResponse, PathfindingResult)> {
Ok(train_simulation_batch(
conn,
Expand All @@ -388,6 +390,7 @@ pub async fn train_simulation(
&[train_schedule],
infra,
electrical_profile_set_id,
physics_consist_parameters,
)
.await?
.pop()
Expand All @@ -404,6 +407,7 @@ pub async fn train_simulation_batch(
train_schedules: &[TrainSchedule],
infra: &Infra,
electrical_profile_set_id: Option<i64>,
physics_consist_parameters: Option<PhysicsConsistParameters>,
) -> Result<Vec<(SimulationResponse, PathfindingResult)>> {
let mut valkey_conn = valkey_client.get_connection().await?;
// Compute path
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<i64>,
physics_consist_parameters: PhysicsConsistParameters,
) -> SimulationRequest {
assert_eq!(path_item_positions.len(), train_schedule.path.len());
// Project path items to path offset
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -697,6 +709,7 @@ async fn simulation_summary(
&train_schedules,
&infra,
electrical_profile_set_id,
None,
)
.await?;

Expand Down
1 change: 1 addition & 0 deletions editoast/src/views/train_schedule/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ async fn project_path(
&trains,
&infra,
electrical_profile_set_id,
None,
)
.await?;

Expand Down

0 comments on commit f0f89c1

Please sign in to comment.