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

org.opentripplanner.routing.algorithm.raptor.transit.mappers.TransfersMapper Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.routing.algorithm.raptor.transit.mappers;

import com.google.common.collect.Multimap;
import org.opentripplanner.model.SimpleTransfer;
import org.opentripplanner.model.Stop;
import org.opentripplanner.model.StopLocation;
import org.opentripplanner.routing.algorithm.raptor.transit.StopIndexForRaptor;
import org.opentripplanner.routing.algorithm.raptor.transit.Transfer;

import java.util.ArrayList;
import java.util.List;

class TransfersMapper {

    /**
     * Copy pre-calculated transfers from the original graph
     */
    static List> mapTransfers(
        StopIndexForRaptor stopIndex,
        Multimap transfersByStop
    ) {

        List> transferByStopIndex = new ArrayList<>();

        for (int i = 0; i < stopIndex.stopsByIndex.size(); ++i) {
            Stop stop = stopIndex.stopsByIndex.get(i);
            ArrayList list = new ArrayList<>();
            transferByStopIndex.add(list);

            for (SimpleTransfer simpleTransfer : transfersByStop.get(stop)) {
                double effectiveDistance = simpleTransfer.getEffectiveWalkDistance();
                if (simpleTransfer.to instanceof Stop) {
                    int toStopIndex = stopIndex.indexByStop.get(simpleTransfer.to);
                    Transfer transfer = new Transfer(toStopIndex, (int) effectiveDistance,
                        simpleTransfer.getEdges());

                    list.add(transfer);
                }
            }
        }
        return transferByStopIndex;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy