use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method testTransfers.
/**
* Make sure that transfers work
*/
@Test
public void testTransfers() throws Exception {
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(false));
AddTripPattern atp2 = getAddTripPattern(RouteSelector.BEXLEY_CMH);
atp2.timetables.add(getTimetable(true));
// get a graph
Graph g = buildGraphNoTransit();
addTransit(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
// materialize the trip pattern
atp.materialize(g);
atp2.materialize(g);
TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, g.index.servicesRunning(new LocalDate(2015, 6, 10)), DayOfWeek.WEDNESDAY);
Scenario scenario = new Scenario(0);
scenario.modifications = Lists.newArrayList(atp, atp2);
ProfileRequest req = new ProfileRequest();
req.scenario = scenario;
req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
RaptorWorkerData data = new RaptorWorkerData(g, window, req);
// make sure that we have transfers a) between the new lines b) from the new lines
// to the existing lines c) from the existing lines to the new lines
// stop IDs in the data will be 0 and 1 for existing stops, 2 - 6 for Broad/High and 7 - 11 for Bexley/CMH
int[] txFromExisting = data.transfersForStop.get(0);
if (txFromExisting.length == 0)
txFromExisting = data.transfersForStop.get(1);
// make sure there's a transfer to stop 4 (Broad/High)
// the AddTripPattern instructions are processed in order
// also recall that each transfer has two ints in the array as it's a jagged array of
// dest_pattern, distance
assertTrue(txFromExisting.length > 0);
boolean foundTx = false;
for (int i = 0; i < txFromExisting.length; i += 2) {
if (txFromExisting[i] == 4) {
foundTx = true;
break;
}
}
assertTrue("transfer from existing to new", foundTx);
// Check that there are transfers from the new route to the existing route
// This is the stop at Broad and High
int[] txToExisting = data.transfersForStop.get(4);
assertTrue(txToExisting.length > 0);
foundTx = false;
for (int i = 0; i < txToExisting.length; i += 2) {
if (txToExisting[i] == 0 || txToExisting[i] == 1) {
// stop from existing route
foundTx = true;
break;
}
}
assertTrue("transfer from new to existing", foundTx);
// Check that there are transfers between the new routes
int[] txBetweenNew = data.transfersForStop.get(7);
assertTrue(txBetweenNew.length > 0);
foundTx = false;
for (int i = 0; i < txBetweenNew.length; i += 2) {
if (txBetweenNew[i] == 2) {
foundTx = true;
break;
}
}
assertTrue(foundTx);
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class LinkingTest method testStopsLinkedIdentically.
/**
* Test that all the stops are linked identically
* to the street network on two builds of similar graphs
* with additional stops in one.
*
* We do this by building the graphs and then comparing the stop tree caches.
*/
@Test
public void testStopsLinkedIdentically() throws UnsupportedEncodingException {
// build the graph without the added stops
Graph g1 = buildGraphNoTransit();
addRegularStopGrid(g1);
link(g1);
Graph g2 = buildGraphNoTransit();
addExtraStops(g2);
addRegularStopGrid(g2);
link(g2);
// compare the linkages
for (TransitStop ts : Iterables.filter(g1.getVertices(), TransitStop.class)) {
Collection<Edge> stls = stls(ts.getOutgoing());
assertTrue(stls.size() >= 1);
StreetTransitLink exemplar = (StreetTransitLink) stls.iterator().next();
TransitStop other = (TransitStop) g2.getVertex(ts.getLabel());
Collection<Edge> ostls = stls(other.getOutgoing());
assertEquals("Unequal number of links from stop " + ts, stls.size(), ostls.size());
StreetTransitLink oe = (StreetTransitLink) ostls.iterator().next();
assertEquals(exemplar.getToVertex().getLat(), oe.getToVertex().getLat(), 1e-10);
assertEquals(exemplar.getToVertex().getLon(), oe.getToVertex().getLon(), 1e-10);
}
// compare the stop tree caches
g1.index(new DefaultStreetVertexIndexFactory());
g2.index(new DefaultStreetVertexIndexFactory());
g1.rebuildVertexAndEdgeIndices();
g2.rebuildVertexAndEdgeIndices();
StopTreeCache s1 = g1.index.getStopTreeCache();
StopTreeCache s2 = g2.index.getStopTreeCache();
// convert the caches to be by stop label
Map<String, int[]> l1 = cacheByLabel(s1);
Map<String, int[]> l2 = cacheByLabel(s2);
// do the comparison
for (Entry<String, int[]> e : l1.entrySet()) {
// graph 2 should contain all stops in graph 1 (and a few more)
assertTrue(l2.containsKey(e.getKey()));
TObjectIntMap<String> g1t = jaggedArrayToVertexMap(e.getValue(), g1);
TObjectIntMap<String> g2t = jaggedArrayToVertexMap(l2.get(e.getKey()), g2);
for (TObjectIntIterator<String> it = g1t.iterator(); it.hasNext(); ) {
it.advance();
assertTrue(g2t.containsKey(it.key()));
int newv = g2t.get(it.key());
assertTrue("At " + it.key() + " from stop " + g1.getVertex(e.getKey()) + ", difference in walk distances: " + it.value() + "m without extra stops," + newv + "m with", Math.abs(it.value() - newv) <= EPSILON);
}
}
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class GtfsGraphBuilderModuleTest method testNoBikesByDefault.
@Test
public void testNoBikesByDefault() throws IOException {
// We configure two trip: one with unknown bikes_allowed and the second with bikes
// allowed.
MockGtfs gtfs = getSimpleGtfs();
gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
gtfs.putStopTimes("t0,t1", "s0,s1");
List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
bundleList.get(0).setDefaultBikesAllowed(false);
_builder = new GtfsModule(bundleList);
Graph graph = new Graph();
_builder.buildGraph(graph, _extra);
graph.index(new DefaultStreetVertexIndexFactory());
// Feed id is used instead of the agency id for OBA entities.
GtfsBundle gtfsBundle = bundleList.get(0);
GtfsFeedId feedId = gtfsBundle.getFeedId();
Trip trip = graph.index.tripForId.get(new AgencyAndId(feedId.getId(), "t0"));
TripPattern pattern = graph.index.patternForTrip.get(trip);
List<Trip> trips = pattern.getTrips();
assertEquals(BikeAccess.UNKNOWN, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t1"))));
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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));
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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));
}
Aggregations