Skip to content

Commit 85d0b39

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 f2c04ca commit 85d0b39

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
@@ -321,7 +321,7 @@ export class TrainrunSectionService implements OnDestroy {
321321
node: Node,
322322
stopNodeId: number,
323323
) {
324-
const iterator = this.trainrunService.getNonStopIterator(node, trainrunSection);
324+
const iterator = this.trainrunService.getNextExpandedStopIterator(node, trainrunSection);
325325
while (iterator.hasNext()) {
326326
iterator.next();
327327
if (iterator.current().node.getId() === stopNodeId) {
@@ -875,12 +875,30 @@ export class TrainrunSectionService implements OnDestroy {
875875
const trsTimeStructure = TrainrunsectionHelper.getDefaultTimeStructure(timeStructure);
876876
let summedTravelTime = 0;
877877

878-
const iterator = this.trainrunService.getNonStopIterator(leftNode, trs);
878+
const iterator = this.trainrunService.getNextExpandedStopIterator(leftNode, trs);
879+
let prevInitialLeftArrival: number = null;
880+
let stopTime: number;
879881
while (iterator.hasNext()) {
880882
const nextPair = iterator.next();
883+
const rightIsTarget =
884+
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();
885+
886+
if (prevInitialLeftArrival !== null) {
887+
stopTime = MathUtils.mod60(
888+
(rightIsTarget
889+
? nextPair.trainrunSection.getSourceDeparture()
890+
: nextPair.trainrunSection.getTargetDeparture()) - prevInitialLeftArrival,
891+
);
892+
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime + stopTime;
893+
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime - stopTime;
894+
}
895+
prevInitialLeftArrival = rightIsTarget
896+
? nextPair.trainrunSection.getTargetArrival()
897+
: nextPair.trainrunSection.getSourceArrival();
881898

882-
const isLastNode = !nextPair.node.isNonStop(nextPair.trainrunSection);
883-
trsTimeStructure.travelTime = isLastNode
899+
const isLastRightNode =
900+
!nextPair.node.isNonStop(nextPair.trainrunSection) && !nextPair.node.getIsCollapsed();
901+
trsTimeStructure.travelTime = isLastRightNode
884902
? TrainrunsectionHelper.getLastSectionTravelTime(
885903
newTotalTravelTime,
886904
summedTravelTime,
@@ -891,6 +909,7 @@ export class TrainrunSectionService implements OnDestroy {
891909
travelTimeFactor,
892910
precision,
893911
);
912+
894913
trsTimeStructure.rightArrivalTime = TrainrunsectionHelper.getRightArrivalTime(
895914
trsTimeStructure,
896915
precision,
@@ -899,8 +918,7 @@ export class TrainrunSectionService implements OnDestroy {
899918
trsTimeStructure,
900919
precision,
901920
);
902-
const rightIsTarget =
903-
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();
921+
904922
this.updateTrainrunSectionTime(
905923
nextPair.trainrunSection.getId(),
906924
rightIsTarget ? trsTimeStructure.leftArrivalTime : trsTimeStructure.rightArrivalTime,
@@ -910,8 +928,6 @@ export class TrainrunSectionService implements OnDestroy {
910928
trsTimeStructure.travelTime,
911929
);
912930

913-
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime;
914-
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime;
915931
summedTravelTime += trsTimeStructure.travelTime;
916932
}
917933

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)