Search in sources :

Example 11 with BooleanEncodedValue

use of com.graphhopper.routing.ev.BooleanEncodedValue in project graphhopper by graphhopper.

the class LocationIndexTreeTest method testDifferentVehicles.

@Test
public void testDifferentVehicles() {
    final EncodingManager encodingManager = EncodingManager.create("car,foot");
    GraphHopperStorage g = new GraphBuilder(encodingManager).create();
    initSimpleGraph(g, encodingManager);
    LocationIndexTree idx = (LocationIndexTree) createIndexNoPrepare(g, 500000).prepareIndex();
    assertEquals(0, findClosestEdge(idx, 1, -1));
    // now make all edges from node 1 accessible for CAR only
    EdgeIterator iter = g.createEdgeExplorer().setBaseNode(1);
    FlagEncoder encoder = encodingManager.getEncoder("foot");
    BooleanEncodedValue accessEnc = encoder.getAccessEnc();
    while (iter.next()) {
        iter.set(accessEnc, false, false);
    }
    idx = (LocationIndexTree) createIndexNoPrepare(g, 500000).prepareIndex();
    FootFlagEncoder footEncoder = (FootFlagEncoder) encodingManager.getEncoder("foot");
    assertEquals(2, idx.findClosest(1, -1, AccessFilter.allEdges(footEncoder.getAccessEnc())).getClosestNode());
    Helper.close((Closeable) g);
}
Also used : BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with BooleanEncodedValue

use of com.graphhopper.routing.ev.BooleanEncodedValue in project graphhopper by graphhopper.

the class LocationIndexTreeTest method testSearchWithFilter_issue318.

@Test
public void testSearchWithFilter_issue318() {
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEM = EncodingManager.create(carEncoder, bikeEncoder);
    Graph graph = new GraphBuilder(tmpEM).create();
    NodeAccess na = graph.getNodeAccess();
    // distance from point to point is roughly 1 km
    int MAX = 5;
    for (int latIdx = 0; latIdx < MAX; latIdx++) {
        for (int lonIdx = 0; lonIdx < MAX; lonIdx++) {
            int index = lonIdx * 10 + latIdx;
            na.setNode(index, 0.01 * latIdx, 0.01 * lonIdx);
            if (latIdx < MAX - 1)
                GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(index, index + 1));
            if (lonIdx < MAX - 1)
                GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(index, index + 10));
        }
    }
    // reduce access for bike to two edges only
    AllEdgesIterator iter = graph.getAllEdges();
    BooleanEncodedValue accessEnc = bikeEncoder.getAccessEnc();
    while (iter.next()) {
        iter.set(accessEnc, false, false);
    }
    for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(graph, 0, 1), GHUtility.getEdge(graph, 1, 2))) {
        edge.set(accessEnc, true, true);
    }
    LocationIndexTree index = createIndexNoPrepare(graph, 500);
    index.prepareIndex();
    index.setMaxRegionSearch(8);
    EdgeFilter carFilter = AccessFilter.allEdges(carEncoder.getAccessEnc());
    Snap snap = index.findClosest(0.03, 0.03, carFilter);
    assertTrue(snap.isValid());
    assertEquals(33, snap.getClosestNode());
    EdgeFilter bikeFilter = AccessFilter.allEdges(bikeEncoder.getAccessEnc());
    snap = index.findClosest(0.03, 0.03, bikeFilter);
    assertTrue(snap.isValid());
    assertEquals(2, snap.getClosestNode());
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with BooleanEncodedValue

use of com.graphhopper.routing.ev.BooleanEncodedValue in project graphhopper by graphhopper.

the class CHTurnCostTest method test_astar_issue2061.

