Search in sources :

Example 6 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project OpenTripPlanner by opentripplanner.

the class AddTripPatternTest method testStopLinking.

/**
 * Make sure that stops are properly linked into the graph
 */
@Test
public void testStopLinking() throws Exception {
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(true));
    // get a graph
    Graph g = buildGraphNoTransit();
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    // materialize the trip pattern
    atp.materialize(g);
    // there should be five stops because one point is not a stop
    assertEquals(5, atp.temporaryStops.length);
    // they should all be linked into the graph
    for (int i = 0; i < atp.temporaryStops.length; i++) {
        assertNotNull(atp.temporaryStops[i].sample);
        assertNotNull(atp.temporaryStops[i].sample.v0);
        assertNotNull(atp.temporaryStops[i].sample.v1);
    }
    // no services running: not needed for trips added on the fly.
    TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
    Scenario scenario = new Scenario(0);
    scenario.modifications = Lists.newArrayList(atp);
    ProfileRequest req = new ProfileRequest();
    req.scenario = scenario;
    req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
    RaptorWorkerData data = new RaptorWorkerData(g, window, req);
    assertEquals(5, data.nStops);
    // make sure we can find the stops
    AStar aStar = new AStar();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(39.963417, -82.980799);
    rr.batch = true;
    rr.setRoutingContext(g);
    rr.batch = true;
    ShortestPathTree spt = aStar.getShortestPathTree(rr);
    TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
    // we should have found stops
    assertFalse(stops.isEmpty());
    // ensure that the times made it into the data
    // This assumes worst-case departure, and the first worst departure is 10:30 after the service
    // starts running (dwell + headway)
    assertEquals(4 * 3600 + 600 + 30, data.timetablesForPattern.get(0).getFrequencyDeparture(0, 0, 39 * 360, -1, null));
}
Also used : BitSet(java.util.BitSet) AStar(org.opentripplanner.routing.algorithm.AStar) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TIntIntMap(gnu.trove.map.TIntIntMap) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 7 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project OpenTripPlanner by opentripplanner.

the class AddTripPatternTest method testTimetableTrips.

/**
 * Test adding trips with a timetable rather than frequencies
 */
@Test
public void testTimetableTrips() throws Exception {
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(false));
    // get a graph
    Graph g = buildGraphNoTransit();
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    // materialize the trip pattern
    atp.materialize(g);
    // there should be five stops because one point is not a stop
    assertEquals(5, atp.temporaryStops.length);
    // they should all be linked into the graph
    for (int i = 0; i < atp.temporaryStops.length; i++) {
        assertNotNull(atp.temporaryStops[i].sample);
        assertNotNull(atp.temporaryStops[i].sample.v0);
        assertNotNull(atp.temporaryStops[i].sample.v1);
    }
    // no services running: not needed for trips added on the fly.
    TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
    Scenario scenario = new Scenario(0);
    scenario.modifications = Lists.newArrayList(atp);
    ProfileRequest req = new ProfileRequest();
    req.scenario = scenario;
    req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
    RaptorWorkerData data = new RaptorWorkerData(g, window, req);
    assertEquals(5, data.nStops);
    // make sure we can find the stops
    AStar aStar = new AStar();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.from = new GenericLocation(39.963417, -82.980799);
    rr.batch = true;
    rr.setRoutingContext(g);
    rr.batch = true;
    ShortestPathTree spt = aStar.getShortestPathTree(rr);
    TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
    // we should have found stops
    assertFalse(stops.isEmpty());
    // ensure that the times made it into the data
    // This is after the first dwell time has been applied
    assertEquals(7 * 3600 + 30, data.timetablesForPattern.get(0).getDeparture(0, 0));
}
Also used : BitSet(java.util.BitSet) AStar(org.opentripplanner.routing.algorithm.AStar) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TIntIntMap(gnu.trove.map.TIntIntMap) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 8 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project OpenTripPlanner by opentripplanner.

the class RaptorWorkerData method findStopsNear.

/**
 * find stops from a given SPT, including temporary stops. If useTimes is true, use times from the SPT, otherwise use distances
 */
public TIntIntMap findStopsNear(ShortestPathTree spt, Graph graph, boolean useTimes, float walkSpeed) {
    TIntIntMap accessTimes = new TIntIntHashMap();
    for (TransitStop tstop : graph.index.stopVertexForStop.values()) {
        State s = spt.getState(tstop);
        if (s != null) {
            // note that we calculate the time based on the walk speed here rather than
            // based on the time. this matches what we do in the stop tree cache.
            int stopIndex = indexForStop.get(tstop.getIndex());
            if (stopIndex != -1) {
                if (useTimes)
                    accessTimes.put(stopIndex, (int) s.getElapsedTimeSeconds());
                else
                    accessTimes.put(stopIndex, (int) (s.getWalkDistance() / walkSpeed));
            }
        }
    }
    // and handle the additional stops
    for (TObjectIntIterator<AddTripPattern.TemporaryStop> it = addedStops.iterator(); it.hasNext(); ) {
        it.advance();
        AddTripPattern.TemporaryStop tstop = it.key();
        if (tstop.sample == null) {
            continue;
        }
        double dist = Double.POSITIVE_INFINITY;
        if (tstop.sample.v0 != null) {
            State s0 = spt.getState(tstop.sample.v0);
            if (s0 != null) {
                dist = s0.getWalkDistance() + tstop.sample.d0;
            }
        }
        if (tstop.sample.v1 != null) {
            State s1 = spt.getState(tstop.sample.v1);
            if (s1 != null) {
                double d1 = s1.getWalkDistance() + tstop.sample.d1;
                dist = Double.isInfinite(dist) ? d1 : Math.min(d1, dist);
            }
        }
        if (Double.isInfinite(dist))
            continue;
        // NB using the index in the worker data not the index in the graph!
        accessTimes.put(it.value(), (int) (dist / walkSpeed));
    }
    return accessTimes;
}
Also used : AddTripPattern(org.opentripplanner.analyst.scenario.AddTripPattern) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) TIntIntMap(gnu.trove.map.TIntIntMap)

