All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.transit.raptor.rangeraptor.standard.ArrivalTimeRoutingStrategy Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.transit.raptor.rangeraptor.standard;

import java.util.function.IntConsumer;
import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripPattern;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripScheduleBoardOrAlightEvent;
import org.opentripplanner.transit.raptor.api.transit.TransitArrival;
import org.opentripplanner.transit.raptor.rangeraptor.RoutingStrategy;
import org.opentripplanner.transit.raptor.rangeraptor.transit.TransitCalculator;


/**
 * The purpose of this class is to implement a routing strategy for finding the best arrival-time.
 * This class optimize the raptor search on a single criteria.
 * 

* Note! Raptor give us number-of-transfer as a second pareto criteria - which is outside the scope * of this class. *

* Note! This strategy can be used with RangeRaptor - iterating over a time-window to get pareto * optimal solution for departure time. Which is outside the scope of this class. * * @param The TripSchedule type defined by the user of the raptor API. */ public final class ArrivalTimeRoutingStrategy implements RoutingStrategy { private static final int NOT_SET = -1; private final TransitCalculator calculator; private final StdWorkerState state; private int onTripIndex; private int onTripBoardTime; private int onTripBoardStop; private T onTrip; public ArrivalTimeRoutingStrategy(TransitCalculator calculator, StdWorkerState state) { this.calculator = calculator; this.state = state; } @Override public void setAccessToStop( RaptorTransfer accessPath, int iterationDepartureTime, int timeDependentDepartureTime ) { state.setAccessToStop(accessPath, timeDependentDepartureTime); } @Override public int onTripIndex() { return onTripIndex; } @Override public void prepareForTransitWith(RaptorTripPattern pattern) { this.onTripIndex = NOT_SET; this.onTripBoardTime = NOT_SET; this.onTripBoardStop = NOT_SET; this.onTrip = null; } @Override public void alight(final int stopIndex, final int stopPos, final int alightSlack) { if (onTripIndex != NOT_SET) { final int stopArrivalTime = calculator.stopArrivalTime(onTrip, stopPos, alightSlack); state.transitToStop(stopIndex, stopArrivalTime, onTripBoardStop, onTripBoardTime, onTrip); } } @Override public void forEachBoarding(int stopIndex, IntConsumer prevStopArrivalTimeConsumer) { // Don't attempt to board if this stop was not reached in the last round. // Allow to reboard the same pattern - a pattern may loop and visit the same stop twice if (state.isStopReachedInPreviousRound(stopIndex)) { prevStopArrivalTimeConsumer.accept(state.bestTimePreviousRound(stopIndex)); } } @Override public void board( int stopIndex, final int earliestBoardTime, RaptorTripScheduleBoardOrAlightEvent boarding ) { onTripIndex = boarding.getTripIndex(); onTrip = boarding.getTrip(); onTripBoardTime = boarding.getTime(); onTripBoardStop = stopIndex; } @Override public TransitArrival previousTransit(int boardStopIndex) { return state.previousTransit(boardStopIndex); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy