Search in sources :

Example 1 with GenericLocation

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

the class LIsochrone method computeIsochrone.

/**
 * Generic method to compute isochrones. Parse the request, call the adequate builder, and
 * return a list of generic isochrone data.
 *
 * @return
 * @throws Exception
 */
public List<IsochroneData> computeIsochrone() throws Exception {
    if (debug == null)
        debug = false;
    if (precisionMeters < 10)
        throw new IllegalArgumentException("Too small precisionMeters: " + precisionMeters);
    if (offRoadDistanceMeters < 10)
        throw new IllegalArgumentException("Too small offRoadDistanceMeters: " + offRoadDistanceMeters);
    IsoChroneRequest isoChroneRequest = new IsoChroneRequest(cutoffSecList);
    isoChroneRequest.includeDebugGeometry = debug;
    isoChroneRequest.precisionMeters = precisionMeters;
    isoChroneRequest.offRoadDistanceMeters = offRoadDistanceMeters;
    if (coordinateOrigin != null)
        isoChroneRequest.coordinateOrigin = new GenericLocation(null, coordinateOrigin).getCoordinate();
    RoutingRequest sptRequest = buildRequest();
    if (maxTimeSec != null) {
        isoChroneRequest.maxTimeSec = maxTimeSec;
    } else {
        isoChroneRequest.maxTimeSec = isoChroneRequest.maxCutoffSec;
    }
    Router router = otpServer.getRouter(routerId);
    return router.isoChroneSPTRenderer.getIsochrones(isoChroneRequest, sptRequest);
}
Also used : GenericLocation(org.opentripplanner.common.model.GenericLocation) Router(org.opentripplanner.standalone.Router) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) IsoChroneRequest(org.opentripplanner.analyst.request.IsoChroneRequest)

Example 2 with GenericLocation

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

the class OnBoardDepartServiceImplTest method testOnBoardAtStation.

@Test
public final void testOnBoardAtStation() {
    TransitStop station0 = mock(TransitStop.class);
    TransitStop station1 = mock(TransitStop.class);
    TransitStop station2 = mock(TransitStop.class);
    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"));
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    Agency agency = new Agency();
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
    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(new AgencyAndId("Station", "0"));
    stopDwell.setId(new AgencyAndId("Station", "1"));
    stopArrive.setId(new AgencyAndId("Station", "2"));
    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.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(graph.getVertex("Station_0")).thenReturn(station0);
    when(graph.getVertex("Station_1")).thenReturn(station1);
    when(graph.getVertex("Station_2")).thenReturn(station2);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(0);
    assertEquals(station0, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(20);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(30);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(40);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(60);
    assertEquals(station2, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) 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) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 3 with GenericLocation

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

the class OnBoardDepartServiceImplTest method testOnBoardDepartureAtArrivalTime.

@Test
public final void testOnBoardDepartureAtArrivalTime() {
    Coordinate[] coordinates = new Coordinate[2];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    TransitStop station0 = mock(TransitStop.class);
    TransitStop station1 = mock(TransitStop.class);
    PatternDepartVertex depart = mock(PatternDepartVertex.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"));
    when(station0.getX()).thenReturn(coordinates[0].x);
    when(station0.getY()).thenReturn(coordinates[0].y);
    when(station1.getX()).thenReturn(coordinates[1].x);
    when(station1.getY()).thenReturn(coordinates[1].y);
    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>(2);
    StopTime stopDepartTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = 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(new AgencyAndId("Station", "0"));
    stopArrive.setId(new AgencyAndId("Station", "1"));
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopArriveTime.setArrivalTime(10);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    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);
    PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0);
    when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop));
    when(depart.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(10);
    when(graph.getVertex("Station_0")).thenReturn(station0);
    when(graph.getVertex("Station_1")).thenReturn(station1);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    assertEquals(coordinates[1].x, vertex.getX(), 0.0);
    assertEquals(coordinates[1].y, vertex.getY(), 0.0);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) 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) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Test(org.junit.Test)

Example 4 with GenericLocation

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

the class RepeatedRaptorProfileRouter method findInitialStops.

/**
 * Find all transit stops accessible by streets around the origin, leaving behind a shortest path tree of the
 * reachable area in the field preTransitSpt.
 *
 * @param data the raptor data table to use. If this is null (i.e. there is no transit) range is extended,
 *             and we don't care if we actually find any stops, we just want the tree of on-street distances.
 */
