Skip to content

Commit d184532

Browse files
committed
one-way: update analytics
Signed-off-by: Louis Greiner <[email protected]>
1 parent 7db2551 commit d184532

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

src/app/services/analytics/algorithms/shortest-travel-time-search.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {TrainrunService} from "../../data/trainrun.service";
77
import {ShortestDistanceNode} from "./shortest-distance-node";
88
import {ShortestDistanceEdge} from "./shortest-distance-edge";
99
import {FilterService} from "../../ui/filter.service";
10+
import {Direction} from "src/app/data-structures/business.data.structures";
1011

1112
//
1213
// The shortest travel time search method is based on the Dijkstra Algorithm.
@@ -26,12 +27,12 @@ export class ShortestTravelTimeSearch {
2627
this.simulationChangeTrainPenalty = 0;
2728
}
2829

29-
private static getInitalShortestDistanceEdges(
30+
private static getInitialShortestDistanceEdges(
3031
node: Node,
3132
initDepartureTime: number,
3233
): ShortestDistanceEdge[] {
33-
const initalEdges: ShortestDistanceEdge[] = [];
34-
initalEdges.push(
34+
const initialEdges: ShortestDistanceEdge[] = [];
35+
initialEdges.push(
3536
new ShortestDistanceEdge(
3637
node,
3738
node,
@@ -40,7 +41,7 @@ export class ShortestTravelTimeSearch {
4041
[],
4142
),
4243
);
43-
return initalEdges;
44+
return initialEdges;
4445
}
4546

4647
private static correctHourOverflowFromToTime(
@@ -143,21 +144,31 @@ export class ShortestTravelTimeSearch {
143144
return !trans.getIsNonStopTransit();
144145
}
145146

147+
private static isDirectionCompatible(
148+
currentNode: Node,
149+
departureTrainrunSection: TrainrunSection,
150+
): boolean {
151+
// ROUND_TRIP: always compatible
152+
// ONE_WAY: only allow if currentNode is the source node
153+
return departureTrainrunSection.getTrainrun().isRoundTrip() ||
154+
departureTrainrunSection.getSourceNodeId() === currentNode.getId();
155+
}
156+
146157
calculateShortestDistanceNodesFromStartingNode(
147158
departureNodeId: number,
148159
): ShortestDistanceNode[] {
149160
const departureNode = this.nodeService.getNodeFromId(departureNodeId);
150-
const initalShortestDistanceNode = new ShortestDistanceNode(
161+
const initialShortestDistanceNode = new ShortestDistanceNode(
151162
departureNode,
152163
0,
153164
);
154165
const shortestDistanceEdgeStack: ShortestDistanceEdge[] =
155-
ShortestTravelTimeSearch.getInitalShortestDistanceEdges(
166+
ShortestTravelTimeSearch.getInitialShortestDistanceEdges(
156167
departureNode,
157168
this.getSimulationDepartureMinute(),
158169
);
159170
const initialFinalShortestDistanceNodes: ShortestDistanceNode[] = [
160-
initalShortestDistanceNode,
171+
initialShortestDistanceNode,
161172
];
162173
return Object.assign(
163174
[],
@@ -175,23 +186,23 @@ export class ShortestTravelTimeSearch {
175186
const departureNode = this.nodeService.getNodeFromId(departureNodeId);
176187
const departureTrainrunSection =
177188
this.trainrunSectionService.getTrainrunSectionFromId(trainrunSectionId);
178-
const initalShortestDistanceNodeFrom = new ShortestDistanceNode(
189+
const initialShortestDistanceNodeFrom = new ShortestDistanceNode(
179190
departureNode,
180191
0,
181192
);
182-
const initalShortestDistanceNodeTo = new ShortestDistanceNode(
193+
const initialShortestDistanceNodeTo = new ShortestDistanceNode(
183194
departureNode.getOppositeNode(departureTrainrunSection),
184195
departureTrainrunSection.getTravelTime(),
185196
);
186-
initalShortestDistanceNodeTo.setPath([departureTrainrunSection]);
197+
initialShortestDistanceNodeTo.setPath([departureTrainrunSection]);
187198
const outgoingEdge = this.getOutgoingEdge(
188199
departureTrainrunSection,
189200
departureNode,
190201
);
191202
const shortestDistanceEdgeStack: ShortestDistanceEdge[] = [outgoingEdge];
192203
let initialFinalShortestDistanceNodes: ShortestDistanceNode[] = [
193-
initalShortestDistanceNodeFrom,
194-
initalShortestDistanceNodeTo,
204+
initialShortestDistanceNodeFrom,
205+
initialShortestDistanceNodeTo,
195206
];
196207
initialFinalShortestDistanceNodes =
197208
ShortestTravelTimeSearch.updateFinalAndStackData(
@@ -312,12 +323,19 @@ export class ShortestTravelTimeSearch {
312323
incomingEdge
313324
.getToNode()
314325
.getPorts()
315-
.filter((p: Port) =>
316-
ShortestTravelTimeSearch.isEdgeChangeAllowed(
326+
.filter((p: Port) => {
327+
// only allow sections that go "away" from the current node
328+
const isDirectionCompatible = ShortestTravelTimeSearch.isDirectionCompatible(
329+
incomingEdge.getToNode(),
330+
p.getTrainrunSection(),
331+
);
332+
const isEdgeChangeAllowed = ShortestTravelTimeSearch.isEdgeChangeAllowed(
317333
incomingEdge,
318334
p.getTrainrunSection(),
319-
),
320-
)
335+
);
336+
337+
return isDirectionCompatible && isEdgeChangeAllowed;
338+
})
321339
.forEach((p: Port) => {
322340
const outgoingTrainrunSection: TrainrunSection =
323341
p.getTrainrunSection();
@@ -363,7 +381,7 @@ export class ShortestTravelTimeSearch {
363381
}
364382
});
365383

366-
// get next edge to visite -> visited the closed (smallest distance) next edge before others (pop)
384+
// get next edge to visit -> visited the closed (smallest distance) next edge before others (pop)
367385
incomingEdge = this.getNextShortestDistanceEdge(
368386
shortestDistanceEdgeStack,
369387
);

0 commit comments

Comments
 (0)