Example 9 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project OpenTripPlanner by opentripplanner.

the class RepeatedRaptorProfileRouter method route.

public ResultEnvelope route() {
    // When no sample set is provided, we're making isochrones.
    boolean isochrone = (sampleSet == null);
    // Does the search involve transit at all?
    boolean transit = (request.transitModes != null && request.transitModes.isTransit());
    long computationStartTime = System.currentTimeMillis();
    LOG.info("Begin profile request");
    // We only create data tables if transit is in use, otherwise they wouldn't serve any purpose.
    if (raptorWorkerData == null && transit) {
        long dataStart = System.currentTimeMillis();
        raptorWorkerData = getRaptorWorkerData(request, graph, sampleSet, ts);
        ts.raptorData = (int) (System.currentTimeMillis() - dataStart);
    }
    // Find the transit stops that are accessible from the origin, leaving behind an SPT behind of access
    // times to all reachable vertices.
    long initialStopStartTime = System.currentTimeMillis();
    // This will return null if we have no transit data, but will leave behind a pre-transit SPT.
    TIntIntMap transitStopAccessTimes = findInitialStops(false, raptorWorkerData);
    // Create an array containing the best travel time in seconds to each vertex in the graph when not using transit.
    int[] nonTransitTimes = new int[Vertex.getMaxIndex()];
    Arrays.fill(nonTransitTimes, Integer.MAX_VALUE);
    for (State state : preTransitSpt.getAllStates()) {
        // Note that we are using the walk distance divided by speed here in order to be consistent with the
        // least-walk optimization in the initial stop search (and the stop tree cache which is used at egress)
        // TODO consider why this matters, I'm using reported travel time from the states
        int time = (int) state.getElapsedTimeSeconds();
        int vidx = state.getVertex().getIndex();
        int otime = nonTransitTimes[vidx];
        // There may be dominated states in the SPT. Make sure we don't include them here.
        if (otime > time) {
            nonTransitTimes[vidx] = time;
        }
    }
    ts.initialStopSearch = (int) (System.currentTimeMillis() - initialStopStartTime);
    // FIXME wasn't the walk search already performed above?
    long walkSearchStart = System.currentTimeMillis();
    // in the graph. Therefore we must replace the vertex-indexed array with a new point-indexed array.
    if (sampleSet != null) {
        nonTransitTimes = sampleSet.eval(nonTransitTimes);
    }
    ts.walkSearch = (int) (System.currentTimeMillis() - walkSearchStart);
    if (transit) {
        RaptorWorker worker = new RaptorWorker(raptorWorkerData, request);
        propagatedTimesStore = worker.runRaptor(graph, transitStopAccessTimes, nonTransitTimes, ts);
        ts.initialStopCount = transitStopAccessTimes.size();
    } else {
        // Nontransit case: skip transit routing and make a propagated times store based on only one row.
        propagatedTimesStore = new PropagatedTimesStore(graph, request, nonTransitTimes.length);
        int[][] singleRoundResults = new int[1][];
        singleRoundResults[0] = nonTransitTimes;
        propagatedTimesStore.setFromArray(singleRoundResults, new boolean[] { true }, PropagatedTimesStore.ConfidenceCalculationMethod.MIN_MAX);
    }
    for (int min : propagatedTimesStore.mins) {
        if (min != RaptorWorker.UNREACHED)
            ts.targetsReached++;
    }
    ts.compute = (int) (System.currentTimeMillis() - computationStartTime);
    LOG.info("Profile request finished in {} seconds", (ts.compute) / 1000.0);
    // Turn the results of the search into isochrone geometries or accessibility data as requested.
    long resultSetStart = System.currentTimeMillis();
    ResultEnvelope envelope = new ResultEnvelope();
    if (isochrone) {
        // No destination point set was provided and we're just making isochrones based on travel time to vertices,
        // rather than finding access times to a set of user-specified points.
        envelope = propagatedTimesStore.makeIsochronesForVertices();
    } else {
        // A destination point set was provided. We've found access times to a set of specified points.
        // TODO actually use those boolean params to calculate isochrones on a regular grid pointset
        // TODO maybe there's a better way to pass includeTimes in here from the clusterRequest,
        // maybe we should just provide the whole clusterRequest not just the wrapped profileRequest.
        envelope = propagatedTimesStore.makeResults(sampleSet, includeTimes, true, false);
    }
    ts.resultSets = (int) (System.currentTimeMillis() - resultSetStart);
    return envelope;
}
Also used : ResultEnvelope(org.opentripplanner.analyst.cluster.ResultEnvelope) State(org.opentripplanner.routing.core.State) TIntIntMap(gnu.trove.map.TIntIntMap)

Aggregations

TIntIntMap (gnu.trove.map.TIntIntMap)9 Test (org.junit.Test)4 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)4 Graph (org.opentripplanner.routing.graph.Graph)4 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)4 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)3 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)3 GenericLocation (org.opentripplanner.common.model.GenericLocation)3 AStar (org.opentripplanner.routing.algorithm.AStar)3 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)2 BitSet (java.util.BitSet)2 LocalDate (org.joda.time.LocalDate)2 TaskStatistics (org.opentripplanner.analyst.cluster.TaskStatistics)2 ProfileRequest (org.opentripplanner.profile.ProfileRequest)2 RaptorWorkerData (org.opentripplanner.profile.RaptorWorkerData)2 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)2 State (org.opentripplanner.routing.core.State)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)2