Search in sources :

Example 6 with Graph

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

the class LocationIndexTreeTest method createTestGraph2.

// see testgraph2.jpg
Graph createTestGraph2() {
    Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(8, 49.94553, 11.57214);
    na.setNode(9, 49.94553, 11.57314);
    na.setNode(10, 49.94553, 11.57414);
    na.setNode(11, 49.94553, 11.57514);
    na.setNode(12, 49.94553, 11.57614);
    na.setNode(13, 49.94553, 11.57714);
    na.setNode(0, 49.94653, 11.57114);
    na.setNode(1, 49.94653, 11.57214);
    na.setNode(2, 49.94653, 11.57314);
    na.setNode(3, 49.94653, 11.57414);
    na.setNode(4, 49.94653, 11.57514);
    na.setNode(5, 49.94653, 11.57614);
    na.setNode(6, 49.94653, 11.57714);
    na.setNode(7, 49.94653, 11.57814);
    na.setNode(14, 49.94753, 11.57214);
    na.setNode(15, 49.94753, 11.57314);
    na.setNode(16, 49.94753, 11.57614);
    na.setNode(17, 49.94753, 11.57814);
    na.setNode(18, 49.94853, 11.57114);
    na.setNode(19, 49.94853, 11.57214);
    na.setNode(20, 49.94853, 11.57814);
    na.setNode(21, 49.94953, 11.57214);
    na.setNode(22, 49.94953, 11.57614);
    na.setNode(23, 49.95053, 11.57114);
    na.setNode(24, 49.95053, 11.57214);
    na.setNode(25, 49.95053, 11.57314);
    na.setNode(26, 49.95053, 11.57514);
    na.setNode(27, 49.95053, 11.57614);
    na.setNode(28, 49.95053, 11.57714);
    na.setNode(29, 49.95053, 11.57814);
    na.setNode(30, 49.95153, 11.57214);
    na.setNode(31, 49.95153, 11.57314);
    na.setNode(32, 49.95153, 11.57514);
    na.setNode(33, 49.95153, 11.57614);
    na.setNode(34, 49.95153, 11.57714);
    na.setNode(34, 49.95153, 11.57714);
    // to create correct bounds
    // bottom left
    na.setNode(100, 49.941, 11.56614);
    // top right
    na.setNode(101, 49.96053, 11.58814);
    graph.edge(0, 1, 10, true);
    graph.edge(1, 2, 10, true);
    graph.edge(2, 3, 10, true);
    graph.edge(3, 4, 10, true);
    graph.edge(4, 5, 10, true);
    graph.edge(6, 7, 10, true);
    graph.edge(8, 2, 10, true);
    graph.edge(9, 2, 10, true);
    graph.edge(10, 3, 10, true);
    graph.edge(11, 4, 10, true);
    graph.edge(12, 5, 10, true);
    graph.edge(13, 6, 10, true);
    graph.edge(1, 14, 10, true);
    graph.edge(2, 15, 10, true);
    graph.edge(5, 16, 10, true);
    graph.edge(14, 15, 10, true);
    graph.edge(16, 17, 10, true);
    graph.edge(16, 20, 10, true);
    graph.edge(16, 25, 10, true);
    graph.edge(18, 14, 10, true);
    graph.edge(18, 19, 10, true);
    graph.edge(18, 21, 10, true);
    graph.edge(19, 21, 10, true);
    graph.edge(21, 24, 10, true);
    graph.edge(23, 24, 10, true);
    graph.edge(24, 25, 10, true);
    graph.edge(26, 27, 10, true);
    graph.edge(27, 28, 10, true);
    graph.edge(28, 29, 10, true);
    graph.edge(24, 30, 10, true);
    graph.edge(24, 31, 10, true);
    graph.edge(26, 32, 10, true);
    graph.edge(27, 33, 10, true);
    graph.edge(28, 34, 10, true);
    return graph;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) RAMDirectory(com.graphhopper.storage.RAMDirectory)

Example 7 with Graph

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

the class InstructionListTest method testEmptyList.

@Test
public void testEmptyList() {
    Graph g = new GraphBuilder(carManager).create();
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 1);
    InstructionList il = p.calcInstructions(usTR);
    assertEquals(0, il.size());
    assertEquals(0, il.createStartPoints().size());
}
Also used : Path(com.graphhopper.routing.Path) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Test(org.junit.Test)

Example 8 with Graph

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

the class LocationIndexTreeTest method testFindNClosest.

