Search in sources :

Example 26 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage 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 27 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method testRemoveNode.

@Test
public void testRemoveNode() {
    FlagEncoder carEncoder = new CarFlagEncoder();
    BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
    EncodingManager em2 = new EncodingManager(carEncoder, bikeEncoder);
    GraphHopperStorage g = createSubnetworkTestStorage2(em2);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
    EdgeExplorer edgeExplorer = g.createEdgeExplorer();
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
    assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
    // mark certain edges inaccessible for all encoders
    for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(g, 5, 6), GHUtility.getEdge(g, 4, 5), GHUtility.getEdge(g, 4, 6))) {
        for (FlagEncoder encoders : em2.fetchEdgeEncoders()) {
            edge.setFlags(encoders.setAccess(0, false, false));
        }
    }
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
    assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 28 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage 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)

Example 29 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method testTarjan.

@Test
public void testTarjan() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    // Requires a single vehicle type, otherwise we throw.
    final EdgeFilter filter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(g, filter, false);
    List<IntArrayList> components = tarjan.findComponents();
    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));
}
Also used : PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) IntArrayList(com.carrotsearch.hppc.IntArrayList) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 30 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method testRemoveSubnetworkWhenMultipleVehicles.

@Test
public void testRemoveSubnetworkWhenMultipleVehicles() {
    FlagEncoder carEncoder = new CarFlagEncoder();
    BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
    EncodingManager em2 = new EncodingManager(carEncoder, bikeEncoder);
    GraphHopperStorage g = createSubnetworkTestStorage2(em2);
    GHUtility.getEdge(g, 3, 4).setFlags(carEncoder.setProperties(10, false, false) | bikeEncoder.setProperties(5, true, true));
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
    instance.setMinNetworkSize(5);
    instance.doWork();
    g.optimize();
    // remove nothing because of two vehicles with different subnetworks
    assertEquals(9, g.getNodes());
    EdgeExplorer carExplorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder));
    assertEquals(GHUtility.asSet(7, 2, 1), GHUtility.getNeighbors(carExplorer.setBaseNode(3)));
    EdgeExplorer bikeExplorer = g.createEdgeExplorer(new DefaultEdgeFilter(bikeEncoder));
    assertEquals(GHUtility.asSet(7, 2, 1, 4), GHUtility.getNeighbors(bikeExplorer.setBaseNode(3)));
    GHUtility.getEdge(g, 3, 4).setFlags(carEncoder.setProperties(10, false, false) | bikeEncoder.setProperties(5, false, false));
    instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
    instance.setMinNetworkSize(5);
    instance.doWork();
    g.optimize();
    assertEquals(6, g.getNodes());
}
Also used : EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 Test (org.junit.Test)28 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 EdgeExplorer (com.graphhopper.util.EdgeExplorer)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 Random (java.util.Random)3 GraphHopper (com.graphhopper.GraphHopper)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 HintsMap (com.graphhopper.routing.util.HintsMap)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2