Search in sources :

Example 21 with Route

use of org.onebusaway.gtfs.model.Route 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 22 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class TestRouteMatcher method testRouteMatcher.

public void testRouteMatcher() {
    Route r1 = new Route();
    r1.setId(new AgencyAndId("A1", "42"));
    r1.setShortName("R1");
    Route r2 = new Route();
    r2.setId(new AgencyAndId("A1", "43"));
    r2.setShortName("R2");
    Route r1b = new Route();
    r1b.setId(new AgencyAndId("A2", "42"));
    r1b.setShortName("R1");
    Route r3 = new Route();
    r3.setId(new AgencyAndId("A1", "44"));
    r3.setShortName("R3_b");
    RouteMatcher emptyMatcher = RouteMatcher.emptyMatcher();
    assertFalse(emptyMatcher.matches(r1));
    assertFalse(emptyMatcher.matches(r1b));
    assertFalse(emptyMatcher.matches(r2));
    RouteMatcher matcherR1i = RouteMatcher.parse("A1__42");
    assertTrue(matcherR1i.matches(r1));
    assertFalse(matcherR1i.matches(r1b));
    assertFalse(matcherR1i.matches(r2));
    RouteMatcher matcherR2n = RouteMatcher.parse("A1_R2");
    assertFalse(matcherR2n.matches(r1));
    assertFalse(matcherR2n.matches(r1b));
    assertTrue(matcherR2n.matches(r2));
    RouteMatcher matcherR1R2 = RouteMatcher.parse("A1_R1,A1__43,A2__43");
    assertTrue(matcherR1R2.matches(r1));
    assertFalse(matcherR1R2.matches(r1b));
    assertTrue(matcherR1R2.matches(r2));
    RouteMatcher matcherR1n = RouteMatcher.parse("_R1");
    assertTrue(matcherR1n.matches(r1));
    assertTrue(matcherR1n.matches(r1b));
    assertFalse(matcherR1n.matches(r2));
    RouteMatcher matcherR1R1bR2 = RouteMatcher.parse("A1_R1,A2_R1,A1_R2");
    assertTrue(matcherR1R1bR2.matches(r1));
    assertTrue(matcherR1R1bR2.matches(r1b));
    assertTrue(matcherR1R1bR2.matches(r2));
    RouteMatcher matcherR3e = RouteMatcher.parse("A1_R3 b");
    assertFalse(matcherR3e.matches(r1));
    assertFalse(matcherR3e.matches(r1b));
    assertFalse(matcherR3e.matches(r2));
    assertTrue(matcherR3e.matches(r3));
    RouteMatcher nullList = RouteMatcher.parse(null);
    assertTrue(nullList == RouteMatcher.emptyMatcher());
    RouteMatcher emptyList = RouteMatcher.parse("");
    assertTrue(emptyList == RouteMatcher.emptyMatcher());
    RouteMatcher degenerate = RouteMatcher.parse(",,,");
    assertTrue(degenerate == RouteMatcher.emptyMatcher());
    boolean thrown = false;
    try {
        RouteMatcher badMatcher = RouteMatcher.parse("A1_R1_42");
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertTrue(thrown);
    Route r1c = new Route();
    r1c.setId(new AgencyAndId("A_1", "R_42"));
    r1c.setShortName("R_42");
    RouteMatcher matcherR1c = RouteMatcher.parse("A\\_1_R 42");
    assertTrue(matcherR1c.matches(r1c));
    assertFalse(matcherR1c.matches(r1));
    assertFalse(matcherR1c.matches(r1b));
    RouteMatcher matcherR1c2 = RouteMatcher.parse("A\\_1__R\\_42");
    assertTrue(matcherR1c2.matches(r1c));
    assertFalse(matcherR1c2.matches(r1));
    assertFalse(matcherR1c2.matches(r1b));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

Example 23 with Route

use of org.onebusaway.gtfs.model.Route in project OpenTripPlanner by opentripplanner.

the class TestSpecificTransfer method testSpecificTransfer.

/**
 * Test different specific transfers
 */
public void testSpecificTransfer() {
    // Setup from trip with route
    Route fromRoute = new Route();
    fromRoute.setId(new AgencyAndId("A1", "R1"));
    Trip fromTrip = new Trip();
    fromTrip.setId(new AgencyAndId("A1", "T1"));
    fromTrip.setRoute(fromRoute);
    // Setup to trip with route
    Route toRoute = new Route();
    toRoute.setId(new AgencyAndId("A1", "R2"));
    Trip toTrip = new Trip();
    toTrip.setId(new AgencyAndId("A1", "T2"));
    toTrip.setRoute(toRoute);
    // Create full SpecificTransfer
    SpecificTransfer s1 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), fromTrip.getId(), toTrip.getId(), 1);
    assertTrue(s1.matches(fromTrip, toTrip));
    assertTrue(s1.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s1.transferTime == 1);
    // Create empty SpecificTransfer
    SpecificTransfer s2 = new SpecificTransfer((AgencyAndId) null, null, null, null, 2);
    assertTrue(s2.matches(fromTrip, toTrip));
    assertTrue(s2.getSpecificity() == SpecificTransfer.MIN_SPECIFICITY);
    assertTrue(s2.transferTime == 2);
    // Create SpecificTransfer one trip missing
    SpecificTransfer s3 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), null, toTrip.getId(), 3);
    assertTrue(s3.matches(fromTrip, toTrip));
    assertTrue(s3.getSpecificity() == 3);
    assertTrue(s3.transferTime == 3);
    // Create SpecificTransfer one trip different
    SpecificTransfer s4 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), new AgencyAndId("A1", "T3"), toTrip.getId(), 4);
    assertFalse(s4.matches(fromTrip, toTrip));
    assertTrue(s4.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s4.transferTime == 4);
    // Create SpecificTransfer one trip and route missing
    SpecificTransfer s5 = new SpecificTransfer(null, toRoute.getId(), null, toTrip.getId(), 5);
    assertTrue(s5.matches(fromTrip, toTrip));
    assertTrue(s5.getSpecificity() == 2);
    assertTrue(s5.transferTime == 5);
    // Create SpecificTransfer one trip only
    SpecificTransfer s6 = new SpecificTransfer(null, null, null, toTrip.getId(), 6);
    assertTrue(s6.matches(fromTrip, toTrip));
    assertTrue(s6.getSpecificity() == 2);
    assertTrue(s6.transferTime == 6);
    // Create SpecificTransfer one route only
    SpecificTransfer s7 = new SpecificTransfer(fromRoute.getId(), null, null, null, 7);
    assertTrue(s7.matches(fromTrip, toTrip));
    assertTrue(s7.getSpecificity() == 1);
    assertTrue(s7.transferTime == 7);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

