Search in sources :

Example 1 with StreetVertexIndexServiceImpl

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)));
            }
        }
    }
}
Also used : TransitStopStreetVertex(org.opentripplanner.routing.vertextype.TransitStopStreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ArrayList(java.util.ArrayList) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 2 with StreetVertexIndexServiceImpl

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();*/
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl) Test(org.junit.Test)

Example 3 with StreetVertexIndexServiceImpl

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());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.Router) GraphService(org.opentripplanner.routing.services.GraphService) Graph(org.opentripplanner.routing.graph.Graph) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 4 with StreetVertexIndexServiceImpl

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());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl) Test(org.junit.Test)

Aggregations

StreetVertexIndexServiceImpl (org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)4 Test (org.junit.Test)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 Edge (org.opentripplanner.routing.graph.Edge)2 Graph (org.opentripplanner.routing.graph.Graph)2 Vertex (org.opentripplanner.routing.graph.Vertex)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 GenericLocation (org.opentripplanner.common.model.GenericLocation)1 FileBasedOpenStreetMapProviderImpl (org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl)1 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)1 TemporaryFreeEdge (org.opentripplanner.routing.edgetype.TemporaryFreeEdge)1 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)1 MemoryGraphSource (org.opentripplanner.routing.impl.MemoryGraphSource)1 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)1 GraphService (org.opentripplanner.routing.services.GraphService)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)1