Search in sources :

Example 11 with AStar

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

the class AlertPatchTest method setUp.

public void setUp() throws Exception {
    aStar = new AStar();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    options = new RoutingRequest();
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    graph.index(new DefaultStreetVertexIndexFactory());
    feedId = context.getFeedId().getId();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) File(java.io.File)

Example 12 with AStar

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

the class ProfileRouter method findClosestStops.

/**
 * Perform an on-street search around a point with a specific mode to find nearby stops.
 * @param dest : whether to search at the destination instead of the origin.
 */
private Collection<StopAtDistance> findClosestStops(final QualifiedMode qmode, boolean dest) {
    // Make a normal OTP routing request so we can traverse edges and use GenericAStar
    // TODO make a function that builds normal routing requests from profile requests
    RoutingRequest rr = new RoutingRequest(new TraverseModeSet());
    qmode.applyToRoutingRequest(rr, request.transitModes.isTransit());
    rr.from = (new GenericLocation(request.fromLat, request.fromLon));
    // FIXME requires destination to be set, not necessary for analyst
    rr.to = new GenericLocation(request.toLat, request.toLon);
    rr.setArriveBy(dest);
    rr.setRoutingContext(graph);
    // Set batch after context, so both origin and dest vertices will be found.
    rr.batch = (true);
    rr.walkSpeed = request.walkSpeed;
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    int minAccessTime = 0;
    int maxAccessTime = request.maxWalkTime;
    if (qmode.mode == TraverseMode.BICYCLE) {
        rr.bikeSpeed = request.bikeSpeed;
        minAccessTime = request.minBikeTime;
        maxAccessTime = request.maxBikeTime;
        rr.optimize = OptimizeType.TRIANGLE;
        rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
    } else if (qmode.mode == TraverseMode.CAR) {
        rr.carSpeed = request.carSpeed;
        minAccessTime = request.minCarTime;
        maxAccessTime = request.maxCarTime;
    }
    // convert from minutes to seconds
    long worstElapsedTimeSeconds = maxAccessTime * 60;
    if (dest)
        worstElapsedTimeSeconds *= -1;
    rr.worstTime = (rr.dateTime + worstElapsedTimeSeconds);
    AStar astar = new AStar();
    rr.setNumItineraries(1);
    StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(qmode, minAccessTime * 60);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 5);
    // Save the routing context for later cleanup. We need its temporary edges to render street segments at the end.
    routingContexts.add(rr.rctx);
    return visitor.stopClustersFound.values();
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 13 with AStar

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

the class ProfileRouter method findDirectOption.

/**
 * Look for an option connecting origin to destination without using transit.
 */
