Search in sources :

Example 66 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class OnBoardDepartPatternHop method traverse.

public State traverse(State state0) {
    RoutingRequest options = state0.getOptions();
    if (options.reverseOptimizing || options.reverseOptimizeOnTheFly) {
        throw new UnsupportedOperationException("Cannot (yet) reverse-optimize depart-on-board mode.");
    }
    /* Can't be traversed backwards. */
    if (options.arriveBy)
        return null;
    StateEditor s1 = state0.edit(this);
    // s1.setBackMode(TraverseMode.BOARDING); TODO Do we need this?
    s1.setServiceDay(serviceDay);
    s1.setTripTimes(tripTimes);
    // s1.incrementNumBoardings(); TODO Needed?
    s1.setTripId(trip.getId());
    s1.setPreviousTrip(trip);
    s1.setZone(endStop.getZoneId());
    s1.setRoute(trip.getRoute().getId());
    int remainingTime = (int) Math.round((1.0 - positionInHop) * tripTimes.getRunningTime(stopIndex));
    s1.incrementTimeInSeconds(remainingTime);
    s1.incrementWeight(remainingTime);
    s1.setBackMode(getMode());
    s1.setEverBoarded(true);
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 67 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class BatchProcessor method buildRequest.

private RoutingRequest buildRequest(Individual i) {
    RoutingRequest req = prototypeRoutingRequest.clone();
    req.setDateTime(date, time, timeZone);
    if (searchCutoffSeconds > 0) {
        req.worstTime = req.dateTime + (req.arriveBy ? -searchCutoffSeconds : searchCutoffSeconds);
    }
    GenericLocation latLon = new GenericLocation(i.lat, i.lon);
    req.batch = true;
    if (req.arriveBy)
        req.to = latLon;
    else
        req.from = latLon;
    try {
        req.setRoutingContext(graphService.getRouter(req.routerId).graph);
        return req;
    } catch (VertexNotFoundException vnfe) {
        LOG.debug("no vertex could be created near the origin point");
        return null;
    }
}
Also used : GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Example 68 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class GraphPathToTripPlanConverterTest method testEmptyGraphPath.

/**
 * Test that empty graph paths throw a TrivialPathException
 */
@Test(expected = TrivialPathException.class)
public void testEmptyGraphPath() {
    RoutingRequest options = new RoutingRequest();
    Graph graph = new Graph();
    ExitVertex vertex = new ExitVertex(graph, "Vertex", 0, 0, 0);
    options.rctx = new RoutingContext(options, graph, vertex, vertex);
    GraphPath graphPath = new GraphPath(new State(options), false);
    GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) RoutingContext(org.opentripplanner.routing.core.RoutingContext) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 69 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class Router method startup.

/**
 * Below is functionality moved into Router from the "router lifecycle manager" interface and implementation.
 * Current responsibilities are: 1) Binding proper services (depending on the configuration from command-line or
 * JSON config files) and 2) starting / stopping real-time updaters (delegated to the GraphUpdaterConfigurator class).
 */
/**
 * Start up a new router once it has been created.
 * @param config The configuration (loaded from Graph.properties for example).
 */
public void startup(JsonNode config) {
    this.tileRendererManager = new TileRendererManager(this.graph);
    // Analyst Modules FIXME make these optional based on JSON?
    {
        this.tileCache = new TileCache(this.graph);
        this.renderer = new Renderer(this.tileCache);
        this.sampleGridRenderer = new SampleGridRenderer(this.graph);
        this.isoChroneSPTRenderer = new IsoChroneSPTRendererAccSampling(this.sampleGridRenderer);
    }
    /* Create the default router parameters from the JSON router config. */
    JsonNode routingDefaultsNode = config.get("routingDefaults");
    if (routingDefaultsNode != null) {
        LOG.info("Loading default routing parameters from JSON:");
        ReflectiveInitializer<RoutingRequest> scraper = new ReflectiveInitializer(RoutingRequest.class);
        this.defaultRoutingRequest = scraper.scrape(routingDefaultsNode);
    } else {
        LOG.info("No default routing parameters were found in the router config JSON. Using built-in OTP defaults.");
        this.defaultRoutingRequest = new RoutingRequest();
    }
    /* Apply single timeout. */
    JsonNode timeout = config.get("timeout");
    if (timeout != null) {
        if (timeout.isNumber()) {
            this.timeouts = new double[] { timeout.doubleValue() };
        } else {
            LOG.error("The 'timeout' configuration option should be a number of seconds.");
        }
    }
    /* Apply multiple timeouts. */
    JsonNode timeouts = config.get("timeouts");
    if (timeouts != null) {
        if (timeouts.isArray() && timeouts.size() > 0) {
            this.timeouts = new double[timeouts.size()];
            int i = 0;
            for (JsonNode node : timeouts) {
                this.timeouts[i++] = node.doubleValue();
            }
        } else {
            LOG.error("The 'timeouts' configuration option should be an array of values in seconds.");
        }
    }
    LOG.info("Timeouts for router '{}': {}", this.id, this.timeouts);
    JsonNode requestLogFile = config.get("requestLogFile");
    if (requestLogFile != null) {
        this.requestLogger = createLogger(requestLogFile.asText());
        LOG.info("Logging incoming requests at '{}'", requestLogFile.asText());
    } else {
        LOG.info("Incoming requests will not be logged.");
    }
    JsonNode boardTimes = config.get("boardTimes");
    if (boardTimes != null && boardTimes.isObject()) {
        graph.boardTimes = new EnumMap<>(TraverseMode.class);
        for (TraverseMode mode : TraverseMode.values()) {
            if (boardTimes.has(mode.name())) {
                graph.boardTimes.put(mode, boardTimes.get(mode.name()).asInt(0));
            }
        }
    }
    JsonNode alightTimes = config.get("alightTimes");
    if (alightTimes != null && alightTimes.isObject()) {
        graph.alightTimes = new EnumMap<>(TraverseMode.class);
        for (TraverseMode mode : TraverseMode.values()) {
            if (alightTimes.has(mode.name())) {
                graph.alightTimes.put(mode, alightTimes.get(mode.name()).asInt(0));
            }
        }
    }
    JsonNode stopClusterMode = config.get("stopClusterMode");
    if (stopClusterMode != null) {
        graph.stopClusterMode = stopClusterMode.asText();
    } else {
        graph.stopClusterMode = "proximity";
    }
    /* Create Graph updater modules from JSON config. */
    GraphUpdaterConfigurator.setupGraph(this.graph, config);
    /* Compute ellipsoidToGeoidDifference for this Graph */
    try {
        WorldEnvelope env = graph.getEnvelope();
        double lat = (env.getLowerLeftLatitude() + env.getUpperRightLatitude()) / 2;
        double lon = (env.getLowerLeftLongitude() + env.getUpperRightLongitude()) / 2;
        graph.ellipsoidToGeoidDifference = ElevationUtils.computeEllipsoidToGeoidDifference(lat, lon);
        LOG.info("Computed ellipsoid/geoid offset at (" + lat + ", " + lon + ") as " + graph.ellipsoidToGeoidDifference);
    } catch (Exception e) {
        LOG.error("Error computing ellipsoid/geoid difference");
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ReflectiveInitializer(org.opentripplanner.reflect.ReflectiveInitializer) TileRendererManager(org.opentripplanner.inspector.TileRendererManager) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseMode(org.opentripplanner.routing.core.TraverseMode) WorldEnvelope(org.opentripplanner.util.WorldEnvelope)

Example 70 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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

RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)124 GraphPath (org.opentripplanner.routing.spt.GraphPath)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)52 State (org.opentripplanner.routing.core.State)42 Test (org.junit.Test)35 Vertex (org.opentripplanner.routing.graph.Vertex)35 Graph (org.opentripplanner.routing.graph.Graph)24 GenericLocation (org.opentripplanner.common.model.GenericLocation)21 Edge (org.opentripplanner.routing.graph.Edge)18 StateEditor (org.opentripplanner.routing.core.StateEditor)17 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)17 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 AStar (org.opentripplanner.routing.algorithm.AStar)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11 Trip (org.onebusaway.gtfs.model.Trip)9