Skip to content

Commit

Permalink
editoast: add call to conflict detection core endpoint
Browse files Browse the repository at this point in the history
- Handle batch simulation for better performances
- Rename signal projection endpoint url
  • Loading branch information
flomonster committed May 2, 2024
1 parent 6a31fd8 commit 73c143f
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 226 deletions.
179 changes: 133 additions & 46 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,41 @@ components:
- end_time
- conflict_type
type: object
ConflictDetectionResponse:
properties:
conflicts:
description: List of conflicts detected
items:
properties:
conflict_type:
enum:
- Spacing
- Routing
type: string
end_time:
description: Datetime of the end of the conflict
format: date-time
type: string
start_time:
description: Datetime of the start of the conflict
format: date-time
type: string
train_ids:
description: List of train ids involved in the conflict
items:
format: int64
type: integer
type: array
required:
- train_ids
- start_time
- end_time
- conflict_type
type: object
type: array
required:
- conflicts
type: object
ConflictType:
enum:
- Spacing
Expand All @@ -229,25 +264,26 @@ components:
ConflictV2:
properties:
conflict_type:
$ref: '#/components/schemas/ConflictType'
enum:
- Spacing
- Routing
type: string
end_time:
description: Datetime of the end of the conflict
format: date-time
type: string
start_time:
description: Datetime of the start of the conflict
format: date-time
type: string
train_ids:
description: List of train ids involved in the conflict
items:
format: int64
type: integer
type: array
train_names:
items:
type: string
type: array
required:
- train_ids
- train_names
- start_time
- end_time
- conflict_type
Expand Down Expand Up @@ -862,6 +898,7 @@ components:
- $ref: '#/components/schemas/EditoastStdcmErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastStudyErrorNotFound'
- $ref: '#/components/schemas/EditoastStudyErrorStartDateAfterEndDate'
- $ref: '#/components/schemas/EditoastTimetableErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastTimetableErrorInfraNotLoaded'
- $ref: '#/components/schemas/EditoastTimetableErrorNotFound'
- $ref: '#/components/schemas/EditoastTimetableErrorNotFound'
Expand Down Expand Up @@ -2425,6 +2462,30 @@ components:
- status
- message
type: object
EditoastTimetableErrorInfraNotFound:
properties:
context:
properties:
infra_id:
type: integer
required:
- infra_id
type: object
message:
type: string
status:
enum:
- 404
type: integer
type:
enum:
- editoast:timetable:InfraNotFound
type: string
required:
- type
- status
- message
type: object
EditoastTimetableErrorInfraNotLoaded:
properties:
context:
Expand Down Expand Up @@ -5011,6 +5072,17 @@ components:
- rolling_stock_name
- status
type: object
- properties:
core_error:
$ref: '#/components/schemas/InternalError'
status:
enum:
- pathfinding_failed
type: string
required:
- core_error
- status
type: object
PathfindingStep:
properties:
duration:
Expand Down Expand Up @@ -7097,7 +7169,7 @@ components:
- electrification_ranges
- power_restriction_ranges
type: object
SimulationResult:
SimulationResponse:
oneOf:
- properties:
base:
Expand Down Expand Up @@ -7210,40 +7282,56 @@ components:
SimulationSummaryResult:
oneOf:
- properties:
Success:
properties:
energy_consumption:
format: double
type: number
length:
format: int64
minimum: 0
type: integer
time:
format: int64
minimum: 0
type: integer
required:
- length
- time
- energy_consumption
type: object
energy_consumption:
format: double
type: number
length:
format: int64
minimum: 0
type: integer
status:
enum:
- success
type: string
time:
format: int64
minimum: 0
type: integer
required:
- Success
- length
- time
- energy_consumption
- status
type: object
- enum:
- PathfindingFailed
type: string
- properties:
SimulationFailed:
properties:
error_type:
type: string
required:
- error_type
type: object
status:
enum:
- pathfinding_not_found
type: string
required:
- SimulationFailed
- status
type: object
- properties:
error_type:
type: string
status:
enum:
- pathfinding_failed
type: string
required:
- error_type
- status
type: object
- properties:
error_type:
type: string
status:
enum:
- simulation_failed
type: string
required:
- error_type
- status
type: object
SingleSimulationRequest:
allOf:
Expand Down Expand Up @@ -11636,15 +11724,14 @@ paths:
get:
description: Retrieve the list of conflict of the timetable (invalid trains are ignored)
parameters:
- description: The timetable id
- description: A timetable ID
in: path
name: id
required: true
schema:
format: int64
type: integer
- description: The infra id
in: query
- in: query
name: infra_id
required: true
schema:
Expand All @@ -11658,7 +11745,7 @@ paths:
items:
$ref: '#/components/schemas/ConflictV2'
type: array
description: list of conflict
description: List of conflict
summary: Retrieve the list of conflict of the timetable (invalid trains are ignored)
tags:
- timetablev2
Expand Down Expand Up @@ -11756,8 +11843,8 @@ paths:
/v2/train_schedule/simulation_summary/:
get:
description: |-
Retrieve simulation information for a given train list.
Useful for finding out whether pathfinding/simulation was successful.
Associate each train id with its simulation summary response
If the simulation fails, it associates the reason: pathfinding failed or running time failed
parameters:
- description: The infra id
in: query
Expand All @@ -11783,8 +11870,8 @@ paths:
additionalProperties:
$ref: '#/components/schemas/SimulationSummaryResult'
type: object
description: Project Path Output
summary: Retrieve simulation information for a given train list.
description: Associate each train id with its simulation summary
summary: Associate each train id with its simulation summary response
tags:
- train_schedulev2
/v2/train_schedule/{id}/:
Expand Down Expand Up @@ -11887,7 +11974,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/SimulationResult'
$ref: '#/components/schemas/SimulationResponse'
description: Simulation Output
summary: Retrieve the space, speed and time curve of a given train
tags:
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/core/conflicts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::Deserialize;
use serde::Serialize;

