Search in sources :

Example 6 with FreeEdge

use of org.opentripplanner.routing.edgetype.FreeEdge in project OpenTripPlanner by opentripplanner.

the class GraphPathToTripPlanConverterTest method testLegSwitchOnlyGraphPath.

/**
 * Test that graph paths with only null and LEG_SWITCH modes throw a TrivialPathException
 */
@Test(expected = TrivialPathException.class)
public void testLegSwitchOnlyGraphPath() {
    RoutingRequest options = new RoutingRequest();
    Graph graph = new Graph();
    ExitVertex start = new ExitVertex(graph, "Start", 0, -90, 0);
    ExitVertex middle = new ExitVertex(graph, "Middle", 0, 0, 0);
    ExitVertex end = new ExitVertex(graph, "End", 0, 90, 0);
    FreeEdge depart = new FreeEdge(start, middle);
    LegSwitchingEdge arrive = new LegSwitchingEdge(middle, end);
    options.rctx = new RoutingContext(options, graph, start, end);
    State intermediate = depart.traverse(new State(options));
    GraphPath graphPath = new GraphPath(arrive.traverse(intermediate), false);
    GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) LegSwitchingEdge(org.opentripplanner.routing.edgetype.LegSwitchingEdge) 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) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Test(org.junit.Test)

Example 7 with FreeEdge

use of org.opentripplanner.routing.edgetype.FreeEdge in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactory method createParentStationTransfers.

/**
 * Create bidirectional, "free" edges (zero-time, low-cost edges) between stops and their
 * parent stations. This is used to produce implicit transfers between all stops that are
 * part of the same parent station. It was introduced as a workaround to allow in-station
 * transfers for underground/grade-separated transportation systems like the NYC subway (where
 * it's important to provide in-station transfers for fare computation).
 *
 * This step used to be automatically applied whenever transfers.txt was used to create
 * transfers (rather than or in addition to transfers through the street netowrk),
 * but has been separated out since it is really a separate process.
 */
public void createParentStationTransfers() {
    for (Stop stop : _dao.getAllStops()) {
        String parentStation = stop.getParentStation();
        if (parentStation != null) {
            Vertex stopVertex = context.stationStopNodes.get(stop);
            String agencyId = stop.getId().getAgencyId();
            AgencyAndId parentStationId = new AgencyAndId(agencyId, parentStation);
            Stop parentStop = _dao.getStopForId(parentStationId);
            Vertex parentStopVertex = context.stationStopNodes.get(parentStop);
            new FreeEdge(parentStopVertex, stopVertex);
            new FreeEdge(stopVertex, parentStopVertex);
            // Stops with location_type=2 (entrances as defined in the pathways.txt
            // proposal) have no arrive/depart vertices, hence the null checks.
            Vertex stopArriveVertex = context.stopArriveNodes.get(stop);
            Vertex parentStopArriveVertex = context.stopArriveNodes.get(parentStop);
            if (stopArriveVertex != null && parentStopArriveVertex != null) {
                new FreeEdge(parentStopArriveVertex, stopArriveVertex);
                new FreeEdge(stopArriveVertex, parentStopArriveVertex);
            }
            Vertex stopDepartVertex = context.stopDepartNodes.get(stop);
            Vertex parentStopDepartVertex = context.stopDepartNodes.get(parentStop);
            if (stopDepartVertex != null && parentStopDepartVertex != null) {
                new FreeEdge(parentStopDepartVertex, stopDepartVertex);
                new FreeEdge(stopDepartVertex, parentStopDepartVertex);
            }
        // TODO: provide a cost for these edges when stations and
        // stops have different locations
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop) LineString(com.vividsolutions.jts.geom.LineString) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge)

Example 8 with FreeEdge

use of org.opentripplanner.routing.edgetype.FreeEdge in project OpenTripPlanner by opentripplanner.

the class TestGraph method testGetEdgesMultiple.

public void testGetEdgesMultiple() {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    Vertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> expectedEdges = new HashSet<Edge>(4);
    expectedEdges.add(new FreeEdge(a, b));
    expectedEdges.add(new FreeEdge(b, c));
    expectedEdges.add(new FreeEdge(c, b));
    expectedEdges.add(new FreeEdge(c, a));
    Set<Edge> edges = new HashSet<Edge>(g.getEdges());
    assertEquals(4, edges.size());
    assertEquals(expectedEdges, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 9 with FreeEdge

use of org.opentripplanner.routing.edgetype.FreeEdge in project OpenTripPlanner by opentripplanner.

the class TestOverlayGraph method testBasic.

public void testBasic() throws Exception {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "a", 5, 5);
    Vertex b = new IntersectionVertex(g, "b", 6, 5);
    Vertex c = new IntersectionVertex(g, "c", 7, 5);
    Vertex d = new IntersectionVertex(g, "d", 8, 5);
    // vary weights so edges are not considered equal
    Edge ab = new SimpleEdge(a, b, 1, 1);
    Edge bc1 = new SimpleEdge(b, c, 1, 1);
    Edge bc2 = new SimpleEdge(b, c, 2, 2);
    Edge bc3 = new SimpleEdge(b, c, 3, 3);
    Edge cd1 = new SimpleEdge(c, d, 1, 1);
    Edge cd2 = new SimpleEdge(c, d, 2, 2);
    Edge cd3 = new SimpleEdge(c, d, 3, 3);
    OverlayGraph og = new OverlayGraph(g);
    assertEquals(g.countVertices(), og.countVertices());
    assertEquals(g.countEdges(), og.countEdges());
    for (Vertex v : g.getVertices()) {
        for (Edge e : v.getOutgoing()) {
            assertTrue(og.getOutgoing(v).contains(e));
            assertTrue(og.getIncoming(e.getToVertex()).contains(e));
        }
        for (Edge e : v.getIncoming()) {
            assertTrue(og.getIncoming(v).contains(e));
            assertTrue(og.getOutgoing(e.getFromVertex()).contains(e));
        }
    }
    assertTrue(og.getIncoming(a).size() == 0);
    assertTrue(og.getOutgoing(d).size() == 0);
    // add an edge that is not in the overlay
    Edge ad = new FreeEdge(a, d);
    assertTrue(d.getIncoming().size() == 4);
    assertTrue(og.getIncoming(d).size() == 3);
    assertTrue(a.getOutgoing().size() == 2);
    assertTrue(og.getOutgoing(a).size() == 1);
    // remove edges from overlaygraph
    og.removeEdge(bc1);
    og.removeEdge(bc2);
    assertEquals(og.countEdges(), g.countEdges() - 3);
    assertTrue(og.getOutgoing(b).size() == 1);
    assertTrue(og.getIncoming(c).size() == 1);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) SimpleEdge(org.opentripplanner.routing.edgetype.SimpleEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) SimpleEdge(org.opentripplanner.routing.edgetype.SimpleEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)9 Graph (org.opentripplanner.routing.graph.Graph)7 Vertex (org.opentripplanner.routing.graph.Vertex)7 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)6 Edge (org.opentripplanner.routing.graph.Edge)5 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)3 LineString (com.vividsolutions.jts.geom.LineString)2 HashSet (java.util.HashSet)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 Stop (org.onebusaway.gtfs.model.Stop)2 RoutingContext (org.opentripplanner.routing.core.RoutingContext)2 State (org.opentripplanner.routing.core.State)2 LegSwitchingEdge (org.opentripplanner.routing.edgetype.LegSwitchingEdge)2 GraphPath (org.opentripplanner.routing.spt.GraphPath)2 ExitVertex (org.opentripplanner.routing.vertextype.ExitVertex)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1