Search in sources :

Example 11 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class LuceneIndex method index.

/**
 * Index stations, stops, intersections, streets, and addresses by name and location.
 */
private void index() {
    try {
        long startTime = System.currentTimeMillis();
        /* Create or re-open a disk-backed Lucene Directory under the OTP server base filesystem directory. */
        directory = FSDirectory.open(new File(basePath, "lucene"));
        // TODO reuse the index if it exists?
        // directory = new RAMDirectory(); // only a little faster
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer).setOpenMode(OpenMode.CREATE);
        final IndexWriter writer = new IndexWriter(directory, config);
        for (Stop stop : graphIndex.stopForId.values()) {
            addStop(writer, stop);
        }
        graphIndex.clusterStopsAsNeeded();
        for (StopCluster stopCluster : graphIndex.stopClusterForId.values()) {
            addCluster(writer, stopCluster);
        }
        for (StreetVertex sv : Iterables.filter(graphIndex.vertexForId.values(), StreetVertex.class)) {
            addCorner(writer, sv);
        }
        writer.close();
        long elapsedTime = System.currentTimeMillis() - startTime;
        LOG.info("Built Lucene index in {} msec", elapsedTime);
        // Make the IndexSearcher necessary for querying.
        searcher = new IndexSearcher(DirectoryReader.open(directory));
    } catch (Exception ex) {
        throw new RuntimeException("Lucene indexing failed.", ex);
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) Stop(org.onebusaway.gtfs.model.Stop) StopCluster(org.opentripplanner.profile.StopCluster) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) File(java.io.File) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 12 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class StreetUtils method pruneFloatingIslands.

public static void pruneFloatingIslands(Graph graph, int maxIslandSize, int islandWithStopMaxSize, String islandLogName) {
    LOG.debug("pruning");
    PrintWriter islandLog = null;
    if (islandLogName != null && !islandLogName.isEmpty()) {
        try {
            islandLog = new PrintWriter(new File(islandLogName));
        } catch (Exception e) {
            LOG.error("Failed to write islands log file", e);
        }
    }
    if (islandLog != null) {
        islandLog.printf("%s\t%s\t%s\t%s\t%s\n", "id", "stopCount", "streetCount", "wkt", "hadRemoved");
    }
    Map<Vertex, Subgraph> subgraphs = new HashMap<Vertex, Subgraph>();
    Map<Vertex, ArrayList<Vertex>> neighborsForVertex = new HashMap<Vertex, ArrayList<Vertex>>();
    // RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT));
    RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        State s0 = new State(gv, options);
        for (Edge e : gv.getOutgoing()) {
            Vertex in = gv;
            if (!(e instanceof StreetEdge || e instanceof StreetTransitLink || e instanceof ElevatorEdge || e instanceof FreeEdge)) {
                continue;
            }
            State s1 = e.traverse(s0);
            if (s1 == null) {
                continue;
            }
            Vertex out = s1.getVertex();
            ArrayList<Vertex> vertexList = neighborsForVertex.get(in);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(in, vertexList);
            }
            vertexList.add(out);
            vertexList = neighborsForVertex.get(out);
            if (vertexList == null) {
                vertexList = new ArrayList<Vertex>();
                neighborsForVertex.put(out, vertexList);
            }
            vertexList.add(in);
        }
    }
    ArrayList<Subgraph> islands = new ArrayList<Subgraph>();
    /* associate each node with a subgraph */
    for (Vertex gv : graph.getVertices()) {
        if (!(gv instanceof StreetVertex)) {
            continue;
        }
        Vertex vertex = gv;
        if (subgraphs.containsKey(vertex)) {
            continue;
        }
        if (!neighborsForVertex.containsKey(vertex)) {
            continue;
        }
        Subgraph subgraph = computeConnectedSubgraph(neighborsForVertex, vertex);
        if (subgraph != null) {
            for (Iterator<Vertex> vIter = subgraph.streetIterator(); vIter.hasNext(); ) {
                Vertex subnode = vIter.next();
                subgraphs.put(subnode, subgraph);
            }
            islands.add(subgraph);
        }
    }
    LOG.info(islands.size() + " sub graphs found");
    /* remove all tiny subgraphs and large subgraphs without stops */
    for (Subgraph island : islands) {
        boolean hadRemoved = false;
        if (island.stopSize() > 0) {
            // for islands with stops
            if (island.streetSize() < islandWithStopMaxSize) {
                depedestrianizeOrRemove(graph, island);
                hadRemoved = true;
            }
        } else {
            // for islands without stops
            if (island.streetSize() < maxIslandSize) {
                depedestrianizeOrRemove(graph, island);
                hadRemoved = true;
            }
        }
        if (islandLog != null) {
            WriteNodesInSubGraph(island, islandLog, hadRemoved);
        }
    }
    if (graph.removeEdgelessVertices() > 0) {
        LOG.warn("Removed edgeless vertices after pruning islands");
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) State(org.opentripplanner.routing.core.State) Subgraph(org.opentripplanner.common.geometry.Subgraph) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) File(java.io.File) Edge(org.opentripplanner.routing.graph.Edge) PrintWriter(java.io.PrintWriter)

