Search in sources :

Example 36 with Graph

use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.

the class LocationIndexTreeTest method testSnappedPointAndGeometry.

@Test
public void testSnappedPointAndGeometry() {
    Graph graph = createTestGraph(encodingManager);
    LocationIndex index = createIndex(graph, -1);
    // query directly the tower node
    QueryResult res = index.findClosest(-0.4, 0.9, EdgeFilter.ALL_EDGES);
    assertTrue(res.isValid());
    assertEquals(new GHPoint(-0.4, 0.9), res.getSnappedPoint());
    res = index.findClosest(-0.6, 1.6, EdgeFilter.ALL_EDGES);
    assertTrue(res.isValid());
    assertEquals(new GHPoint(-0.6, 1.6), res.getSnappedPoint());
    // query the edge (1,3). The edge (0,4) has 27674 as distance
    res = index.findClosest(-0.2, 0.3, EdgeFilter.ALL_EDGES);
    assertTrue(res.isValid());
    assertEquals(26936, res.getQueryDistance(), 1);
    assertEquals(new GHPoint(-0.441624, 0.317259), res.getSnappedPoint());
}
Also used : Graph(com.graphhopper.storage.Graph) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 37 with Graph

use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.

the class LocationIndexTreeTest method testMoreReal.

@Test
public void testMoreReal() {
    Graph graph = createGHStorage(new EncodingManager("car"));
    NodeAccess na = graph.getNodeAccess();
    na.setNode(1, 51.2492152, 9.4317166);
    na.setNode(0, 52, 9);
    na.setNode(2, 51.2, 9.4);
    na.setNode(3, 49, 10);
    graph.edge(1, 0, 1000, true);
    graph.edge(0, 2, 1000, true);
    graph.edge(0, 3, 1000, true).setWayGeometry(Helper.createPointList(51.21, 9.43));
    LocationIndex index = createIndex(graph, -1);
    assertEquals(2, findID(index, 51.2, 9.4));
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Example 38 with Graph

use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.

the class BreadthFirstSearchTest method testBFS.

@Test
public void testBFS() {
    BreadthFirstSearch bfs = new BreadthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    Graph g = new GraphBuilder(new EncodingManager("car")).create();
    g.edge(0, 1, 85, true);
    g.edge(0, 2, 217, true);
    g.edge(0, 3, 173, true);
    g.edge(0, 5, 173, true);
    g.edge(1, 6, 75, true);
    g.edge(2, 7, 51, true);
    g.edge(3, 8, 23, true);
    g.edge(4, 8, 793, true);
    g.edge(8, 10, 343, true);
    g.edge(6, 9, 72, true);
    g.edge(9, 10, 8, true);
    g.edge(5, 10, 1, true);
    bfs.start(g.createEdgeExplorer(), 0);
    assertTrue(counter > 0);
    assertEquals(g.getNodes(), counter);
    assertEquals("[0, 5, 3, 2, 1, 10, 8, 7, 6, 9, 4]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 39 with Graph

use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.

the class BreadthFirstSearchTest method testBFS2.

@Test
public void testBFS2() {
    BreadthFirstSearch bfs = new BreadthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    Graph g = new GraphBuilder(new EncodingManager("car")).create();
    g.edge(1, 2, 1, false);
    g.edge(2, 3, 1, false);
    g.edge(3, 4, 1, false);
    g.edge(1, 5, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 4, 1, false);
    bfs.start(g.createEdgeExplorer(), 1);
    assertTrue(counter > 0);
    assertEquals("[1, 5, 2, 6, 3, 4]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 40 with Graph

use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.

the class DepthFirstSearchTest method testDFS1.

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

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

Aggregations

Graph (com.graphhopper.storage.Graph)47 Test (org.junit.Test)40 GraphBuilder (com.graphhopper.storage.GraphBuilder)21 NodeAccess (com.graphhopper.storage.NodeAccess)18 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)9 EdgeExplorer (com.graphhopper.util.EdgeExplorer)8 Dijkstra (com.graphhopper.routing.Dijkstra)7 Path (com.graphhopper.routing.Path)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 RAMDirectory (com.graphhopper.storage.RAMDirectory)5 ReaderWay (com.graphhopper.reader.ReaderWay)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 GHRequest (com.graphhopper.GHRequest)3 GHResponse (com.graphhopper.GHResponse)3 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)3 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CHGraph (com.graphhopper.storage.CHGraph)3 BBox (com.graphhopper.util.shapes.BBox)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3