Skip to content

Commit 97b10f1

Browse files
JohannesPelzerPeter
authored and
Peter
committed
Fixing issue 218: Autoexpanding search for nodes around a GPS coordinate, bug fix in SpatialKeyAlgo, Bresenham, and avoid the trap graphhopper#232
1 parent 2a21fad commit 97b10f1

20 files changed

+611
-267
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ debug.sh
2727
core/TODO*.txt
2828
srtmprovider/
2929
core/docs/
30-
.*#
30+
.*#
31+
cgiarprovider/

config-example.properties

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
# graph.dataaccess=MMAP_STORE_SYNC
55
graph.dataaccess=RAM_STORE
66

7-
# The high-resolution index is bigger and slightly slower but a lot more precise. see #17.
8-
# Resolution is in meter, decrease from 1000 to 500 in order to speed up queries (but will increase size)
9-
#index.highResolution=-1
10-
index.highResolution=500
11-
12-
137
# use contraction hierarchies to speed things up. requires more RAM/disc space for holding the graph
148
# uncomment this if you need more control of you algorithm. then use graphhopper.chShortcuts(false, false)
159
prepare.chShortcuts=fastest
@@ -39,4 +33,7 @@ osmreader.acceptWay=car
3933
# If you have a slow disk or plenty of RAM change the default MMAP to
4034
# graph.elevation.dataaccess=RAM_STORE
4135

42-
36+
# Location index lookup. Advanced customization. Resolution is in meter, the search specifies the 'radius' in number of tiles.
37+
# E.g. decrease resolution for a faster lookup and increase region search for a more dynamic search and less 'location not found' results
38+
# index.highResolution=300
39+
# index.maxRegionSearch=4

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public static void main( String[] strs ) throws Exception
7676
private boolean simplifyRequest = true;
7777
// for index
7878
private LocationIndex locationIndex;
79-
private int preciseIndexResolution = 500;
80-
private boolean searchRegion = true;
79+
private int preciseIndexResolution = 300;
80+
private int maxRegionSearch = 4;
8181
// for prepare
8282
private int minNetworkSize = 200;
8383
// for CH prepare
@@ -538,6 +538,7 @@ public GraphHopper init( CmdArgs args )
538538

539539
// index
540540
preciseIndexResolution = args.getInt("index.highResolution", preciseIndexResolution);
541+
maxRegionSearch = args.getInt("index.maxRegionSearch", maxRegionSearch);
541542
return this;
542543
}
543544

