Search in sources :

Example 76 with RoutingRequest

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

the class GtfsTest method plan.

public Leg[] plan(long dateTime, String fromVertex, String toVertex, String onTripId, boolean wheelchairAccessible, boolean preferLeastTransfers, TraverseMode preferredMode, String excludedRoute, String excludedStop, int legCount) {
    final TraverseMode mode = preferredMode != null ? preferredMode : TraverseMode.TRANSIT;
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setNumItineraries(1);
    routingRequest.setArriveBy(dateTime < 0);
    routingRequest.dateTime = Math.abs(dateTime);
    if (fromVertex != null && !fromVertex.isEmpty()) {
        routingRequest.from = (new GenericLocation(null, feedId.getId() + ":" + fromVertex));
    }
    if (toVertex != null && !toVertex.isEmpty()) {
        routingRequest.to = new GenericLocation(null, feedId.getId() + ":" + toVertex);
    }
    if (onTripId != null && !onTripId.isEmpty()) {
        routingRequest.startingTransitTripId = (new AgencyAndId(feedId.getId(), onTripId));
    }
    routingRequest.setRoutingContext(graph);
    routingRequest.setWheelchairAccessible(wheelchairAccessible);
    routingRequest.transferPenalty = (preferLeastTransfers ? 300 : 0);
    routingRequest.setModes(new TraverseModeSet(TraverseMode.WALK, mode));
    // TODO route matcher still using underscores because it's quite nonstandard and should be eliminated from the 1.0 release rather than reworked
    if (excludedRoute != null && !excludedRoute.isEmpty()) {
        routingRequest.setBannedRoutes(feedId.getId() + "__" + excludedRoute);
    }
    if (excludedStop != null && !excludedStop.isEmpty()) {
        routingRequest.setBannedStopsHard(feedId.getId() + ":" + excludedStop);
    }
    routingRequest.setOtherThanPreferredRoutesPenalty(0);
    // The walk board cost is set low because it interferes with test 2c1.
    // As long as boarding has a very low cost, waiting should not be "better" than riding
    // since this makes interlining _worse_ than alighting and re-boarding the same line.
    // TODO rethink whether it makes sense to weight waiting to board _less_ than 1.
    routingRequest.setWaitReluctance(1);
    routingRequest.setWalkBoardCost(30);
    List<GraphPath> paths = new GraphPathFinder(router).getPaths(routingRequest);
    TripPlan tripPlan = GraphPathToTripPlanConverter.generatePlan(paths, routingRequest);
    // Stored in instance field for use in individual tests
    itinerary = tripPlan.itinerary.get(0);
    assertEquals(legCount, itinerary.legs.size());
    return itinerary.legs.toArray(new Leg[legCount]);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GraphPath(org.opentripplanner.routing.spt.GraphPath) TripPlan(org.opentripplanner.api.model.TripPlan) GenericLocation(org.opentripplanner.common.model.GenericLocation) TraverseMode(org.opentripplanner.routing.core.TraverseMode) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder)

Example 77 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 78 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 79 with RoutingRequest

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

the class AlertPatchTest method setUp.

public void setUp() throws Exception {
    aStar = new AStar();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    options = new RoutingRequest();
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    graph.index(new DefaultStreetVertexIndexFactory());
    feedId = context.getFeedId().getId();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) File(java.io.File)

Example 80 with RoutingRequest

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

the class TestAStar method testBasic.

public void testBasic() throws Exception {
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.CALTRAIN_GTFS));
    Graph gg = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    RoutingRequest options = new RoutingRequest();
    ShortestPathTree spt;
    GraphPath path = null;
    String feedId = gg.getFeedIds().iterator().next();
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
    long endTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 13, 29, 0);
    assertEquals(path.getEndTime(), endTime);
    /* test backwards traversal */
    options.setArriveBy(true);
    options.dateTime = endTime;
    options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":Millbrae Caltrain"), true);
    long expectedStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 39, 0);
    assertTrue(path.getStartTime() - expectedStartTime <= 1);
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File)

Aggregations

RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)124 GraphPath (org.opentripplanner.routing.spt.GraphPath)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)52 State (org.opentripplanner.routing.core.State)42 Test (org.junit.Test)35 Vertex (org.opentripplanner.routing.graph.Vertex)35 Graph (org.opentripplanner.routing.graph.Graph)24 GenericLocation (org.opentripplanner.common.model.GenericLocation)21 Edge (org.opentripplanner.routing.graph.Edge)18 StateEditor (org.opentripplanner.routing.core.StateEditor)17 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)17 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 AStar (org.opentripplanner.routing.algorithm.AStar)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11 Trip (org.onebusaway.gtfs.model.Trip)9