use of com.graphhopper.storage.GraphBuilder 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));
}
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method createSubnetworkTestStorageWithOneWays.
private GraphHopperStorage createSubnetworkTestStorageWithOneWays(EncodingManager em, FlagEncoder encoder) {
if (em.fetchEdgeEncoders().size() > 1)
fail("Warning: This method only sets access/speed for a single encoder, but the given encoding manager has multiple encoders");
GraphHopperStorage g = new GraphBuilder(em).create();
// 0 - 1 - 2 - 3 - 4 <- 5 - 6
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, 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(3, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, g.edge(5, 6).setDistance(1));
// 7 -> 8 - 9 - 10
GHUtility.setSpeed(60, true, false, encoder, g.edge(7, 8).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, g.edge(8, 9).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, g.edge(9, 10).setDistance(1));
return g;
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method createSubnetworkTestStorage.
private static GraphHopperStorage createSubnetworkTestStorage(EncodingManager encodingManager) {
GraphHopperStorage g = new GraphBuilder(encodingManager).create();
// 5 - 6
// | /
// 4
// | <- (no access flags unless we change it)
// 0 - 1 - 3 - 7 - 8
// | |
// 2 -------
g.edge(3, 4).setDistance(1);
g.edge(0, 1).setDistance(1);
g.edge(1, 3).setDistance(1);
g.edge(0, 2).setDistance(1);
g.edge(2, 3).setDistance(1);
g.edge(3, 7).setDistance(1);
g.edge(7, 8).setDistance(1);
g.edge(4, 5).setDistance(1);
g.edge(5, 6).setDistance(1);
g.edge(4, 6).setDistance(1);
// set access for all encoders
AllEdgesIterator iter = g.getAllEdges();
while (iter.next()) {
// edge 3-4 gets no speed/access by default
if (iter.getEdge() == 0)
continue;
for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) {
iter.set(encoder.getAverageSpeedEnc(), 10);
iter.set(encoder.getAccessEnc(), true, true);
}
}
return g;
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class TarjanSCCTest method testTarjan_issue761.
@Test
public void testTarjan_issue761() {
GraphHopperStorage graph = new GraphBuilder(em).create();
// 11-10-9
// | |
// 0-1-2->3->4->5
// | |
// 6 12
// | |
// 7 13-14
// | \|
// 8 15-16
// oneway main road
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 5).setDistance(1));
// going south from main road
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 6).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 8).setDistance(1));
// connects the two nodes 2 and 4
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 9).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 10).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 11).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 2).setDistance(1));
// eastern part (only connected by a single directed edge to the rest of the graph)
GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 12).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 13).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 14).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(14, 15).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(15, 13).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(15, 16).setDistance(1));
TarjanSCC.ConnectedComponents scc = TarjanSCC.findComponentsRecursive(graph, edgeFilter, false);
assertEquals(2, scc.getTotalComponents());
assertTrue(scc.getSingleNodeComponents().isEmpty());
assertEquals(17, scc.getNodes());
assertEquals(scc.getComponents().get(1), scc.getBiggestComponent());
assertEquals(2, scc.getComponents().size());
assertEquals(IntArrayList.from(14, 16, 15, 13, 12, 5), scc.getComponents().get(0));
assertEquals(IntArrayList.from(8, 7, 6, 3, 4, 9, 10, 11, 2, 1, 0), scc.getComponents().get(1));
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class TarjanSCCTest method testFindComponents.
@Test
public void testFindComponents() {
GraphHopperStorage graph = new GraphBuilder(em).create();
// big network (has two components actually, because 9->12 is a one-way)
// ---
// / \
// 4 < 1 - 2
// | |
// <-- 8 - 11 - 12 < 9 - 15
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 8).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(8, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 11).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 11).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(9, 12).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 15).setDistance(1));
// large network
// 5 --------
// | |
// 3 - 0 - 13
// \ |
// 7
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 13).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 5).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 5).setDistance(1));
// small network
// 6 - 14 - 10
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 14).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 14).setDistance(1));
TarjanSCC.ConnectedComponents scc = TarjanSCC.findComponentsRecursive(graph, edgeFilter, false);
List<IntArrayList> components = scc.getComponents();
assertEquals(4, components.size());
assertEquals(IntArrayList.from(13, 5, 3, 7, 0), components.get(0));
assertEquals(IntArrayList.from(2, 4, 12, 11, 8, 1), components.get(1));
assertEquals(IntArrayList.from(10, 14, 6), components.get(2));
assertEquals(IntArrayList.from(15, 9), components.get(3));
assertEquals(16, scc.getNodes());
assertEquals(0, scc.getSingleNodeComponents().cardinality());
assertEquals(components.get(1), scc.getBiggestComponent());
}
Aggregations