@VisibleForTesting
public TIntIntMap findInitialStops(boolean dest, RaptorWorkerData data) {
    LOG.info("Finding initial stops");
    double lat = dest ? request.toLat : request.fromLat;
    double lon = dest ? request.toLon : request.fromLon;
    QualifiedModeSet modes = dest ? request.egressModes : request.accessModes;
    RoutingRequest rr = new RoutingRequest(modes);
    rr.batch = true;
    rr.from = new GenericLocation(lat, lon);
    // rr.walkSpeed = request.walkSpeed;
    rr.to = rr.from;
    rr.setRoutingContext(graph);
    rr.dateTime = request.date.toDateMidnight(DateTimeZone.forTimeZone(graph.getTimeZone())).getMillis() / 1000 + request.fromTime;
    rr.walkSpeed = request.walkSpeed;
    rr.bikeSpeed = request.bikeSpeed;
    if (data == null) {
        // Non-transit mode. Search out to the full 120 minutes.
        // Should really use directModes.
        rr.worstTime = rr.dateTime + RaptorWorker.MAX_DURATION;
        rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    } else {
        // Transit mode, limit pre-transit travel.
        if (rr.modes.contains(TraverseMode.BICYCLE)) {
            rr.dominanceFunction = new DominanceFunction.EarliestArrival();
            rr.worstTime = rr.dateTime + request.maxBikeTime * 60;
        } else {
            // We use walk-distance limiting and a least-walk dominance function in order to be consistent with egress walking
            // which is implemented this way because walk times can change when walk speed changes. Also, walk times are floating
            // point and can change slightly when streets are split. Street lengths are internally fixed-point ints, which do not
            // suffer from roundoff. Great care is taken when splitting to preserve sums.
            // When cycling, this is not an issue; we already have an explicitly asymmetrical search (cycling at the origin, walking at the destination),
            // so we need not preserve symmetry.
            // We use the max walk time for the search at the origin, but we clamp it to MAX_WALK_METERS so that we don;t
            // have every transit stop in the state as an initial transit stop if someone sets max walk time to four days,
            // and so that symmetry is preserved.
            // FIXME kind of arbitrary
            rr.maxWalkDistance = Math.min(request.maxWalkTime * 60 * request.walkSpeed, GraphIndex.MAX_WALK_METERS);
            rr.softWalkLimiting = false;
            rr.dominanceFunction = new DominanceFunction.LeastWalk();
        }
    }
    rr.numItineraries = 1;
    rr.longDistance = true;
    AStar aStar = new AStar();
    preTransitSpt = aStar.getShortestPathTree(rr, 5);
    // otherwise return null and leave preTransitSpt around for later use.
    if (data != null) {
        TIntIntMap accessTimes = data.findStopsNear(preTransitSpt, graph, rr.modes.contains(TraverseMode.BICYCLE), request.walkSpeed);
        LOG.info("Found {} transit stops", accessTimes.size());
        return accessTimes;
    } else {
        return null;
    }
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) TIntIntMap(gnu.trove.map.TIntIntMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with GenericLocation

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

the class RoundBasedProfileRouter method makeSurfaces.

/**
 * analyst mode: propagate to street network
 */
private void makeSurfaces() {
    LOG.info("Propagating from transit stops to the street network...");
    List<State> lower = Lists.newArrayList();
    List<State> upper = Lists.newArrayList();
    List<State> avg = Lists.newArrayList();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.batch = (true);
    rr.from = new GenericLocation(request.fromLat, request.fromLon);
    rr.setRoutingContext(graph);
    rr.longDistance = true;
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.setNumItineraries(1);
    rr.worstTime = rr.dateTime + CUTOFF_SECONDS;
    long startTime = rr.dateTime;
    State origin = new State(rr);
    // Multi-origin Dijkstra search; preinitialize the queue with states at each transit stop
    for (Collection<ProfileState> pss : retainedStates.asMap().values()) {
        TransitStop tstop = null;
        int lowerBound = Integer.MAX_VALUE;
        int upperBound = Integer.MAX_VALUE;
        for (ProfileState ps : pss) {
            if (tstop == null)
                tstop = ps.stop;
            if (ps.lowerBound < lowerBound)
                lowerBound = ps.lowerBound;
            if (ps.upperBound < upperBound)
                upperBound = ps.upperBound;
        }
        if (lowerBound == Integer.MAX_VALUE || upperBound == Integer.MAX_VALUE)
            throw new IllegalStateException("Invalid bound!");
        lower.add(new State(tstop, null, lowerBound + startTime, startTime, rr));
        upper.add(new State(tstop, null, upperBound + startTime, startTime, rr));
        // TODO extremely incorrect hack!
        avg.add(new State(tstop, null, (upperBound + lowerBound) / 2 + startTime, startTime, rr));
    }
    // get direct trips as well
    lower.add(origin);
    upper.add(origin);
    avg.add(origin);
    // create timesurfaces
    timeSurfaceRangeSet = new TimeSurface.RangeSet();
    AStar astar = new AStar();
    timeSurfaceRangeSet.min = new TimeSurface(astar.getShortestPathTree(rr, 20, null, lower), false);
    astar = new AStar();
    timeSurfaceRangeSet.max = new TimeSurface(astar.getShortestPathTree(rr, 20, null, upper), false);
    astar = new AStar();
    timeSurfaceRangeSet.avg = new TimeSurface(astar.getShortestPathTree(rr, 20, null, avg), false);
    rr.cleanup();
    LOG.info("Done with propagation.");
/* Store the results in a field in the router object. */
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TimeSurface(org.opentripplanner.analyst.TimeSurface) AStar(org.opentripplanner.routing.algorithm.AStar) RangeSet(org.opentripplanner.analyst.TimeSurface.RangeSet) State(org.opentripplanner.routing.core.State) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

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