Search in sources :

Example 81 with Edge

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

the class GraphPathToTripPlanConverter method addModeAndAlerts.

/**
 * Add mode and alerts fields to a {@link Leg}.
 *
 * @param leg The leg to add the mode and alerts to
 * @param states The states that go with the leg
 */
private static void addModeAndAlerts(Graph graph, Leg leg, State[] states, boolean disableAlertFiltering, Locale requestedLocale) {
    for (State state : states) {
        TraverseMode mode = state.getBackMode();
        Set<Alert> alerts = graph.streetNotesService.getNotes(state);
        Edge edge = state.getBackEdge();
        if (mode != null) {
            leg.mode = mode.toString();
        }
        if (alerts != null) {
            for (Alert alert : alerts) {
                leg.addAlert(alert, requestedLocale);
            }
        }
        for (AlertPatch alertPatch : graph.getAlertPatches(edge)) {
            if (disableAlertFiltering || alertPatch.displayDuring(state)) {
                if (alertPatch.hasTrip()) {
                    // this leg.
                    if (alertPatch.getTrip().equals(leg.tripId)) {
                        leg.addAlert(alertPatch.getAlert(), requestedLocale);
                    }
                } else {
                    // If we are not matching a particular trip add all known alerts for this trip pattern.
                    leg.addAlert(alertPatch.getAlert(), requestedLocale);
                }
            }
        }
    }
}
Also used : AlertPatch(org.opentripplanner.routing.alertpatch.AlertPatch) Alert(org.opentripplanner.routing.alertpatch.Alert) Edge(org.opentripplanner.routing.graph.Edge)

Example 82 with Edge

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

the class GraphPathToTripPlanConverter method calculateElevations.

/**
 * Calculate the elevationGained and elevationLost fields of an {@link Itinerary}.
 *
 * @param itinerary The itinerary to calculate the elevation changes for
 * @param edges The edges that go with the itinerary
 */
private static void calculateElevations(Itinerary itinerary, Edge[] edges) {
    for (Edge edge : edges) {
        if (!(edge instanceof StreetEdge))
            continue;
        StreetEdge edgeWithElevation = (StreetEdge) edge;
        PackedCoordinateSequence coordinates = edgeWithElevation.getElevationProfile();
        if (coordinates == null)
            continue;
        // TODO Check the test below, AFAIU current elevation profile has 3 dimensions.
        if (coordinates.getDimension() != 2)
            continue;
        for (int i = 0; i < coordinates.size() - 1; i++) {
            double change = coordinates.getOrdinate(i + 1, 1) - coordinates.getOrdinate(i, 1);
            if (change > 0) {
                itinerary.elevationGained += change;
            } else if (change < 0) {
                itinerary.elevationLost -= change;
            }
        }
    }
}
Also used : Edge(org.opentripplanner.routing.graph.Edge) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence)

Example 83 with Edge

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

the class GraphPathToTripPlanConverter method generateLeg.

/**
 * Generate one leg of an itinerary from a {@link State} array.
 *
 * @param states The array of states to base the leg on
 * @param showIntermediateStops Whether to include intermediate stops in the leg or not
 * @return The generated leg
 */
private static Leg generateLeg(Graph graph, State[] states, boolean showIntermediateStops, boolean disableAlertFiltering, Locale requestedLocale) {
    Leg leg = new Leg();
    Edge[] edges = new Edge[states.length - 1];
    leg.startTime = makeCalendar(states[0]);
    leg.endTime = makeCalendar(states[states.length - 1]);
    // Calculate leg distance and fill array of edges
    leg.distance = 0.0;
    for (int i = 0; i < edges.length; i++) {
        edges[i] = states[i + 1].getBackEdge();
        leg.distance += edges[i].getDistance();
    }
    TimeZone timeZone = leg.startTime.getTimeZone();
    leg.agencyTimeZoneOffset = timeZone.getOffset(leg.startTime.getTimeInMillis());
    addTripFields(leg, states, requestedLocale);
    addPlaces(leg, states, edges, showIntermediateStops, requestedLocale);
    CoordinateArrayListSequence coordinates = makeCoordinates(edges);
    Geometry geometry = GeometryUtils.getGeometryFactory().createLineString(coordinates);
    leg.legGeometry = PolylineEncoder.createEncodings(geometry);
    leg.interlineWithPreviousLeg = states[0].getBackEdge() instanceof PatternInterlineDwell;
    addFrequencyFields(states, leg);
    leg.rentedBike = states[0].isBikeRenting() && states[states.length - 1].isBikeRenting();
    addModeAndAlerts(graph, leg, states, disableAlertFiltering, requestedLocale);
    if (leg.isTransitLeg())
        addRealTimeData(leg, states);
    return leg;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Edge(org.opentripplanner.routing.graph.Edge)

Example 84 with Edge

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

the class GraphPathToTripPlanConverter method createWalkStep.

private static WalkStep createWalkStep(Graph graph, State s, Locale wantedLocale) {
    Edge en = s.getBackEdge();
    WalkStep step;
    step = new WalkStep();
    step.streetName = en.getName(wantedLocale);
    step.lon = en.getFromVertex().getX();
    step.lat = en.getFromVertex().getY();
    step.elevation = encodeElevationProfile(s.getBackEdge(), 0, s.getOptions().geoidElevation ? -graph.ellipsoidToGeoidDifference : 0);
    step.bogusName = en.hasBogusName();
    step.addAlerts(graph.streetNotesService.getNotes(s), wantedLocale);
    step.angle = DirectionUtils.getFirstAngle(s.getBackEdge().getGeometry());
    if (s.getBackEdge() instanceof AreaEdge) {
        step.area = true;
    }
    return step;
}
Also used : Edge(org.opentripplanner.routing.graph.Edge)

Example 85 with Edge

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

the class GraphCoherencyCheckerModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    boolean coherent = true;
    LOG.info("checking graph coherency...");
    for (Vertex v : graph.getVertices()) {
        if (v.getOutgoing().isEmpty() && v.getIncoming().isEmpty()) {
            LOG.error("vertex {} has no edges", v);
            coherent = false;
        }
        for (Edge e : v.getOutgoing()) {
            if (e.getFromVertex() != v) {
                LOG.error("outgoing edge of {}: from vertex {} does not match", v, e);
                coherent = false;
            }
            if (e.getToVertex() == null) {
                LOG.error("outgoing edge has no to vertex {}", e);
                coherent = false;
            }
        }
        for (Edge e : v.getIncoming()) {
            if (e.getFromVertex() == null) {
                LOG.error("incoming edge has no from vertex {}", e);
                coherent = false;
            }
            if (e.getToVertex() != v) {
                LOG.error("incoming edge of {}: to vertex {} does not match", v, e);
                coherent = false;
            }
        }
    }
    LOG.info("edge lists and from/to members are {}coherent.", coherent ? "" : "not ");
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Edge (org.opentripplanner.routing.graph.Edge)113 Vertex (org.opentripplanner.routing.graph.Vertex)61 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)53 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)26 HashSet (java.util.HashSet)23 State (org.opentripplanner.routing.core.State)22 Coordinate (com.vividsolutions.jts.geom.Coordinate)19 Graph (org.opentripplanner.routing.graph.Graph)19 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)18 Test (org.junit.Test)17 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)17 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)17 ArrayList (java.util.ArrayList)16 LineString (com.vividsolutions.jts.geom.LineString)15 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Stop (org.onebusaway.gtfs.model.Stop)9 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)9