Search in sources :

Example 21 with EdgeIteratorState

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

the class PrepareRoutingSubnetworksTest method check.

public static boolean check(GraphHopperStorage storage, EdgeExplorer edgeExplorer, int node) {
    List<Integer> toNodes = new ArrayList<>();
    List<Integer> edges = new ArrayList<>();
    EdgeIterator edgeIterator = edgeExplorer.setBaseNode(node);
    while (edgeIterator.next()) {
        if (edgeIterator.getBaseNode() < 0 || edgeIterator.getAdjNode() < 0) {
            return false;
        }
        toNodes.add(edgeIterator.getAdjNode());
        edges.add(edgeIterator.getEdge());
    }
    for (int i = 0; i < toNodes.size(); i++) {
        EdgeIteratorState edgeIteratorState = storage.getEdgeIteratorState(edges.get(i), toNodes.get(i));
        if (edgeIteratorState == null) {
            return false;
        }
        EdgeIteratorState edgeIteratorState2 = storage.getEdgeIteratorState(edges.get(i), node);
        if (edgeIteratorState2 == null) {
            return false;
        }
    }
    return true;
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 22 with EdgeIteratorState

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

the class NameSimilarityEdgeFilterTest method testAcceptWithTypos.

/**
 * We ignore Typos for now, most GeoCoders return pretty good results, we might allow some typos
 */
@Ignore
public void testAcceptWithTypos() {
    EdgeFilter edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Laufamholzstraße 154 Nürnberg");
    EdgeIteratorState edge = createTestEdgeIterator("Laufamholzstraße, ST1333");
    assertTrue(edgeFilter.accept(edge));
    // Single Typo
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Kaufamholzstraße 154 Nürnberg");
    assertTrue(edgeFilter.accept(edge));
    // Two Typos
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Kaufamholystraße 154 Nürnberg");
    assertTrue(edgeFilter.accept(edge));
    // Three Typos
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Kaufmholystraße 154 Nürnberg");
    assertFalse(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Hauptstraße");
    edge = createTestEdgeIterator("Hauptstraße");
    assertTrue(edgeFilter.accept(edge));
    // Single Typo
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Hauptstrase");
    assertTrue(edgeFilter.accept(edge));
    // Two Typos
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Lauptstrase");
    assertTrue(edgeFilter.accept(edge));
// We ignore too short Strings for now
/*
        // Distance - PerfectDistance = 1
        edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "z");
        assertFalse(edgeFilter.accept(edge));
        // Distance - PerfectDistance = 1
        edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "az");
        assertFalse(edgeFilter.accept(edge));

        // Distance - PerfectDistance = 2
        edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "xy");
        assertFalse(edgeFilter.accept(edge));
        */
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Ignore(org.junit.Ignore)

Example 23 with EdgeIteratorState

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

the class GenericWeightingTest method testRoadAttributeRestriction.

@Test
public void testRoadAttributeRestriction() {
    EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
    Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0));
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
    instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Also used : HintsMap(com.graphhopper.routing.util.HintsMap) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 24 with EdgeIteratorState

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

the class GraphEdgeIdFinder method findEdgesInShape.

/**
 * This method fills the edgeIds hash with edgeIds found inside the specified shape
 */
public void findEdgesInShape(final GHIntHashSet edgeIds, final Shape shape, EdgeFilter filter) {
    GHPoint center = shape.getCenter();
    QueryResult qr = locationIndex.findClosest(center.getLat(), center.getLon(), filter);
    // TODO: if there is no street close to the center it'll fail although there are roads covered. Maybe we should check edge points or some random points in the Shape instead?
    if (!qr.isValid())
        throw new IllegalArgumentException("Shape " + shape + " does not cover graph");
    if (shape.contains(qr.getSnappedPoint().lat, qr.getSnappedPoint().lon))
        edgeIds.add(qr.getClosestEdge().getEdge());
    BreadthFirstSearch bfs = new BreadthFirstSearch() {

        final NodeAccess na = graph.getNodeAccess();

        final Shape localShape = shape;

        @Override
        protected boolean goFurther(int nodeId) {
            return localShape.contains(na.getLatitude(nodeId), na.getLongitude(nodeId));
        }

        @Override
        protected boolean checkAdjacent(EdgeIteratorState edge) {
            if (localShape.contains(na.getLatitude(edge.getAdjNode()), na.getLongitude(edge.getAdjNode()))) {
                edgeIds.add(edge.getEdge());
                return true;
            }
            return false;
        }
    };
    bfs.start(graph.createEdgeExplorer(filter), qr.getClosestNode());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Shape(com.graphhopper.util.shapes.Shape) BreadthFirstSearch(com.graphhopper.util.BreadthFirstSearch) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 25 with EdgeIteratorState

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

the class DijkstraBidirectionCHTest method testPathRecursiveUnpacking.

@Test
public void testPathRecursiveUnpacking() {
    // use an encoder where it is possible to store 2 weights per edge
    FlagEncoder encoder = new Bike2WeightFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    GraphHopperStorage ghStorage = createGHStorage(em, Arrays.asList(weighting), false);
    CHGraphImpl g2 = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting);
    g2.edge(0, 1, 1, true);
    EdgeIteratorState iter1_1 = g2.edge(0, 2, 1.4, false);
    EdgeIteratorState iter1_2 = g2.edge(2, 5, 1.4, false);
    g2.edge(1, 2, 1, true);
    g2.edge(1, 3, 3, true);
    g2.edge(2, 3, 1, true);
    g2.edge(4, 3, 1, true);
    g2.edge(2, 5, 1.4, true);
    g2.edge(3, 5, 1, true);
    g2.edge(5, 6, 1, true);
    g2.edge(4, 6, 1, true);
    g2.edge(6, 7, 1, true);
    EdgeIteratorState iter2_2 = g2.edge(5, 7);
    iter2_2.setDistance(1.4).setFlags(encoder.setProperties(10, true, false));
    ghStorage.freeze();
    // simulate preparation
    CHEdgeIteratorState iter2_1 = g2.shortcut(0, 5);
    iter2_1.setDistance(2.8).setFlags(encoder.setProperties(10, true, false));
    iter2_1.setSkippedEdges(iter1_1.getEdge(), iter1_2.getEdge());
    CHEdgeIteratorState tmp = g2.shortcut(0, 7);
    tmp.setDistance(4.2).setFlags(encoder.setProperties(10, true, false));
    tmp.setSkippedEdges(iter2_1.getEdge(), iter2_2.getEdge());
    g2.setLevel(1, 0);
    g2.setLevel(3, 1);
    g2.setLevel(4, 2);
    g2.setLevel(6, 3);
    g2.setLevel(2, 4);
    g2.setLevel(5, 5);
    g2.setLevel(7, 6);
    g2.setLevel(0, 7);
    AlgorithmOptions opts = new AlgorithmOptions(Parameters.Algorithms.DIJKSTRA_BI, weighting);
    Path p = new PrepareContractionHierarchies(new GHDirectory("", DAType.RAM_INT), ghStorage, g2, weighting, TraversalMode.NODE_BASED).createAlgo(g2, opts).calcPath(0, 7);
    assertEquals(Helper.createTList(0, 2, 5, 7), p.calcNodes());
    assertEquals(1064, p.getTime());
    assertEquals(4.2, p.getDistance(), 1e-5);
}
Also used : PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) Test(org.junit.Test)

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