Search in sources :

Example 6 with ConnectedComponents

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

the class EdgeBasedTarjanSCCTest method linearSimple.

@Test
public void linearSimple() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 0 - 1 - 2
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(4, result.getEdgeKeys());
    assertEquals(1, result.getTotalComponents());
    assertEquals(1, result.getComponents().size());
    assertTrue(result.getSingleEdgeComponents().isEmpty());
    assertEquals(result.getComponents().get(0), result.getBiggestComponent());
    assertEquals(IntArrayList.from(1, 3, 2, 0), result.getComponents().get(0));
}
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 7 with ConnectedComponents

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

the class EdgeBasedTarjanSCCTest method linearSingle.

@Test
public void linearSingle() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 0 - 1
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(2, result.getEdgeKeys());
    assertEquals(1, result.getTotalComponents());
    assertEquals(1, result.getComponents().size());
    assertTrue(result.getSingleEdgeComponents().isEmpty());
    assertEquals(result.getComponents().get(0), result.getBiggestComponent());
    assertEquals(IntArrayList.from(1, 0), result.getComponents().get(0));
}
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 8 with ConnectedComponents

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

the class EdgeBasedTarjanSCCTest method linearBidirectionalEdge.

@Test
public void linearBidirectionalEdge() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 0 -> 1 - 2 <- 3
    GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(3, 2).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(6, result.getEdgeKeys());
    assertEquals(5, result.getTotalComponents());
    // a single bidirectional edge is treated as a 'real' component with two edge-keys. this is not nearly as
    // common as the single-edge-key components so no real need to do a special treatment for these as well.
    assertEquals(1, result.getComponents().size());
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    assertEquals(result.getComponents().get(0), 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 9 with ConnectedComponents

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

the class EdgeBasedTarjanSCCTest method biggerGraph.

@Test
public void biggerGraph() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // this graph has two bigger components (nodes 0, 1, 3 and the others). Still there are some (directed) edges
    // that do not belong to these components but rather represent isolated single-edge components
    // 0 - 1 < 2 - 4 > 5
    // |   |       |
    // |    \< 6 - 7
    // 3        \- 8
    // edge-keys 0,1
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
    // edge-keys 2,3
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 1).setDistance(1));
    // edge-keys 4,5
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 3).setDistance(1));
    // edge-keys 6,7
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 4).setDistance(1));
    // edge-keys 8,9
    GHUtility.setSpeed(60, true, false, encoder, g.edge(6, 2).setDistance(1));
    // edge-keys 10,11
    GHUtility.setSpeed(60, true, false, encoder, g.edge(4, 5).setDistance(1));
    // edge-keys 12,13
    GHUtility.setSpeed(60, true, true, encoder, g.edge(5, 7).setDistance(1));
    // edge-keys 14,15
    GHUtility.setSpeed(60, true, true, encoder, g.edge(6, 7).setDistance(1));
    // edge-keys 16,17
    GHUtility.setSpeed(60, true, true, encoder, g.edge(6, 8).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(18, result.getEdgeKeys());
    assertEquals(6, result.getTotalComponents());
    assertEquals(2, result.getComponents().size());
    assertEquals(result.getComponents().get(1), result.getBiggestComponent());
    assertEquals(IntArrayList.from(1, 5, 4, 0), result.getComponents().get(0));
    assertEquals(IntArrayList.from(7, 8, 13, 14, 17, 16, 15, 12, 10, 6), result.getComponents().get(1));
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    for (IntCursor c : IntArrayList.from(9, 2, 3, 11)) {
        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 10 with ConnectedComponents

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

the class EdgeBasedTarjanSCCTest method oneWayBridges.

@Test
public void oneWayBridges() {
    GraphHopperStorage g = new GraphBuilder(em).create();
    // 0 - 1 -> 2 - 3
    // |   |
    // 4 - 5 -> 6 - 7
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 4).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 5).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 5).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 6).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(6, 7).setDistance(1));
    ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
    assertEquals(16, result.getEdgeKeys());
    assertEquals(7, result.getTotalComponents());
    // 0-1, 2-3-5-4-2 and 6-7
    assertEquals(3, result.getComponents().size());
    // 1->2, 2->1 and 5->6, 6<-5
    assertEquals(4, result.getSingleEdgeComponents().cardinality());
    assertEquals(result.getComponents().get(1), 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)

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