use of org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl in project OpenTripPlanner by opentripplanner.
the class TransitToTaggedStopsModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
LOG.info("Linking transit stops to tagged bus stops...");
index = new StreetVertexIndexServiceImpl(graph);
// iterate over a copy of vertex list because it will be modified
ArrayList<Vertex> vertices = new ArrayList<>();
vertices.addAll(graph.getVertices());
for (TransitStop ts : Iterables.filter(vertices, TransitStop.class)) {
// if the street is already linked there is no need to linked it again,
// could happened if using the prune isolated island
boolean alreadyLinked = false;
for (Edge e : ts.getOutgoing()) {
if (e instanceof StreetTransitLink) {
alreadyLinked = true;
break;
}
}
if (alreadyLinked)
continue;
// entrances
if (ts.isEntrance() || !ts.hasEntrances()) {
boolean wheelchairAccessible = ts.hasWheelchairEntrance();
if (!connectVertexToStop(ts, wheelchairAccessible)) {
LOG.debug("Could not connect " + ts.getStopCode() + " at " + ts.getCoordinate().toString());
// LOG.warn(graph.addBuilderAnnotation(new StopUnlinked(ts)));
}
}
}
}
use of org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testStreetLocationFinder.
@Test
public void testStreetLocationFinder() {
StreetVertexIndexServiceImpl finder = new StreetVertexIndexServiceImpl(graph);
// test that the local stop finder finds stops
GenericLocation loc = new GenericLocation(40.01, -74.005000001);
assertTrue(finder.getNearbyTransitStops(loc.getCoordinate(), 100).size() > 0);
// test that the closest vertex finder returns the closest vertex
TemporaryStreetLocation some = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.00, -74.00), null, true);
assertNotNull(some);
some.dispose();
// test that the closest vertex finder correctly splits streets
TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.01), null, false);
assertNotNull(start);
assertTrue("wheelchair accessibility is correctly set (splitting)", start.isWheelchairAccessible());
Collection<Edge> edges = start.getOutgoing();
start.dispose();
assertEquals(2, edges.size());
RoutingRequest biking = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), biking, true);
assertNotNull(end);
edges = end.getIncoming();
end.dispose();
assertEquals(2, edges.size());
// test that it is possible to travel between two splits on the same street
RoutingRequest walking = new RoutingRequest(TraverseMode.WALK);
start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.0), walking, false);
exception.expect(TrivialPathException.class);
end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), walking, true);
/*assertNotNull(end);
// The visibility for temp edges for start and end is set in the setRoutingContext call
walking.setRoutingContext(graph, start, end);
ShortestPathTree spt = aStar.getShortestPathTree(walking);
GraphPath path = spt.getPath(end, false);
for (State s : path.states) {
assertFalse(s.getBackEdge() == top);
}
walking.cleanup();*/
}
use of org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testBuildingAreas.
/**
* This reads test file with area
* and tests if it can be routed if visibility is used and if it isn't
*
* Routing needs to be successful in both options since without visibility calculation
* area rings are used.
* @param skipVisibility if true visibility calculations are skipped
* @throws UnsupportedEncodingException
*/
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
Graph gg = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.skipVisibility = skipVisibility;
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.gz").getFile(), "UTF-8"));
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, extra);
new StreetVertexIndexServiceImpl(gg);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", gg));
Router a = otpServer.getGraphService().getRouter("A");
RoutingRequest request = new RoutingRequest("WALK");
// This are vertices that can be connected only over edges on area (with correct permissions)
// It tests if it is possible to route over area without visibility calculations
Vertex bottomV = gg.getVertex("osm:node:580290955");
Vertex topV = gg.getVertex("osm:node:559271124");
request.setRoutingContext(a.graph, bottomV, topV);
GraphPathFinder graphPathFinder = new GraphPathFinder(a);
List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
assertNotNull(pathList);
assertFalse(pathList.isEmpty());
for (GraphPath path : pathList) {
assertFalse(path.states.isEmpty());
}
}
use of org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl in project OpenTripPlanner by opentripplanner.
the class StateEditorTest method testSetNonTransitOptionsFromState.
/**
* Test update of non transit options.
*/
@Test
public final void testSetNonTransitOptionsFromState() {
RoutingRequest request = new RoutingRequest();
request.setMode(TraverseMode.CAR);
request.parkAndRide = true;
Graph graph = new Graph();
graph.streetIndex = new StreetVertexIndexServiceImpl(graph);
request.rctx = new RoutingContext(request, graph);
State state = new State(request);
state.stateData.carParked = true;
state.stateData.bikeParked = true;
state.stateData.usingRentedBike = false;
state.stateData.nonTransitMode = TraverseMode.WALK;
StateEditor se = new StateEditor(request, null);
se.setNonTransitOptionsFromState(state);
State updatedState = se.makeState();
assertEquals(TraverseMode.WALK, updatedState.getNonTransitMode());
assertEquals(true, updatedState.isCarParked());
assertEquals(true, updatedState.isBikeParked());
assertEquals(false, updatedState.isBikeRenting());
}
Aggregations