Search in sources :

Example 41 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class LocationIndexExample method lowLevelLocationIndex.

public static void lowLevelLocationIndex() {
    // If you don't use the GraphHopper class you have to use the low level API:
    GraphHopperStorage graph = new GraphBuilder(EncodingManager.create(new CarFlagEncoder())).create();
    graph.edge(0, 1).setName("test edge");
    graph.getNodeAccess().setNode(0, 12, 42);
    graph.getNodeAccess().setNode(1, 12.01, 42.01);
    LocationIndexTree index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
    index.setResolution(300);
    index.setMaxRegionSearch(4);
    if (!index.loadExisting())
        index.prepareIndex();
    Snap snap = index.findClosest(12, 42, EdgeFilter.ALL_EDGES);
    EdgeIteratorState edge = snap.getClosestEdge();
    assert edge.getName().equals("test edge");
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) Snap(com.graphhopper.storage.index.Snap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Example 42 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class AlternativeRouteCH method sharedDistance.

private double sharedDistance(Path path) {
    double sharedDistance = 0.0;
    List<EdgeIteratorState> edges = path.calcEdges();
    for (EdgeIteratorState edge : edges) {
        if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
            sharedDistance += edge.getDistance();
        }
    }
    return sharedDistance;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 43 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class AlternativeRouteEdgeCH method tTest.

private boolean tTest(Path path, int vIndex) {
    if (path.getEdgeCount() == 0)
        return true;
    double detourDistance = detourDistance(path);
    double T = 0.5 * localOptimalityFactor * detourDistance;
    EdgeIteratorState fromNode = getPreviousNodeTMetersAway(path, vIndex, T);
    EdgeIteratorState toNode = getNextNodeTMetersAway(path, vIndex, T);
    DijkstraBidirectionEdgeCHNoSOD tRouter = new DijkstraBidirectionEdgeCHNoSOD(graph);
    Path tPath = tRouter.calcPath(fromNode.getBaseNode(), toNode.getAdjNode(), fromNode.getEdge(), toNode.getEdge());
    extraVisitedNodes += tRouter.getVisitedNodes();
    IntIndexedContainer tNodes = tPath.calcNodes();
    int v = path.calcNodes().get(vIndex);
    return tNodes.contains(v);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer)

Example 44 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class Path method calcNodes.

/**
 * @return the uncached node indices of the tower nodes in this path.
 */
public IntIndexedContainer calcNodes() {
    final IntArrayList nodes = new IntArrayList(edgeIds.size() + 1);
    if (edgeIds.isEmpty()) {
        if (isFound()) {
            nodes.add(endNode);
        }
        return nodes;
    }
    int tmpNode = getFromNode();
    nodes.add(tmpNode);
    forEveryEdge(new EdgeVisitor() {

        @Override
        public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
            nodes.add(eb.getAdjNode());
        }

        @Override
        public void finish() {
        }
    });
    return nodes;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 45 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class Path method calcPoints.

/**
 * This method calculated a list of points for this path
 * <p>
 *
 * @return the geometry of this path
 */
public PointList calcPoints() {
    final PointList points = new PointList(edgeIds.size() + 1, nodeAccess.is3D());
    if (edgeIds.isEmpty()) {
        if (isFound()) {
            points.add(nodeAccess, endNode);
        }
        return points;
    }
    int tmpNode = getFromNode();
    points.add(nodeAccess, tmpNode);
    forEveryEdge(new EdgeVisitor() {

        @Override
        public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
            PointList pl = eb.fetchWayGeometry(FetchMode.PILLAR_AND_ADJ);
            for (int j = 0; j < pl.size(); j++) {
                points.add(pl, j);
            }
        }

        @Override
        public void finish() {
        }
    });
    return points;
}
Also used : PointList(com.graphhopper.util.PointList) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Aggregations

EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)137 Test (org.junit.jupiter.api.Test)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 Test (org.junit.Test)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)17 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)13 Snap (com.graphhopper.storage.index.Snap)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)11 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)11 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)10 NodeAccess (com.graphhopper.storage.NodeAccess)10 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)7 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 GHPoint (com.graphhopper.util.shapes.GHPoint)6 Fun (org.mapdb.Fun)6 IntArrayList (com.carrotsearch.hppc.IntArrayList)5