/** * This method removes networks that will be never be visited by this filter. See #235 for * example, small areas like parking lots are sometimes connected to the whole network through a * one-way road. This is clearly an error - but is causes the routing to fail when a point gets * connected to this small area. This routine removes all these networks from the graph. * <p> * * @return number of removed edges */ int removeDeadEndUnvisitedNetworks(final PrepEdgeFilter bothFilter) { StopWatch sw = new StopWatch(bothFilter.getEncoder() + " findComponents").start(); final EdgeFilter outFilter = DefaultEdgeFilter.outEdges(bothFilter.getEncoder()); // partition graph into strongly connected components using Tarjan's algorithm TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(ghStorage, outFilter, true); List<IntArrayList> components = tarjan.findComponents(); logger.info(sw.stop() + ", size:" + components.size()); return removeEdges(bothFilter, components, minOneWayNetworkSize); }
/** * Find and return list of all strongly connected components in g. */ public List<IntArrayList> findComponents() { int nodes = graph.getNodes(); for (int start = 0; start < nodes; start++) { if (nodeIndex[start] == 0 && !ignoreSet.contains(start) && !graph.isNodeRemoved(start)) strongConnect(start); } return components; }
@Test public void testTarjan() { GraphHopperStorage g = createSubnetworkTestStorage(); // Requires a single vehicle type, otherwise we throw. final EdgeFilter filter = DefaultEdgeFilter.outEdges(carFlagEncoder); 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)); }
/** * Find and return list of all strongly connected components in g. */ public List<IntArrayList> findComponents() { int nodes = graph.getNodes(); for (int start = 0; start < nodes; start++) { if (nodeIndex[start] == 0 && !ignoreSet.contains(start) && !graph.isNodeRemoved(start)) strongConnect(start); } return components; }
/** * This method removes networks that will be never be visited by this filter. See #235 for * example, small areas like parking lots are sometimes connected to the whole network through a * one-way road. This is clearly an error - but is causes the routing to fail when a point gets * connected to this small area. This routine removes all these networks from the graph. * <p> * * @return number of removed edges */ int removeDeadEndUnvisitedNetworks(final PrepEdgeFilter bothFilter) { StopWatch sw = new StopWatch(bothFilter.getEncoder() + " findComponents").start(); final EdgeFilter outFilter = DefaultEdgeFilter.outEdges(bothFilter.getEncoder()); // partition graph into strongly connected components using Tarjan's algorithm TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(ghStorage, outFilter, true); List<IntArrayList> components = tarjan.findComponents(); logger.info(sw.stop() + ", size:" + components.size()); return removeEdges(bothFilter, components, minOneWayNetworkSize); }
/** * Find and return list of all strongly connected components in g. */ public List<IntArrayList> findComponents() { int nodes = graph.getNodes(); for (int start = 0; start < nodes; start++) { if (nodeIndex[start] == 0 && !ignoreSet.contains(start) && !graph.isNodeRemoved(start)) strongConnect(start); } return components; }
/** * This method removes networks that will be never be visited by this filter. See #235 for * example, small areas like parking lots are sometimes connected to the whole network through a * one-way road. This is clearly an error - but is causes the routing to fail when a point gets * connected to this small area. This routine removes all these networks from the graph. * <p> * * @return number of removed edges */ int removeDeadEndUnvisitedNetworks(final PrepEdgeFilter bothFilter) { StopWatch sw = new StopWatch(bothFilter.getEncoder() + " findComponents").start(); final EdgeFilter outFilter = new DefaultEdgeFilter(bothFilter.getEncoder(), false, true); // partition graph into strongly connected components using Tarjan's algorithm TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(ghStorage, outFilter, true); List<IntArrayList> components = tarjan.findComponents(); logger.info(sw.stop() + ", size:" + components.size()); return removeEdges(bothFilter, components, minOneWayNetworkSize); }