Search in sources :

Example 21 with GraphBuilder

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

the class InstructionListTest method testEmptyList.

@Test
public void testEmptyList() {
    Graph g = new GraphBuilder(carManager).create();
    g.getNodeAccess().setNode(1, 0, 0);
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, tMode).calcPath(0, 1);
    InstructionList il = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    assertEquals(0, il.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.jupiter.api.Test)

Example 22 with GraphBuilder

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

the class LocationIndexExample method lowLevelLocationIndex.

public static void lowLevelLocationIndex() {
    // If you don't use the GraphHopper class you have to use the low level API:
    GraphHopperStorage graph = new GraphBuilder(EncodingManager.create(new CarFlagEncoder())).create();
    graph.edge(0, 1).setName("test edge");
    graph.getNodeAccess().setNode(0, 12, 42);
    graph.getNodeAccess().setNode(1, 12.01, 42.01);
    LocationIndexTree index = new LocationIndexTree(graph.getBaseGraph(), graph.getDirectory());
    index.setResolution(300);
    index.setMaxRegionSearch(4);
    if (!index.loadExisting())
        index.prepareIndex();
    Snap snap = index.findClosest(12, 42, EdgeFilter.ALL_EDGES);
    EdgeIteratorState edge = snap.getClosestEdge();
    assert edge.getName().equals("test edge");
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) Snap(com.graphhopper.storage.index.Snap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Example 23 with GraphBuilder

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

the class EdgeBasedTarjanSCCTest method smallGraphWithLoops.

@Test
public void smallGraphWithLoops() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 3<-0->2-1o
    // o
    // edge-keys 0,1
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 0).setDistance(1));
    // edge-keys 2,3
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 2).setDistance(1));
    // edge-keys 4,5
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 3).setDistance(1));
    // edge-keys 6,7
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 1).setDistance(1));
    // edge-keys 8,9
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 1).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(10, result.getEdgeKeys());
    assertEquals(6, result.getTotalComponents());
    assertEquals(2, result.getComponents().size());
    assertEquals(result.getComponents().get(0), result.getBiggestComponent());
    assertEquals(IntArrayList.from(7, 9, 8, 6), result.getComponents().get(0));
    assertEquals(IntArrayList.from(1, 0), result.getComponents().get(1));
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    for (IntCursor c : IntArrayList.from(2, 3, 4, 5)) {
        assertTrue(result.getSingleEdgeComponents().get(c.value));
    }
}
Also used : ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 24 with GraphBuilder

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

the class EdgeBasedTarjanSCCTest method withStartEdges_comparison.

@RepeatedTest(20)
public void withStartEdges_comparison() {
    // we test the case where we specify all start edges (in this case the behavior should be the same for both methods)
    GraphHopperStorage g = new GraphBuilder(em).create();
    long seed = System.nanoTime();
    Random rnd = new Random(seed);
    GHUtility.buildRandomGraph(g, rnd, 500, 2, true, true, encoder.getAccessEnc(), encoder.getAverageSpeedEnc(), 60d, 0.8, 0.7, 0);
    ConnectedComponents components = EdgeBasedTarjanSCC.findComponents(g, fwdAccessFilter, true);
    IntArrayList edges = new IntArrayList();
    AllEdgesIterator iter = g.getAllEdges();
    while (iter.next()) edges.add(iter.getEdge());
    ConnectedComponents componentsForStartEdges = EdgeBasedTarjanSCC.findComponentsForStartEdges(g, fwdAccessFilter, edges);
    compareResults(g, seed, components, componentsForStartEdges);
}
Also used : Random(java.util.Random) ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntArrayList(com.carrotsearch.hppc.IntArrayList) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 25 with GraphBuilder

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

the class EdgeBasedTarjanSCCTest method withStartEdges_simple.

@Test
public void withStartEdges_simple() {
    // 0 - 1   4 - 5 - 6 - 7
    // |   |
    // 3 - 2   8 - 9
    GraphHopperStorage g = new GraphBuilder(em).create();
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 0).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 5).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(5, 6).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(6, 7).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(8, 9).setDistance(10));
    // just the left island
    ConnectedComponents components = EdgeBasedTarjanSCC.findComponentsForStartEdges(g, (prev, edge) -> true, IntArrayList.from(0));
    assertEquals(8, components.getEdgeKeys());
    assertEquals(1, components.getComponents().size());
    // all islands
    components = EdgeBasedTarjanSCC.findComponentsForStartEdges(g, (prev, edge) -> true, IntArrayList.from(0, 4, 7));
    assertEquals(16, components.getEdgeKeys());
    assertEquals(3, components.getComponents().size());
    // here we initialize as for all islands but the filter still prevents some edges to be found
    components = EdgeBasedTarjanSCC.findComponentsForStartEdges(g, (prev, edge) -> edge.getEdge() > 3 && edge.getEdge() < 7, IntArrayList.from(0, 4, 7));
    assertEquals(6, components.getEdgeKeys());
    assertEquals(1, components.getComponents().size());
}
Also used : RepeatedTest(org.junit.jupiter.api.RepeatedTest) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) TarjanSCCTest.buildComponentSet(com.graphhopper.routing.subnetwork.TarjanSCCTest.buildComponentSet) ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Set(java.util.Set) Random(java.util.Random) GHUtility(com.graphhopper.util.GHUtility) EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.jupiter.api.Test) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) IntWithArray(com.graphhopper.routing.subnetwork.TarjanSCCTest.IntWithArray) IntArrayList(com.carrotsearch.hppc.IntArrayList) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) com.graphhopper.routing.util(com.graphhopper.routing.util) ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

GraphBuilder (com.graphhopper.storage.GraphBuilder)98 Test (org.junit.jupiter.api.Test)60 Graph (com.graphhopper.storage.Graph)48 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 NodeAccess (com.graphhopper.storage.NodeAccess)30 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)22 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 EncodingManager (com.graphhopper.routing.util.EncodingManager)19 Test (org.junit.Test)16 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)14 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)12 Dijkstra (com.graphhopper.routing.Dijkstra)10 Path (com.graphhopper.routing.Path)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)6 IntsRef (com.graphhopper.storage.IntsRef)6 Random (java.util.Random)6