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

org.opentripplanner.transit.raptor.rangeraptor.standard.besttimes.SimpleBestNumberOfTransfers Maven / Gradle / Ivy

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

import org.opentripplanner.transit.raptor.rangeraptor.RoundProvider;
import org.opentripplanner.transit.raptor.rangeraptor.standard.BestNumberOfTransfers;
import org.opentripplanner.transit.raptor.util.IntUtils;


/**
 * The responsibility for this class is to keep track of the best (minimun)
 * number of transfers for all stops reached.
 */
public class SimpleBestNumberOfTransfers implements BestNumberOfTransfers {
    private final int[] bestNumOfTransfers;
    private final RoundProvider roundProvider;

    public SimpleBestNumberOfTransfers(int nStops, RoundProvider roundProvider) {
        this.bestNumOfTransfers = IntUtils.intArray(nStops, unreachedMinNumberOfTransfers());
        this.roundProvider = roundProvider;
    }

    /**
     * Call this method to notify that the given stop is reached in the current round of Raptor.
     */
    void arriveAtStop(int stop) {
        final int numOfTransfers = roundProvider.round() - 1;
        if(numOfTransfers < bestNumOfTransfers[stop] ) {
            bestNumOfTransfers[stop] = numOfTransfers;
        }
    }

    @Override
    public int calculateMinNumberOfTransfers(int stop) {
        return bestNumOfTransfers[stop];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy