Search in sources :

Example 1 with EdgeIteratorState

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

the class ChangeGraphHelper method applyChange.

private long applyChange(JsonFeature jsonFeature, FlagEncoder encoder) {
    long updates = 0;
    EdgeFilter filter = new DefaultEdgeFilter(encoder);
    GHIntHashSet edges = new GHIntHashSet();
    if (jsonFeature.hasGeometry()) {
        graphBrowser.fillEdgeIDs(edges, jsonFeature.getGeometry(), filter);
    } else if (jsonFeature.getBBox() != null) {
        graphBrowser.findEdgesInShape(edges, jsonFeature.getBBox(), filter);
    } else
        throw new IllegalArgumentException("Feature " + jsonFeature.getId() + " has no geometry and no bbox");
    Iterator<IntCursor> iter = edges.iterator();
    Map<String, Object> props = jsonFeature.getProperties();
    while (iter.hasNext()) {
        int edgeId = iter.next().value;
        EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE);
        if (props.containsKey("access")) {
            boolean value = (boolean) props.get("access");
            updates++;
            if (enableLogging)
                logger.info(encoder.toString() + " - access change via feature " + jsonFeature.getId());
            edge.setFlags(encoder.setAccess(edge.getFlags(), value, value));
        } else if (props.containsKey("speed")) {
            // TODO use different speed for the different directions (see e.g. Bike2WeightFlagEncoder)
            double value = ((Number) props.get("speed")).doubleValue();
            double oldSpeed = encoder.getSpeed(edge.getFlags());
            if (oldSpeed != value) {
                updates++;
                if (enableLogging)
                    logger.info(encoder.toString() + " - speed change via feature " + jsonFeature.getId() + ". Old: " + oldSpeed + ", new:" + value);
                edge.setFlags(encoder.setSpeed(edge.getFlags(), value));
            }
        }
    }
    return updates;
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) IntCursor(com.carrotsearch.hppc.cursors.IntCursor)

Example 2 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 : 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)

Example 3 with EdgeIteratorState

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

the class EdgeBasedRoutingAlgorithmTest method testBasicTurnCosts.

@Test
public void testBasicTurnCosts() {
    GraphHopperStorage g = createStorage(createEncodingManager(false));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    Path p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(5, 1);
    // no restriction and costs
    EdgeIteratorState e3_6 = getEdge(g, 5, 6);
    e3_6.setDistance(2);
    assertEquals(Helper.createTList(5, 2, 3, 1), p.calcNodes());
    // now introduce some turn costs
    long tflags = carEncoder.getTurnFlags(false, 2);
    tcs.addTurnInfo(getEdge(g, 5, 2).getEdge(), 2, getEdge(g, 2, 3).getEdge(), tflags);
    p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(5, 1);
    assertEquals(Helper.createTList(5, 6, 3, 1), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 4 with EdgeIteratorState

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

the class EdgeBasedRoutingAlgorithmTest method testUTurns.

@Test
public void testUTurns() {
    GraphHopperStorage g = createStorage(createEncodingManager(true));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    long tflags = carEncoder.getTurnFlags(true, 0);
    // force u-turn via lowering the cost for it
    EdgeIteratorState e3_6 = getEdge(g, 3, 6);
    e3_6.setDistance(0.1);
    getEdge(g, 3, 2).setDistance(864);
    getEdge(g, 1, 0).setDistance(864);
    tcs.addTurnInfo(getEdge(g, 7, 6).getEdge(), 6, getEdge(g, 6, 5).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 4, 3).getEdge(), 3, e3_6.getEdge(), tflags);
    AlgorithmOptions opts = AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 50)).traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build();
    Path p = createAlgo(g, opts).calcPath(7, 5);
    assertEquals(Helper.createTList(7, 6, 3, 6, 5), p.calcNodes());
    // no u-turn for 6-3
    opts = AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 100)).traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build();
    tcs.addTurnInfo(getEdge(g, 6, 3).getEdge(), 3, getEdge(g, 3, 6).getEdge(), tflags);
    p = createAlgo(g, opts).calcPath(7, 5);
    assertEquals(Helper.createTList(7, 6, 3, 2, 5), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 5 with EdgeIteratorState

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

the class NameSimilarityEdgeFilterTest method testAcceptFromGoogleMapsGeocoding.

@Test
public void testAcceptFromGoogleMapsGeocoding() {
    EdgeFilter edgeFilter;
    EdgeIteratorState edge;
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Rue Notre-Dame O Montréal");
    edge = createTestEdgeIterator("Rue Dupré");
    assertFalse(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Rue Notre-Dame Ouest");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "227 Rue Saint-Antoine O, Montréal");
    edge = createTestEdgeIterator("Rue Saint-Antoine O");
    assertTrue(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Rue Saint-Jacques");
    assertFalse(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "1025 Rue de Bleury, Montréal, QC H2Z 1M7");
    edge = createTestEdgeIterator("Rue de Bleury");
    assertTrue(edgeFilter.accept(edge));
    edge = createTestEdgeIterator("Rue Balmoral");
    assertFalse(edgeFilter.accept(edge));
    // Modified Test from Below
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "257 Main Road, Claremont, Cape Town, 7708, Afrique du Sud");
    edge = createTestEdgeIterator("Main Road");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Cape Point Rd, Cape Peninsula, Cape Town, 8001, Afrique du Sud");
    edge = createTestEdgeIterator("Cape Point / Cape of Good Hope");
    assertTrue(edgeFilter.accept(edge));
    edgeFilter = new NameSimilarityEdgeFilter(new DefaultEdgeFilter(new CarFlagEncoder()), "Viale Puglie, 26, 20137 Milano, Italy");
    edge = createTestEdgeIterator("Viale Puglie");
    assertTrue(edgeFilter.accept(edge));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) 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