Search in sources :

Example 36 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class EuclideanRemainingWeightHeuristic method initialize.

@Override
public void initialize(RoutingRequest options, long abortTime) {
    RoutingRequest req = options;
    Vertex target = req.rctx.target;
    this.transit = req.modes.isTransit();
    maxStreetSpeed = req.getStreetSpeedUpperBound();
    maxTransitSpeed = req.getTransitSpeedUpperBound();
    if (target.getDegreeIn() == 1) {
        Edge edge = Iterables.getOnlyElement(target.getIncoming());
        if (edge instanceof FreeEdge) {
            target = edge.getFromVertex();
        }
    }
    lat = target.getLat();
    lon = target.getLon();
    requiredWalkDistance = determineRequiredWalkDistance(req);
    walkReluctance = req.walkReluctance;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 37 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class EuclideanRemainingWeightHeuristic method estimateRemainingWeight.

/**
 * On a non-transit trip, the remaining weight is simply distance / street speed.
 * On a transit trip, there are two cases:
 * (1) we're not on a transit vehicle. In this case, there are two possible ways to compute
 *     the remaining distance, and we take whichever is smaller:
 *     (a) walking distance / walking speed
 *     (b) boarding cost + transit distance / transit speed (this is complicated a bit when
 *         we know that there is some walking portion of the trip).
 * (2) we are on a transit vehicle, in which case the remaining weight is simply transit
 *     distance / transit speed (no need for boarding cost), again considering any mandatory
 *     walking.
 */
@Override
public double estimateRemainingWeight(State s) {
    Vertex sv = s.getVertex();
    double euclideanDistance = SphericalDistanceLibrary.fastDistance(sv.getLat(), sv.getLon(), lat, lon);
    if (transit) {
        if (euclideanDistance < requiredWalkDistance) {
            return walkReluctance * euclideanDistance / maxStreetSpeed;
        }
        /* Due to the above conditional, the following value is known to be positive. */
        double transitWeight = (euclideanDistance - requiredWalkDistance) / maxTransitSpeed;
        double streetWeight = walkReluctance * (requiredWalkDistance / maxStreetSpeed);
        return transitWeight + streetWeight;
    } else {
        // all travel is on-street, no transit involved
        return walkReluctance * euclideanDistance / maxStreetSpeed;
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex)

Example 38 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class MultiTargetTerminationStrategy method shouldSearchTerminate.

/**
 * Updates the list of reached targets and returns True if all the
 * targets have been reached.
 */
@Override
public boolean shouldSearchTerminate(Vertex origin, Vertex target, State current, ShortestPathTree spt, RoutingRequest traverseOptions) {
    Vertex currentVertex = current.getVertex();
    // but rather along edges in the graph.
    if (unreachedTargets.contains(currentVertex)) {
        unreachedTargets.remove(currentVertex);
        reachedTargets.add(currentVertex);
    }
    return unreachedTargets.size() == 0;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex)

Example 39 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class State method multipleOptionsBefore.

public boolean multipleOptionsBefore() {
    boolean foundAlternatePaths = false;
    TraverseMode requestedMode = getNonTransitMode();
    for (Edge out : backState.vertex.getOutgoing()) {
        if (out == backEdge) {
            continue;
        }
        if (!(out instanceof StreetEdge)) {
            continue;
        }
        State outState = out.traverse(backState);
        if (outState == null) {
            continue;
        }
        if (!outState.getBackMode().equals(requestedMode)) {
            // walking a bike, so, not really an exit
            continue;
        }
        // this section handles the case of an option which is only an option if you walk your
        // bike. It is complicated because you will not need to walk your bike until one
        // edge after the current edge.
        // now, from here, try a continuing path.
        Vertex tov = outState.getVertex();
        boolean found = false;
        for (Edge out2 : tov.getOutgoing()) {
            State outState2 = out2.traverse(outState);
            if (outState2 != null && !outState2.getBackMode().equals(requestedMode)) {
                // walking a bike, so, not really an exit
                continue;
            }
            found = true;
            break;
        }
        if (!found) {
            continue;
        }
        // there were paths we didn't take.
        foundAlternatePaths = true;
        break;
    }
    return foundAlternatePaths;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Edge(org.opentripplanner.routing.graph.Edge)

Example 40 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class SimpleIsochrone method makeContours.

/**
 * @return a map from contour (isochrone) thresholds in seconds to geometries.
 */
private Map<Integer, Geometry> makeContours() throws Exception {
    Map<Vertex, Double> points = makePoints();
    if (points == null || points.isEmpty()) {
        LOG.error("No destinations were reachable.");
        return null;
    }
    /* Set up transforms into projected coordinates (necessary for buffering in meters) */
    /* We could avoid projection by equirectangular approximation */
    CoordinateReferenceSystem wgs = DefaultGeographicCRS.WGS84;
    CoordinateReferenceSystem crs = CRS.decode(crsCode);
    MathTransform toMeters = CRS.findMathTransform(wgs, crs, false);
    MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false);
    GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();
    /* One list of geometries for each contour */
    Multimap<Integer, Geometry> bufferLists = ArrayListMultimap.create();
    for (int c = 0; c < nContours; ++c) {
        int thresholdSeconds = (c + 1) * contourSpacingMinutes * 60;
        for (Map.Entry<Vertex, Double> vertexSeconds : points.entrySet()) {
            double remainingSeconds = thresholdSeconds - vertexSeconds.getValue();
            if (remainingSeconds > 60) {
                // avoid degenerate geometries
                double remainingMeters = remainingSeconds * request.walkSpeed;
                Geometry point = geomf.createPoint(vertexSeconds.getKey().getCoordinate());
                point = JTS.transform(point, toMeters);
                Geometry buffer = point.buffer(remainingMeters);
                bufferLists.put(thresholdSeconds, buffer);
            }
        }
    }
    /* Union the geometries at each contour threshold. */
    Map<Integer, Geometry> contours = Maps.newHashMap();
    for (Integer threshold : bufferLists.keys()) {
        Collection<Geometry> buffers = bufferLists.get(threshold);
        // make geometry collection
        Geometry geom = geomf.buildGeometry(buffers);
        // combine all individual buffers in this contour into one
        geom = geom.union();
        if (!resultsProjected)
            geom = JTS.transform(geom, fromMeters);
        contours.put(threshold, geom);
    }
    return contours;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) MathTransform(org.opengis.referencing.operation.MathTransform) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11