use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method setUp.
@Before
public void setUp() {
graph = new Graph();
// a 0.1 degree x 0.1 degree square
tl = new IntersectionVertex(graph, "tl", -74.01, 40.01);
tr = new IntersectionVertex(graph, "tr", -74.0, 40.01);
bl = new IntersectionVertex(graph, "bl", -74.01, 40.0);
br = new IntersectionVertex(graph, "br", -74.00, 40.0);
top = new StreetEdge(tl, tr, GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01), "top", 1500, StreetTraversalPermission.ALL, false);
bottom = new StreetEdge(br, bl, GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0), "bottom", 1500, StreetTraversalPermission.ALL, false);
left = new StreetEdge(bl, tl, GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01), "left", 1500, StreetTraversalPermission.ALL, false);
right = new StreetEdge(br, tr, GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01), "right", 1500, StreetTraversalPermission.PEDESTRIAN, false);
@SuppressWarnings("unused") StreetEdge topBack = new StreetEdge(tr, tl, (LineString) top.getGeometry().reverse(), "topBack", 1500, StreetTraversalPermission.ALL, true);
@SuppressWarnings("unused") StreetEdge bottomBack = new StreetEdge(br, bl, (LineString) bottom.getGeometry().reverse(), "bottomBack", 1500, StreetTraversalPermission.ALL, true);
leftBack = new StreetEdge(tl, bl, (LineString) left.getGeometry().reverse(), "leftBack", 1500, StreetTraversalPermission.ALL, true);
rightBack = new StreetEdge(tr, br, (LineString) right.getGeometry().reverse(), "rightBack", 1500, StreetTraversalPermission.ALL, true);
Stop s1 = Stop.stopForTest("fleem station", 40.0099999, -74.005);
Stop s2 = Stop.stopForTest("morx station", 40.0099999, -74.002);
station1 = new TransitStopVertex(graph, s1, null);
station2 = new TransitStopVertex(graph, s2, null);
station1.addMode(TransitMode.RAIL);
station2.addMode(TransitMode.RAIL);
// Linkers aren't run otherwise in testNetworkLinker
graph.hasStreets = true;
graph.hasTransit = true;
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class TestGraphPath method testGraphPathOptimize.
public void testGraphPathOptimize() {
String feedId = graph.getFeedIds().iterator().next();
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_e = graph.getVertex(feedId + ":E");
ShortestPathTree spt;
GraphPath path;
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_a.getLabel(), stop_e.getLabel());
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, false);
/* do not optimize yet, since we are testing optimization */
assertNotNull(path);
// Check that the resulting path visits the stops in the right order.
List<Vertex> stopvs = Lists.newArrayList();
for (State state : path.states) {
if (state.getVertex() instanceof TransitStopVertex) {
stopvs.add(state.getVertex());
}
}
assertTrue(stopvs.get(0) == stop_a);
assertTrue(stopvs.get(1) == stop_c);
assertTrue(stopvs.get(2) == stop_e);
long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
assertNotSame(bestStart, path.getStartTime());
path = spt.getPath(stop_e, true);
/* optimize */
assertEquals(bestStart, path.getStartTime());
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class FakeGraph method addExtraStops.
/**
* add some extra stops to the graph
*/
public static void addExtraStops(Graph g) {
int count = 0;
double lon = -83;
for (double lat = 40; lat < 40.01; lat += 0.005) {
String id = "EXTRA_" + count++;
Stop stop = Stop.stopForTest(id, lat, lon);
new TransitStopVertex(g, stop, null);
}
// add some duplicate stops, identical to the regular stop grid
lon = -83.1341 + 0.1;
for (double lat = 39.9058; lat < 40.0281; lat += 0.005) {
String id = "DUPE_" + count++;
Stop stop = Stop.stopForTest(id, lat, lon);
new TransitStopVertex(g, stop, null);
}
// add some almost duplicate stops
lon = -83.1341 + 0.15;
for (double lat = 39.9059; lat < 40.0281; lat += 0.005) {
String id = "ALMOST_" + count++;
Stop stop = Stop.stopForTest(id, lat, lon);
new TransitStopVertex(g, stop, null);
}
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class FakeGraph method addRegularStopGrid.
/**
* Add a regular grid of stops to the graph
*/
public static void addRegularStopGrid(Graph g) {
int count = 0;
for (double lat = 39.9058; lat < 40.0281; lat += 0.005) {
for (double lon = -83.1341; lon < -82.8646; lon += 0.005) {
String id = Integer.toString(count++);
Stop stop = Stop.stopForTest(id, lat, lon);
new TransitStopVertex(g, stop, null);
}
}
}
use of org.opentripplanner.routing.vertextype.TransitStopVertex in project OpenTripPlanner by opentripplanner.
the class LinkingTest method testStopsLinkedIdentically.
/**
* Test that all the stops are linked identically
* to the street network on two builds of similar graphs
* with additional stops in one.
*
* We do this by building the graphs and then comparing the stop tree caches.
*/
@Test
public void testStopsLinkedIdentically() throws UnsupportedEncodingException {
// build the graph without the added stops
Graph g1 = buildGraphNoTransit();
addRegularStopGrid(g1);
link(g1);
Graph g2 = buildGraphNoTransit();
addExtraStops(g2);
addRegularStopGrid(g2);
link(g2);
// compare the linkages
for (TransitStopVertex ts : Iterables.filter(g1.getVertices(), TransitStopVertex.class)) {
List<StreetTransitLink> stls1 = outgoingStls(ts);
assertTrue(stls1.size() >= 1);
TransitStopVertex other = (TransitStopVertex) g2.getVertex(ts.getLabel());
List<StreetTransitLink> stls2 = outgoingStls(other);
assertEquals("Unequal number of links from stop " + ts, stls1.size(), stls2.size());
for (int i = 0; i < stls1.size(); i++) {
Vertex v1 = stls1.get(i).getToVertex();
Vertex v2 = stls2.get(i).getToVertex();
assertEquals(v1.getLat(), v2.getLat(), 1e-10);
assertEquals(v1.getLon(), v2.getLon(), 1e-10);
}
}
}
Aggregations