use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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();
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class ConvertToFrequencyTest method testSimpleConversion.
/**
* The simplest case of frequency conversion: no weird loop routes or anything like that, travel times always same, etc.
*/
@Test
public void testSimpleConversion() throws Exception {
Graph gg = buildGraphNoTransit();
addTransit(gg);
link(gg);
gg.index(new DefaultStreetVertexIndexFactory());
ProfileRequest pr1 = new ProfileRequest();
pr1.date = new LocalDate(2015, 6, 10);
pr1.fromTime = 7 * 3600;
pr1.toTime = 9 * 3600;
pr1.fromLat = pr1.toLat = 39.9621;
pr1.fromLon = pr1.toLon = -83.0007;
pr1.accessModes = pr1.egressModes = pr1.directModes = new QualifiedModeSet("WALK");
pr1.transitModes = new TraverseModeSet("TRANSIT");
RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(gg, pr1);
rrpr1.route();
ProfileRequest pr2 = new ProfileRequest();
pr2.date = new LocalDate(2015, 6, 10);
pr2.fromTime = 7 * 3600;
pr2.toTime = 9 * 3600;
pr2.fromLat = pr2.toLat = 39.9621;
pr2.fromLon = pr2.toLon = -83.0007;
pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
pr2.transitModes = new TraverseModeSet("TRANSIT");
ConvertToFrequency ctf = new ConvertToFrequency();
ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
ctf.routeId = new String[] { "route" };
ctf.windowStart = 5 * 3600;
ctf.windowEnd = 10 * 3600;
pr2.scenario = new Scenario(0);
pr2.scenario.modifications = Arrays.asList(ctf);
RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
rrpr2.route();
assertFalse(rrpr1.raptorWorkerData.hasFrequencies);
assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
assertEquals(FakeGraph.FREQUENCY, tt.headwaySecs[0]);
assertEquals(FakeGraph.TRAVEL_TIME, tt.frequencyTrips[0][2]);
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class ConvertToFrequencyTest method testMultiplePatterns.
/**
* Test the case where there are multiple patterns that need to be chosen from.
*/
@Test
public void testMultiplePatterns() throws Exception {
Graph gg = buildGraphNoTransit();
addMultiplePatterns(gg);
link(gg);
gg.index(new DefaultStreetVertexIndexFactory());
ProfileRequest pr1 = new ProfileRequest();
pr1.date = new LocalDate(2015, 6, 10);
pr1.fromTime = 7 * 3600;
pr1.toTime = 9 * 3600;
pr1.fromLat = pr1.toLat = 39.9621;
pr1.fromLon = pr1.toLon = -83.0007;
pr1.accessModes = pr1.egressModes = pr1.directModes = new QualifiedModeSet("WALK");
pr1.transitModes = new TraverseModeSet("TRANSIT");
RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(gg, pr1);
rrpr1.route();
ProfileRequest pr2 = new ProfileRequest();
pr2.date = new LocalDate(2015, 6, 10);
pr2.fromTime = 7 * 3600;
pr2.toTime = 9 * 3600;
pr2.fromLat = pr2.toLat = 39.9621;
pr2.fromLon = pr2.toLon = -83.0007;
pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
pr2.transitModes = new TraverseModeSet("TRANSIT");
ConvertToFrequency ctf = new ConvertToFrequency();
ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
ctf.routeId = new String[] { "route" };
ctf.windowStart = 5 * 3600;
ctf.windowEnd = 10 * 3600;
pr2.scenario = new Scenario(0);
pr2.scenario.modifications = Arrays.asList(ctf);
RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
rrpr2.route();
assertFalse(rrpr1.raptorWorkerData.hasFrequencies);
assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
// everything should have gotten merged into one pattern
assertEquals(1, rrpr2.raptorWorkerData.timetablesForPattern.size());
RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
// should be no frequency variation because trips on all patterns are considered for frequencies.
// there should be no travel time variation because only trips on the dominant pattern are considered
// for travel time.
assertEquals(FakeGraph.FREQUENCY, tt.headwaySecs[0]);
assertEquals(FakeGraph.TRAVEL_TIME, tt.frequencyTrips[0][2]);
// now try it with groupings by pattern
ConvertToFrequency ctf3 = new ConvertToFrequency();
ctf3.groupBy = ConvertToFrequency.ConversionGroup.PATTERN;
ctf3.routeId = new String[] { "route" };
ctf3.windowStart = 5 * 3600;
ctf3.windowEnd = 10 * 3600;
ProfileRequest pr3 = new ProfileRequest();
pr3.date = new LocalDate(2015, 6, 10);
pr3.fromTime = 7 * 3600;
pr3.toTime = 9 * 3600;
pr3.fromLat = pr2.toLat = 39.9621;
pr3.fromLon = pr2.toLon = -83.0007;
pr3.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
pr3.transitModes = new TraverseModeSet("TRANSIT");
pr3.scenario = new Scenario(0);
pr3.scenario.modifications = Arrays.asList(ctf3);
RepeatedRaptorProfileRouter rrpr3 = new RepeatedRaptorProfileRouter(gg, pr3);
rrpr3.route();
assertTrue(rrpr3.raptorWorkerData.hasFrequencies);
// should be converted to two independent patterns
assertEquals(2, rrpr3.raptorWorkerData.timetablesForPattern.size());
RaptorWorkerTimetable shrt, lng;
if (rrpr3.raptorWorkerData.timetablesForPattern.get(0).nStops == 2) {
shrt = rrpr3.raptorWorkerData.timetablesForPattern.get(0);
lng = rrpr3.raptorWorkerData.timetablesForPattern.get(1);
} else {
lng = rrpr3.raptorWorkerData.timetablesForPattern.get(0);
shrt = rrpr3.raptorWorkerData.timetablesForPattern.get(1);
}
assertEquals(3, lng.nStops);
assertEquals(2, shrt.nStops);
assertEquals(675, lng.headwaySecs[0]);
assertEquals((int) (FakeGraph.FREQUENCY / 0.1), shrt.headwaySecs[0]);
// make sure that the hop time is always FakeGraph.TRAVEL_TIME
assertEquals(FakeGraph.TRAVEL_TIME, shrt.frequencyTrips[0][2]);
assertEquals(FakeGraph.TRAVEL_TIME, lng.frequencyTrips[0][2]);
assertEquals(FakeGraph.TRAVEL_TIME * 2, lng.frequencyTrips[0][4]);
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class BusRouteStreetMatcher method buildGraph.
/*
The "extra" parameter is a mechanism for passing arbitrary things between graph builder modules.
Whether or not this is a good idea is open to debate, but that's what it is.
An EdgesForRoute instance is generated by MapBuilder and StreetMatcher, then retrieved later by the
NetworkLinkerLibrary later (actually in LinkRequests).
*/
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
// Mapbuilder needs transit index
graph.index(new DefaultStreetVertexIndexFactory());
StreetMatcher matcher = new StreetMatcher(graph);
EdgesForRoute edgesForRoute = new EdgesForRoute();
extra.put(EdgesForRoute.class, edgesForRoute);
log.info("Finding corresponding street edges for trip patterns...");
// Why do we need to iterate over the routes? Why not just patterns?
for (Route route : graph.index.routeForId.values()) {
for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
if (pattern.mode == TraverseMode.BUS) {
/* we can only match geometry to streets on bus routes */
log.debug("Matching {}", pattern);
// that is why pattern.geometry is null in that case
if (pattern.geometry == null) {
continue;
}
List<Edge> edges = matcher.match(pattern.geometry);
if (edges == null || edges.isEmpty()) {
log.warn("Could not match to street network: {}", pattern);
continue;
}
List<Coordinate> coordinates = new ArrayList<Coordinate>();
for (Edge e : edges) {
coordinates.addAll(Arrays.asList(e.getGeometry().getCoordinates()));
edgesForRoute.edgesForRoute.put(route, e);
}
Coordinate[] coordinateArray = new Coordinate[coordinates.size()];
LineString ls = GeometryUtils.getGeometryFactory().createLineString(coordinates.toArray(coordinateArray));
// Replace the pattern's geometry from GTFS with that of the equivalent OSM edges.
pattern.geometry = ls;
}
}
}
}
use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.
the class OTPMain method run.
/**
* Making OTPMain a concrete class and placing this logic an instance method instead of embedding it in the static
* main method makes it possible to build graphs from web services or scripts, not just from the command line.
*/
public void run() {
// TODO do params.infer() here to ensure coherency?
/* Create the top-level objects that represent the OTP server. */
makeGraphService();
otpServer = new OTPServer(params, graphService);
/* Start graph builder if requested */
if (params.build != null) {
// TODO multiple directories
GraphBuilder graphBuilder = GraphBuilder.forDirectory(params, params.build);
if (graphBuilder != null) {
graphBuilder.run();
/* If requested, hand off the graph to the server as the default graph using an in-memory GraphSource. */
if (params.inMemory || params.preFlight) {
Graph graph = graphBuilder.getGraph();
graph.index(new DefaultStreetVertexIndexFactory());
// FIXME set true router IDs
graphService.registerGraph("", new MemoryGraphSource("", graph));
}
} else {
LOG.error("An error occurred while building the graph. Exiting.");
System.exit(-1);
}
}
// FIXME eventually router IDs will be present even when just building a graph.
if ((params.routerIds != null && params.routerIds.size() > 0) || params.autoScan) {
/* Auto-register pre-existing graph on disk, with optional auto-scan. */
GraphScanner graphScanner = new GraphScanner(graphService, params.graphDirectory, params.autoScan);
graphScanner.basePath = params.graphDirectory;
if (params.routerIds != null && params.routerIds.size() > 0) {
graphScanner.defaultRouterId = params.routerIds.get(0);
}
graphScanner.autoRegister = params.routerIds;
graphScanner.startup();
}
/* Start visualizer if requested */
if (params.visualize) {
Router defaultRouter = graphService.getRouter();
defaultRouter.graphVisualizer = new GraphVisualizer(defaultRouter);
defaultRouter.graphVisualizer.run();
// avoid timeouts due to search animation
defaultRouter.timeouts = new double[] { 60 };
}
/* Start script if requested */
if (params.scriptFile != null) {
try {
OTPScript otpScript = new BSFOTPScript(otpServer, params.scriptFile);
if (otpScript != null) {
Object retval = otpScript.run();
if (retval != null) {
LOG.warn("Your script returned something, no idea what to do with it: {}", retval);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/* Start web server if requested */
if (params.server) {
GrizzlyServer grizzlyServer = new GrizzlyServer(params, otpServer);
while (true) {
// Loop to restart server on uncaught fatal exceptions.
try {
grizzlyServer.run();
return;
} catch (Throwable throwable) {
LOG.error("An uncaught {} occurred inside OTP. Restarting server.", throwable.getClass().getSimpleName(), throwable);
}
}
}
}
Aggregations