Search in sources :

Example 6 with Graph

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

the class BarrierVertexTest method testStreetsWithBollard.

@Test
public void testStreetsWithBollard() {
    Graph _graph = new Graph();
    // default permissions are PEDESTRIAND and BICYCLE
    BarrierVertex bv = new BarrierVertex(_graph, "start_bollard", 2.0, 2.0, 0);
    StreetVertex endVertex = new IntersectionVertex(_graph, "end_vertex", 1.0, 2.0);
    StreetEdge bv_to_endVertex_forward = edge(bv, endVertex, 100, false);
    assertTrue(bv_to_endVertex_forward.canTraverse(new TraverseModeSet("CAR")));
    assertTrue(bv_to_endVertex_forward.canTraverse(new TraverseModeSet("BICYCLE")));
    assertTrue(bv_to_endVertex_forward.canTraverse(new TraverseModeSet("WALK")));
    assertFalse(bv_to_endVertex_forward.canTraverseIncludingBarrier(TraverseMode.CAR));
    assertTrue(bv_to_endVertex_forward.canTraverseIncludingBarrier(TraverseMode.BICYCLE));
    assertTrue(bv_to_endVertex_forward.canTraverseIncludingBarrier(TraverseMode.WALK));
    StreetEdge endVertex_to_bv_backward = edge(endVertex, bv, 100, true);
    assertTrue(endVertex_to_bv_backward.canTraverse(new TraverseModeSet("CAR")));
    assertTrue(endVertex_to_bv_backward.canTraverse(new TraverseModeSet("BICYCLE")));
    assertTrue(endVertex_to_bv_backward.canTraverse(new TraverseModeSet("WALK")));
    assertFalse(endVertex_to_bv_backward.canTraverseIncludingBarrier(TraverseMode.CAR));
    assertTrue(endVertex_to_bv_backward.canTraverseIncludingBarrier(TraverseMode.BICYCLE));
    assertTrue(endVertex_to_bv_backward.canTraverseIncludingBarrier(TraverseMode.WALK));
    StreetEdge bv_to_endVertex_backward = edge(bv, endVertex, 100, true);
    assertTrue(bv_to_endVertex_backward.canTraverse(new TraverseModeSet("CAR")));
    assertTrue(bv_to_endVertex_backward.canTraverse(new TraverseModeSet("BICYCLE")));
    assertTrue(bv_to_endVertex_backward.canTraverse(new TraverseModeSet("WALK")));
    assertFalse(bv_to_endVertex_backward.canTraverseIncludingBarrier(TraverseMode.CAR));
    assertTrue(bv_to_endVertex_backward.canTraverseIncludingBarrier(TraverseMode.BICYCLE));
    assertTrue(bv_to_endVertex_backward.canTraverseIncludingBarrier(TraverseMode.WALK));
    StreetEdge endVertex_to_bv_forward = edge(endVertex, bv, 100, false);
    assertTrue(endVertex_to_bv_forward.canTraverse(new TraverseModeSet("CAR")));
    assertTrue(endVertex_to_bv_forward.canTraverse(new TraverseModeSet("BICYCLE")));
    assertTrue(endVertex_to_bv_forward.canTraverse(new TraverseModeSet("WALK")));
    assertFalse(endVertex_to_bv_forward.canTraverseIncludingBarrier(TraverseMode.CAR));
    assertTrue(endVertex_to_bv_forward.canTraverseIncludingBarrier(TraverseMode.BICYCLE));
    assertTrue(endVertex_to_bv_forward.canTraverseIncludingBarrier(TraverseMode.WALK));
    // tests bollard which doesn't allow cycling
    BarrierVertex noBicycleBollard = new BarrierVertex(_graph, "no_bike_bollard", 1.5, 1, 0);
    noBicycleBollard.setBarrierPermissions(StreetTraversalPermission.PEDESTRIAN);
    StreetEdge no_bike_to_endVertex = edge(noBicycleBollard, endVertex, 100, false);
    assertTrue(no_bike_to_endVertex.canTraverse(new TraverseModeSet("CAR")));
    assertTrue(no_bike_to_endVertex.canTraverse(new TraverseModeSet("BICYCLE")));
    assertTrue(no_bike_to_endVertex.canTraverse(new TraverseModeSet("WALK")));
    assertFalse(no_bike_to_endVertex.canTraverseIncludingBarrier(TraverseMode.CAR));
    assertFalse(no_bike_to_endVertex.canTraverseIncludingBarrier(TraverseMode.BICYCLE));
    assertTrue(no_bike_to_endVertex.canTraverseIncludingBarrier(TraverseMode.WALK));
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) Test(org.junit.Test)

