use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class RepeatedRaptorComparison method buildGraph.
private static Graph buildGraph(File directory) {
CommandLineParameters params = new CommandLineParameters();
params.build = directory;
params.inMemory = true;
GraphBuilder graphBuilder = GraphBuilder.forDirectory(params, params.build);
graphBuilder.run();
Graph graph = graphBuilder.getGraph();
graph.routerId = "GRAPH";
graph.index(new DefaultStreetVertexIndexFactory());
graph.index.clusterStopsAsNeeded();
return graph;
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class ClusterGraphService method getRouter.
@Override
public synchronized Router getRouter(String graphId) {
GRAPH_DIR.mkdirs();
if (!graphMap.containsKey(graphId)) {
try {
if (!bucketCached(graphId)) {
if (!workOffline) {
downloadGraphSourceFiles(graphId, GRAPH_DIR);
}
}
} catch (IOException e) {
LOG.error("exception finding graph {}", graphId, e);
}
CommandLineParameters params = new CommandLineParameters();
params.build = new File(GRAPH_DIR, graphId);
params.inMemory = true;
GraphBuilder gbt = GraphBuilder.forDirectory(params, params.build);
gbt.run();
Graph g = gbt.getGraph();
g.routerId = graphId;
g.index(new DefaultStreetVertexIndexFactory());
g.index.clusterStopsAsNeeded();
Router r = new Router(graphId, g);
return r;
} else {
return graphMap.get(graphId);
}
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class Routers method buildGraphOverWire.
/**
* Build a graph from data in the ZIP file posted over the wire, associating it with the given router ID.
* This method will be selected when the Content-Type is application/zip.
*/
@RolesAllowed({ "ROUTERS" })
@POST
@Path("{routerId}")
@Consumes({ "application/zip" })
@Produces({ MediaType.TEXT_PLAIN })
public Response buildGraphOverWire(@PathParam("routerId") String routerId, @QueryParam("preEvict") @DefaultValue("true") boolean preEvict, InputStream input) {
if (preEvict) {
LOG.debug("Pre-evicting graph with routerId {} before building new graph", routerId);
otpServer.getGraphService().evictRouter(routerId);
}
// get a temporary directory, using Google Guava
File tempDir = Files.createTempDir();
// extract the zip file to the temp dir
ZipInputStream zis = new ZipInputStream(input);
try {
for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
if (entry.isDirectory())
// we only support flat ZIP files
return Response.status(Response.Status.BAD_REQUEST).entity("ZIP files containing directories are not supported").build();
File file = new File(tempDir, entry.getName());
if (!file.getParentFile().equals(tempDir))
return Response.status(Response.Status.BAD_REQUEST).entity("ZIP files containing directories are not supported").build();
OutputStream os = new FileOutputStream(file);
ByteStreams.copy(zis, os);
os.close();
}
} catch (Exception ex) {
return Response.status(Response.Status.BAD_REQUEST).entity("Could not extract zip file: " + ex.getMessage()).build();
}
// set up the build, using default parameters
// this is basically simulating calling otp -b on the command line
CommandLineParameters params = otpServer.params.clone();
params.build = tempDir;
params.inMemory = true;
GraphBuilder graphBuilder = GraphBuilder.forDirectory(params, tempDir);
graphBuilder.run();
// so we'll crash long before we get here . . .
for (File file : tempDir.listFiles()) {
file.delete();
}
tempDir.delete();
Graph graph = graphBuilder.getGraph();
graph.index(new DefaultStreetVertexIndexFactory());
GraphService graphService = otpServer.getGraphService();
graphService.registerGraph(routerId, new MemoryGraphSource(routerId, graph));
return Response.status(Status.CREATED).entity(graph.toString() + "\n").build();
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class TestIntermediatePlaces method setUp.
@BeforeClass
public static void setUp() {
try {
Graph graph = FakeGraph.buildGraphNoTransit();
FakeGraph.addPerpendicularRoutes(graph);
FakeGraph.link(graph);
graph.index(new DefaultStreetVertexIndexFactory());
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", graph));
Router router = otpServer.getGraphService().getRouter("A");
TestIntermediatePlaces.graphPathFinder = new GraphPathFinder(router);
timeZone = graph.getTimeZone();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
assert false : "Could not build graph: " + e.getMessage();
} catch (Exception e) {
e.printStackTrace();
assert false : "Could not add transit data: " + e.getMessage();
}
}
use of org.opentripplanner.standalone.CommandLineParameters in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testBuildingAreas.
/**
* This reads test file with area
* and tests if it can be routed if visibility is used and if it isn't
*
* Routing needs to be successful in both options since without visibility calculation
* area rings are used.
* @param skipVisibility if true visibility calculations are skipped
* @throws UnsupportedEncodingException
*/
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
Graph gg = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.skipVisibility = skipVisibility;
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.gz").getFile(), "UTF-8"));
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, extra);
new StreetVertexIndexServiceImpl(gg);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", gg));
Router a = otpServer.getGraphService().getRouter("A");
RoutingRequest request = new RoutingRequest("WALK");
// This are vertices that can be connected only over edges on area (with correct permissions)
// It tests if it is possible to route over area without visibility calculations
Vertex bottomV = gg.getVertex("osm:node:580290955");
Vertex topV = gg.getVertex("osm:node:559271124");
request.setRoutingContext(a.graph, bottomV, topV);
GraphPathFinder graphPathFinder = new GraphPathFinder(a);
List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
assertNotNull(pathList);
assertFalse(pathList.isEmpty());
for (GraphPath path : pathList) {
assertFalse(path.states.isEmpty());
}
}
Aggregations