Tweak routing params
This commit is contained in:
parent
1aac6c9cb7
commit
fd34527520
6 changed files with 68 additions and 22 deletions
|
@ -1962,15 +1962,22 @@ public class BinaryMapIndexReader {
|
||||||
public void initRouteRegionsIfNeeded(SearchRequest<RouteDataObject> req) throws IOException {
|
public void initRouteRegionsIfNeeded(SearchRequest<RouteDataObject> req) throws IOException {
|
||||||
routeAdapter.initRouteTypesIfNeeded(req);
|
routeAdapter.initRouteTypesIfNeeded(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void searchRouteIndex(SearchRequest<RouteDataObject> req, List<RouteSubregion> list) throws IOException {
|
public List<RouteSubregion> searchRouteIndexTree(SearchRequest<RouteDataObject> req, List<RouteSubregion> list) throws IOException {
|
||||||
req.numberOfVisitedObjects = 0;
|
req.numberOfVisitedObjects = 0;
|
||||||
req.numberOfAcceptedObjects = 0;
|
req.numberOfAcceptedObjects = 0;
|
||||||
req.numberOfAcceptedSubtrees = 0;
|
req.numberOfAcceptedSubtrees = 0;
|
||||||
req.numberOfReadSubtrees = 0;
|
req.numberOfReadSubtrees = 0;
|
||||||
if(routeAdapter != null){
|
if(routeAdapter != null){
|
||||||
initRouteRegionsIfNeeded(req);
|
initRouteRegionsIfNeeded(req);
|
||||||
routeAdapter.searchRouteRegion(req, list);
|
return routeAdapter.searchRouteRegionTree(req, list, new ArrayList<BinaryMapRouteReaderAdapter.RouteSubregion>());
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadRouteIndexData(List<RouteSubregion> toLoad, ResultMatcher<RouteDataObject> matcher) throws IOException {
|
||||||
|
if(routeAdapter != null){
|
||||||
|
routeAdapter.loadRouteRegionData(toLoad, matcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||||
import net.osmand.binary.OsmandOdb.IdTable;
|
import net.osmand.binary.OsmandOdb.IdTable;
|
||||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock;
|
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock;
|
||||||
|
@ -154,7 +155,7 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RouteRegion extends BinaryIndexPart {
|
public static class RouteRegion extends BinaryIndexPart {
|
||||||
int regionsRead;
|
public int regionsRead;
|
||||||
|
|
||||||
List<RouteSubregion> subregions = new ArrayList<RouteSubregion>();
|
List<RouteSubregion> subregions = new ArrayList<RouteSubregion>();
|
||||||
List<RouteTypeRule> routeEncodingRules = new ArrayList<BinaryMapRouteReaderAdapter.RouteTypeRule>();
|
List<RouteTypeRule> routeEncodingRules = new ArrayList<BinaryMapRouteReaderAdapter.RouteTypeRule>();
|
||||||
|
@ -250,6 +251,16 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
}
|
}
|
||||||
return shallow;
|
return shallow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int countSubregions(){
|
||||||
|
int cnt = 1;
|
||||||
|
if (subregions != null) {
|
||||||
|
for (RouteSubregion s : subregions) {
|
||||||
|
cnt += s.countSubregions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CodedInputStreamRAF codedIS;
|
private CodedInputStreamRAF codedIS;
|
||||||
|
@ -576,6 +587,11 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
break;
|
break;
|
||||||
case RouteDataBox.SHIFTTODATA_FIELD_NUMBER :
|
case RouteDataBox.SHIFTTODATA_FIELD_NUMBER :
|
||||||
thisTree.shiftToData = readInt();
|
thisTree.shiftToData = readInt();
|
||||||
|
if(!readChildren) {
|
||||||
|
// usually 0
|
||||||
|
thisTree.subregions = new ArrayList<BinaryMapRouteReaderAdapter.RouteSubregion>();
|
||||||
|
readChildren = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RouteDataBox.BOXES_FIELD_NUMBER :
|
case RouteDataBox.BOXES_FIELD_NUMBER :
|
||||||
if(readChildren){
|
if(readChildren){
|
||||||
|
@ -617,12 +633,10 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void searchRouteRegion(SearchRequest<RouteDataObject> req, List<RouteSubregion> list) throws IOException {
|
public void loadRouteRegionData(List<RouteSubregion> toLoad, ResultMatcher<RouteDataObject> matcher) throws IOException {
|
||||||
List<RouteSubregion> toLoad = new ArrayList<BinaryMapRouteReaderAdapter.RouteSubregion>();
|
|
||||||
searchRouteRegion(req, list, toLoad);
|
|
||||||
Collections.sort(toLoad, new Comparator<RouteSubregion>() {
|
Collections.sort(toLoad, new Comparator<RouteSubregion>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(RouteSubregion o1, RouteSubregion o2) {
|
public int compare(RouteSubregion o1, RouteSubregion o2) {
|
||||||
|
@ -643,7 +657,7 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
}
|
}
|
||||||
for (RouteDataObject ro : rs.dataObjects) {
|
for (RouteDataObject ro : rs.dataObjects) {
|
||||||
if (ro != null) {
|
if (ro != null) {
|
||||||
req.publish(ro);
|
matcher.publish(ro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// free objects
|
// free objects
|
||||||
|
@ -651,7 +665,8 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void searchRouteRegion(SearchRequest<RouteDataObject> req, List<RouteSubregion> list, List<RouteSubregion> toLoad) throws IOException {
|
public List<RouteSubregion> searchRouteRegionTree(SearchRequest<RouteDataObject> req, List<RouteSubregion> list, List<RouteSubregion> toLoad)
|
||||||
|
throws IOException {
|
||||||
for(RouteSubregion rs : list){
|
for(RouteSubregion rs : list){
|
||||||
if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) {
|
if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) {
|
||||||
if (rs.subregions == null) {
|
if (rs.subregions == null) {
|
||||||
|
@ -660,13 +675,14 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
readRouteTree(rs, null, req.contains(rs.left, rs.top, rs.right, rs.bottom) ? -1 : 1, false);
|
readRouteTree(rs, null, req.contains(rs.left, rs.top, rs.right, rs.bottom) ? -1 : 1, false);
|
||||||
codedIS.popLimit(old);
|
codedIS.popLimit(old);
|
||||||
}
|
}
|
||||||
searchRouteRegion(req, rs.subregions, toLoad);
|
searchRouteRegionTree(req, rs.subregions, toLoad);
|
||||||
|
|
||||||
if (rs.shiftToData != 0) {
|
if (rs.shiftToData != 0) {
|
||||||
toLoad.add(rs);
|
toLoad.add(rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return toLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,8 @@ public class BinaryRoutePlanner {
|
||||||
|
|
||||||
public void printDebugMemoryInformation(RoutingContext ctx, PriorityQueue<RouteSegment> graphDirectSegments, PriorityQueue<RouteSegment> graphReverseSegments,
|
public void printDebugMemoryInformation(RoutingContext ctx, PriorityQueue<RouteSegment> graphDirectSegments, PriorityQueue<RouteSegment> graphReverseSegments,
|
||||||
TLongObjectHashMap<RouteSegment> visitedDirectSegments,TLongObjectHashMap<RouteSegment> visitedOppositeSegments) {
|
TLongObjectHashMap<RouteSegment> visitedDirectSegments,TLongObjectHashMap<RouteSegment> visitedOppositeSegments) {
|
||||||
printInfo("Time to calculate : " + (System.nanoTime() - ctx.timeToCalculate) / 1e6 + ", time to load : " + ctx.timeToLoad / 1e6);
|
printInfo("Time to calculate : " + (System.nanoTime() - ctx.timeToCalculate) / 1e6 + ", time to load : " + ctx.timeToLoad / 1e6 + ", time to load headers : " + ctx.timeToLoadHeaders / 1e6);
|
||||||
|
printInfo("Loaded file tiles: " + ctx.routingSubregionLoaded + " distinct " + ctx.routingSubregionsSet.size());
|
||||||
printInfo("Current loaded tiles : " + ctx.getCurrentlyLoadedTiles() + ", maximum loaded tiles " + ctx.maxLoadedTiles);
|
printInfo("Current loaded tiles : " + ctx.getCurrentlyLoadedTiles() + ", maximum loaded tiles " + ctx.maxLoadedTiles);
|
||||||
printInfo("Loaded tiles " + ctx.loadedTiles + " (distinct "+ctx.distinctLoadedTiles+ "), unloaded tiles " + ctx.unloadedTiles +
|
printInfo("Loaded tiles " + ctx.loadedTiles + " (distinct "+ctx.distinctLoadedTiles+ "), unloaded tiles " + ctx.unloadedTiles +
|
||||||
" (distinct " + ctx.distinctUnloadedTiles.size()+") "+ ", loaded more than once same tiles "
|
" (distinct " + ctx.distinctUnloadedTiles.size()+") "+ ", loaded more than once same tiles "
|
||||||
|
@ -530,7 +531,9 @@ public class BinaryRoutePlanner {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public RoutingTile loadRoutes(final RoutingContext ctx, int tile31X, int tile31Y) {
|
public RoutingTile loadRoutes(final RoutingContext ctx, int tile31X, int tile31Y) {
|
||||||
|
|
||||||
final RoutingTile tile = ctx.getRoutingTile(tile31X, tile31Y);
|
final RoutingTile tile = ctx.getRoutingTile(tile31X, tile31Y);
|
||||||
if (tile.isLoaded()) {
|
if (tile.isLoaded()) {
|
||||||
tile.access++;
|
tile.access++;
|
||||||
|
@ -552,6 +555,11 @@ public class BinaryRoutePlanner {
|
||||||
float mb = (1 << 20);
|
float mb = (1 << 20);
|
||||||
log.warn("Unload tiles : estimated " + (sz1 - sz2) / mb + " ?= " + (h1 - h2) / mb+ " actual");
|
log.warn("Unload tiles : estimated " + (sz1 - sz2) / mb + " ?= " + (h1 - h2) / mb+ " actual");
|
||||||
log.warn("Used after " + h2 / mb + " of " + Runtime.getRuntime().totalMemory() / mb + " max " + Runtime.getRuntime().maxMemory() / mb);
|
log.warn("Used after " + h2 / mb + " of " + Runtime.getRuntime().totalMemory() / mb + " max " + Runtime.getRuntime().maxMemory() / mb);
|
||||||
|
} else {
|
||||||
|
float mb = (1 << 20);
|
||||||
|
int sz2 = ctx.getCurrentEstimatedSize();
|
||||||
|
log.warn("Unload tiles : occupied before " + sz1/ mb + " Mb - now " + sz2/mb + "MB ");
|
||||||
|
log.warn("Memory free " + Runtime.getRuntime().freeMemory() / mb + " of " + Runtime.getRuntime().totalMemory() / mb + " max " + Runtime.getRuntime().maxMemory() / mb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.loadTileData(tile, null, nativeLib, map);
|
ctx.loadTileData(tile, null, nativeLib, map);
|
||||||
|
|
|
@ -11,9 +11,11 @@ import gnu.trove.set.hash.TLongHashSet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.osmand.NativeLibrary;
|
import net.osmand.NativeLibrary;
|
||||||
import net.osmand.NativeLibrary.NativeRouteSearchResult;
|
import net.osmand.NativeLibrary.NativeRouteSearchResult;
|
||||||
|
@ -59,6 +61,7 @@ public class RoutingContext {
|
||||||
|
|
||||||
// 5. debug information (package accessor)
|
// 5. debug information (package accessor)
|
||||||
long timeToLoad = 0;
|
long timeToLoad = 0;
|
||||||
|
long timeToLoadHeaders = 0;
|
||||||
long timeToCalculate = 0;
|
long timeToCalculate = 0;
|
||||||
public int loadedTiles = 0;
|
public int loadedTiles = 0;
|
||||||
int distinctLoadedTiles = 0;
|
int distinctLoadedTiles = 0;
|
||||||
|
@ -70,6 +73,8 @@ public class RoutingContext {
|
||||||
public int relaxedSegments = 0;
|
public int relaxedSegments = 0;
|
||||||
// callback of processing segments
|
// callback of processing segments
|
||||||
RouteSegmentVisitor visitor = null;
|
RouteSegmentVisitor visitor = null;
|
||||||
|
public int routingSubregionLoaded = 0;
|
||||||
|
public Set<RouteSubregion> routingSubregionsSet = new LinkedHashSet<RouteSubregion>();
|
||||||
|
|
||||||
private TileStatistics global = new TileStatistics();
|
private TileStatistics global = new TileStatistics();
|
||||||
|
|
||||||
|
@ -239,12 +244,9 @@ public class RoutingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void loadTileData(final RoutingTile tile, final List<RouteDataObject> toFillIn, NativeLibrary nativeLib,
|
public void loadTileData(final RoutingTile tile, final List<RouteDataObject> toFillIn, NativeLibrary nativeLib,
|
||||||
Map<BinaryMapIndexReader, List<RouteSubregion>> map) {
|
Map<BinaryMapIndexReader, List<RouteSubregion>> map) {
|
||||||
|
|
||||||
long now = System.nanoTime();
|
|
||||||
final int zoomToLoad = 31 - tile.getZoom();
|
final int zoomToLoad = 31 - tile.getZoom();
|
||||||
final int tileX = tile.getTileX();
|
final int tileX = tile.getTileX();
|
||||||
final int tileY = tile.getTileY();
|
final int tileY = tile.getTileY();
|
||||||
|
@ -325,7 +327,19 @@ public class RoutingContext {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
r.getKey().searchRouteIndex(request, r.getValue());
|
if (r.getValue().size() > 0) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
// int rg = r.getValue().get(0).routeReg.regionsRead;
|
||||||
|
List<RouteSubregion> subregs = r.getKey().searchRouteIndexTree(request, r.getValue());
|
||||||
|
for(RouteSubregion s : subregs) {
|
||||||
|
routingSubregionLoaded ++;
|
||||||
|
routingSubregionsSet.add(s);
|
||||||
|
}
|
||||||
|
timeToLoadHeaders += (System.nanoTime() - now);
|
||||||
|
now = System.nanoTime();
|
||||||
|
r.getKey().loadRouteIndexData(subregs, matcher);
|
||||||
|
timeToLoad += (System.nanoTime() - now);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Loading data exception", e);
|
throw new RuntimeException("Loading data exception", e);
|
||||||
}
|
}
|
||||||
|
@ -351,7 +365,7 @@ public class RoutingContext {
|
||||||
tile.nativeResults = nativeRouteSearchResults;
|
tile.nativeResults = nativeRouteSearchResults;
|
||||||
|
|
||||||
}
|
}
|
||||||
timeToLoad += (System.nanoTime() - now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
<attribute name="heuristicCoefficient" value="1.0" />
|
<attribute name="heuristicCoefficient" value="1.0" />
|
||||||
|
|
||||||
<!-- 1.1 tile load parameters (should not affect routing) -->
|
<!-- 1.1 tile load parameters (should not affect routing) -->
|
||||||
<attribute name="zoomToLoadTiles" value="13" />
|
<!-- by default 13 -->
|
||||||
<attribute name="iterationsToRunGC" value="125" />
|
<!-- OPTIMAL -->
|
||||||
<!-- by default it is 25 -->
|
<attribute name="zoomToLoadTiles" value="16" />
|
||||||
<attribute name="desirableTilesInMemory" value="" />
|
<!-- by default it is 15 -->
|
||||||
|
<attribute name="memoryLimitInMB" value="90" />
|
||||||
|
|
||||||
<!-- 1.2 Dynamic road prioritizing (heuristic) -->
|
<!-- 1.2 Dynamic road prioritizing (heuristic) -->
|
||||||
<attribute name="useDynamicRoadPrioritising" value="true" />
|
<attribute name="useDynamicRoadPrioritising" value="true" />
|
||||||
|
|
|
@ -612,7 +612,7 @@ public class MapRouterLayer implements MapPanelLayer {
|
||||||
String m = DataExtractionSettings.getSettings().getRouteMode();
|
String m = DataExtractionSettings.getSettings().getRouteMode();
|
||||||
String[] props = m.split("\\,");
|
String[] props = m.split("\\,");
|
||||||
BinaryRoutePlanner router = new BinaryRoutePlanner(NativeSwingRendering.getDefaultFromSettings(), rs);
|
BinaryRoutePlanner router = new BinaryRoutePlanner(NativeSwingRendering.getDefaultFromSettings(), rs);
|
||||||
RoutingConfiguration config = builder.build(props[0], RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, props);
|
RoutingConfiguration config = builder.build(props[0], RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 2, props);
|
||||||
// config.NUMBER_OF_DESIRABLE_TILES_IN_MEMORY = 300;
|
// config.NUMBER_OF_DESIRABLE_TILES_IN_MEMORY = 300;
|
||||||
// config.ZOOM_TO_LOAD_TILES = 14;
|
// config.ZOOM_TO_LOAD_TILES = 14;
|
||||||
RoutingContext ctx = new RoutingContext(config);
|
RoutingContext ctx = new RoutingContext(config);
|
||||||
|
|
Loading…
Reference in a new issue