Search in sources :

Example 56 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class HeadingResolverTest method curvyEdge.

@Test
public void curvyEdge() {
    // 1 -|
    // |- 0 -|
    // |- 2
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(1, 0.01, 0.00);
    na.setNode(0, 0.00, 0.00);
    na.setNode(2, -0.01, 0.00);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, 0.01, 0.01, 0.01));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 2).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, -0.01, -0.01, -0.01));
    HeadingResolver resolver = new HeadingResolver(graph);
    resolver.setTolerance(120);
    // asking for the edges not going east returns 0-2
    assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(0, 90));
    // asking for the edges not going west returns 0-1
    assertEquals(IntArrayList.from(0), resolver.getEdgesWithDifferentHeading(0, 270));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) NodeAccess(com.graphhopper.storage.NodeAccess) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 57 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class EdgeBasedRoutingAlgorithmTest method testRandomGraph.

@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testRandomGraph(String algoStr) {
    long seed = System.nanoTime();
    final int numQueries = 100;
    Random rnd = new Random(seed);
    EncodingManager em = createEncodingManager(false);
    GraphHopperStorage g = createStorage(em);
    GHUtility.buildRandomGraph(g, rnd, 50, 2.2, true, true, carEncoder.getAccessEnc(), carEncoder.getAverageSpeedEnc(), null, 0.8, 0.8, 0.8);
    GHUtility.addRandomTurnCosts(g, seed, em, carEncoder, 3, tcs);
    g.freeze();
    int numPathsNotFound = 0;
    // todo: reduce redundancy with RandomCHRoutingTest
    List<String> strictViolations = new ArrayList<>();
    for (int i = 0; i < numQueries; i++) {
        int from = rnd.nextInt(g.getNodes());
        int to = rnd.nextInt(g.getNodes());
        Weighting w = createWeighting();
        RoutingAlgorithm refAlgo = new Dijkstra(g, w, EDGE_BASED);
        Path refPath = refAlgo.calcPath(from, to);
        double refWeight = refPath.getWeight();
        if (!refPath.isFound()) {
            numPathsNotFound++;
            continue;
        }
        Path path = calcPath(g, from, to, algoStr);
        if (!path.isFound()) {
            fail("path not found for " + from + "->" + to + ", expected weight: " + refWeight);
        }
        double weight = path.getWeight();
        if (Math.abs(refWeight - weight) > 1.e-2) {
            LOGGER.warn("expected: " + refPath.calcNodes());
            LOGGER.warn("given:    " + path.calcNodes());
            fail("wrong weight: " + from + "->" + to + ", dijkstra: " + refWeight + " vs. " + algoStr + ": " + path.getWeight());
        }
        if (Math.abs(path.getDistance() - refPath.getDistance()) > 1.e-1) {
            strictViolations.add("wrong distance " + from + "->" + to + ", expected: " + refPath.getDistance() + ", given: " + path.getDistance());
        }
        if (Math.abs(path.getTime() - refPath.getTime()) > 50) {
            strictViolations.add("wrong time " + from + "->" + to + ", expected: " + refPath.getTime() + ", given: " + path.getTime());
        }
    }
    if (numPathsNotFound > 0.9 * numQueries) {
        fail("Too many paths not found: " + numPathsNotFound + "/" + numQueries);
    }
    if (strictViolations.size() > 0.05 * numQueries) {
        fail("Too many strict violations: " + strictViolations.size() + "/" + numQueries + "\n" + Helper.join("\n", strictViolations));
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) Random(java.util.Random) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 58 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class HeadingRoutingTest method createSquareGraphWithTunnel.

private GraphHopperStorage createSquareGraphWithTunnel() {
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).add(Subnetwork.create("profile")).build();
    GraphHopperStorage g = new GraphBuilder(encodingManager).create();
    // 2----3---4
    // |    |   |
    // 1->- 8 >-5 (edge 1->5 is not connected to 8)
    // |    |   |
    // 0----7---6
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0.000, 0.000);
    na.setNode(1, 0.001, 0.000);
    na.setNode(2, 0.002, 0.000);
    na.setNode(3, 0.002, 0.001);
    na.setNode(4, 0.002, 0.002);
    na.setNode(5, 0.001, 0.002);
    na.setNode(6, 0.000, 0.002);
    na.setNode(7, 0.000, 0.001);
    na.setNode(8, 0.001, 0.001);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 6).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 0).setDistance(100));
    GHUtility.setSpeed(60, true, false, carEncoder, g.edge(1, 5).setDistance(110));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 8).setDistance(110));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(110));
    return g;
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder)

Example 59 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class DepthFirstSearchTest method testDFS2.

@Test
public void testDFS2() {
    DepthFirstSearch dfs = new DepthFirstSearch() {

        @Override
        protected GHBitSet createBitSet() {
            return new GHBitSetImpl();
        }

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue(!set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    EncodingManager em = EncodingManager.create("car");
    FlagEncoder encoder = em.getEncoder("car");
    Graph g = new GraphBuilder(em).create();
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 3).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 3).setDistance(1));
    dfs.start(g.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc())), 1);
    assertTrue(counter > 0);
    assertEquals(list.toString(), "[1, 2, 3, 4]");
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) Graph(com.graphhopper.storage.Graph) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test)

Example 60 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class DepthFirstSearchTest method testDFS1.

@Test
public void testDFS1() {
    DepthFirstSearch dfs = new DepthFirstSearch() {

        @Override
        protected GHBitSet createBitSet() {
            return new GHBitSetImpl();
        }

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue(!set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    EncodingManager em = EncodingManager.create("car");
    FlagEncoder encoder = em.getEncoder("car");
    Graph g = new GraphBuilder(em).create();
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 5).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 6).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(6, 4).setDistance(1));
    dfs.start(g.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc())), 1);
    assertTrue(counter > 0);
    assertEquals(list.toString(), "[1, 2, 3, 4, 5, 6]");
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) Graph(com.graphhopper.storage.Graph) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)60 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)19 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)18 Test (org.junit.jupiter.api.Test)18 GraphBuilder (com.graphhopper.storage.GraphBuilder)17 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)15 Test (org.junit.Test)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)9 Graph (com.graphhopper.storage.Graph)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)5 IntsRef (com.graphhopper.storage.IntsRef)5 GraphHopper (com.graphhopper.GraphHopper)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3