Search in sources :

Example 1 with Graph

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

the class AlternativeRouteTest method testDisconnectedAreas.

@Test
public void testDisconnectedAreas() {
    Graph g = createTestGraph(true, em);
    // one single disconnected node
    updateDistancesFor(g, 20, 0.00, -0.01);
    Weighting weighting = new FastestWeighting(carFE);
    AlternativeBidirSearch altDijkstra = new AlternativeBidirSearch(g, weighting, traversalMode, 1);
    Path path = altDijkstra.calcPath(1, 20);
    assertFalse(path.isFound());
    // make sure not the full graph is traversed!
    assertEquals(3, altDijkstra.getVisitedNodes());
}
Also used : AlternativeBidirSearch(com.graphhopper.routing.AlternativeRoute.AlternativeBidirSearch) Graph(com.graphhopper.storage.Graph) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 2 with Graph

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

the class PrinctonReaderTest method testRead.

@Test
public void testRead() {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrinctonReader(graph).setStream(PrinctonReader.class.getResourceAsStream("tinyEWD.txt")).read();
    assertEquals(8, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(2, count(explorer.setBaseNode(0)));
    assertEquals(3, count(explorer.setBaseNode(6)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 3 with Graph

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

the class LocationIndexTreeTest method testFindingWayGeometry.

@Test
public void testFindingWayGeometry() {
    Graph g = createGHStorage(encodingManager);
    NodeAccess na = g.getNodeAccess();
    na.setNode(10, 51.2492152, 9.4317166);
    na.setNode(20, 52, 9);
    na.setNode(30, 51.2, 9.4);
    na.setNode(50, 49, 10);
    g.edge(20, 50, 1, true).setWayGeometry(Helper.createPointList(51.25, 9.43));
    g.edge(10, 20, 1, true);
    g.edge(20, 30, 1, true);
    LocationIndex index = createIndex(g, 2000);
    assertEquals(20, findID(index, 51.25, 9.43));
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Example 4 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)

Example 5 with Graph

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

the class LocationIndexTreeTest method testWayGeometry.

@Test
public void testWayGeometry() {
    Graph g = createTestGraphWithWayGeometry();
    LocationIndex index = createIndex(g, -1);
    assertEquals(1, findID(index, 0, 0));
    assertEquals(1, findID(index, 0, 0.1));
    assertEquals(1, findID(index, 0.1, 0.1));
    assertEquals(1, findID(index, -0.5, -0.5));
}
Also used : Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Aggregations

Graph (com.graphhopper.storage.Graph)41 Test (org.junit.Test)36 GraphBuilder (com.graphhopper.storage.GraphBuilder)17 NodeAccess (com.graphhopper.storage.NodeAccess)14 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)8 Dijkstra (com.graphhopper.routing.Dijkstra)6 Path (com.graphhopper.routing.Path)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)5 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 RAMDirectory (com.graphhopper.storage.RAMDirectory)5 EdgeExplorer (com.graphhopper.util.EdgeExplorer)5 Weighting (com.graphhopper.routing.weighting.Weighting)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 GHRequest (com.graphhopper.GHRequest)3 GHResponse (com.graphhopper.GHResponse)3 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)3 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)3 LocationIndex (com.graphhopper.storage.index.LocationIndex)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JsonFeature (com.graphhopper.json.geo.JsonFeature)2