Skip to content

Commit

Permalink
editoast: adapt conflicts endpoint to paced trains
Browse files Browse the repository at this point in the history
Signed-off-by: Youness CHRIFI ALAOUI <[email protected]>
  • Loading branch information
younesschrifi committed Feb 13, 2025
1 parent 8aaefd4 commit 9badbe7
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static class ConflictDetectionResult {

@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public static class Conflict {
@Json(name = "train_ids")
public final Collection<Long> trainIds;
@Json(name = "train_schedule_ids")
public final Collection<Long> trainScheduleIds;

public final transient Collection<Long> workScheduleIds;

Expand All @@ -97,12 +97,12 @@ public enum ConflictType {
public final transient Collection<ConflictRequirement> requirements;

public Conflict(
Collection<Long> trainIds,
Collection<Long> trainScheduleIds,
double startTime,
double endTime,
@NotNull ConflictType conflictType,
Collection<ConflictRequirement> requirements) {
this.trainIds = trainIds;
this.trainScheduleIds = trainScheduleIds;
this.workScheduleIds = List.of();
this.startTime = startTime;
this.endTime = endTime;
Expand All @@ -111,13 +111,13 @@ public Conflict(
}

public Conflict(
Collection<Long> trainIds,
Collection<Long> trainScheduleIds,
Collection<Long> workScheduleIds,
double startTime,
double endTime,
@NotNull ConflictType conflictType,
Collection<ConflictRequirement> requirements) {
this.trainIds = trainIds;
this.trainScheduleIds = trainScheduleIds;
this.workScheduleIds = workScheduleIds;
this.startTime = startTime;
this.endTime = endTime;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/fr/sncf/osrd/conflicts/Conflicts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fun mergeMap(
if (--eventCount > 0) continue
newConflicts.add(
Conflict(
key.trainIds.toMutableList(),
key.trainScheduleIds.toMutableList(),
key.workScheduleIds.toMutableList(),
eventBeginning,
event.time,
Expand All @@ -312,7 +312,7 @@ fun mergeMap(
return newConflicts
}

data class ConflictingGroupKey(val trainIds: Set<Long>, val workScheduleIds: Set<Long>)
data class ConflictingGroupKey(val trainScheduleIds: Set<Long>, val workScheduleIds: Set<Long>)

fun mergeConflicts(conflicts: List<Conflict>): List<Conflict> {
// group conflicts by sets of conflicting trains
Expand All @@ -321,7 +321,7 @@ fun mergeConflicts(conflicts: List<Conflict>): List<Conflict> {

for (conflict in conflicts) {
val conflictingGroupKey =
ConflictingGroupKey(conflict.trainIds.toSet(), conflict.workScheduleIds.toSet())
ConflictingGroupKey(conflict.trainScheduleIds.toSet(), conflict.workScheduleIds.toSet())
val conflictingMap =
when (conflict.conflictType) {
ConflictType.SPACING -> spacingResources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private fun makeConflictDetectionResponse(
return ConflictDetectionResponse(
conflicts.map {
Conflict(
it.trainIds,
it.trainScheduleIds,
it.workScheduleIds,
startTime.plus(Duration.ofMillis((it.startTime * 1000).toLong())),
startTime.plus(Duration.ofMillis((it.endTime * 1000).toLong())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConflictDetectionResponse(
*/
class Conflict(
/** List of train IDs for this given conflict. Can't be empty. */
@Json(name = "train_ids") val trainIds: Collection<Long>,
@Json(name = "train_schedule_ids") val trainScheduleIds: Collection<Long>,
/** List of work schedule IDs for this given conflict, if any. */
@Json(name = "work_schedule_ids") val workScheduleIds: Collection<Long>,
/** Start of the conflict time range. This is the *union* of all the conflicting time ranges. */
Expand Down
46 changes: 40 additions & 6 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,7 @@ components:
Conflict:
type: object
required:
- train_ids
- train_schedule_ids
- work_schedule_ids
- start_time
- end_time
Expand All @@ -3842,6 +3842,23 @@ components:
type: string
format: date-time
description: Datetime of the end of the conflict
paced_train_occurrence_ids:
type: array
items:
type: object
required:
- paced_train_id
- index
properties:
index:
type: integer
format: int64
paced_train_id:
type: integer
format: int64
description: |-
List of paced train occurrences involved in the conflict.
Each occurrence is identified by a `paced_train_id` and its `index`
requirements:
type: array
items:
Expand All @@ -3851,12 +3868,12 @@ components:
type: string
format: date-time
description: Datetime of the start of the conflict
train_ids:
train_schedule_ids:
type: array
items:
type: integer
format: int64
description: List of train ids involved in the conflict
description: List of train schedule ids involved in the conflict
work_schedule_ids:
type: array
items:
Expand All @@ -3873,7 +3890,7 @@ components:
items:
type: object
required:
- train_ids
- train_schedule_ids
- work_schedule_ids
- start_time
- end_time
Expand All @@ -3889,6 +3906,23 @@ components:
type: string
format: date-time
description: Datetime of the end of the conflict
paced_train_occurrence_ids:
type: array
items:
type: object
required:
- paced_train_id
- index
properties:
index:
type: integer
format: int64
paced_train_id:
type: integer
format: int64
description: |-
List of paced train occurrences involved in the conflict.
Each occurrence is identified by a `paced_train_id` and its `index`
requirements:
type: array
items:
Expand All @@ -3898,12 +3932,12 @@ components:
type: string
format: date-time
description: Datetime of the start of the conflict
train_ids:
train_schedule_ids:
type: array
items:
type: integer
format: int64
description: List of train ids involved in the conflict
description: List of train schedule ids involved in the conflict
work_schedule_ids:
type: array
items:
Expand Down
15 changes: 13 additions & 2 deletions editoast/src/core/conflict_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ pub struct ConflictDetectionResponse {
pub conflicts: Vec<Conflict>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct PacedTrainOccurrenceId {
paced_train_id: i64,
index: i64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
/// List of train schedule ids involved in the conflict
pub train_schedule_ids: Vec<i64>,
/// List of paced train occurrences involved in the conflict.
/// Each occurrence is identified by a `paced_train_id` and its `index`
#[serde(default)]
#[schema(inline)]
pub paced_train_occurrence_ids: Vec<PacedTrainOccurrenceId>,
/// List of work schedule ids involved in the conflict
pub work_schedule_ids: Vec<i64>,
/// Datetime of the start of the conflict
Expand Down
5 changes: 3 additions & 2 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,10 @@ mod tests {
);
}

fn get_conflict_data(train_ids: Vec<i64>, work_schedule_ids: Vec<i64>) -> Conflict {
fn get_conflict_data(train_schedule_ids: Vec<i64>, work_schedule_ids: Vec<i64>) -> Conflict {
Conflict {
train_ids,
train_schedule_ids,
paced_train_occurrence_ids: vec![],
work_schedule_ids,
start_time: DateTime::from_str("2024-01-01T06:00:00Z")
.expect("Failed to parse datetime"),
Expand Down
6 changes: 4 additions & 2 deletions editoast/src/views/timetable/stdcm/failure_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ impl SimulationFailureHandler {
let conflicts: Vec<_> = conflict_detection_response
.conflicts
.into_iter()
.filter(|conflict| conflict.train_ids.contains(&virtual_train_id))
.filter(|conflict| conflict.train_schedule_ids.contains(&virtual_train_id))
.map(|mut conflict| {
conflict.train_ids.retain(|id| id != &virtual_train_id);
conflict
.train_schedule_ids
.retain(|id| id != &virtual_train_id);
conflict
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/stdcm/utils/formatConflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const formatConflicts = (
)?.name ?? null; // Extract only the ID of the operational point after

const formattedConflict = {
trainIds: conflict.train_ids,
trainIds: conflict.train_schedule_ids,
startDate: dayjs(conflict.start_time).format('DD/MM/YYYY'),
endDate: dayjs(conflict.end_time).format('DD/MM/YYYY'),
startTime: dayjs(conflict.start_time).format('HH:mm'),
Expand Down
10 changes: 8 additions & 2 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3625,12 +3625,18 @@ export type Conflict = {
conflict_type: 'Spacing' | 'Routing';
/** Datetime of the end of the conflict */
end_time: string;
/** List of paced train occurrences involved in the conflict.
Each occurrence is identified by a `paced_train_id` and its `index` */
paced_train_occurrence_ids?: {
index: number;
paced_train_id: number;
}[];
/** List of requirements causing the conflict */
requirements: ConflictRequirement[];
/** Datetime of the start of the conflict */
start_time: string;
/** List of train ids involved in the conflict */
train_ids: number[];
/** List of train schedule ids involved in the conflict */
train_schedule_ids: number[];
/** List of work schedule ids involved in the conflict */
work_schedule_ids: number[];
};
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/conflict/components/ConflictsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ConflictsList = ({
<div className={cx('conflicts-container', expanded && 'expanded')}>
{enrichedConflicts.map((conflict, index) => (
<ConflictCard
key={`${conflict.train_ids.join(', ')}-${conflict.conflict_type}-${index}`}
key={`${conflict.train_schedule_ids.join(', ')}-${conflict.conflict_type}-${index}`}
conflict={conflict}
onConflictClick={onConflictClick}
/>
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/conflict/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default function addTrainNamesToConflicts(

return conflicts.map((conflict) => ({
...conflict,
trainNames: conflict.train_ids.map((id) => trainNameMap[id] || ''),
trainNames: conflict.train_schedule_ids.map((id) => trainNameMap[id] || ''),
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const Timetable = ({
);

const handleConflictClick = (conflict: Conflict) => {
if (conflict.train_ids.length > 0) {
const firstTrainId = conflict.train_ids[0];
if (conflict.train_schedule_ids.length > 0) {
const firstTrainId = conflict.train_schedule_ids[0];
dispatch(updateSelectedTrainId(firstTrainId));
}
};
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/test_stdcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def test_max_running_time(small_scenario: Scenario, fast_rolling_stock: int):
"conflict_type": "Spacing",
"start_time": "2023-01-01T08:00:00Z",
"end_time": "2024-01-01T16:00:00Z",
"train_ids": [],
"paced_train_occurrence_ids": [],
"train_schedule_ids": [],
"work_schedule_ids": [0],
"requirements": [
{
Expand Down

0 comments on commit 9badbe7

Please sign in to comment.