@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void test_astar_issue2061(String algo) {
    // here the direct path 0-2-3-4-5 is clearly the shortest, however there was a bug in the a-star(-like)
    // algo: first the non-optimal path 0-1-5 is found, but before we find the actual shortest path we explore
    // node 6 during the forward search. the path 0-6-x-5 cannot possibly be the shortest path because 0-6-5
    // is already worse than 0-1-5, even if there was a beeline link from 6 to 5. the problem was that then we
    // cancelled the entire fwd search instead of simply stalling node 6.
    // |-------1-|
    // 7-6---0---2-3-4-5
    BooleanEncodedValue accessEnc = encoder.getAccessEnc();
    DecimalEncodedValue speedEnc = encoder.getAverageSpeedEnc();
    graph.edge(0, 1).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(1, 5).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(0, 2).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(2, 3).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(3, 4).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(4, 5).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(0, 6).set(accessEnc, true).set(speedEnc, 60);
    graph.edge(6, 7).set(accessEnc, true).set(speedEnc, 60);
    updateDistancesFor(graph, 0, 46.5, 9.7);
    updateDistancesFor(graph, 1, 46.9, 9.8);
    updateDistancesFor(graph, 2, 46.7, 9.7);
    updateDistancesFor(graph, 4, 46.9, 9.7);
    updateDistancesFor(graph, 3, 46.8, 9.7);
    updateDistancesFor(graph, 5, 47.0, 9.7);
    updateDistancesFor(graph, 6, 46.3, 9.7);
    updateDistancesFor(graph, 7, 46.2, 9.7);
    graph.freeze();
    automaticPrepareCH();
    RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(chGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
    Path path = chAlgo.calcPath(0, 5);
    assertEquals(IntArrayList.from(0, 2, 3, 4, 5), path.calcNodes());
}
Also used : RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm) Path(com.graphhopper.routing.Path) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with BooleanEncodedValue

use of com.graphhopper.routing.ev.BooleanEncodedValue in project graphhopper by graphhopper.

the class QueryGraphTest method testOneWayLoop_Issue162.

@Test
public void testOneWayLoop_Issue162() {
    // do query at x, where edge is oneway
    // 
    // |\
    // | x
    // 0<-\
    // |
    // 1
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0, 0);
    na.setNode(1, 0, -0.001);
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10));
    BooleanEncodedValue accessEnc = encoder.getAccessEnc();
    DecimalEncodedValue avSpeedEnc = encoder.getAverageSpeedEnc();
    // in the case of identical nodes the wayGeometry defines the direction!
    EdgeIteratorState edge = g.edge(0, 0).setDistance(100).set(accessEnc, true, false).set(avSpeedEnc, 20.0).setWayGeometry(Helper.createPointList(0.001, 0, 0, 0.001));
    Snap snap = new Snap(0.0011, 0.0009);
    snap.setClosestEdge(edge);
    snap.setWayIndex(1);
    snap.calcSnappedPoint(new DistanceCalcEuclidean());
    QueryGraph qg = lookup(snap);
    EdgeExplorer ee = qg.createEdgeExplorer();
    assertTrue(snap.getClosestNode() > 1);
    assertEquals(2, GHUtility.count(ee.setBaseNode(snap.getClosestNode())));
    EdgeIterator iter = ee.setBaseNode(snap.getClosestNode());
    iter.next();
    assertTrue(iter.get(accessEnc), iter.toString());
    assertFalse(iter.getReverse(accessEnc), iter.toString());
    iter.next();
    assertFalse(iter.get(accessEnc), iter.toString());
    assertTrue(iter.getReverse(accessEnc), iter.toString());
}
Also used : BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) Snap(com.graphhopper.storage.index.Snap) Test(org.junit.jupiter.api.Test)

Example 15 with BooleanEncodedValue

use of com.graphhopper.routing.ev.BooleanEncodedValue in project graphhopper by graphhopper.

the class ShortestPathTreeTest method countDirectedEdges.

private int countDirectedEdges(GraphHopperStorage graph) {
    BooleanEncodedValue accessEnc = carEncoder.getAccessEnc();
    int result = 0;
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        if (iter.get(accessEnc))
            result++;
        if (iter.getReverse(accessEnc))
            result++;
    }
    return result;
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue)

Aggregations

BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)16 Test (org.junit.jupiter.api.Test)8 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 ArrayList (java.util.ArrayList)4 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 Snap (com.graphhopper.storage.index.Snap)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 Profile (com.graphhopper.config.Profile)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 Path (com.graphhopper.routing.Path)2 RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)2 Subnetwork (com.graphhopper.routing.ev.Subnetwork)2 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)2 IntsRef (com.graphhopper.storage.IntsRef)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 IntObjectPredicate (com.carrotsearch.hppc.predicates.IntObjectPredicate)1