-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathstdcm.rs
141 lines (127 loc) · 4.93 KB
/
stdcm.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::collections::HashMap;
use chrono::DateTime;
use chrono::Utc;
use editoast_schemas::infra::TrackOffset;
use editoast_schemas::rolling_stock::LoadingGaugeType;
use editoast_schemas::rolling_stock::RollingStockSupportedSignalingSystems;
use editoast_schemas::train_schedule::Comfort;
use editoast_schemas::train_schedule::MarginValue;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
use super::conflict_detection::TrainRequirements;
use super::pathfinding::PathfindingResultSuccess;
use super::pathfinding::TrackRange;
use super::simulation::PhysicsConsist;
use super::simulation::SimulationResponse;
use crate::core::AsCoreRequest;
use crate::core::Json;
#[derive(Debug, Serialize)]
pub struct Request {
/// Infrastructure id
pub infra: i64,
/// Infrastructure expected version
pub expected_version: String,
// Pathfinding inputs
/// List of waypoints. Each waypoint is a list of track offset.
pub path_items: Vec<PathItem>,
/// The loading gauge of the rolling stock
pub rolling_stock_loading_gauge: LoadingGaugeType,
/// List of supported signaling systems
pub rolling_stock_supported_signaling_systems: RollingStockSupportedSignalingSystems,
// Simulation inputs
/// The comfort of the train
pub comfort: Comfort,
pub speed_limit_tag: Option<String>,
pub rolling_stock: PhysicsConsist,
// STDCM search parameters
pub trains_requirements: HashMap<i64, TrainRequirements>,
/// Numerical integration time step in milliseconds. Use default value if not specified.
pub time_step: Option<u64>,
pub start_time: DateTime<Utc>,
/// Maximum departure delay in milliseconds.
pub maximum_departure_delay: u64,
/// Maximum run time of the simulation in milliseconds
pub maximum_run_time: u64,
/// Gap between the created train and previous trains in milliseconds
pub time_gap_before: u64,
/// Gap between the created train and following trains in milliseconds
pub time_gap_after: u64,
/// Margin to apply to the whole train
pub margin: Option<MarginValue>,
/// List of planned work schedules
pub work_schedules: Vec<WorkSchedule>,
/// List of applicable temporary speed limits between the train departure and arrival
pub temporary_speed_limits: Vec<TemporarySpeedLimit>,
}
#[derive(Debug, Serialize)]
pub struct PathItem {
/// The track offsets of the path item
pub locations: Vec<TrackOffset>,
/// Stop duration in milliseconds. None if the train does not stop at this path item.
pub stop_duration: Option<u64>,
/// If specified, describes when the train may arrive at the location
pub step_timing_data: Option<StepTimingData>,
}
/// Contains the data of a step timing, when it is specified
#[derive(Debug, Serialize)]
pub struct StepTimingData {
/// Time the train should arrive at this point
pub arrival_time: DateTime<Utc>,
/// Tolerance for the arrival time, when it arrives before the expected time, in ms
pub arrival_time_tolerance_before: u64,
/// Tolerance for the arrival time, when it arrives after the expected time, in ms
pub arrival_time_tolerance_after: u64,
}
/// Lighter description of a work schedule, with only the relevant information for core
#[derive(Debug, Serialize)]
pub struct WorkSchedule {
/// Start time as a time delta from the stdcm start time in ms
pub start_time: u64,
/// End time as a time delta from the stdcm start time in ms
pub end_time: u64,
/// List of unavailable track ranges
pub track_ranges: Vec<UndirectedTrackRange>,
}
/// Lighter description of a work schedule with only the relevant information for core
#[derive(Debug, Serialize)]
pub struct TemporarySpeedLimit {
/// Speed limitation in m/s
pub speed_limit: f64,
/// Track ranges on which the speed limitation applies
pub track_ranges: Vec<TrackRange>,
}
/// A range on a track section.
/// `begin` is always less than `end`.
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema, Hash, PartialEq, Eq)]
pub struct UndirectedTrackRange {
/// The track section identifier.
pub track_section: String,
/// The beginning of the range in mm.
pub begin: u64,
/// The end of the range in mm.
pub end: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[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
#[allow(clippy::large_enum_variant)]
pub enum Response {
Success {
simulation: SimulationResponse,
path: PathfindingResultSuccess,
departure_time: DateTime<Utc>,
},
PathNotFound,
PreprocessingSimulationError {
error: SimulationResponse,
},
}
impl AsCoreRequest<Json<Response>> for Request {
const METHOD: reqwest::Method = reqwest::Method::POST;
const URL_PATH: &'static str = "/v2/stdcm";
fn infra_id(&self) -> Option<i64> {
Some(self.infra)
}
}