Search in sources :

Example 46 with RoutingRequest

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

the class AStarTest method testBackExtraEdges.

@Test
public void testBackExtraEdges() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setArriveBy(true);
    TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
    new TemporaryConcreteEdge(from, _graph.getVertex("shilshole_22nd"));
    TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
    new TemporaryConcreteEdge(_graph.getVertex("56th_20th"), to);
    options.setRoutingContext(_graph, from, to);
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    options.cleanup();
    GraphPath path = tree.getPath(from, false);
    List<State> states = path.states;
    assertEquals(9, states.size());
    assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
    assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
    assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("market_russell", states.get(5).getVertex().getLabel());
    assertEquals("market_20th", states.get(6).getVertex().getLabel());
    assertEquals("56th_20th", states.get(7).getVertex().getLabel());
    assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) TemporaryConcreteEdge(org.opentripplanner.routing.graph.TemporaryConcreteEdge) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 47 with RoutingRequest

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

the class AStarTest method testForward.

@Test
public void testForward() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(_graph.getVertex("leary_20th"), false);
    List<State> states = path.states;
    assertEquals(7, states.size());
    assertEquals("56th_24th", states.get(0).getVertex().getLabel());
    assertEquals("market_24th", states.get(1).getVertex().getLabel());
    assertEquals("market_ballard", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("leary_vernon", states.get(5).getVertex().getLabel());
    assertEquals("leary_20th", states.get(6).getVertex().getLabel());
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 48 with RoutingRequest

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

the class TestBanning method testBannedRoutes.

public void testBannedRoutes() {
    Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
    String feedId = graph.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    Vertex start = graph.getVertex(feedId + ":8371");
    Vertex end = graph.getVertex(feedId + ":8374");
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
    // must set routing context _after_ options is fully configured (time)
    options.setRoutingContext(graph, start, end);
    ShortestPathTree spt = null;
    /*
         * The MAX Red, Blue, and Green lines all run along the same trackage between the stops 8374 and 8371. Together, they form the white line. No,
         * wait, that's light. They make a pretty good test case for banned routes, since if one is banned, you can always take another.
         */
    String[][] maxLines = { { "MAX Red Line", null }, { "MAX Blue Line", null }, { "MAX Green Line", null }, { null, "90" }, { null, "100" }, { null, "200" } };
    for (int i = 0; i < maxLines.length; ++i) {
        String lineName = maxLines[i][0];
        String lineId = maxLines[i][1];
        String routeSpecStr = feedId + "_" + (lineName != null ? lineName : "") + (lineId != null ? "_" + lineId : "");
        options.setBannedRoutes(routeSpecStr);
        spt = aStar.getShortestPathTree(options);
        GraphPath path = spt.getPath(end, true);
        for (State s : path.states) {
            if (s.getBackEdge() instanceof PatternHop) {
                PatternHop e = (PatternHop) s.getBackEdge();
                Route route = e.getPattern().route;
                assertFalse(options.bannedRoutes.matches(route));
                boolean foundMaxLine = false;
                for (int j = 0; j < maxLines.length; ++j) {
                    if (j != i) {
                        if (e.getName().equals(maxLines[j][0])) {
                            foundMaxLine = true;
                        }
                    }
                }
                assertTrue(foundMaxLine);
            }
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route)

Example 49 with RoutingRequest

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

the class TestFares method testKCM.

public void testKCM() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.KCM_GTFS));
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.setFareServiceFactory(new SeattleFareServiceFactory());
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    RoutingRequest options = new RoutingRequest();
    String feedId = gg.getFeedIds().iterator().next();
    String vertex0 = feedId + ":2010";
    String vertex1 = feedId + ":2140";
    ShortestPathTree spt;
    GraphPath path = null;
    FareService fareService = gg.getService(FareService.class);
    long offPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 5, 0, 0);
    options.dateTime = offPeakStartTime;
    options.setRoutingContext(gg, vertex0, vertex1);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(vertex1), true);
    Fare costOffPeak = fareService.getCost(path);
    assertEquals(costOffPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 250));
    long onPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 8, 0, 0);
    options.dateTime = onPeakStartTime;
    options.setRoutingContext(gg, vertex0, vertex1);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(vertex1), true);
    Fare costOnPeak = fareService.getCost(path);
    assertEquals(costOnPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 275));
}
Also used : SeattleFareServiceFactory(org.opentripplanner.routing.impl.SeattleFareServiceFactory) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File)

Example 50 with RoutingRequest

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

the class TestFares method testBasic.

public void testBasic() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.CALTRAIN_GTFS));
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    RoutingRequest options = new RoutingRequest();
    String feedId = gg.getFeedIds().iterator().next();
    long startTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    options.dateTime = startTime;
    options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
    ShortestPathTree spt;
    GraphPath path = null;
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
    FareService fareService = gg.getService(FareService.class);
    Fare cost = fareService.getCost(path);
    assertEquals(cost.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 425));
}
Also used : GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) 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