Search in sources :

Example 1 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSourceTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    GtfsRelationalDao dao = context.getDao();
    feedId = context.getFeedId().getId();
    for (ShapePoint shapePoint : dao.getAllEntitiesForType(ShapePoint.class)) {
        shapePoint.getShapeId().setAgencyId(feedId);
    }
    for (Route route : dao.getAllEntitiesForType(Route.class)) {
        route.getId().setAgencyId(feedId);
    }
    for (Stop stop : dao.getAllEntitiesForType(Stop.class)) {
        stop.getId().setAgencyId(feedId);
    }
    for (Trip trip : dao.getAllEntitiesForType(Trip.class)) {
        trip.getId().setAgencyId(feedId);
    }
    for (ServiceCalendar serviceCalendar : dao.getAllEntitiesForType(ServiceCalendar.class)) {
        serviceCalendar.getServiceId().setAgencyId(feedId);
    }
    for (ServiceCalendarDate serviceCalendarDate : dao.getAllEntitiesForType(ServiceCalendarDate.class)) {
        serviceCalendarDate.getServiceId().setAgencyId(feedId);
    }
    for (FareAttribute fareAttribute : dao.getAllEntitiesForType(FareAttribute.class)) {
        fareAttribute.getId().setAgencyId(feedId);
    }
    for (Pathway pathway : dao.getAllEntitiesForType(Pathway.class)) {
        pathway.getId().setAgencyId(feedId);
    }
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.index(new DefaultStreetVertexIndexFactory());
    final TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("1.1");
    tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
    final TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();
    tripUpdateBuilder.setTrip(tripDescriptorBuilder);
    cancellation = tripUpdateBuilder.build().toByteArray();
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 2 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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;
}
Also used : CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) GraphBuilder(org.opentripplanner.graph_builder.GraphBuilder) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)

Example 3 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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);
    }
}
Also used : CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) Router(org.opentripplanner.standalone.Router) GraphBuilder(org.opentripplanner.graph_builder.GraphBuilder) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ZipFile(java.util.zip.ZipFile)

Example 4 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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();
}
Also used : GraphService(org.opentripplanner.routing.services.GraphService) ZipInputStream(java.util.zip.ZipInputStream) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) GraphBuilder(org.opentripplanner.graph_builder.GraphBuilder) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) File(java.io.File) GraphNotFoundException(org.opentripplanner.routing.error.GraphNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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();
    }
}
Also used : GraphService(org.opentripplanner.routing.services.GraphService) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) Router(org.opentripplanner.standalone.Router) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)21 Graph (org.opentripplanner.routing.graph.Graph)19 Test (org.junit.Test)11 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)10 LocalDate (org.joda.time.LocalDate)6 File (java.io.File)5 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)5 GraphBuilder (org.opentripplanner.graph_builder.GraphBuilder)5 ProfileRequest (org.opentripplanner.profile.ProfileRequest)5 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)5 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)5 TIntIntMap (gnu.trove.map.TIntIntMap)4 CommandLineParameters (org.opentripplanner.standalone.CommandLineParameters)4 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)3 AStar (org.opentripplanner.routing.algorithm.AStar)3 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 Router (org.opentripplanner.standalone.Router)3 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)2 LineString (com.vividsolutions.jts.geom.LineString)2 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)2