Skip to content

Commit 6ba4a9e

Browse files
committed
feat: correctly update arrival/departure/travel times when a node is masked
The behavior is pretty much the same as when a node is a non-stop node, except when updating the travel time, because we need to take into account the stop times of the reduced nodes. Signed-off-by: Clara Ni <[email protected]>
1 parent c33bcb8 commit 6ba4a9e

File tree

5 files changed

+48
-22
lines changed

5 files changed

+48
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class ShortestTravelTimeSearch {
352352

353353
private getOutgoingEdge(trainrunSection: TrainrunSection, node: Node): ShortestDistanceEdge {
354354
const path: TrainrunSection[] = [];
355-
const iterator = this.trainrunService.getNonStopIterator(node, trainrunSection);
355+
const iterator = this.trainrunService.getNextExpandedStopIterator(node, trainrunSection);
356356

357357
while (iterator.hasNext()) {
358358
iterator.next();

src/app/services/data/trainrun.service.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {GeneralViewFunctions} from "../../view/util/generalViewFunctions";
2020
import {
2121
BackwardNonStopTrainrunIterator,
2222
BackwardTrainrunIterator,
23-
NonStopTrainrunIterator,
23+
NextExpandedStopIterator,
2424
TrainrunIterator,
2525
} from "../util/trainrun.iterator";
2626
import {LogService} from "../../logger/log.service";
@@ -663,7 +663,7 @@ export class TrainrunService {
663663
}
664664

665665
getLastNonStopNode(node: Node, trainrunSection: TrainrunSection): Node {
666-
const iterator = this.getNonStopIterator(node, trainrunSection);
666+
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
667667
while (iterator.hasNext()) {
668668
iterator.next();
669669
}
@@ -680,7 +680,7 @@ export class TrainrunService {
680680
}
681681

682682
getLastNonStopTrainrunSection(node: Node, trainrunSection: TrainrunSection): TrainrunSection {
683-
const iterator = this.getNonStopIterator(node, trainrunSection);
683+
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
684684
while (iterator.hasNext()) {
685685
iterator.next();
686686
}
@@ -725,7 +725,7 @@ export class TrainrunService {
725725

726726
sumTravelTimeUpToLastNonStopNode(node: Node, trainrunSection: TrainrunSection): number {
727727
let summedTravelTime = 0;
728-
const iterator = this.getNonStopIterator(node, trainrunSection);
728+
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
729729
while (iterator.hasNext()) {
730730
const nextPair = iterator.next();
731731
summedTravelTime += nextPair.trainrunSection.getTravelTime();
@@ -734,7 +734,10 @@ export class TrainrunService {
734734
}
735735

736736
getCumulativeTravelTime(trainrunSection: TrainrunSection) {
737-
const iterator = this.getNonStopIterator(trainrunSection.getSourceNode(), trainrunSection);
737+
const iterator = this.getNextExpandedStopIterator(
738+
trainrunSection.getSourceNode(),
739+
trainrunSection,
740+
);
738741
while (iterator.hasNext()) {
739742
iterator.next();
740743
}
@@ -753,7 +756,7 @@ export class TrainrunService {
753756
},
754757
];
755758
let summedTravelTime = 0;
756-
const iterator = this.getNonStopIterator(n, ts);
759+
const iterator = this.getNextExpandedStopIterator(n, ts);
757760
while (iterator.hasNext()) {
758761
const nextPair = iterator.next();
759762
summedTravelTime += nextPair.trainrunSection.getTravelTime();
@@ -767,7 +770,10 @@ export class TrainrunService {
767770
}
768771

769772
getCumulativeTravelTimeAndNodePath(trainrunSection: TrainrunSection) {
770-
const iterator = this.getNonStopIterator(trainrunSection.getSourceNode(), trainrunSection);
773+
const iterator = this.getNextExpandedStopIterator(
774+
trainrunSection.getSourceNode(),
775+
trainrunSection,
776+
);
771777
while (iterator.hasNext()) {
772778
iterator.next();
773779
}
@@ -788,8 +794,8 @@ export class TrainrunService {
788794
return new TrainrunIterator(this.logService, node, trainrunSection);
789795
}
790796

791-
public getNonStopIterator(node: Node, trainrunSection: TrainrunSection) {
792-
return new NonStopTrainrunIterator(this.logService, node, trainrunSection);
797+
public getNextExpandedStopIterator(node: Node, trainrunSection: TrainrunSection) {
798+
return new NextExpandedStopIterator(this.logService, node, trainrunSection);
793799
}
794800

795801
public getBackwardIterator(node: Node, trainrunSection: TrainrunSection) {

src/app/services/data/trainrunsection.service.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class TrainrunSectionService implements OnDestroy {
324324
node: Node,
325325
stopNodeId: number,
326326
) {
327-
const iterator = this.trainrunService.getNonStopIterator(node, trainrunSection);
327+
const iterator = this.trainrunService.getNextExpandedStopIterator(node, trainrunSection);
328328
while (iterator.hasNext()) {
329329
iterator.next();
330330
if (iterator.current().node.getId() === stopNodeId) {
@@ -878,12 +878,30 @@ export class TrainrunSectionService implements OnDestroy {
878878
const trsTimeStructure = TrainrunsectionHelper.getDefaultTimeStructure(timeStructure);
879879
let summedTravelTime = 0;
880880

881-
const iterator = this.trainrunService.getNonStopIterator(leftNode, trs);
881+
const iterator = this.trainrunService.getNextExpandedStopIterator(leftNode, trs);
882+
let prevInitialLeftArrival: number = null;
883+
let stopTime: number;
882884
while (iterator.hasNext()) {
883885
const nextPair = iterator.next();
886+
const rightIsTarget =
887+
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();
888+
889+
if (prevInitialLeftArrival !== null) {
890+
stopTime = MathUtils.mod60(
891+
(rightIsTarget
892+
? nextPair.trainrunSection.getSourceDeparture()
893+
: nextPair.trainrunSection.getTargetDeparture()) - prevInitialLeftArrival,
894+
);
895+
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime + stopTime;
896+
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime - stopTime;
897+
}
898+
prevInitialLeftArrival = rightIsTarget
899+
? nextPair.trainrunSection.getTargetArrival()
900+
: nextPair.trainrunSection.getSourceArrival();
884901

885-
const isLastNode = !nextPair.node.isNonStop(nextPair.trainrunSection);
886-
trsTimeStructure.travelTime = isLastNode
902+
const isLastRightNode =
903+
!nextPair.node.isNonStop(nextPair.trainrunSection) && !nextPair.node.getIsCollapsed();
904+
trsTimeStructure.travelTime = isLastRightNode
887905
? TrainrunsectionHelper.getLastSectionTravelTime(
888906
newTotalTravelTime,
889907
summedTravelTime,
@@ -894,6 +912,7 @@ export class TrainrunSectionService implements OnDestroy {
894912
travelTimeFactor,
895913
precision,
896914
);
915+
897916
trsTimeStructure.rightArrivalTime = TrainrunsectionHelper.getRightArrivalTime(
898917
trsTimeStructure,
899918
precision,
@@ -902,8 +921,7 @@ export class TrainrunSectionService implements OnDestroy {
902921
trsTimeStructure,
903922
precision,
904923
);
905-
const rightIsTarget =
906-
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();
924+
907925
this.updateTrainrunSectionTime(
908926
nextPair.trainrunSection.getId(),
909927
rightIsTarget ? trsTimeStructure.leftArrivalTime : trsTimeStructure.rightArrivalTime,
@@ -913,8 +931,6 @@ export class TrainrunSectionService implements OnDestroy {
913931
trsTimeStructure.travelTime,
914932
);
915933

916-
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime;
917-
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime;
918934
summedTravelTime += trsTimeStructure.travelTime;
919935
}
920936

src/app/services/util/trainrun.iterator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ export class BackwardTrainrunIterator extends TrainrunIterator {
112112
}
113113
}
114114

115-
export class NonStopTrainrunIterator extends TrainrunIterator {
115+
/** Iterate on the trainrun sections until we find a node which is a stop of the trainrun and not collapsed */
116+
export class NextExpandedStopIterator extends TrainrunIterator {
116117
public next(): TrainrunSectionNodePair {
117-
if (!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection)) {
118+
if (
119+
!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection) &&
120+
!this.pointerElement.node.getIsCollapsed()
121+
) {
118122
// The trainrun has a stop and break the forward iteration
119123
this.currentElement = Object.assign({}, this.pointerElement);
120124
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);

src/integration-testing/trainIterator.test.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {ResourceService} from "../app/services/data/resource.service";
77
import {LogService} from "../app/logger/log.service";
88
import {LogPublishersService} from "../app/logger/log.publishers.service";
99
import {NetzgrafikUnitTesting} from "./netzgrafik.unit.testing";
10-
import {NonStopTrainrunIterator, TrainrunIterator} from "../app/services/util/trainrun.iterator";
10+
import {NextExpandedStopIterator, TrainrunIterator} from "../app/services/util/trainrun.iterator";
1111
import {NoteService} from "../app/services/data/note.service";
1212
import {LabelGroupService} from "../app/services/data/labelgroup.service";
1313
import {LabelService} from "../app/services/data/label.service";
@@ -146,7 +146,7 @@ describe("TrainrunSection Service Test", () => {
146146

147147
const iteratorNodeIds = [1, 2];
148148

149-
const itr = new NonStopTrainrunIterator(
149+
const itr = new NextExpandedStopIterator(
150150
logService,
151151
node2,
152152
node2.getTrainrunSection(startingTrainrunSection.getTrainrun()),

0 commit comments

Comments
 (0)