Search in sources :

Example 26 with GenericLocation

use of org.opentripplanner.common.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class AnalystProfileRouterPrototype method findClosestStops.

/**
 * Perform an on-street search around a point with a specific mode to find nearby stops.
 * TODO merge with NearbyStopFinder
 */
private TObjectIntMap<Stop> findClosestStops(final TraverseMode mode) {
    RoutingRequest rr = new RoutingRequest(mode);
    GenericLocation gl = new GenericLocation(request.fromLat, request.fromLon);
    rr.from = gl;
    // FIXME destination must be set, even though this is meaningless for one-to-many
    rr.to = gl;
    rr.setRoutingContext(graph);
    // Set batch after context, so both origin and dest vertices will be found.
    rr.batch = (true);
    rr.walkSpeed = request.walkSpeed;
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    int minAccessTime = 0;
    int maxAccessTime = request.maxWalkTime;
    rr.worstTime = (rr.dateTime + maxAccessTime * 60);
    AStar astar = new AStar();
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.setNumItineraries(1);
    StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(mode, minAccessTime * 60);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 5);
    rr.cleanup();
    return visitor.stopsFound;
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 27 with GenericLocation

use of org.opentripplanner.common.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class OnBoardDepartServiceImplTest method testOnBoardDepartureTime.

@Test
public final void testOnBoardDepartureTime() {
    Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    coordinates[2] = new Coordinate(2.0, 1.0);
    coordinates[3] = new Coordinate(5.0, 1.0);
    coordinates[4] = new Coordinate(5.0, 5.0);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex dwell = mock(PatternArriveVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    CoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.getCoordinateSequenceFactory();
    CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
    LineString geometry = new LineString(coordinateSequence, geometryFactory);
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(3);
    StopTime stopDepartTime = new StopTime();
    StopTime stopDwellTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopDwell = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(agencyAndId);
    stopDwell.setId(agencyAndId);
    stopArrive.setId(agencyAndId);
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopDwellTime.setArrivalTime(20);
    stopDwellTime.setStop(stopDwell);
    stopDwellTime.setDepartureTime(40);
    stopArriveTime.setArrivalTime(60);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopDwellTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setTripHeadsign("The right");
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    when(dwell.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
    PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
    hops.add(patternHop0);
    hops.add(patternHop1);
    when(graph.getEdges()).thenReturn(hops);
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(9);
    patternHop0.setGeometry(geometry);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    coordinates = new Coordinate[3];
    coordinates[0] = new Coordinate(3.5, 1.0);
    coordinates[1] = new Coordinate(5.0, 1.0);
    coordinates[2] = new Coordinate(5.0, 5.0);
    coordinateSequence = coordinateSequenceFactory.create(coordinates);
    geometry = new LineString(coordinateSequence, geometryFactory);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    Edge edge = vertex.getOutgoing().toArray(new Edge[1])[0];
    assertEquals(vertex, edge.getFromVertex());
    assertEquals(dwell, edge.getToVertex());
    assertEquals("The right", edge.getDirection());
    assertEquals(geometry, edge.getGeometry());
    assertEquals(coordinates[0].x, vertex.getX(), 0.0);
    assertEquals(coordinates[0].y, vertex.getY(), 0.0);
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 28 with GenericLocation

use of org.opentripplanner.common.model.GenericLocation in project OpenTripPlanner by opentripplanner.

the class GraphPathFinder method getGraphPathsConsideringIntermediates.

/**
 * Break up a RoutingRequest with intermediate places into separate requests, in the given order.
 *
 * If there are no intermediate places, issue a single request. Otherwise process the places
 * list [from, i1, i2, ..., to] either from left to right (if {@code request.arriveBy==false})
 * or from right to left (if {@code request.arriveBy==true}). In the latter case the order of
 * the requested subpaths is (i2, to), (i1, i2), and (from, i1) which has to be reversed at
 * the end.
 */
private List<GraphPath> getGraphPathsConsideringIntermediates(RoutingRequest request) {
    if (request.hasIntermediatePlaces()) {
        List<GenericLocation> places = Lists.newArrayList(request.from);
        places.addAll(request.intermediatePlaces);
        places.add(request.to);
        long time = request.dateTime;
        List<GraphPath> paths = new ArrayList<>();
        DebugOutput debugOutput = null;
        int placeIndex = (request.arriveBy ? places.size() - 1 : 1);
        while (0 < placeIndex && placeIndex < places.size()) {
            RoutingRequest intermediateRequest = request.clone();
            intermediateRequest.setNumItineraries(1);
            intermediateRequest.dateTime = time;
            intermediateRequest.from = places.get(placeIndex - 1);
            intermediateRequest.to = places.get(placeIndex);
            intermediateRequest.rctx = null;
            intermediateRequest.setRoutingContext(router.graph);
            if (debugOutput != null) {
                // Restore the previous debug info accumulator
                intermediateRequest.rctx.debugOutput = debugOutput;
            } else {
                // Store the debug info accumulator
                debugOutput = intermediateRequest.rctx.debugOutput;
            }
            List<GraphPath> partialPaths = getPaths(intermediateRequest);
            if (partialPaths.size() == 0) {
                return partialPaths;
            }
            GraphPath path = partialPaths.get(0);
            paths.add(path);
            time = (request.arriveBy ? path.getStartTime() : path.getEndTime());
            placeIndex += (request.arriveBy ? -1 : +1);
        }
        request.setRoutingContext(router.graph);
        request.rctx.debugOutput = debugOutput;
        if (request.arriveBy) {
            Collections.reverse(paths);
        }
        return Collections.singletonList(joinPaths(paths));
    } else {
        return getPaths(request);
    }
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) DebugOutput(org.opentripplanner.api.resource.DebugOutput) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

GenericLocation (org.opentripplanner.common.model.GenericLocation)28 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)20 Test (org.junit.Test)14 AStar (org.opentripplanner.routing.algorithm.AStar)9 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 Graph (org.opentripplanner.routing.graph.Graph)5 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)4 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 TIntIntMap (gnu.trove.map.TIntIntMap)3 ArrayList (java.util.ArrayList)3 Agency (org.onebusaway.gtfs.model.Agency)3 Route (org.onebusaway.gtfs.model.Route)3 Stop (org.onebusaway.gtfs.model.Stop)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 Trip (org.onebusaway.gtfs.model.Trip)3 StopPattern (org.opentripplanner.model.StopPattern)3