@@ -15,6 +15,7 @@ import fr.sncf.osrd.utils.units.meters
15
15
import kotlin.math.min
16
16
17
17
/* * This class handles the creation of new edges, handling the many optional parameters. */
18
+ @ConsistentCopyVisibility
18
19
data class STDCMEdgeBuilder
19
20
internal constructor (
20
21
/* * Instance used to explore the infra, contains the underlying edge */
@@ -23,26 +24,8 @@ internal constructor(
23
24
private val graph: STDCMGraph ,
24
25
/* * Previous node, used to compute the final path */
25
26
private var prevNode: STDCMNode ,
26
- /* * Start time of the edge */
27
- private var startTime: Double = 0.0 ,
28
-
29
- /* * Start speed, ignored if envelope is specified */
30
- private var startSpeed: Double = 0.0 ,
31
-
32
27
/* * Start offset on the given block */
33
28
private var startOffset: Offset <Block > = Offset (0 .meters),
34
-
35
- /* *
36
- * Maximum delay we can add on any of the previous edges by shifting the departure time, without
37
- * causing a conflict
38
- */
39
- private var prevMaximumAddedDelay: Double = 0.0 ,
40
-
41
- /* *
42
- * Sum of all the delay that has been added in the previous edges by shifting the departure time
43
- */
44
- private var prevAddedDelay: Double = 0.0 ,
45
-
46
29
/* * Envelope to use on the edge, if unspecified we try to go at maximum allowed speed */
47
30
private var envelope: Envelope ? = null ,
48
31
@@ -51,46 +34,7 @@ internal constructor(
51
34
* for the resource generator caches. This is the instance that must be used for next edges
52
35
*/
53
36
private var explorerWithNewEnvelope: InfraExplorerWithEnvelope ? = null ,
54
-
55
- /* * Index of the last waypoint passed by the train */
56
- private var waypointIndex: Int = 0
57
37
) {
58
- // region SETTERS
59
- /* * Sets the start time of the edge */
60
- fun setStartTime (startTime : Double ): STDCMEdgeBuilder {
61
- this .startTime = startTime
62
- return this
63
- }
64
-
65
- /* * Sets the start speed, ignored if the envelope has been specified */
66
- fun setStartSpeed (startSpeed : Double ): STDCMEdgeBuilder {
67
- this .startSpeed = startSpeed
68
- return this
69
- }
70
-
71
- /* * Start offset on the given block */
72
- fun setStartOffset (startOffset : Offset <Block >): STDCMEdgeBuilder {
73
- this .startOffset = startOffset
74
- return this
75
- }
76
-
77
- /* *
78
- * Sets the maximum delay we can add on any of the previous edges by shifting the departure time
79
- */
80
- fun setPrevMaximumAddedDelay (prevMaximumAddedDelay : Double ): STDCMEdgeBuilder {
81
- this .prevMaximumAddedDelay = prevMaximumAddedDelay
82
- return this
83
- }
84
-
85
- /* *
86
- * Sets the sum of all the delay that has been added in the previous edges by shifting the
87
- * departure time
88
- */
89
- fun setPrevAddedDelay (prevAddedDelay : Double ): STDCMEdgeBuilder {
90
- this .prevAddedDelay = prevAddedDelay
91
- return this
92
- }
93
-
94
38
/* *
95
39
* Sets the envelope to use on the edge, if unspecified we try to go at maximum allowed speed
96
40
*/
@@ -99,16 +43,6 @@ internal constructor(
99
43
return this
100
44
}
101
45
102
- /* *
103
- * Sets the waypoint index on the new edge (i.e. the index of the last waypoint passed by the
104
- * train)
105
- */
106
- fun setWaypointIndex (waypointIndex : Int ): STDCMEdgeBuilder {
107
- this .waypointIndex = waypointIndex
108
- return this
109
- }
110
- // endregion SETTERS
111
- // region BUILDERS
112
46
/* *
113
47
* Creates all edges that can be accessed on the given block, using all the parameters
114
48
* specified.
@@ -143,12 +77,10 @@ internal constructor(
143
77
val delay =
144
78
getDelaysPerOpening()
145
79
.stream()
146
- .filter { x: Double -> startTime + x <= timeNextOccupancy }
80
+ .filter { x: Double -> prevNode.time + x <= timeNextOccupancy }
147
81
.max { obj: Double , anotherDouble: Double? -> obj.compareTo(anotherDouble!! ) }
148
82
return delay.map { delayNeeded: Double -> makeSingleEdge(delayNeeded) }.orElse(null )
149
83
}
150
- // endregion BUILDERS
151
- // region UTILITIES
152
84
/* * Returns the envelope to be used for the new edges */
153
85
private fun getEnvelope (): Envelope ? {
154
86
if (envelope == null )
@@ -162,13 +94,13 @@ internal constructor(
162
94
infraExplorer,
163
95
BlockSimulationParameters (
164
96
infraExplorer.getCurrentBlock(),
165
- startSpeed ,
97
+ prevNode.speed ,
166
98
startOffset,
167
99
getStopOnBlock(
168
100
graph,
169
101
infraExplorer.getCurrentBlock(),
170
102
startOffset,
171
- waypointIndex
103
+ prevNode. waypointIndex
172
104
)
173
105
)
174
106
)
@@ -213,7 +145,7 @@ internal constructor(
213
145
private fun getDelaysPerOpening (): Set <Double > {
214
146
return graph.delayManager.minimumDelaysPerOpening(
215
147
getExplorerWithNewEnvelope()!! ,
216
- startTime ,
148
+ prevNode.time ,
217
149
envelope!! ,
218
150
startOffset,
219
151
)
@@ -222,33 +154,37 @@ internal constructor(
222
154
/* * Returns the stop duration at the end of the edge being built, or null if there's no stop */
223
155
private fun getEndStopDuration (): Double? {
224
156
val endAtStop =
225
- getStopOnBlock(graph, infraExplorer.getCurrentBlock(), startOffset, waypointIndex) !=
226
- null
157
+ getStopOnBlock(
158
+ graph,
159
+ infraExplorer.getCurrentBlock(),
160
+ startOffset,
161
+ prevNode.waypointIndex
162
+ ) != null
227
163
if (! endAtStop) return null
228
- return graph.getFirstStopAfterIndex(waypointIndex)!! .duration!!
164
+ return graph.getFirstStopAfterIndex(prevNode. waypointIndex)!! .duration!!
229
165
}
230
166
231
167
/* * Creates a single STDCM edge, adding the given amount of delay */
232
168
private fun makeSingleEdge (delayNeeded : Double ): STDCMEdge ? {
233
169
if (java.lang.Double .isInfinite(delayNeeded)) return null
234
- val actualStartTime = startTime + delayNeeded
170
+ val actualStartTime = prevNode.time + delayNeeded
235
171
236
172
var maximumDelay = 0.0
237
173
var departureTimeShift = delayNeeded
238
- if (delayNeeded > prevMaximumAddedDelay ) {
174
+ if (delayNeeded > prevNode.maximumAddedDelay ) {
239
175
// We can't just shift the departure time, we need an engineering allowance
240
176
// It's not computed yet, we just check that it's possible
241
177
if (! graph.allowanceManager.checkEngineeringAllowance(prevNode, actualStartTime))
242
178
return null
243
179
// We still need to adapt the delay values
244
- departureTimeShift = prevMaximumAddedDelay
180
+ departureTimeShift = prevNode.maximumAddedDelay
245
181
} else {
246
182
maximumDelay =
247
183
min(
248
- prevMaximumAddedDelay - delayNeeded,
184
+ prevNode.maximumAddedDelay - delayNeeded,
249
185
graph.delayManager.findMaximumAddedDelay(
250
186
getExplorerWithNewEnvelope()!! ,
251
- startTime + delayNeeded,
187
+ prevNode.time + delayNeeded,
252
188
startOffset,
253
189
envelope!! ,
254
190
)
@@ -266,14 +202,14 @@ internal constructor(
266
202
departureTimeShift,
267
203
graph.delayManager.findNextOccupancy(
268
204
getExplorerWithNewEnvelope()!! ,
269
- startTime + delayNeeded,
205
+ prevNode.time + delayNeeded,
270
206
startOffset,
271
207
envelope!! ,
272
208
),
273
- prevAddedDelay + departureTimeShift,
209
+ prevNode.totalPrevAddedDelay + departureTimeShift,
274
210
prevNode,
275
211
startOffset,
276
- waypointIndex,
212
+ prevNode. waypointIndex,
277
213
endAtStop,
278
214
envelope!! .beginSpeed,
279
215
envelope!! .endSpeed,
@@ -293,7 +229,7 @@ internal constructor(
293
229
return true
294
230
node = prevEdge.previousNode
295
231
}
296
- } // endregion UTILITIES
232
+ }
297
233
298
234
companion object {
299
235
fun fromNode (
@@ -305,12 +241,7 @@ internal constructor(
305
241
if (node.locationOnEdge != null ) {
306
242
builder.startOffset = node.locationOnEdge
307
243
}
308
- builder.startTime = node.time
309
- builder.startSpeed = node.speed
310
- builder.prevMaximumAddedDelay = node.maximumAddedDelay
311
- builder.prevAddedDelay = node.totalPrevAddedDelay
312
244
builder.prevNode = node
313
- builder.waypointIndex = node.waypointIndex
314
245
return builder
315
246
}
316
247
}
0 commit comments