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);
}
}
}
}
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));
}
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);
}
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);
}
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());
}
}
Aggregations