Search in sources :

Example 1 with EarliestArrivalSearch

use of org.opentripplanner.routing.algorithm.EarliestArrivalSearch in project OpenTripPlanner by opentripplanner.

the class SurfaceResource method createSurface.

@POST
public Response createSurface(@QueryParam("cutoffMinutes") @DefaultValue("90") int cutoffMinutes, @QueryParam("routerId") String routerId) {
    // Build the request
    try {
        // batch must be true
        RoutingRequest req = buildRequest();
        // routerId is optional -- select default graph if not set
        Router router = otpServer.getRouter(routerId);
        req.setRoutingContext(router.graph);
        EarliestArrivalSearch sptService = new EarliestArrivalSearch();
        sptService.maxDuration = (60 * cutoffMinutes);
        ShortestPathTree spt = sptService.getShortestPathTree(req);
        req.cleanup();
        if (spt != null) {
            TimeSurface surface = new TimeSurface(spt);
            surface.params = Maps.newHashMap();
            for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
                // include only the first instance of each query parameter
                surface.params.put(e.getKey(), e.getValue().get(0));
            }
            surface.cutoffMinutes = cutoffMinutes;
            otpServer.surfaceCache.add(surface);
            // .created(URI)
            return Response.ok().entity(new TimeSurfaceShort(surface)).build();
        } else {
            return Response.noContent().entity("NO SPT").build();
        }
    } catch (ParameterException pex) {
        return Response.status(Response.Status.BAD_REQUEST).entity("BAD USER").build();
    }
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TimeSurfaceShort(org.opentripplanner.api.model.TimeSurfaceShort) TimeSurface(org.opentripplanner.analyst.TimeSurface) Router(org.opentripplanner.standalone.Router) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) EarliestArrivalSearch(org.opentripplanner.routing.algorithm.EarliestArrivalSearch) ArrayList(java.util.ArrayList) List(java.util.List) ParameterException(org.opentripplanner.api.common.ParameterException) Map(java.util.Map) POST(javax.ws.rs.POST)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 TimeSurface (org.opentripplanner.analyst.TimeSurface)1 ParameterException (org.opentripplanner.api.common.ParameterException)1 TimeSurfaceShort (org.opentripplanner.api.model.TimeSurfaceShort)1 EarliestArrivalSearch (org.opentripplanner.routing.algorithm.EarliestArrivalSearch)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)1 Router (org.opentripplanner.standalone.Router)1