Search in sources :

Example 11 with ConnectedComponents

use of com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents in project graphhopper by graphhopper.

the class EdgeBasedTarjanSCCTest method linearOneWay.

@Test
public void linearOneWay() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 0 -> 1 -> 2
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(4, result.getEdgeKeys());
    assertEquals(4, result.getTotalComponents());
    assertEquals(0, result.getComponents().size());
    // we only have two directed edges here, but we always calculate the component indices for all edge keys and
    // here every (directed) edge belongs to its own component
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    assertEquals(IntArrayList.from(), result.getBiggestComponent());
}
Also used : 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)

Example 12 with ConnectedComponents

use of com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents in project graphhopper by graphhopper.

the class EdgeBasedTarjanSCCTest method doImplicitVsExplicit.

private void doImplicitVsExplicit(boolean excludeSingle) {
    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 implicit = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, excludeSingle);
    ConnectedComponents explicit = EdgeBasedTarjanSCC.findComponents(g, fwdAccessFilter, excludeSingle);
    assertEquals(2 * g.getEdges(), implicit.getEdgeKeys(), "total number of edge keys in connected components should equal twice the number of edges in graph");
    assertEquals(2 * g.getEdges(), explicit.getEdgeKeys(), "total number of edge keys in connected components should equal twice the number of edges in graph");
    compareResults(g, seed, implicit, explicit);
}
Also used : Random(java.util.Random) ConnectedComponents(com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

Aggregations

ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)12 GraphBuilder (com.graphhopper.storage.GraphBuilder)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)12 RepeatedTest (org.junit.jupiter.api.RepeatedTest)11 Test (org.junit.jupiter.api.Test)10 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)4 Random (java.util.Random)4 IntArrayList (com.carrotsearch.hppc.IntArrayList)3 IntWithArray (com.graphhopper.routing.subnetwork.TarjanSCCTest.IntWithArray)2 TarjanSCCTest.buildComponentSet (com.graphhopper.routing.subnetwork.TarjanSCCTest.buildComponentSet)2 com.graphhopper.routing.util (com.graphhopper.routing.util)2 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 GHUtility (com.graphhopper.util.GHUtility)2 Set (java.util.Set)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2