Example 13 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitter method link.

/**
 * split the edge and link in the transit stop
 */
private void link(Vertex tstop, StreetEdge edge, double xscale, RoutingRequest options) {
    // TODO: we've already built this line string, we should save it
    LineString orig = edge.getGeometry();
    LineString transformed = equirectangularProject(orig, xscale);
    LocationIndexedLine il = new LocationIndexedLine(transformed);
    LinearLocation ll = il.project(new Coordinate(tstop.getLon() * xscale, tstop.getLat()));
    // street to use the same vertices. Otherwise the order the stops are loaded in will affect where they are snapped.
    if (ll.getSegmentIndex() == 0 && ll.getSegmentFraction() < 1e-8) {
        makeLinkEdges(tstop, (StreetVertex) edge.getFromVertex());
    } else // past the last point
    if (ll.getSegmentIndex() == orig.getNumPoints() - 1) {
        makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
    } else // nPoints - 2: -1 to correct for index vs count, -1 to account for fencepost problem
    if (ll.getSegmentIndex() == orig.getNumPoints() - 2 && ll.getSegmentFraction() > 1 - 1e-8) {
        makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
    } else {
        TemporaryVertex temporaryVertex = null;
        boolean endVertex = false;
        if (tstop instanceof TemporaryVertex) {
            temporaryVertex = (TemporaryVertex) tstop;
            endVertex = temporaryVertex.isEndVertex();
        }
        // It is only used in origin/destination linking since otherwise options is null
        if (options != null) {
            options.canSplitEdge(edge);
        }
        // split the edge, get the split vertex
        SplitterVertex v0 = split(edge, ll, temporaryVertex != null, endVertex);
        makeLinkEdges(tstop, v0);
    }
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) LocationIndexedLine(com.vividsolutions.jts.linearref.LocationIndexedLine) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TemporarySplitterVertex(org.opentripplanner.routing.vertextype.TemporarySplitterVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex)

Example 14 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class StreetVertexIndexServiceImpl method getIntersectionAt.

/**
 * @param coordinate Location to search intersection at. Look in a MAX_CORNER_DISTANCE_METERS radius.
 * @return The nearest intersection, null if none found.
 */
public StreetVertex getIntersectionAt(Coordinate coordinate) {
    double dLon = SphericalDistanceLibrary.metersToLonDegrees(MAX_CORNER_DISTANCE_METERS, coordinate.y);
    double dLat = SphericalDistanceLibrary.metersToDegrees(MAX_CORNER_DISTANCE_METERS);
    Envelope envelope = new Envelope(coordinate);
    envelope.expandBy(dLon, dLat);
    List<Vertex> nearby = getVerticesForEnvelope(envelope);
    StreetVertex nearest = null;
    double bestDistanceMeter = Double.POSITIVE_INFINITY;
    for (Vertex v : nearby) {
        if (v instanceof StreetVertex) {
            v.getLabel().startsWith("osm:");
            double distanceMeter = SphericalDistanceLibrary.fastDistance(coordinate, v.getCoordinate());
            if (distanceMeter < MAX_CORNER_DISTANCE_METERS) {
                if (distanceMeter < bestDistanceMeter) {
                    bestDistanceMeter = distanceMeter;
                    nearest = (StreetVertex) v;
                }
            }
        }
    }
    return nearest;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) SampleVertex(org.opentripplanner.routing.vertextype.SampleVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 15 with StreetVertex

use of org.opentripplanner.routing.vertextype.StreetVertex in project OpenTripPlanner by opentripplanner.

the class TurnRestrictionTest 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);
    broad1_2 = edge(broad1, broad2, 100.0, false);
    StreetEdge broad2_3 = edge(broad2, broad3, 100.0, false);
    // Each cross-street connects
    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);
    // Turn restrictions are only for driving modes.
    // - can't turn from 1st onto Main.
    // - can't turn from 2nd onto Main.
    // - can't turn from 2nd onto Broad.
    DisallowTurn(maple_main1, main1_2);
    DisallowTurn(maple_main2, main2_3);
    DisallowTurn(main_broad2, broad2_3);
    // Hold onto some vertices for the tests
    topRight = maple1;
    bottomLeft = broad3;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Before(org.junit.Before)

Aggregations

StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)18 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)8 Graph (org.opentripplanner.routing.graph.Graph)7 Vertex (org.opentripplanner.routing.graph.Vertex)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)4 State (org.opentripplanner.routing.core.State)4 Edge (org.opentripplanner.routing.graph.Edge)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 File (java.io.File)2 Before (org.junit.Before)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)2 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)2 SplitterVertex (org.opentripplanner.routing.vertextype.SplitterVertex)2 Envelope (com.vividsolutions.jts.geom.Envelope)1