use of org.opentripplanner.routing.edgetype.StreetEdge 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));
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class BarrierVertexTest method edge.
/**
* Create an edge. If twoWay, create two edges (back and forth).
*
* @param vA
* @param vB
* @param length
* @param back true if this is a reverse edge
*/
private StreetEdge edge(StreetVertex vA, StreetVertex vB, double length, boolean back) {
String labelA = vA.getLabel();
String labelB = vB.getLabel();
String name = String.format("%s_%s", labelA, labelB);
Coordinate[] coords = new Coordinate[2];
coords[0] = vA.getCoordinate();
coords[1] = vB.getCoordinate();
LineString geom = GeometryUtils.getGeometryFactory().createLineString(coords);
StreetTraversalPermission perm = StreetTraversalPermission.ALL;
return new StreetEdge(vA, vB, geom, name, length, perm, back);
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class EdgeTest method testEdgeRemoval.
@Test
public void testEdgeRemoval() {
Graph graph = new Graph();
StreetVertex va = new IntersectionVertex(graph, "A", 10.0, 10.0);
StreetVertex vb = new IntersectionVertex(graph, "B", 10.1, 10.1);
StreetVertex vc = new IntersectionVertex(graph, "C", 10.2, 10.2);
StreetVertex vd = new IntersectionVertex(graph, "D", 10.3, 10.3);
Edge eab = new StreetEdge(va, vb, null, "AB", 10, StreetTraversalPermission.ALL, false);
Edge ebc = new StreetEdge(vb, vc, null, "BC", 10, StreetTraversalPermission.ALL, false);
Edge ecd = new StreetEdge(vc, vd, null, "CD", 10, StreetTraversalPermission.ALL, false);
// remove an edge that is not connected to this vertex
va.removeOutgoing(ecd);
assertEquals(va.getDegreeOut(), 1);
// remove an edge from an edgelist that is empty
vd.removeOutgoing(eab);
assertEquals(vd.getDegreeOut(), 0);
// remove an edge that is actually connected
assertEquals(va.getDegreeOut(), 1);
va.removeOutgoing(eab);
assertEquals(va.getDegreeOut(), 0);
// remove an edge that is actually connected
assertEquals(vb.getDegreeIn(), 1);
assertEquals(vb.getDegreeOut(), 1);
vb.removeIncoming(eab);
assertEquals(vb.getDegreeIn(), 0);
assertEquals(vb.getDegreeOut(), 1);
vb.removeOutgoing(ebc);
assertEquals(vb.getDegreeIn(), 0);
assertEquals(vb.getDegreeOut(), 0);
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class IntersectionVertexTest method before.
@Before
public void before() {
_graph = new Graph();
// Graph for a fictional grid city with turn restrictions
StreetVertex maple1 = vertex("maple_1st", 2.0, 2.0);
StreetVertex maple2 = vertex("maple_2nd", 1.0, 2.0);
StreetVertex maple3 = vertex("maple_3rd", 0.0, 2.0);
StreetVertex main1 = vertex("main_1st", 2.0, 1.0);
StreetVertex main2 = vertex("main_2nd", 1.0, 1.0);
StreetVertex main3 = vertex("main_3rd", 0.0, 1.0);
StreetVertex broad1 = vertex("broad_1st", 2.0, 0.0);
StreetVertex broad2 = vertex("broad_2nd", 1.0, 0.0);
StreetVertex broad3 = vertex("broad_3rd", 0.0, 0.0);
// Each block along the main streets has unit length and is one-way
StreetEdge maple1_2 = edge(maple1, maple2, 100.0, false);
StreetEdge maple2_3 = edge(maple2, maple3, 100.0, false);
StreetEdge main1_2 = edge(main1, main2, 100.0, false);
StreetEdge main2_3 = edge(main2, main3, 100.0, false);
StreetEdge broad1_2 = edge(broad1, broad2, 100.0, false);
StreetEdge broad2_3 = edge(broad2, broad3, 100.0, false);
// Each cross-street connects
StreetEdge maple_main1 = edge(maple1, main1, 50.0, false);
StreetEdge main_broad1 = edge(main1, broad1, 100.0, false);
StreetEdge maple_main2 = edge(maple2, main2, 50.0, false);
StreetEdge main_broad2 = edge(main2, broad2, 50.0, false);
StreetEdge maple_main3 = edge(maple3, main3, 100.0, false);
StreetEdge main_broad3 = edge(main3, broad3, 100.0, false);
this.fromEdge = maple1_2;
this.straightAheadEdge = maple2_3;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class StreetSpeedSourceTest method testMatching.
@Test
public void testMatching() {
Graph g = new Graph();
OsmVertex v1 = new OsmVertex(g, "v1", 0, 0, 5l);
OsmVertex v2 = new OsmVertex(g, "v2", 0, 0.01, 6l);
StreetEdge se = new StreetEdge(v1, v2, null, "test", 1000, StreetTraversalPermission.CAR, false);
se.wayId = 10;
// create a speed sample
SegmentSpeedSample s = getSpeedSample();
Map<Segment, SegmentSpeedSample> speeds = Maps.newHashMap();
Segment seg = new Segment(10l, 5l, 6l);
speeds.put(seg, s);
g.streetSpeedSource = new StreetSpeedSnapshotSource();
g.streetSpeedSource.setSnapshot(new StreetSpeedSnapshot(speeds));
// confirm that we get the correct speeds.
// This also implicitly tests encoding/decoding
OffsetDateTime odt = OffsetDateTime.of(2015, 6, 1, 8, 5, 0, 0, ZoneOffset.UTC);
StreetSpeedSnapshot snap = g.streetSpeedSource.getSnapshot();
double monday8am = snap.getSpeed(se, TraverseMode.CAR, odt.toInstant().toEpochMilli());
// no data: should use average
assertEquals(1.33, monday8am, 0.1);
odt = odt.plusHours(1);
double monday9am = snap.getSpeed(se, TraverseMode.CAR, odt.toInstant().toEpochMilli());
assertEquals(6.1, monday9am, 0.1);
odt = odt.plusHours(1);
double monday10am = snap.getSpeed(se, TraverseMode.CAR, odt.toInstant().toEpochMilli());
assertEquals(33.3, monday10am, 0.1);
se.wayId = 102;
double wrongStreet = snap.getSpeed(se, TraverseMode.CAR, odt.toInstant().toEpochMilli());
assertTrue(Double.isNaN(wrongStreet));
}
Aggregations