Example 24 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.

the class AddOmnySubwayData method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    int stop_count = 0;
    int route_count = 0;
    // Per MOTP-1770 all stops/routes are now OMNY enabled.
    for (Stop stop : dao.getAllStops()) {
        stop.setRegionalFareCardAccepted(1);
        stop_count++;
    }
    for (Route route : dao.getAllRoutes()) {
        route.setRegionalFareCardAccepted(1);
        route_count++;
    }
    _log.info("Set {} stops and {} routes to omny_enabled Y", stop_count, route_count);
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Example 25 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderExampleMain method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("usage: gtfsPath");
        System.exit(-1);
    }
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    /**
     * You can register an entity handler that listens for new objects as they
     * are read
     */
    reader.addEntityHandler(new GtfsEntityHandler());
    /**
     * Or you can use the internal entity store, which has references to all the
     * loaded entities
     */
    GtfsDaoImpl store = new GtfsDaoImpl();
    reader.setEntityStore(store);
    reader.run();
    // Access entities through the store
    Map<AgencyAndId, Route> routesById = store.getEntitiesByIdForEntityType(AgencyAndId.class, Route.class);
    for (Route route : routesById.values()) {
        System.out.println("route: " + route.getShortName());
    }
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsDaoImpl(org.onebusaway.gtfs.impl.GtfsDaoImpl) File(java.io.File) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5