Skip to content

Commit 5b5ad5d

Browse files
author
Peter
committed
minor cleanup for graphhopper#487
1 parent 881f9a2 commit 5b5ad5d

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

core/src/main/java/com/graphhopper/GraphHopper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,7 @@ protected void cleanUp()
10881088
preparation.setMinOneWayNetworkSize(minOneWayNetworkSize);
10891089
logger.info("start finding subnetworks, " + Helper.getMemInfo());
10901090
preparation.doWork();
1091-
int currNodeCount = ghStorage.getNodes();
1092-
// int remainingSubnetworks = preparation.findSubnetworks().size();
1091+
int currNodeCount = ghStorage.getNodes();
10931092
logger.info("edges: " + ghStorage.getAllEdges().getMaxId() + ", nodes " + currNodeCount
10941093
+ ", there were " + preparation.getMaxSubnetworks()
10951094
+ " subnetworks. removed them => " + (prevNodeCount - currNodeCount)

core/src/main/java/com/graphhopper/routing/util/DefaultEdgeFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DefaultEdgeFilter( FlagEncoder encoder, boolean in, boolean out )
4141
this.encoder = encoder;
4242
this.in = in;
4343
this.out = out;
44-
}
44+
}
4545

4646
@Override
4747
public final boolean accept( EdgeIteratorState iter )

core/src/main/java/com/graphhopper/routing/util/PrepareRoutingSubnetworks.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,16 @@ String toString( FlagEncoder encoder, EdgeIterator iter )
211211
}
212212

213213
/**
214-
* Clean small networks that will be never be visited by this explorer See #86 for example,
215-
* small areas like parking lots are sometimes connected to the whole network through a one-way
216-
* road. This is clearly an error - but is causes the routing to fail when a point gets
217-
* connected to this small area. This routine removes all these points from the graph.
214+
* This method removes networks that will be never be visited by this filter. See #235 for
215+
* example, small areas like parking lots are sometimes connected to the whole network through a
216+
* one-way road. This is clearly an error - but is causes the routing to fail when a point gets
217+
* connected to this small area. This routine removes all these networks from the graph.
218218
* <p/>
219219
* @return number of removed edges
220220
*/
221221
int removeDeadEndUnvisitedNetworks( final PrepEdgeFilter bothFilter )
222222
{
223-
// Partition g into strongly connected components using Tarjan's algorithm.
224-
223+
// partition ghStorage into strongly connected components using Tarjan's algorithm
225224
final EdgeFilter outFilter = new DefaultEdgeFilter(bothFilter.getEncoder(), false, true);
226225
List<TIntArrayList> components = new TarjansStronglyConnectedComponentsAlgorithm(ghStorage, outFilter).
227226
findComponents();

core/src/test/java/com/graphhopper/routing/util/PrepareRoutingSubnetworksTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testKeepLargestNetworks()
131131
assertEquals(Arrays.<String>asList(), GHUtility.getProblems(g));
132132

133133
components = instance.findSubnetworks(filter);
134-
assertEquals(1, components.size());
134+
assertEquals(1, components.size());
135135
}
136136

137137
@Test
@@ -166,6 +166,7 @@ public void testRemoveNode()
166166
PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
167167

168168
EdgeExplorer edgeExplorer = g.createEdgeExplorer();
169+
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
169170
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
170171
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
171172

@@ -186,8 +187,6 @@ public void testRemoveNode()
186187
@Test
187188
public void testRemoveSubnetworkWhenMultipleVehicles()
188189
{
189-
// do not remove because of two vehicles with different subnetworks
190-
// TODO create different access for bike and car
191190
FlagEncoder carEncoder = new CarFlagEncoder();
192191
BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
193192
EncodingManager em2 = new EncodingManager(carEncoder, bikeEncoder);
@@ -197,12 +196,20 @@ public void testRemoveSubnetworkWhenMultipleVehicles()
197196
instance.setMinNetworkSize(5);
198197
instance.doWork();
199198
g.optimize();
199+
// remove nothing because of two vehicles with different subnetworks
200200
assertEquals(9, g.getNodes());
201201

202-
EdgeExplorer explorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder));
203-
assertEquals(GHUtility.asSet(7, 2, 1), GHUtility.getNeighbors(explorer.setBaseNode(3)));
204-
205-
// TODO remove only nodes which are removed for both vehicles
202+
EdgeExplorer carExplorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder));
203+
assertEquals(GHUtility.asSet(7, 2, 1), GHUtility.getNeighbors(carExplorer.setBaseNode(3)));
204+
EdgeExplorer bikeExplorer = g.createEdgeExplorer(new DefaultEdgeFilter(bikeEncoder));
205+
assertEquals(GHUtility.asSet(7, 2, 1, 4), GHUtility.getNeighbors(bikeExplorer.setBaseNode(3)));
206+
207+
GHUtility.getEdge(g, 3, 4).setFlags(carEncoder.setProperties(10, false, false) | bikeEncoder.setProperties(5, false, false));
208+
instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
209+
instance.setMinNetworkSize(5);
210+
instance.doWork();
211+
g.optimize();
212+
assertEquals(6, g.getNodes());
206213
}
207214

208215
GraphHopperStorage createDeadEndUnvisitedNetworkStorage( EncodingManager em )

core/src/test/java/com/graphhopper/util/GHUtilityTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void testSort2()
7878
{
7979
Graph g = initUnsorted(createGraph());
8080
Graph newG = GHUtility.sortDFS(g, createGraph());
81-
// TODO does not handle subnetworks
8281
assertEquals(g.getNodes(), newG.getNodes());
8382
NodeAccess na = newG.getNodeAccess();
8483
assertEquals(0, na.getLatitude(0), 1e-4); // 0

0 commit comments

Comments
 (0)