Search in sources :

Example 31 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class StreetUtils method computeConnectedSubgraph.

private static Subgraph computeConnectedSubgraph(Map<Vertex, ArrayList<Vertex>> neighborsForVertex, Vertex startVertex) {
    Subgraph subgraph = new Subgraph();
    Queue<Vertex> q = new LinkedList<Vertex>();
    q.add(startVertex);
    while (!q.isEmpty()) {
        Vertex vertex = q.poll();
        for (Vertex neighbor : neighborsForVertex.get(vertex)) {
            if (!subgraph.contains(neighbor)) {
                subgraph.addVertex(neighbor);
                q.add(neighbor);
            }
        }
    }
    return subgraph;
// if(subgraph.size()>1) return subgraph;
// return null;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Subgraph(org.opentripplanner.common.geometry.Subgraph)

Example 32 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class PropagatedTimesStore method makeSurfaces.

public TimeSurface.RangeSet makeSurfaces(RepeatedRaptorProfileRouter repeatedRaptorProfileRouter) {
    TimeSurface.RangeSet rangeSet = new TimeSurface.RangeSet();
    rangeSet.min = new TimeSurface(repeatedRaptorProfileRouter);
    rangeSet.avg = new TimeSurface(repeatedRaptorProfileRouter);
    rangeSet.max = new TimeSurface(repeatedRaptorProfileRouter);
    for (Vertex vertex : graph.index.vertexForId.values()) {
        int min = mins[vertex.getIndex()];
        int max = maxs[vertex.getIndex()];
        int avg = avgs[vertex.getIndex()];
        if (avg == Integer.MAX_VALUE)
            continue;
        // Count is positive, extrema and sum must also be present
        rangeSet.min.times.put(vertex, min);
        rangeSet.max.times.put(vertex, max);
        rangeSet.avg.times.put(vertex, avg);
    }
    return rangeSet;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TimeSurface(org.opentripplanner.analyst.TimeSurface)

Example 33 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class PropagatedTimesStore method makeSampleGridForVertices.

/**
 * Create a SampleGrid from only the times stored in this PropagatedTimesStore.
 * This assumes that the target indexes in this router/propagatedTimesStore are vertex indexes, not pointset indexes.
 * This is not really ideal since it includes only intersection nodes, and no points along the road segments.
 * FIXME this may be why we're getting hole-punching failures.
 * TODO: rewrite the isoline code to use only primitive collections and operate on a scalar field.
 */
public SparseMatrixZSampleGrid<WTWD> makeSampleGridForVertices(int[] times, final double gridSizeMeters) {
    SparseMatrixZSampleGrid<WTWD> grid;
    long t0 = System.currentTimeMillis();
    // Off-road max distance MUST be APPROX EQUALS to the grid precision
    // TODO: Loosen this restriction (by adding more closing sample).
    // Change the 0.8 magic factor here with caution. Should be roughly grid size.
    final double offroadWalkDistance = 0.8 * gridSizeMeters;
    // in m/sec
    final double offroadWalkSpeed = 1.00;
    Coordinate coordinateOrigin = graph.getCenter().get();
    final double cosLat = FastMath.cos(toRadians(coordinateOrigin.y));
    double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / cosLat;
    grid = new SparseMatrixZSampleGrid<WTWD>(16, times.length, dX, dY, coordinateOrigin);
    AccumulativeGridSampler.AccumulativeMetric<SampleGridRenderer.WTWD> metric = new WTWDAccumulativeMetric(cosLat, offroadWalkDistance, offroadWalkSpeed, gridSizeMeters);
    AccumulativeGridSampler<WTWD> sampler = new AccumulativeGridSampler<>(grid, metric);
    // Iterate over every vertex, adding it to the ZSampleGrid if it was reached.
    for (int v = 0; v < times.length; v++) {
        int time = times[v];
        if (time == Integer.MAX_VALUE) {
            // MAX_VALUE is the "unreached" value
            continue;
        }
        WTWD z = new WTWD();
        z.w = 1.0;
        z.d = 0.0;
        z.wTime = time;
        // unused
        z.wBoardings = 0;
        // unused
        z.wWalkDist = 0;
        // FIXME ack, this uses a hashtable and autoboxing!
        Vertex vertex = graph.getVertexById(v);
        // FIXME we should propagate along street geometries here
        if (vertex != null) {
            sampler.addSamplingPoint(vertex.getCoordinate(), z, offroadWalkSpeed);
        }
    }
    sampler.close();
    long t1 = System.currentTimeMillis();
    LOG.info("Made scalar SampleGrid from TimeSurface in {} msec.", (int) (t1 - t0));
    return grid;
}
Also used : WTWDAccumulativeMetric(org.opentripplanner.analyst.request.SampleGridRenderer.WTWDAccumulativeMetric) Vertex(org.opentripplanner.routing.graph.Vertex) WTWD(org.opentripplanner.analyst.request.SampleGridRenderer.WTWD) Coordinate(com.vividsolutions.jts.geom.Coordinate) AccumulativeGridSampler(org.opentripplanner.common.geometry.AccumulativeGridSampler)

Example 34 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactory method loadPathways.

private void loadPathways(Graph graph) {
    for (Pathway pathway : _dao.getAllPathways()) {
        Vertex fromVertex = context.stationStopNodes.get(pathway.getFromStop());
        Vertex toVertex = context.stationStopNodes.get(pathway.getToStop());
        if (pathway.isWheelchairTraversalTimeSet()) {
            new PathwayEdge(fromVertex, toVertex, pathway.getTraversalTime(), pathway.getWheelchairTraversalTime());
        } else {
            new PathwayEdge(fromVertex, toVertex, pathway.getTraversalTime());
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Pathway(org.onebusaway.gtfs.model.Pathway) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge)

Example 35 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class AnalystProfileRouterPrototype method route.

public TimeSurface.RangeSet route() {
    // NOT USED here, however FIXME this is not threadsafe, needs lock graph.index.clusterStopsAsNeeded();
    LOG.info("access modes: {}", request.accessModes);
    LOG.info("egress modes: {}", request.egressModes);
    LOG.info("direct modes: {}", request.directModes);
    // Establish search timeouts
    searchBeginTime = System.currentTimeMillis();
    abortTime = searchBeginTime + TIMEOUT * 1000;
    // TimeWindow could constructed in the caller, which does have access to the graph index.
    this.window = new TimeWindow(request.fromTime, request.toTime, graph.index.servicesRunning(request.date));
    fromStops = findClosestStops(TraverseMode.WALK);
    LOG.info("From patterns/stops: {}", fromStops);
    /* Initialize time range tracker to begin the search. */
    TimeRange.Tracker times = new TimeRange.Tracker();
    for (Stop stop : fromStops.keySet()) {
        times.set(stop, fromStops.get(stop));
    }
    Set<Stop> stopsUpdated = fromStops.keySet();
    for (int round = 0; round < MAX_RIDES; round++) {
        // TODO maybe even loop until no updates happen? That should happen automatically if MAX_RIDES is high enough.
        /* Get all patterns passing through stops updated in the last round, then reinitialize the updated stops set. */
        Set<TripPattern> patternsUpdated = uniquePatternsVisiting(stopsUpdated);
        LOG.info("ROUND {} : {} stops and {} patterns to explore.", round, stopsUpdated.size(), patternsUpdated.size());
        stopsUpdated = Sets.newHashSet();
        /* RAPTOR style: iterate over each pattern once. */
        for (TripPattern pattern : patternsUpdated) {
            // checkTimeout();
            TimeRange rangeBeingPropagated = null;
            List<Stop> stops = pattern.getStops();
            FrequencyEntry freq = pattern.getSingleFrequencyEntry();
            if (freq == null)
                continue;
            TripTimes tt = freq.tripTimes;
            int headway = freq.headway;
            for (int sidx = 0; sidx < stops.size(); sidx++) {
                Stop stop = stops.get(sidx);
                TimeRange existingRange = times.get(stop);
                TimeRange reBoardRange = (existingRange != null) ? existingRange.wait(headway) : null;
                if (rangeBeingPropagated == null) {
                    // We do not yet have a range worth propagating
                    if (reBoardRange != null) {
                        // this is a fresh protective copy
                        rangeBeingPropagated = reBoardRange;
                    }
                } else {
                    // We already have a range that is being propagated along the pattern.
                    // We are certain sidx >= 1 here because we have already boarded in a previous iteration.
                    TimeRange arrivalRange = rangeBeingPropagated.shift(tt.getRunningTime(sidx - 1));
                    if (times.add(stop, arrivalRange)) {
                        // The propagated time improved the best known time in some way.
                        stopsUpdated.add(stop);
                    }
                    // TODO handle case where arrival and departure are different
                    rangeBeingPropagated = arrivalRange.shift(tt.getDwellTime(sidx));
                    if (reBoardRange != null) {
                        rangeBeingPropagated.mergeIn(reBoardRange);
                    }
                }
            }
        }
        /* Transfer from updated stops to adjacent stops before beginning the next round.
               Iterate over a protective copy because we add more stops to the updated list during iteration. */
        if (!graph.hasDirectTransfers) {
            throw new RuntimeException("Requires the SimpleTransfers generated in long distance mode.");
        }
        for (Stop stop : Lists.newArrayList(stopsUpdated)) {
            Collection<Edge> outgoingEdges = graph.index.stopVertexForStop.get(stop).getOutgoing();
            for (SimpleTransfer transfer : Iterables.filter(outgoingEdges, SimpleTransfer.class)) {
                Stop targetStop = ((TransitStop) transfer.getToVertex()).getStop();
                double walkTime = transfer.getDistance() / request.walkSpeed;
                TimeRange rangeAfterTransfer = times.get(stop).shift((int) walkTime);
                if (times.add(targetStop, rangeAfterTransfer)) {
                    stopsUpdated.add(targetStop);
                }
            }
        }
    }
    LOG.info("Done with transit.");
    LOG.info("Propagating from transit stops to the street network...");
    // Grab a cached map of distances to street intersections from each transit stop
    StopTreeCache stopTreeCache = graph.index.getStopTreeCache();
    // Iterate over all stops that were reached in the transit part of the search
    for (Stop stop : times) {
        TransitStop tstop = graph.index.stopVertexForStop.get(stop);
        // Iterate over street intersections in the vicinity of this particular transit stop.
        // Shift the time range at this transit stop, merging it into that for all reachable street intersections.
        TimeRange rangeAtTransitStop = times.get(stop);
        // FIXME stopTreeCache.getDistancesForStop(tstop);
        TObjectIntMap<Vertex> distanceToVertex = null;
        for (TObjectIntIterator<Vertex> iter = distanceToVertex.iterator(); iter.hasNext(); ) {
            iter.advance();
            Vertex vertex = iter.key();
            // distance in meters over walkspeed in meters per second --> seconds
            int egressWalkTimeSeconds = (int) (iter.value() / request.walkSpeed);
            if (egressWalkTimeSeconds > request.maxWalkTime * 60) {
                continue;
            }
            TimeRange propagatedRange = rangeAtTransitStop.shift(egressWalkTimeSeconds);
            TimeRange existingTimeRange = propagatedTimes.get(vertex);
            if (existingTimeRange == null) {
                propagatedTimes.put(vertex, propagatedRange);
            } else {
                existingTimeRange.mergeIn(propagatedRange);
            }
        }
    }
    LOG.info("Done with propagation.");
    TimeSurface.RangeSet result = TimeSurface.makeSurfaces(this);
    LOG.info("Done making time surfaces.");
    return result;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TimeSurface(org.opentripplanner.analyst.TimeSurface) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11