Search in sources :

Example 11 with EdgeExplorer

use of com.graphhopper.util.EdgeExplorer 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 12 with EdgeExplorer

use of com.graphhopper.util.EdgeExplorer 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

EdgeExplorer (com.graphhopper.util.EdgeExplorer)12 Test (org.junit.Test)9 Graph (com.graphhopper.storage.Graph)5 GraphBuilder (com.graphhopper.storage.GraphBuilder)4 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 EdgeIterator (com.graphhopper.util.EdgeIterator)4 SPTEntry (com.graphhopper.storage.SPTEntry)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHBitSetImpl (com.graphhopper.coll.GHBitSetImpl)1 EdgeBasedRoutingAlgorithmTest (com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1 HashMap (java.util.HashMap)1 GZIPInputStream (java.util.zip.GZIPInputStream)1