Skip to content

Commit

Permalink
editoast: return conflicts list when STDCM request fails
Browse files Browse the repository at this point in the history
Signed-off-by: hamz2a <atrari.hamza@gmail.com>
  • Loading branch information
hamz2a committed Oct 24, 2024
1 parent 5977531 commit a19b328
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 82 deletions.
27 changes: 26 additions & 1 deletion editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,16 @@ paths:
post:
tags:
- stdcm
summary: Compute a STDCM and return the simulation result
summary: This function computes a STDCM and returns the result.
description: |-
It first checks user authorization, then retrieves timetable, infrastructure,
train schedules, and rolling stock data, and runs train simulations.
The result contains the simulation output based on the train schedules
and infrastructure provided.
If the simulation fails, the function uses a virtual train to detect conflicts
with existing train schedules. It then returns both the conflict information
and the pathfinding result from the virtual train's simulation.
parameters:
- name: infra
in: query
Expand Down Expand Up @@ -2619,6 +2628,22 @@ paths:
type: string
enum:
- path_not_found
- type: object
required:
- pathfinding_result
- conflicts
- status
properties:
conflicts:
type: array
items:
$ref: '#/components/schemas/Conflict'
pathfinding_result:
$ref: '#/components/schemas/PathfindingResult'
status:
type: string
enum:
- conflicts
- type: object
required:
- error
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/core/conflict_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ConflictDetectionRequest {
pub work_schedules: Option<WorkSchedulesRequest>,
}

#[derive(Debug, Serialize)]
#[derive(Debug, Clone, Serialize)]
pub struct TrainRequirements {
pub start_time: DateTime<Utc>,
pub spacing_requirements: Vec<SpacingRequirement>,
Expand All @@ -49,7 +49,7 @@ pub struct ConflictDetectionResponse {
pub conflicts: Vec<Conflict>,
}

#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
Expand All @@ -70,7 +70,7 @@ pub struct Conflict {
///
/// The start and end time describe the conflicting time span (not the full
/// requirement's time span).
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct ConflictRequirement {
pub zone: String,
pub start_time: DateTime<Utc>,
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub struct SimulationPath {
pub path_item_positions: Vec<u64>,
}

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

#[derive(Deserialize, Default, Serialize, Clone, Debug, ToSchema)]
#[derive(Deserialize, Default, PartialEq, Serialize, Clone, Debug, ToSchema)]
pub struct CompleteReportTrain {
#[serde(flatten)]
pub report_train: ReportTrain,
Expand Down Expand Up @@ -301,7 +301,7 @@ pub struct SimulationRequest {
pub electrical_profile_set_id: Option<i64>,
}

#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, ToSchema)]
#[serde(tag = "status", rename_all = "snake_case")]
// We accepted the difference of memory size taken by variants
// Since there is only on success and others are error cases
Expand Down
8 changes: 7 additions & 1 deletion editoast/src/core/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::conflict_detection::Conflict;
use super::conflict_detection::TrainRequirements;
use super::pathfinding::PathfindingResultSuccess;
use super::pathfinding::TrackRange;
use super::simulation::PhysicsRollingStock;
use super::simulation::SimulationResponse;
use crate::core::{AsCoreRequest, Json};
use crate::views::path::pathfinding::PathfindingResult;

#[derive(Debug, Serialize)]
pub struct STDCMRequest {
Expand Down Expand Up @@ -113,7 +115,7 @@ pub struct UndirectedTrackRange {
pub end: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)]
#[serde(tag = "status", rename_all = "snake_case")]
// We accepted the difference of memory size taken by variants
// Since there is only on success and others are error cases
Expand All @@ -125,6 +127,10 @@ pub enum STDCMResponse {
departure_time: DateTime<Utc>,
},
PathNotFound,
Conflicts {
pathfinding_result: PathfindingResult,
conflicts: Vec<Conflict>,
},
PreprocessingSimulationError {
error: SimulationResponse,
},
Expand Down
Loading

0 comments on commit a19b328

Please sign in to comment.