Skip to content

Commit a19b328

Browse files
committed
editoast: return conflicts list when STDCM request fails
Signed-off-by: hamz2a <[email protected]>
1 parent 5977531 commit a19b328

File tree

7 files changed

+544
-82
lines changed

7 files changed

+544
-82
lines changed

editoast/openapi.yaml

+26-1
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,16 @@ paths:
24722472
post:
24732473
tags:
24742474
- stdcm
2475-
summary: Compute a STDCM and return the simulation result
2475+
summary: This function computes a STDCM and returns the result.
2476+
description: |-
2477+
It first checks user authorization, then retrieves timetable, infrastructure,
2478+
train schedules, and rolling stock data, and runs train simulations.
2479+
The result contains the simulation output based on the train schedules
2480+
and infrastructure provided.
2481+
2482+
If the simulation fails, the function uses a virtual train to detect conflicts
2483+
with existing train schedules. It then returns both the conflict information
2484+
and the pathfinding result from the virtual train's simulation.
24762485
parameters:
24772486
- name: infra
24782487
in: query
@@ -2619,6 +2628,22 @@ paths:
26192628
type: string
26202629
enum:
26212630
- path_not_found
2631+
- type: object
2632+
required:
2633+
- pathfinding_result
2634+
- conflicts
2635+
- status
2636+
properties:
2637+
conflicts:
2638+
type: array
2639+
items:
2640+
$ref: '#/components/schemas/Conflict'
2641+
pathfinding_result:
2642+
$ref: '#/components/schemas/PathfindingResult'
2643+
status:
2644+
type: string
2645+
enum:
2646+
- conflicts
26222647
- type: object
26232648
required:
26242649
- error

editoast/src/core/conflict_detection.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ConflictDetectionRequest {
2929
pub work_schedules: Option<WorkSchedulesRequest>,
3030
}
3131

32-
#[derive(Debug, Serialize)]
32+
#[derive(Debug, Clone, Serialize)]
3333
pub struct TrainRequirements {
3434
pub start_time: DateTime<Utc>,
3535
pub spacing_requirements: Vec<SpacingRequirement>,
@@ -49,7 +49,7 @@ pub struct ConflictDetectionResponse {
4949
pub conflicts: Vec<Conflict>,
5050
}
5151

52-
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
52+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
5353
pub struct Conflict {
5454
/// List of train ids involved in the conflict
5555
pub train_ids: Vec<i64>,
@@ -70,7 +70,7 @@ pub struct Conflict {
7070
///
7171
/// The start and end time describe the conflicting time span (not the full
7272
/// requirement's time span).
73-
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
73+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
7474
pub struct ConflictRequirement {
7575
pub zone: String,
7676
pub start_time: DateTime<Utc>,

editoast/src/core/simulation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub struct SimulationPath {
160160
pub path_item_positions: Vec<u64>,
161161
}
162162

163-
#[derive(Deserialize, Default, Serialize, Clone, Debug, ToSchema)]
163+
#[derive(Deserialize, Default, PartialEq, Serialize, Clone, Debug, ToSchema)]
164164
pub struct ReportTrain {
165165
/// List of positions of a train
166166
/// Both positions (in mm) and times (in ms) must have the same length
@@ -175,7 +175,7 @@ pub struct ReportTrain {
175175
pub path_item_times: Vec<u64>,
176176
}
177177

178-
#[derive(Deserialize, Default, Serialize, Clone, Debug, ToSchema)]
178+
#[derive(Deserialize, Default, PartialEq, Serialize, Clone, Debug, ToSchema)]
179179
pub struct CompleteReportTrain {
180180
#[serde(flatten)]
181181
pub report_train: ReportTrain,
@@ -301,7 +301,7 @@ pub struct SimulationRequest {
301301
pub electrical_profile_set_id: Option<i64>,
302302
}
303303

304-
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
304+
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, ToSchema)]
305305
#[serde(tag = "status", rename_all = "snake_case")]
306306
// We accepted the difference of memory size taken by variants
307307
// Since there is only on success and others are error cases

editoast/src/core/stdcm.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use serde::Deserialize;
1111
use serde::Serialize;
1212
use utoipa::ToSchema;
1313

14+
use super::conflict_detection::Conflict;
1415
use super::conflict_detection::TrainRequirements;
1516
use super::pathfinding::PathfindingResultSuccess;
1617
use super::pathfinding::TrackRange;
1718
use super::simulation::PhysicsRollingStock;
1819
use super::simulation::SimulationResponse;
1920
use crate::core::{AsCoreRequest, Json};
21+
use crate::views::path::pathfinding::PathfindingResult;
2022

2123
#[derive(Debug, Serialize)]
2224
pub struct STDCMRequest {
@@ -113,7 +115,7 @@ pub struct UndirectedTrackRange {
113115
pub end: u64,
114116
}
115117

116-
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
118+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)]
117119
#[serde(tag = "status", rename_all = "snake_case")]
118120
// We accepted the difference of memory size taken by variants
119121
// Since there is only on success and others are error cases
@@ -125,6 +127,10 @@ pub enum STDCMResponse {
125127
departure_time: DateTime<Utc>,
126128
},
127129
PathNotFound,
130+
Conflicts {
131+
pathfinding_result: PathfindingResult,
132+
conflicts: Vec<Conflict>,
133+
},
128134
PreprocessingSimulationError {
129135
error: SimulationResponse,
130136
},

0 commit comments

Comments
 (0)