@@ -863,24 +864,15 @@ else if (algoStr.equals("astarbi"))
863864
protected LocationIndex createLocationIndex( Directory dir )
864865
{
865866
LocationIndex tmpIndex;
866-
if (preciseIndexResolution > 0)
867+
if (graph instanceof LevelGraph)
867868
{
868-
LocationIndexTree tmpNIndex;
869-
if (graph instanceof LevelGraph)
870-
{
871-
tmpNIndex = new LocationIndexTreeSC((LevelGraph) graph, dir);
872-
} else
873-
{
874-
tmpNIndex = new LocationIndexTree(graph, dir);
875-
}
876-
tmpNIndex.setResolution(preciseIndexResolution);
877-
tmpNIndex.setSearchRegion(searchRegion);
878-
tmpIndex = tmpNIndex;
869+
tmpIndex = new LocationIndexTreeSC((LevelGraph) graph, dir);
879870
} else
880871
{
881-
tmpIndex = new Location2IDQuadtree(graph, dir);
882-
tmpIndex.setResolution(Helper.calcIndexSize(graph.getBounds()));
872+
tmpIndex = new LocationIndexTree(graph, dir);
883873
}
874+
tmpIndex.setResolution(preciseIndexResolution);
875+
((LocationIndexTree) tmpIndex).setMaxRegionSearch(maxRegionSearch);
884876

885877
if (!tmpIndex.loadExisting())
886878
tmpIndex.prepareIndex();
@@ -908,7 +900,7 @@ protected void optimize()
908900
logger.info("finished optimize (" + Helper.getMemInfo() + ")");
909901

910902
// Later: move this into the GraphStorage.optimize method
911-
// Or: Doing it after preparation to optimize shortcuts too. But not possible yet https://github.com/graphhopper/graphhopper/issues/12
903+
// Or: Doing it after preparation to optimize shortcuts too. But not possible yet #12
912904
if (sortGraph)
913905
{
914906
if (graph instanceof LevelGraph && isPrepared())

core/src/main/java/com/graphhopper/geohash/SpatialKeyAlgo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public final long encode( double lat, double lon )
162162
if (minLatTmp < maxLatTmp)
163163
{
164164
double midLat = (minLatTmp + maxLatTmp) / 2;
165-
if (lat > midLat)
165+
if (lat < midLat)
166166
{
167-
hash |= 1;
168-
minLatTmp = midLat;
167+
maxLatTmp = midLat;
169168
} else
170169
{
171-
maxLatTmp = midLat;
170+
hash |= 1;
171+
minLatTmp = midLat;
172172
}
173173
}
174174
i++;
@@ -182,13 +182,13 @@ public final long encode( double lat, double lon )
182182
if (minLonTmp < maxLonTmp)
183183
{
184184
double midLon = (minLonTmp + maxLonTmp) / 2;
185-
if (lon > midLon)
185+
if (lon < midLon)
186186
{
187-
hash |= 1;
188-
minLonTmp = midLon;
187+
maxLonTmp = midLon;
189188
} else
190189
{
191-
maxLonTmp = midLon;
190+
hash |= 1;
191+
minLonTmp = midLon;
192192
}
193193
}
194194
i++;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void testAlgos()
8181

8282
for (Entry<AlgorithmPreparation, LocationIndex> entry : prepares)
8383
{
84-
AlgorithmPreparation prepare = entry.getKey();
84+
AlgorithmPreparation prepare = entry.getKey();
8585
int failed = testCollector.errors.size();
8686

8787
OneRun or = new OneRun(50.0314, 10.5105, 50.0303, 10.5070, 571, 22);
@@ -118,12 +118,12 @@ public static Collection<Entry<AlgorithmPreparation, LocationIndex>> createAlgos
118118
{
119119
// List<Entry<AlgorithmPreparation, LocationIndex>> prepare = new ArrayList<Entry<AlgorithmPreparation, LocationIndex>>();
120120
List<Entry<AlgorithmPreparation, LocationIndex>> prepare = new ArrayList<Entry<AlgorithmPreparation, LocationIndex>>();
121-
// prepare.add(new ME(createAlgoPrepare(g, "astar", encoder, weighting), idx));
122-
// // prepare.add(new ME(createAlgoPrepare(g, "dijkstraOneToMany", encoder, weighting), idx));
123-
// prepare.add(new ME(createAlgoPrepare(g, "astarbi", encoder, weighting), idx));
124-
// prepare.add(new ME(createAlgoPrepare(g, "dijkstraNativebi", encoder, weighting), idx));
121+
prepare.add(new ME(createAlgoPrepare(g, "astar", encoder, weighting), idx));
122+
// prepare.add(new ME(createAlgoPrepare(g, "dijkstraOneToMany", encoder, weighting), idx));
123+
prepare.add(new ME(createAlgoPrepare(g, "astarbi", encoder, weighting), idx));
124+
prepare.add(new ME(createAlgoPrepare(g, "dijkstraNativebi", encoder, weighting), idx));
125125
prepare.add(new ME(createAlgoPrepare(g, "dijkstrabi", encoder, weighting), idx));
126-
// prepare.add(new ME(createAlgoPrepare(g, "dijkstra", encoder, weighting), idx));
126+
prepare.add(new ME(createAlgoPrepare(g, "dijkstra", encoder, weighting), idx));
127127

128128
if (withCh)
129129
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ public void setDistance( int index, double dist )
192192
public List<QueryResult> getList( LocationIndex idx, EdgeFilter edgeFilter )
193193
{
194194
List<QueryResult> qr = new ArrayList<QueryResult>();
195-
for (AssumptionPerPath or : assumptions)
195+
for (AssumptionPerPath p : assumptions)
196196
{
197-
qr.add(idx.findClosest(or.lat, or.lon, edgeFilter));
197+
qr.add(idx.findClosest(p.lat, p.lon, edgeFilter));
198198
}
199199
return qr;
200200
}

0 commit comments

Comments
 (0)