Example 7 with Graph

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

the class BarrierVertexTest method testBarrierPermissions.

@Test
public void testBarrierPermissions() throws Exception {
    OSMNode simpleBarier = new OSMNode();
    assertFalse(simpleBarier.isBollard());
    simpleBarier.addTag("barrier", "bollard");
    assertTrue(simpleBarier.isBollard());
    Graph graph = new Graph();
    String label = "simpleBarrier";
    BarrierVertex bv = new BarrierVertex(graph, label, simpleBarier.lon, simpleBarier.lat, 0);
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("foot", "yes");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("bicycle", "yes");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("access", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("motor_vehicle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE, bv.getBarrierPermissions());
    simpleBarier.addTag("bicycle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(simpleBarier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN, bv.getBarrierPermissions());
    OSMNode complexBarrier = new OSMNode();
    complexBarrier.addTag("barrier", "bollard");
    complexBarrier.addTag("access", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(complexBarrier, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.NONE, bv.getBarrierPermissions());
    OSMNode noBikeBollard = new OSMNode();
    noBikeBollard.addTag("barrier", "bollard");
    noBikeBollard.addTag("bicycle", "no");
    bv.setBarrierPermissions(OSMFilter.getPermissionsForEntity(noBikeBollard, BarrierVertex.defaultBarrierPermissions));
    assertEquals(StreetTraversalPermission.PEDESTRIAN, bv.getBarrierPermissions());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 8 with Graph

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

the class PlainStreetEdgeTest method before.

@Before
public void before() {
    _graph = new Graph();
    // label, X, Y
    v0 = vertex("maple_0th", 0.0, 0.0);
    v1 = vertex("maple_1st", 2.0, 2.0);
    v2 = vertex("maple_2nd", 1.0, 2.0);
    proto = new RoutingRequest();
    proto.setDummyRoutingContext(_graph);
    proto.carSpeed = 15.0f;
    proto.walkSpeed = 1.0;
    proto.bikeSpeed = 5.0f;
    proto.setWalkReluctance(1.0);
    proto.stairsReluctance = (1.0);
    proto.turnReluctance = (1.0);
    proto.setModes(TraverseModeSet.allModes());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Before(org.junit.Before)

Example 9 with Graph

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

the class TimetableTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    patternIndex = new HashMap<AgencyAndId, TripPattern>();
    for (TransitStopDepart tsd : Iterables.filter(graph.getVertices(), TransitStopDepart.class)) {
        for (TransitBoardAlight tba : Iterables.filter(tsd.getOutgoing(), TransitBoardAlight.class)) {
            if (!tba.boarding)
                continue;
            TripPattern pattern = tba.getPattern();
            for (Trip trip : pattern.getTrips()) {
                patternIndex.put(trip.getId(), pattern);
            }
        }
    }
    pattern = patternIndex.get(new AgencyAndId("agency", "1.1"));
    timetable = pattern.scheduledTimetable;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart) BeforeClass(org.junit.BeforeClass)

Example 10 with Graph

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

the class TestHopFactory method setUp.

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

Aggregations

Graph (org.opentripplanner.routing.graph.Graph)105 Test (org.junit.Test)39 File (java.io.File)28 Vertex (org.opentripplanner.routing.graph.Vertex)27 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)24 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)20 Edge (org.opentripplanner.routing.graph.Edge)19 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)14 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)13 GraphPath (org.opentripplanner.routing.spt.GraphPath)13 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 Trip (org.onebusaway.gtfs.model.Trip)9