use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class PortlandCustomNamer method nameAccordingToOrigin.
private String nameAccordingToOrigin(Graph graph, StreetEdge e, int maxDepth) {
if (maxDepth == 0) {
return null;
}
Vertex fromVertex = e.getFromVertex();
for (StreetEdge in : Iterables.filter(fromVertex.getIncoming(), StreetEdge.class)) {
if (in.hasBogusName()) {
String name = nameAccordingToOrigin(graph, in, maxDepth - 1);
if (name == null) {
continue;
}
e.setName(new NonLocalizedString(name));
return name;
} else {
String name = in.getName();
e.setName(new NonLocalizedString(name));
return name;
}
}
return null;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class AnalysisUtils method getComponentPolygons.
/**
* Get polygons covering the components of the graph. The largest component (in terms of number
* of nodes) will not overlap any other components (it will have holes); the others may overlap
* each other.
*
* @param dateTime
*/
public static List<Geometry> getComponentPolygons(Graph graph, RoutingRequest options, long time) {
DisjointSet<Vertex> components = getConnectedComponents(graph);
LinkedListMultimap<Integer, Coordinate> componentCoordinates = LinkedListMultimap.create();
options.setDummyRoutingContext(graph);
for (Vertex v : graph.getVertices()) {
for (Edge e : v.getOutgoing()) {
State s0 = new State(v, time, options);
State s1 = e.traverse(s0);
if (s1 != null) {
Integer component = components.find(e.getFromVertex());
Geometry geometry = s1.getBackEdge().getGeometry();
if (geometry != null) {
List<Coordinate> coordinates = new ArrayList<Coordinate>(Arrays.asList(geometry.getCoordinates()));
for (int i = 0; i < coordinates.size(); ++i) {
Coordinate coordinate = new Coordinate(coordinates.get(i));
coordinate.x = Math.round(coordinate.x * PRECISION) / PRECISION;
coordinate.y = Math.round(coordinate.y * PRECISION) / PRECISION;
coordinates.set(i, coordinate);
}
componentCoordinates.putAll(component, coordinates);
}
}
}
}
// generate convex hull of each component
List<Geometry> geoms = new ArrayList<Geometry>();
int mainComponentSize = 0;
int mainComponentIndex = -1;
int component = 0;
for (Integer key : componentCoordinates.keySet()) {
List<Coordinate> coords = componentCoordinates.get(key);
Coordinate[] coordArray = new Coordinate[coords.size()];
ConvexHull hull = new ConvexHull(coords.toArray(coordArray), GeometryUtils.getGeometryFactory());
Geometry geom = hull.getConvexHull();
// buffer components which are mere lines so that they do not disappear.
if (geom instanceof LineString) {
// ~10 meters
geom = geom.buffer(0.01);
} else if (geom instanceof Point) {
// ~50 meters, so that it shows up
geom = geom.buffer(0.05);
}
geoms.add(geom);
if (mainComponentSize < coordArray.length) {
mainComponentIndex = component;
mainComponentSize = coordArray.length;
}
++component;
}
// subtract small components out of main component
// (small components are permitted to overlap each other)
Geometry mainComponent = geoms.get(mainComponentIndex);
for (int i = 0; i < geoms.size(); ++i) {
Geometry geom = geoms.get(i);
if (i == mainComponentIndex) {
continue;
}
mainComponent = mainComponent.difference(geom);
}
geoms.set(mainComponentIndex, mainComponent);
return geoms;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testIdLookup.
public void testIdLookup() {
/* Graph vertices */
for (Vertex vertex : graph.index.vertexForId.values()) {
if (vertex instanceof TransitStop) {
Stop stop = ((TransitStop) vertex).getStop();
Vertex index_vertex = graph.index.stopVertexForStop.get(stop);
assertEquals(index_vertex, vertex);
}
}
/* Agencies */
String feedId = graph.getFeedIds().iterator().next();
Agency agency;
agency = graph.index.agenciesForFeedId.get(feedId).get("azerty");
assertNull(agency);
agency = graph.index.agenciesForFeedId.get(feedId).get("agency");
assertEquals(agency.getId(), "agency");
assertEquals(agency.getName(), "Fake Agency");
/* Stops */
graph.index.stopForId.get(new AgencyAndId("X", "Y"));
/* Trips */
// graph.index.tripForId;
// graph.index.routeForId;
// graph.index.serviceForId;
// graph.index.patternForId;
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TripTimesTest method testBikesAllowed.
@Test
public void testBikesAllowed() {
Graph graph = new Graph();
Trip trip = new Trip();
Route route = new Route();
trip.setRoute(route);
List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
request.setRoutingContext(graph, v, v);
State s0 = new State(request);
assertFalse(s.tripAcceptable(s0, 0));
BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
assertTrue(s.tripAcceptable(s0, 0));
BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
assertFalse(s.tripAcceptable(s0, 0));
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestTransfers method testStopToStopTransfer.
public void testStopToStopTransfer() throws Exception {
// Replace the transfer table with an empty table
TransferTable table = new TransferTable();
when(graph.getTransferTable()).thenReturn(table);
// Compute a normal path between two stops
Vertex origin = graph.getVertex(feedId + ":N");
Vertex destination = graph.getVertex(feedId + ":H");
// Set options like time and routing context
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
options.setRoutingContext(graph, origin, destination);
// Plan journey
GraphPath path;
List<Trip> trips;
path = planJourney(options);
trips = extractTrips(path);
// Validate result
assertEquals("8.1", trips.get(0).getId().getId());
assertEquals("4.2", trips.get(1).getId().getId());
// Add transfer to table, transfer time was 27600 seconds
Stop stopK = new Stop();
stopK.setId(new AgencyAndId(feedId, "K"));
Stop stopF = new Stop();
stopF.setId(new AgencyAndId(feedId, "F"));
table.addTransferTime(stopK, stopF, null, null, null, null, 27601);
// Plan journey
path = planJourney(options);
trips = extractTrips(path);
// Check whether a later second trip was taken
assertEquals("8.1", trips.get(0).getId().getId());
assertEquals("4.3", trips.get(1).getId().getId());
// Revert the graph, thus using the original transfer table again
reset(graph);
}
Aggregations