Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class ShortestTravelTimeSearch {

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

while (iterator.hasNext()) {
iterator.next();
Expand Down
34 changes: 25 additions & 9 deletions src/app/services/data/trainrun-section-times.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class TrainrunSectionTimesService {
rightDepartureTime: 0,
rightArrivalTime: 0,
travelTime: 0,
stopTime: 0,
};

private nodesOrdered: Node[] = [];
Expand Down Expand Up @@ -142,15 +143,20 @@ export class TrainrunSectionTimesService {
);
if (!this.lockStructure.rightLock) {
this.timeStructure.rightArrivalTime =
this.timeStructure.leftDepartureTime + (this.timeStructure.travelTime % 60);
this.timeStructure.leftDepartureTime +
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.rightArrivalTime %= 60;
this.timeStructure.rightDepartureTime = TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
} else if (!this.lockStructure.travelTimeLock && this.lockStructure.rightLock) {
const extraHour = this.timeStructure.travelTime - (this.timeStructure.travelTime % 60);
const extraHour =
this.timeStructure.travelTime -
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.travelTime =
this.timeStructure.rightArrivalTime - this.timeStructure.leftDepartureTime;
this.timeStructure.rightArrivalTime -
this.timeStructure.leftDepartureTime -
this.timeStructure.stopTime;
this.timeStructure.travelTime += this.timeStructure.travelTime < 0 ? 60 : 0;
this.timeStructure.travelTime += extraHour;
} else {
Expand Down Expand Up @@ -234,15 +240,20 @@ export class TrainrunSectionTimesService {

if (!this.lockStructure.leftLock) {
this.timeStructure.leftDepartureTime =
this.timeStructure.rightArrivalTime - (this.timeStructure.travelTime % 60);
this.timeStructure.rightArrivalTime -
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.leftDepartureTime += this.timeStructure.leftDepartureTime < 0 ? 60 : 0;
this.timeStructure.leftArrivalTime = TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftDepartureTime,
);
} else if (!this.lockStructure.travelTimeLock && this.lockStructure.leftLock) {
const extraHour = this.timeStructure.travelTime - (this.timeStructure.travelTime % 60);
const extraHour =
this.timeStructure.travelTime -
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.travelTime =
this.timeStructure.rightArrivalTime - this.timeStructure.leftDepartureTime;
this.timeStructure.rightArrivalTime -
this.timeStructure.leftDepartureTime -
this.timeStructure.stopTime;
this.timeStructure.travelTime += this.timeStructure.travelTime < 0 ? 60 : 0;
this.timeStructure.travelTime += extraHour;
} else {
Expand Down Expand Up @@ -280,15 +291,20 @@ export class TrainrunSectionTimesService {
);
if (!this.lockStructure.leftLock) {
this.timeStructure.leftArrivalTime =
this.timeStructure.rightDepartureTime + (this.timeStructure.travelTime % 60);
this.timeStructure.rightDepartureTime +
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.leftArrivalTime %= 60;
this.timeStructure.leftDepartureTime = TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
} else if (!this.lockStructure.travelTimeLock && this.lockStructure.leftLock) {
const extraHour = this.timeStructure.travelTime - (this.timeStructure.travelTime % 60);
const extraHour =
this.timeStructure.travelTime -
((this.timeStructure.travelTime + this.timeStructure.stopTime) % 60);
this.timeStructure.travelTime =
this.timeStructure.leftArrivalTime - this.timeStructure.rightDepartureTime;
this.timeStructure.leftArrivalTime -
this.timeStructure.rightDepartureTime -
this.timeStructure.stopTime;
this.timeStructure.travelTime += this.timeStructure.travelTime < 0 ? 60 : 0;
this.timeStructure.travelTime += extraHour;
} else {
Expand Down
24 changes: 15 additions & 9 deletions src/app/services/data/trainrun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {GeneralViewFunctions} from "../../view/util/generalViewFunctions";
import {
BackwardNonStopTrainrunIterator,
BackwardTrainrunIterator,
NonStopTrainrunIterator,
NextExpandedStopIterator,
TrainrunIterator,
} from "../util/trainrun.iterator";
import {LogService} from "../../logger/log.service";
Expand Down Expand Up @@ -663,7 +663,7 @@ export class TrainrunService {
}

getLastNonStopNode(node: Node, trainrunSection: TrainrunSection): Node {
const iterator = this.getNonStopIterator(node, trainrunSection);
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
while (iterator.hasNext()) {
iterator.next();
}
Expand All @@ -680,7 +680,7 @@ export class TrainrunService {
}

getLastNonStopTrainrunSection(node: Node, trainrunSection: TrainrunSection): TrainrunSection {
const iterator = this.getNonStopIterator(node, trainrunSection);
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
while (iterator.hasNext()) {
iterator.next();
}
Expand Down Expand Up @@ -725,7 +725,7 @@ export class TrainrunService {

sumTravelTimeUpToLastNonStopNode(node: Node, trainrunSection: TrainrunSection): number {
let summedTravelTime = 0;
const iterator = this.getNonStopIterator(node, trainrunSection);
const iterator = this.getNextExpandedStopIterator(node, trainrunSection);
while (iterator.hasNext()) {
const nextPair = iterator.next();
summedTravelTime += nextPair.trainrunSection.getTravelTime();
Expand All @@ -734,7 +734,10 @@ export class TrainrunService {
}

getCumulativeTravelTime(trainrunSection: TrainrunSection) {
const iterator = this.getNonStopIterator(trainrunSection.getSourceNode(), trainrunSection);
const iterator = this.getNextExpandedStopIterator(
trainrunSection.getSourceNode(),
trainrunSection,
);
while (iterator.hasNext()) {
iterator.next();
}
Expand All @@ -753,7 +756,7 @@ export class TrainrunService {
},
];
let summedTravelTime = 0;
const iterator = this.getNonStopIterator(n, ts);
const iterator = this.getNextExpandedStopIterator(n, ts);
while (iterator.hasNext()) {
const nextPair = iterator.next();
summedTravelTime += nextPair.trainrunSection.getTravelTime();
Expand All @@ -767,7 +770,10 @@ export class TrainrunService {
}

getCumulativeTravelTimeAndNodePath(trainrunSection: TrainrunSection) {
const iterator = this.getNonStopIterator(trainrunSection.getSourceNode(), trainrunSection);
const iterator = this.getNextExpandedStopIterator(
trainrunSection.getSourceNode(),
trainrunSection,
);
while (iterator.hasNext()) {
iterator.next();
}
Expand All @@ -788,8 +794,8 @@ export class TrainrunService {
return new TrainrunIterator(this.logService, node, trainrunSection);
}

public getNonStopIterator(node: Node, trainrunSection: TrainrunSection) {
return new NonStopTrainrunIterator(this.logService, node, trainrunSection);
public getNextExpandedStopIterator(node: Node, trainrunSection: TrainrunSection) {
return new NextExpandedStopIterator(this.logService, node, trainrunSection);
}

public getBackwardIterator(node: Node, trainrunSection: TrainrunSection) {
Expand Down
49 changes: 34 additions & 15 deletions src/app/services/data/trainrunsection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class TrainrunSectionService implements OnDestroy {
node: Node,
stopNodeId: number,
) {
const iterator = this.trainrunService.getNonStopIterator(node, trainrunSection);
const iterator = this.trainrunService.getNextExpandedStopIterator(node, trainrunSection);
while (iterator.hasNext()) {
iterator.next();
if (iterator.current().node.getId() === stopNodeId) {
Expand Down Expand Up @@ -878,19 +878,41 @@ export class TrainrunSectionService implements OnDestroy {
const trsTimeStructure = TrainrunsectionHelper.getDefaultTimeStructure(timeStructure);
let summedTravelTime = 0;

const iterator = this.trainrunService.getNonStopIterator(leftNode, trs);
const iterator = this.trainrunService.getNextExpandedStopIterator(leftNode, trs);
let prevInitialLeftArrival: number = null;
let stopTime: number;
while (iterator.hasNext()) {
const nextPair = iterator.next();
const rightIsTarget =
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();

if (prevInitialLeftArrival !== null) {
stopTime = MathUtils.mod60(
(rightIsTarget
? nextPair.trainrunSection.getSourceDeparture()
: nextPair.trainrunSection.getTargetDeparture()) - prevInitialLeftArrival,
);
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime + stopTime;
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime - stopTime;
}
prevInitialLeftArrival = rightIsTarget
? nextPair.trainrunSection.getTargetArrival()
: nextPair.trainrunSection.getSourceArrival();

const isLastRightNode =
!nextPair.node.isNonStop(nextPair.trainrunSection) && !nextPair.node.getIsCollapsed();
trsTimeStructure.travelTime = isLastRightNode
? TrainrunsectionHelper.getLastSectionTravelTime(
newTotalTravelTime,
summedTravelTime,
precision,
)
: TrainrunsectionHelper.getSectionDistributedTravelTime(
nextPair.trainrunSection.getTravelTime(),
travelTimeFactor,
precision,
);

const isRightNodeNonStop = nextPair.node.isNonStop(nextPair.trainrunSection);
trsTimeStructure.travelTime = TrainrunsectionHelper.getTravelTime(
newTotalTravelTime,
summedTravelTime,
travelTimeFactor,
nextPair.trainrunSection.getTravelTime(),
isRightNodeNonStop,
precision,
);
trsTimeStructure.rightArrivalTime = TrainrunsectionHelper.getRightArrivalTime(
trsTimeStructure,
precision,
Expand All @@ -899,8 +921,7 @@ export class TrainrunSectionService implements OnDestroy {
trsTimeStructure,
precision,
);
const rightIsTarget =
nextPair.node.getId() === nextPair.trainrunSection.getTargetNode().getId();

this.updateTrainrunSectionTime(
nextPair.trainrunSection.getId(),
rightIsTarget ? trsTimeStructure.leftArrivalTime : trsTimeStructure.rightArrivalTime,
Expand All @@ -910,8 +931,6 @@ export class TrainrunSectionService implements OnDestroy {
trsTimeStructure.travelTime,
);

trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime;
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime;
summedTravelTime += trsTimeStructure.travelTime;
}

Expand Down
8 changes: 6 additions & 2 deletions src/app/services/util/trainrun.iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ export class BackwardTrainrunIterator extends TrainrunIterator {
}
}

export class NonStopTrainrunIterator extends TrainrunIterator {
/** Iterate on the trainrun sections until we find a node which is a stop of the trainrun and not collapsed */
export class NextExpandedStopIterator extends TrainrunIterator {
public next(): TrainrunSectionNodePair {
if (!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection)) {
if (
!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection) &&
!this.pointerElement.node.getIsCollapsed()
) {
// The trainrun has a stop and break the forward iteration
this.currentElement = Object.assign({}, this.pointerElement);
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
Expand Down
Loading