@@ -4,6 +4,7 @@ import com.carrotsearch.hppc.IntArrayList
4
4
import com.squareup.moshi.Json
5
5
import fr.sncf.osrd.api.ConflictDetectionEndpoint.ConflictDetectionResult.Conflict
6
6
import fr.sncf.osrd.api.ConflictDetectionEndpoint.ConflictDetectionResult.Conflict.ConflictType
7
+ import fr.sncf.osrd.api.ConflictDetectionEndpoint.ConflictDetectionResult.ConflictRequirement
7
8
import fr.sncf.osrd.standalone_sim.result.ResultTrain.RoutingRequirement
8
9
import fr.sncf.osrd.standalone_sim.result.ResultTrain.SpacingRequirement
9
10
import kotlin.math.max
@@ -171,12 +172,15 @@ class IncrementalConflictDetectorImpl(trainRequirements: List<TrainRequirements>
171
172
// look for requirement times overlaps.
172
173
// as spacing requirements are exclusive, any overlap is a conflict
173
174
val res = mutableListOf<Conflict >()
174
- for (requirements in spacingZoneRequirements.values ) {
175
- for (conflictGroup in detectRequirementConflicts(requirements ) { _, _ -> true }) {
175
+ for (entry in spacingZoneRequirements) {
176
+ for (conflictGroup in detectRequirementConflicts(entry.value ) { _, _ -> true }) {
176
177
val trains = conflictGroup.map { it.trainId }
177
178
val beginTime = conflictGroup.minBy { it.beginTime }.beginTime
178
179
val endTime = conflictGroup.maxBy { it.endTime }.endTime
179
- res.add(Conflict (trains, beginTime, endTime, ConflictType .SPACING ))
180
+ val conflictReq = ConflictRequirement (entry.key, beginTime, endTime)
181
+ res.add(
182
+ Conflict (trains, beginTime, endTime, ConflictType .SPACING , listOf (conflictReq))
183
+ )
180
184
}
181
185
}
182
186
return res
@@ -185,13 +189,16 @@ class IncrementalConflictDetectorImpl(trainRequirements: List<TrainRequirements>
185
189
private fun detectRoutingConflicts (): List <Conflict > {
186
190
// for each zone, check compatibility of overlapping requirements
187
191
val res = mutableListOf<Conflict >()
188
- for (requirements in routingZoneRequirements.values ) {
192
+ for (entry in routingZoneRequirements) {
189
193
for (conflictGroup in
190
- detectRequirementConflicts(requirements ) { a, b -> a.config != b.config }) {
194
+ detectRequirementConflicts(entry.value ) { a, b -> a.config != b.config }) {
191
195
val trains = conflictGroup.map { it.trainId }
192
196
val beginTime = conflictGroup.minBy { it.beginTime }.beginTime
193
197
val endTime = conflictGroup.maxBy { it.endTime }.endTime
194
- res.add(Conflict (trains, beginTime, endTime, ConflictType .ROUTING ))
198
+ val conflictReq = ConflictRequirement (entry.key, beginTime, endTime)
199
+ res.add(
200
+ Conflict (trains, beginTime, endTime, ConflictType .ROUTING , listOf (conflictReq))
201
+ )
195
202
}
196
203
}
197
204
return res
@@ -218,9 +225,16 @@ class IncrementalConflictDetectorImpl(trainRequirements: List<TrainRequirements>
218
225
for (otherReq in requirements) {
219
226
val beginTime = max(req.beginTime, otherReq.beginTime)
220
227
val endTime = min(req.endTime, otherReq.endTime)
228
+ val conflictReq = ConflictRequirement (req.zone, beginTime, endTime)
221
229
if (beginTime < endTime)
222
230
res.add(
223
- Conflict (listOf (otherReq.trainId), beginTime, endTime, ConflictType .SPACING )
231
+ Conflict (
232
+ listOf (otherReq.trainId),
233
+ beginTime,
234
+ endTime,
235
+ ConflictType .SPACING ,
236
+ listOf (conflictReq)
237
+ )
224
238
)
225
239
}
226
240
@@ -238,9 +252,16 @@ class IncrementalConflictDetectorImpl(trainRequirements: List<TrainRequirements>
238
252
if (otherReq.config == zoneReqConfig) continue
239
253
val beginTime = max(req.beginTime, otherReq.beginTime)
240
254
val endTime = min(zoneReq.endTime, otherReq.endTime)
255
+ val conflictReq = ConflictRequirement (zoneReq.zone, beginTime, endTime)
241
256
if (beginTime < endTime)
242
257
res.add(
243
- Conflict (listOf (otherReq.trainId), beginTime, endTime, ConflictType .ROUTING )
258
+ Conflict (
259
+ listOf (otherReq.trainId),
260
+ beginTime,
261
+ endTime,
262
+ ConflictType .ROUTING ,
263
+ listOf (conflictReq)
264
+ )
244
265
)
245
266
}
246
267
}
@@ -421,7 +442,11 @@ enum class EventType {
421
442
END
422
443
}
423
444
424
- class Event (val eventType : EventType , val time : Double ) : Comparable<Event> {
445
+ class Event (
446
+ val eventType : EventType ,
447
+ val time : Double ,
448
+ val requirements : Collection <ConflictRequirement >
449
+ ) : Comparable<Event> {
425
450
override fun compareTo (other : Event ): Int {
426
451
val timeDelta = this .time.compareTo(other.time)
427
452
if (timeDelta != 0 ) return timeDelta
@@ -443,28 +468,32 @@ fun mergeMap(
443
468
// create an event list and sort it
444
469
val events = mutableListOf<Event >()
445
470
for (conflict in conflicts) {
446
- events.add(Event (EventType .BEGIN , conflict.startTime))
447
- events.add(Event (EventType .END , conflict.endTime))
471
+ events.add(Event (EventType .BEGIN , conflict.startTime, conflict.requirements ))
472
+ events.add(Event (EventType .END , conflict.endTime, conflict.requirements ))
448
473
}
449
474
450
475
events.sort()
451
476
var eventCount = 0
452
477
var eventBeginning = 0.0
478
+ var conflictReqs = mutableListOf<ConflictRequirement >()
453
479
for (event in events) {
454
480
when (event.eventType) {
455
481
EventType .BEGIN -> {
456
482
if (++ eventCount == 1 ) eventBeginning = event.time
483
+ conflictReqs.addAll(event.requirements)
457
484
}
458
485
EventType .END -> {
459
- if (-- eventCount == 0 )
460
- newConflicts.add(
461
- Conflict (
462
- trainIds.toMutableList(),
463
- eventBeginning,
464
- event.time,
465
- conflictType
466
- )
486
+ if (-- eventCount > 0 ) continue
487
+ newConflicts.add(
488
+ Conflict (
489
+ trainIds.toMutableList(),
490
+ eventBeginning,
491
+ event.time,
492
+ conflictType,
493
+ conflictReqs
467
494
)
495
+ )
496
+ conflictReqs = mutableListOf ()
468
497
}
469
498
}
470
499
}
0 commit comments