Search in sources :

Example 1 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class IsoChroneSPTRendererRecursiveGrid method computeInitialPoints.

/**
 * Compute a set of initial coordinates for the given SPT
 *
 * @param spt
 * @return
 */
private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
    List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
    for (State s : spt.getAllStates()) {
        Vertex v = s.getVertex();
        // Take only street
        if (v instanceof StreetVertex) {
            retval.add(v.getCoordinate());
        }
    }
    LOG.debug("Created {} initial points from {} vertexes.", retval.size(), spt.getVertexCount());
    return retval;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) ArrayList(java.util.ArrayList) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 2 with State

use of org.opentripplanner.routing.core.State 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)

Example 3 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class Sample method eval.

/**
 * @param spt the ShortestPathTree with respect to which this sample will be evaluated
 * @return the travel time to reach this Sample point from the SPT's origin
 */
public long eval(ShortestPathTree spt) {
    State s0 = spt.getState(v0);
    State s1 = spt.getState(v1);
    long m0 = Long.MAX_VALUE;
    long m1 = Long.MAX_VALUE;
    double walkSpeed = spt.getOptions().walkSpeed;
    if (s0 != null)
        m0 = (int) (s0.getActiveTime() + d0 / walkSpeed);
    if (s1 != null)
        m1 = (int) (s1.getActiveTime() + d1 / walkSpeed);
    return (m0 < m1) ? m0 : m1;
}
Also used : State(org.opentripplanner.routing.core.State)

Example 4 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class Sample method evalWalkDistance.

public double evalWalkDistance(ShortestPathTree spt) {
    State s0 = spt.getState(v0);
    State s1 = spt.getState(v1);
    double m0 = Double.NaN;
    double m1 = Double.NaN;
    if (s0 != null)
        m0 = (s0.getWalkDistance() + d0);
    if (s1 != null)
        m1 = (s1.getWalkDistance() + d1);
    return (m0 < m1) ? m0 : m1;
}
Also used : State(org.opentripplanner.routing.core.State)

Example 5 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class DefaultFareServiceImpl method createRides.

protected List<Ride> createRides(GraphPath path) {
    List<Ride> rides = new LinkedList<Ride>();
    Ride ride = null;
    for (State state : path.states) {
        Edge edge = state.getBackEdge();
        if (!(edge instanceof HopEdge))
            continue;
        HopEdge hEdge = (HopEdge) edge;
        if (ride == null || !state.getRoute().equals(ride.route)) {
            ride = new Ride();
            rides.add(ride);
            ride.startZone = hEdge.getBeginStop().getZoneId();
            ride.zones.add(ride.startZone);
            ride.agency = state.getBackTrip().getRoute().getAgency().getId();
            ride.route = state.getRoute();
            ride.startTime = state.getBackState().getTimeSeconds();
            ride.firstStop = hEdge.getBeginStop();
            ride.trip = state.getTripId();
        }
        ride.lastStop = hEdge.getEndStop();
        ride.endZone = ride.lastStop.getZoneId();
        ride.zones.add(ride.endZone);
        ride.endTime = state.getTimeSeconds();
        // in default fare service, classify rides by mode
        ride.classifier = state.getBackMode();
    }
    return rides;
}
Also used : HopEdge(org.opentripplanner.routing.edgetype.HopEdge) State(org.opentripplanner.routing.core.State) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) Edge(org.opentripplanner.routing.graph.Edge) LinkedList(java.util.LinkedList)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5