use super::v2::conflict_detection::ConflictType;
use super::AsCoreRequest;
use super::Json;
use crate::models::RoutingRequirement;
use crate::models::SpacingRequirement;
use crate::views::timetable::ConflictType;

#[derive(Debug, Serialize)]
pub struct ConflicDetectionRequest {
Expand Down
1 change: 1 addition & 0 deletions editoast/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ editoast_common::schemas! {
simulation::schemas(),
v2::simulation::schemas(),
v2::pathfinding::schemas(),
v2::conflict_detection::schemas(),
}

const MAX_RETRIES: u8 = 5;
Expand Down
63 changes: 63 additions & 0 deletions editoast/src/core/v2/conflict_detection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use chrono::DateTime;
use chrono::Utc;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use utoipa::ToSchema;

use crate::core::{AsCoreRequest, Json};

use super::simulation::RoutingRequirement;
use super::simulation::SpacingRequirement;

editoast_common::schemas! {
ConflictDetectionResponse,
Conflict,
}

#[derive(Debug, Serialize)]
pub struct ConflictDetectionRequest {
/// List of requirements for each train
pub trains_requirements: HashMap<i64, TrainRequirements>,
}

#[derive(Debug, Serialize)]
pub struct TrainRequirements {
pub start_time: DateTime<Utc>,
pub spacing_requirements: Vec<SpacingRequirement>,
pub routing_requirements: Vec<RoutingRequirement>,
}

#[derive(Debug, Deserialize, ToSchema)]
pub struct ConflictDetectionResponse {
/// List of conflicts detected
#[schema(inline)]
pub conflicts: Vec<Conflict>,
}

#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[schema(as=ConflictV2)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
/// Datetime of the start of the conflict
pub start_time: DateTime<Utc>,
/// Datetime of the end of the conflict
pub end_time: DateTime<Utc>,
/// Type of the conflict
#[schema(inline)]
pub conflict_type: ConflictType,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
pub enum ConflictType {
/// Conflict caused by two trains being too close to each other
Spacing,
/// Conflict caused by two trains requiring incompatible routes at the same time
Routing,
}

impl AsCoreRequest<Json<ConflictDetectionResponse>> for ConflictDetectionRequest {
const METHOD: reqwest::Method = reqwest::Method::POST;
const URL_PATH: &'static str = "/v2/conflict_detection";
}
3 changes: 2 additions & 1 deletion editoast/src/core/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod conflict_detection;
pub mod path_properties;
pub mod pathfinding;
pub mod signal_updates;
pub mod signal_projection;
pub mod simulation;
4 changes: 4 additions & 0 deletions editoast/src/core/v2/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::Serialize;
use utoipa::ToSchema;

use crate::core::{AsCoreRequest, Json};
use crate::error::InternalError;

editoast_common::schemas! {
PathfindingResult,
Expand Down Expand Up @@ -96,6 +97,9 @@ pub enum PathfindingResult {
RollingStockNotFound {
rolling_stock_name: String,
},
PathfindingFailed {
core_error: InternalError,
},
}

/// An oriented range on a track section.
Expand Down
Loading

0 comments on commit 73c143f

Please sign in to comment.