Search in sources :

Example 1 with PrepEdgeFilter

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testFindSubnetworks.

@Test
public void testFindSubnetworks() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    PrepEdgeFilter filter = new PrepEdgeFilter(carFlagEncoder);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder));
    List<IntArrayList> components = instance.findSubnetworks(filter);
    assertEquals(3, components.size());
    // start is at 0 => large network
    assertEquals(Helper.createTList(0, 7, 3, 13, 5), components.get(0));
    // next smallest and unvisited node is 1 => big network
    assertEquals(Helper.createTList(1, 8, 4, 2, 11, 12, 9, 15), components.get(1));
    assertEquals(Helper.createTList(6, 14, 10), components.get(2));
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 2 with PrepEdgeFilter

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testRemoveDeadEndUnvisitedNetworks.

@Test
public void testRemoveDeadEndUnvisitedNetworks() {
    GraphHopperStorage g = createDeadEndUnvisitedNetworkStorage(em);
    assertEquals(11, g.getNodes());
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(3);
    int removed = instance.removeDeadEndUnvisitedNetworks(new PrepEdgeFilter(carFlagEncoder));
    assertEquals(3, removed);
    instance.markNodesRemovedIfUnreachable();
    g.optimize();
    assertEquals(8, g.getNodes());
}
Also used : PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 3 with PrepEdgeFilter

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method test481.

@Test
public void test481() {
    // 0->1->3->4->5->6
    //  2        7<--/
    GraphHopperStorage g = createStorage(em);
    g.edge(0, 1, 1, false);
    g.edge(1, 2, 1, false);
    g.edge(2, 0, 1, false);
    g.edge(1, 3, 1, false);
    g.edge(3, 4, 1, false);
    g.edge(4, 5, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 7, 1, false);
    g.edge(7, 4, 1, false);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(2).setMinNetworkSize(4);
    instance.doWork();
    // only one remaining network
    List<IntArrayList> components = instance.findSubnetworks(new PrepEdgeFilter(carFlagEncoder));
    assertEquals(1, components.size());
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 4 with PrepEdgeFilter

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testKeepLargestNetworks.

@Test
public void testKeepLargestNetworks() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    PrepEdgeFilter filter = new PrepEdgeFilter(carFlagEncoder);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder));
    List<IntArrayList> components = instance.findSubnetworks(filter);
    assertEquals(3, components.size());
    int removedEdges = instance.keepLargeNetworks(filter, components);
    assertEquals(8, removedEdges);
    instance.markNodesRemovedIfUnreachable();
    g.optimize();
    assertEquals(8, g.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(g));
    components = instance.findSubnetworks(filter);
    assertEquals(1, components.size());
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 5 with PrepEdgeFilter

use of com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testNodeOrderingRegression.

// Previous two-pass implementation failed on 1 -> 2 -> 0
@Test
public void testNodeOrderingRegression() {
    // 1 -> 2 -> 0
    GraphHopperStorage g = createStorage(em);
    g.edge(1, 2, 1, false);
    g.edge(2, 0, 1, false);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(2);
    int removedEdges = instance.removeDeadEndUnvisitedNetworks(new PrepEdgeFilter(carFlagEncoder));
    assertEquals(2, removedEdges);
}
Also used : PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Test (org.junit.Test)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)3