Search in sources :

Example 16 with AStar

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

the class IsoChroneSPTRendererRecursiveGrid method getIsochrones.

/**
 * @param isoChroneRequest
 * @param sptRequest
 * @return
 */
@Override
public List<IsochroneData> getIsochrones(IsoChroneRequest isoChroneRequest, RoutingRequest sptRequest) {
    if (sptRequest.routerId != null && !sptRequest.routerId.isEmpty())
        throw new IllegalArgumentException("TODO: SampleSource is not multi-router compatible (yet).");
    // 1. Compute the Shortest Path Tree.
    long t0 = System.currentTimeMillis();
    sptRequest.worstTime = (sptRequest.dateTime + (sptRequest.arriveBy ? -isoChroneRequest.maxCutoffSec : isoChroneRequest.maxCutoffSec));
    sptRequest.batch = true;
    sptRequest.setRoutingContext(graph);
    // TODO handle different path dominance conditions
    final ShortestPathTree spt = new AStar().getShortestPathTree(sptRequest);
    sptRequest.cleanup();
    // 2. Compute the set of initial points
    long t1 = System.currentTimeMillis();
    List<Coordinate> initialPoints = computeInitialPoints(spt);
    // 3. Compute the isochrone based on the SPT.
    ZFunc timeFunc = new ZFunc() {

        @Override
        public long z(Coordinate c) {
            Sample sample = sampleSource.getSample(c.x, c.y);
            if (sample == null) {
                return Long.MAX_VALUE;
            }
            Long z = sample.eval(spt);
            return z;
        }
    };
    // TODO Snap the center as XYZ tile grid for better sample-reuse (if using sample cache).
    Coordinate center = sptRequest.from.getCoordinate();
    double gridSizeMeters = isoChroneRequest.precisionMeters;
    double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / Math.cos(Math.toRadians(center.x));
    LOG.info("dX={}, dY={}", dX, dY);
    RecursiveGridIsolineBuilder isolineBuilder = new RecursiveGridIsolineBuilder(dX, dY, center, timeFunc, initialPoints);
    isolineBuilder.setDebugCrossingEdges(isoChroneRequest.includeDebugGeometry);
    isolineBuilder.setDebugSeedGrid(isoChroneRequest.includeDebugGeometry);
    List<IsochroneData> isochrones = new ArrayList<IsochroneData>();
    for (Integer cutoffSec : isoChroneRequest.cutoffSecList) {
        IsochroneData isochrone = new IsochroneData(cutoffSec, isolineBuilder.computeIsoline(cutoffSec));
        if (isoChroneRequest.includeDebugGeometry)
            isochrone.debugGeometry = isolineBuilder.getDebugGeometry();
        isochrones.add(isochrone);
    }
    long t2 = System.currentTimeMillis();
    LOG.info("Computed SPT in {}msec, {} isochrones in {}msec", (int) (t1 - t0), isochrones.size(), (int) (t2 - t1));
    return isochrones;
}
Also used : Sample(org.opentripplanner.analyst.core.Sample) AStar(org.opentripplanner.routing.algorithm.AStar) ArrayList(java.util.ArrayList) ZFunc(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder.ZFunc) IsochroneData(org.opentripplanner.analyst.core.IsochroneData) RecursiveGridIsolineBuilder(org.opentripplanner.common.geometry.RecursiveGridIsolineBuilder) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 17 with AStar

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

the class OtpsRouter method plan.

/**
 * Plan a route on the router given the various options.
 *
 * @param req The routing request options (date/time, modes, etc...)
 * @return A Shortest-path-tree (a time+various states for each vertices around the
 *         origin/destination).
 */
public OtpsSPT plan(OtpsRoutingRequest req) {
    try {
        // TODO Is this correct?
        RoutingRequest req2 = req.req.clone();
        req2.setRoutingContext(router.graph);
        // TODO verify that this is indeed the intended behavior.
        ShortestPathTree spt = new AStar().getShortestPathTree(req2);
        return new OtpsSPT(spt, router.graph.getSampleFactory());
    } catch (VertexNotFoundException e) {
        // Can happen, not really an error
        return null;
    }
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Aggregations

AStar (org.opentripplanner.routing.algorithm.AStar)17 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)15 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)10 GenericLocation (org.opentripplanner.common.model.GenericLocation)9 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)9 State (org.opentripplanner.routing.core.State)4 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)4 Graph (org.opentripplanner.routing.graph.Graph)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 TIntIntMap (gnu.trove.map.TIntIntMap)3 Test (org.junit.Test)3 Edge (org.opentripplanner.routing.graph.Edge)3 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)3 File (java.io.File)2 BitSet (java.util.BitSet)2 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)2 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 GraphPath (org.opentripplanner.routing.spt.GraphPath)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2