Search in sources :

Example 76 with EdgeIteratorState

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

the class NameSimilarityEdgeFilterTest method testAccept.

@Test
public void testAccept() {
    EdgeFilter edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Laufamholzstraße 154 Nürnberg");
    EdgeIteratorState edge = createTestEdgeIterator("Laufamholzstraße, ST1333");
    assertTrue(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Hauptstraße");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Lorem Ipsum");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator(null);
    assertFalse(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), null);
    edge = createTestEdgeIterator("Laufamholzstraße, ST1333");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "");
    edge = createTestEdgeIterator("Laufamholzstraße, ST1333");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Johannesstraße, 99636, Rastenberg, Deutschland");
    edge = createTestEdgeIterator("Laufamholzstraße, ST1333");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Johannesstraße");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Hauptstraße, 39025, Naturns, Italien");
    edge = createTestEdgeIterator("Teststraße");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Hauptstraße");
    assertTrue(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Hauptstrasse");
    assertTrue(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Hauptstr.");
    assertTrue(edgeFilter.accept(edge));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 77 with EdgeIteratorState

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

the class NameSimilarityEdgeFilterTest method testAcceptMashup.

@Test
public void testAcceptMashup() {
    EdgeFilter edgeFilter;
    EdgeIteratorState edge;
    edge = createTestEdgeIterator("Augustine Street");
    // Google Maps
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Augustine St, Hunters Hill NSW 2110, Australia");
    assertTrue(edgeFilter.accept(edge));
    // Opencagedata
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Augustine Street, Sydney Neusüdwales 2110, Australien");
    assertTrue(edgeFilter.accept(edge));
    // Nominatim
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Augustine Street, Sydney, Municipality of Hunters Hill, Neusüdwales, 2111, Australien");
    assertTrue(edgeFilter.accept(edge));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 78 with EdgeIteratorState

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

the class DijkstraOneToManyTest method testDifferentEdgeFilter.

@Test
public void testDifferentEdgeFilter() {
    GraphHopperStorage g = new GraphBuilder(encodingManager).setCHGraph(new FastestWeighting(carEncoder)).create();
    g.edge(4, 3, 10, true);
    g.edge(3, 6, 10, true);
    g.edge(4, 5, 10, true);
    g.edge(5, 6, 10, true);
    DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(g);
    algo.setEdgeFilter(new EdgeFilter() {

        @Override
        public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 5;
        }
    });
    Path p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 3, 6), p.calcNodes());
    // important call!
    algo.clear();
    algo.setEdgeFilter(new EdgeFilter() {

        @Override
        public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 3;
        }
    });
    p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 5, 6), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) GraphBuilder(com.graphhopper.storage.GraphBuilder) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 79 with EdgeIteratorState

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

the class AbstractEdgeElevationInterpolator method gatherOuterAndInnerNodeIds.

public void gatherOuterAndInnerNodeIds(final EdgeExplorer edgeExplorer, final EdgeIteratorState interpolatableEdge, final GHBitSet visitedEdgesIds, final IntSet outerNodeIds, final GHIntHashSet innerNodeIds) {
    final BreadthFirstSearch gatherOuterAndInnerNodeIdsSearch = new BreadthFirstSearch() {

        @Override
        protected boolean checkAdjacent(EdgeIteratorState edge) {
            visitedEdgesIds.add(edge.getEdge());
            final int baseNodeId = edge.getBaseNode();
            boolean isInterpolatableEdge = isInterpolatableEdge(edge);
            if (!isInterpolatableEdge) {
                innerNodeIds.remove(baseNodeId);
                outerNodeIds.add(baseNodeId);
            } else if (!outerNodeIds.contains(baseNodeId)) {
                innerNodeIds.add(baseNodeId);
            }
            return isInterpolatableEdge;
        }
    };
    gatherOuterAndInnerNodeIdsSearch.start(edgeExplorer, interpolatableEdge.getBaseNode());
}
Also used : BreadthFirstSearch(com.graphhopper.util.BreadthFirstSearch) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 80 with EdgeIteratorState

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

the class LocationIndexTreeCHTest method testCHGraph.

@Test
public void testCHGraph() {
    GraphHopperStorage ghStorage = createGHStorage(new RAMDirectory(), encodingManager, false);
    CHGraph lg = ghStorage.getGraph(CHGraph.class);
    // 0
    // 1
    // 2
    // 3
    // 4
    NodeAccess na = ghStorage.getNodeAccess();
    na.setNode(0, 1, 0);
    na.setNode(1, 0.5, 0);
    na.setNode(2, 0, 0);
    na.setNode(3, -1, 1);
    na.setNode(4, -2, 2);
    EdgeIteratorState iter1 = ghStorage.edge(0, 1, 10, true);
    EdgeIteratorState iter2 = ghStorage.edge(1, 2, 10, true);
    EdgeIteratorState iter3 = ghStorage.edge(2, 3, 14, true);
    EdgeIteratorState iter4 = ghStorage.edge(3, 4, 14, true);
    // create shortcuts
    ghStorage.freeze();
    FlagEncoder car = encodingManager.getEncoder("car");
    long flags = car.setProperties(60, true, true);
    CHEdgeIteratorState iter5 = lg.shortcut(0, 2);
    iter5.setDistance(20).setFlags(flags);
    iter5.setSkippedEdges(iter1.getEdge(), iter2.getEdge());
    CHEdgeIteratorState iter6 = lg.shortcut(2, 4);
    iter6.setDistance(28).setFlags(flags);
    iter6.setSkippedEdges(iter3.getEdge(), iter4.getEdge());
    CHEdgeIteratorState tmp = lg.shortcut(0, 4);
    tmp.setDistance(40).setFlags(flags);
    tmp.setSkippedEdges(iter5.getEdge(), iter6.getEdge());
    LocationIndex index = createIndex(ghStorage, -1);
    assertEquals(2, findID(index, 0, 0.5));
}
Also used : CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) 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