private void findDirectOption(QualifiedMode qmode) {
    // Make a normal OTP routing request so we can traverse edges and use GenericAStar
    RoutingRequest rr = new RoutingRequest(new TraverseModeSet());
    // false because we never use transit in direct options
    qmode.applyToRoutingRequest(rr, false);
    if (qmode.mode == TraverseMode.BICYCLE) {
        // TRIANGLE should only affect bicycle searches, but we wrap this in a conditional just to be clear.
        rr.optimize = OptimizeType.TRIANGLE;
        rr.setTriangleNormalized(request.bikeSafe, request.bikeSlope, request.bikeTime);
    }
    rr.from = (new GenericLocation(request.fromLat, request.fromLon));
    rr.to = new GenericLocation(request.toLat, request.toLon);
    rr.setArriveBy(false);
    rr.setRoutingContext(graph);
    rr.dominanceFunction = new DominanceFunction.MinimumWeight();
    // This is not a batch search, it is a point-to-point search with goal direction.
    // Impose a max time to protect against very slow searches.
    int worstElapsedTime = request.streetTime * 60;
    rr.worstTime = (rr.dateTime + worstElapsedTime);
    rr.walkSpeed = request.walkSpeed;
    rr.bikeSpeed = request.bikeSpeed;
    AStar astar = new AStar();
    rr.setNumItineraries(1);
    ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
    State state = spt.getState(rr.rctx.target);
    if (state != null) {
        LOG.info("Found non-transit option for {}", qmode);
        directPaths.add(new StopAtDistance(state, qmode));
    }
    // save context for later cleanup so temp edges remain available
    routingContexts.add(rr.rctx);
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 14 with AStar

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

the class RoundBasedProfileRouter method findInitialStops.

/**
 * find the boarding stops
 */
private Collection<ProfileState> findInitialStops(boolean dest) {
    double lat = dest ? request.toLat : request.fromLat;
    double lon = dest ? request.toLon : request.fromLon;
    QualifiedModeSet modes = dest ? request.accessModes : request.egressModes;
    List<ProfileState> stops = Lists.newArrayList();
    RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.batch = true;
    rr.from = new GenericLocation(lat, lon);
    rr.walkSpeed = request.walkSpeed;
    rr.to = rr.from;
    rr.setRoutingContext(graph);
    // RoutingRequest dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    rr.worstTime = (rr.dateTime + request.maxWalkTime * 60);
    AStar astar = new AStar();
    rr.longDistance = true;
    rr.setNumItineraries(1);
    // timeout in seconds
    ShortestPathTree spt = astar.getShortestPathTree(rr, 5);
    for (TransitStop tstop : graph.index.stopVertexForStop.values()) {
        State s = spt.getState(tstop);
        if (s != null) {
            ProfileState ps = new ProfileState();
            ps.lowerBound = ps.upperBound = (int) s.getElapsedTimeSeconds();
            ps.stop = tstop;
            ps.accessType = Type.STREET;
            stops.add(ps);
        }
    }
    Map<TripPattern, ProfileState> optimalBoardingLocation = Maps.newHashMap();
    TObjectIntMap<TripPattern> minBoardTime = new TObjectIntHashMap<TripPattern>(100, 0.75f, Integer.MAX_VALUE);
    // Only board patterns at the closest possible stop
    for (ProfileState ps : stops) {
        for (TripPattern pattern : graph.index.patternsForStop.get(ps.stop.getStop())) {
            if (ps.lowerBound < minBoardTime.get(pattern)) {
                optimalBoardingLocation.put(pattern, ps);
                minBoardTime.put(pattern, ps.lowerBound);
            }
        }
        ps.targetPatterns = Sets.newHashSet();
    }
    LOG.info("Found {} reachable stops, filtering to only board at closest stops", stops.size());
    for (Entry<TripPattern, ProfileState> e : optimalBoardingLocation.entrySet()) {
        e.getValue().targetPatterns.add(e.getKey());
    }
    for (Iterator<ProfileState> it = stops.iterator(); it.hasNext(); ) {
        if (it.next().targetPatterns.isEmpty())
            it.remove();
    }
    rr.cleanup();
    return stops;
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) AStar(org.opentripplanner.routing.algorithm.AStar) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) State(org.opentripplanner.routing.core.State) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Example 15 with AStar

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

the class AnalystProfileRouterPrototype method findClosestStops.

/**
 * Perform an on-street search around a point with a specific mode to find nearby stops.
 * TODO merge with NearbyStopFinder
 */
private TObjectIntMap<Stop> findClosestStops(final TraverseMode mode) {
    RoutingRequest rr = new RoutingRequest(mode);
    GenericLocation gl = new GenericLocation(request.fromLat, request.fromLon);
    rr.from = gl;
    // FIXME destination must be set, even though this is meaningless for one-to-many
    rr.to = gl;
    rr.setRoutingContext(graph);
    // Set batch after context, so both origin and dest vertices will be found.
    rr.batch = (true);
    rr.walkSpeed = request.walkSpeed;
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    int minAccessTime = 0;
    int maxAccessTime = request.maxWalkTime;
    rr.worstTime = (rr.dateTime + maxAccessTime * 60);
    AStar astar = new AStar();
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.setNumItineraries(1);
    StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(mode, minAccessTime * 60);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 5);
    rr.cleanup();
    return visitor.stopsFound;
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

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