Search in sources :

Example 1 with SPTWalker

use of org.opentripplanner.routing.spt.SPTWalker in project OpenTripPlanner by opentripplanner.

the class SampleGridRenderer method sampleSPT.

/**
 * Sample a SPT using a SPTWalker and an AccumulativeGridSampler.
 */
public static void sampleSPT(final ShortestPathTree spt, ZSampleGrid<WTWD> sampleGrid, final double gridSizeMeters, final double offRoadDistanceMeters, final double offRoadWalkSpeedMps, final double maxWalkDistance, final int maxTimeSec, final double cosLat) {
    AccumulativeMetric<WTWD> accMetric = new WTWDAccumulativeMetric(cosLat, offRoadDistanceMeters, offRoadWalkSpeedMps, gridSizeMeters);
    final AccumulativeGridSampler<WTWD> gridSampler = new AccumulativeGridSampler<WTWD>(sampleGrid, accMetric);
    // At which distance we split edges along the geometry during sampling.
    // For best results, this should be slighly lower than the grid size.
    double walkerSplitDistanceMeters = gridSizeMeters * 0.5;
    SPTWalker johnny = new SPTWalker(spt);
    johnny.walk(new SPTVisitor() {

        @Override
        public final boolean accept(Edge e) {
            return e instanceof StreetEdge;
        }

        @Override
        public final void visit(Edge e, Coordinate c, State s0, State s1, double d0, double d1, double speedAlongEdge) {
            double wd0 = s0.getWalkDistance() + d0;
            double wd1 = s0.getWalkDistance() + d1;
            double t0 = wd0 > maxWalkDistance ? Double.POSITIVE_INFINITY : s0.getActiveTime() + d0 / speedAlongEdge;
            double t1 = wd1 > maxWalkDistance ? Double.POSITIVE_INFINITY : s1.getActiveTime() + d1 / speedAlongEdge;
            if (t0 < maxTimeSec || t1 < maxTimeSec) {
                if (!Double.isInfinite(t0) || !Double.isInfinite(t1)) {
                    WTWD z = new WTWD();
                    z.w = 1.0;
                    z.d = 0.0;
                    if (t0 < t1) {
                        z.wTime = t0;
                        z.wBoardings = s0.getNumBoardings();
                        z.wWalkDist = s0.getWalkDistance() + d0;
                    } else {
                        z.wTime = t1;
                        z.wBoardings = s1.getNumBoardings();
                        z.wWalkDist = s1.getWalkDistance() + d1;
                    }
                    gridSampler.addSamplingPoint(c, z, offRoadWalkSpeedMps);
                }
            }
        }
    }, walkerSplitDistanceMeters);
    gridSampler.close();
}
Also used : SPTVisitor(org.opentripplanner.routing.spt.SPTWalker.SPTVisitor) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) SPTWalker(org.opentripplanner.routing.spt.SPTWalker) Coordinate(com.vividsolutions.jts.geom.Coordinate) AccumulativeGridSampler(org.opentripplanner.common.geometry.AccumulativeGridSampler) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)1 AccumulativeGridSampler (org.opentripplanner.common.geometry.AccumulativeGridSampler)1 State (org.opentripplanner.routing.core.State)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 SPTWalker (org.opentripplanner.routing.spt.SPTWalker)1 SPTVisitor (org.opentripplanner.routing.spt.SPTWalker.SPTVisitor)1