// 0---1---2
// |   |   |
// |10 |   |
// | | |   |
// 3-9-4---5
// |   |   |
// 6---7---8
@Test
public void testFindNClosest() {
    Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0.0010, 0.0000);
    na.setNode(1, 0.0010, 0.0005);
    na.setNode(2, 0.0010, 0.0010);
    na.setNode(3, 0.0005, 0.0000);
    na.setNode(4, 0.0005, 0.0005);
    na.setNode(5, 0.0005, 0.0010);
    na.setNode(6, 0.0000, 0.0000);
    na.setNode(7, 0.0000, 0.0005);
    na.setNode(8, 0.0000, 0.0010);
    na.setNode(9, 0.0005, 0.0002);
    na.setNode(10, 0.0007, 0.0002);
    graph.edge(0, 1);
    graph.edge(1, 2);
    graph.edge(0, 3);
    graph.edge(1, 4);
    graph.edge(2, 5);
    graph.edge(3, 9);
    graph.edge(9, 4);
    EdgeIteratorState edge4_5 = graph.edge(4, 5);
    graph.edge(10, 9);
    graph.edge(3, 6);
    EdgeIteratorState edge4_7 = graph.edge(4, 7);
    graph.edge(5, 8);
    graph.edge(6, 7);
    graph.edge(7, 8);
    LocationIndexTree index = createIndexNoPrepare(graph, 500);
    index.prepareIndex();
    // query node 4 => get at least 4-5, 4-7
    List<QueryResult> result = index.findNClosest(0.0004, 0.0006, EdgeFilter.ALL_EDGES, 15);
    List<Integer> ids = new ArrayList<Integer>();
    for (QueryResult qr : result) {
        ids.add(qr.getClosestEdge().getEdge());
    }
    Collections.sort(ids);
    assertEquals("edge ids do not match", Arrays.asList(edge4_5.getEdge(), edge4_7.getEdge()), ids);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) ArrayList(java.util.ArrayList) RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Example 9 with Graph

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

the class LocationIndexTreeTest method testInMemIndex.

@Test
public void testInMemIndex() {
    Graph graph = createTestGraph(encodingManager);
    LocationIndexTree index = createIndexNoPrepare(graph, 50000);
    index.prepareAlgo();
    LocationIndexTree.InMemConstructionIndex inMemIndex = index.getPrepareInMemIndex();
    assertEquals(Helper.createTList(4, 4), index.getEntries());
    assertEquals(4, inMemIndex.getEntriesOf(0).size());
    assertEquals(10, inMemIndex.getEntriesOf(1).size());
    assertEquals(0, inMemIndex.getEntriesOf(2).size());
    // [LEAF 0 {} {0, 2}, LEAF 2 {} {0, 1}, LEAF 1 {} {2}, LEAF 3 {} {1}, LEAF 8 {} {0}, LEAF 10 {} {0}, LEAF 9 {} {0}, LEAF 4 {} {2}, LEAF 6 {} {0, 1, 2, 3}, LEAF 5 {} {0, 2, 3}, LEAF 7 {} {1, 2, 3}, LEAF 13 {} {1}]
    // System.out.println(inMemIndex.getLayer(2));
    index.dataAccess.create(10);
    inMemIndex.store(inMemIndex.root, LocationIndexTree.START_POINTER);
    // [LEAF 0 {2} {},    LEAF 2 {1} {},    LEAF 1 {2} {}, LEAF 3 {1} {}, LEAF 8 {0} {}, LEAF 10 {0} {}, LEAF 9 {0} {}, LEAF 4 {2} {}, LEAF 6 {0, 3} {},       LEAF 5 {0, 2, 3} {}, LEAF 7 {1, 2, 3} {}, LEAF 13 {1} {}]
    // System.out.println(inMemIndex.getLayer(2));
    GHIntHashSet set = new GHIntHashSet();
    set.add(0);
    GHIntHashSet foundIds = new GHIntHashSet();
    index.findNetworkEntries(0.5, -0.5, foundIds, 0);
    assertEquals(set, foundIds);
    set.add(1);
    set.add(2);
    foundIds.clear();
    index.findNetworkEntries(-0.5, -0.9, foundIds, 0);
    index.findNetworkEntries(-0.5, -0.9, foundIds, 1);
    assertEquals(set, foundIds);
    assertEquals(2, findID(index, -0.5, -0.9));
// The optimization if(dist > normedHalf) => feed nodeA or nodeB
// although this reduces chance of nodes outside of the tile
// in practice it even increases file size!?
// Is this due to the CHGraph disconnect problem?
// set.clear();
// set.add(4);
// assertEquals(set, index.findNetworkEntries(-0.7, 1.5));
// 
// set.clear();
// set.add(4);
// assertEquals(set, index.findNetworkEntries(-0.5, 0.5));
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Example 10 with Graph

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

the class LocationIndexTreeTest method testRMin.

@Test
public void testRMin() {
    Graph graph = createTestGraph(encodingManager);
    LocationIndexTree index = createIndex(graph, 50000);
    // query: 0.05 | -0.3
    DistanceCalc distCalc = new DistancePlaneProjection();
    double rmin = index.calculateRMin(0.05, -0.3);
    double check = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLon(2)) - index.getDeltaLon(), -0.3, -0.3);
    assertTrue((rmin - check) < 0.0001);
    double rmin2 = index.calculateRMin(0.05, -0.3, 1);
    double check2 = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLat(0)), -0.3, -0.3);
    assertTrue((rmin2 - check2) < 0.0001);
    GHIntHashSet points = new GHIntHashSet();
    assertEquals(Double.MAX_VALUE, index.calcMinDistance(0.05, -0.3, points), 1e-1);
    points.add(0);
    points.add(1);
    assertEquals(54757.03, index.calcMinDistance(0.05, -0.3, points), 1e-1);
/*GraphVisualizer gv = new GraphVisualizer(graph, index.getDeltaLat(), index.getDeltaLon(), index.getCenter(0, 0).lat, index.getCenter(0, 0).lon);
         try {
         Thread.sleep(4000);
         } catch(InterruptedException ie) {}*/
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Graph(com.graphhopper.storage.Graph) 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