diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index caf5822a42..357538c433 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1962,15 +1962,22 @@ public class BinaryMapIndexReader { public void initRouteRegionsIfNeeded(SearchRequest req) throws IOException { routeAdapter.initRouteTypesIfNeeded(req); } - - public void searchRouteIndex(SearchRequest req, List list) throws IOException { + + public List searchRouteIndexTree(SearchRequest req, List list) throws IOException { req.numberOfVisitedObjects = 0; req.numberOfAcceptedObjects = 0; req.numberOfAcceptedSubtrees = 0; req.numberOfReadSubtrees = 0; if(routeAdapter != null){ initRouteRegionsIfNeeded(req); - routeAdapter.searchRouteRegion(req, list); + return routeAdapter.searchRouteRegionTree(req, list, new ArrayList()); + } + return Collections.emptyList(); + } + + public void loadRouteIndexData(List toLoad, ResultMatcher matcher) throws IOException { + if(routeAdapter != null){ + routeAdapter.loadRouteRegionData(toLoad, matcher); } } diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index ecc634202f..2450648ef9 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -13,6 +13,7 @@ import java.util.Comparator; import java.util.List; import net.osmand.LogUtil; +import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.OsmandOdb.IdTable; import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock; @@ -154,7 +155,7 @@ public class BinaryMapRouteReaderAdapter { } public static class RouteRegion extends BinaryIndexPart { - int regionsRead; + public int regionsRead; List subregions = new ArrayList(); List routeEncodingRules = new ArrayList(); @@ -250,6 +251,16 @@ public class BinaryMapRouteReaderAdapter { } return shallow; } + + public int countSubregions(){ + int cnt = 1; + if (subregions != null) { + for (RouteSubregion s : subregions) { + cnt += s.countSubregions(); + } + } + return cnt; + } } private CodedInputStreamRAF codedIS; @@ -576,6 +587,11 @@ public class BinaryMapRouteReaderAdapter { break; case RouteDataBox.SHIFTTODATA_FIELD_NUMBER : thisTree.shiftToData = readInt(); + if(!readChildren) { + // usually 0 + thisTree.subregions = new ArrayList(); + readChildren = true; + } break; case RouteDataBox.BOXES_FIELD_NUMBER : if(readChildren){ @@ -617,12 +633,10 @@ public class BinaryMapRouteReaderAdapter { } } } - } + - public void searchRouteRegion(SearchRequest req, List list) throws IOException { - List toLoad = new ArrayList(); - searchRouteRegion(req, list, toLoad); + public void loadRouteRegionData(List toLoad, ResultMatcher matcher) throws IOException { Collections.sort(toLoad, new Comparator() { @Override public int compare(RouteSubregion o1, RouteSubregion o2) { @@ -643,7 +657,7 @@ public class BinaryMapRouteReaderAdapter { } for (RouteDataObject ro : rs.dataObjects) { if (ro != null) { - req.publish(ro); + matcher.publish(ro); } } // free objects @@ -651,7 +665,8 @@ public class BinaryMapRouteReaderAdapter { } } - private void searchRouteRegion(SearchRequest req, List list, List toLoad) throws IOException { + public List searchRouteRegionTree(SearchRequest req, List list, List toLoad) + throws IOException { for(RouteSubregion rs : list){ if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) { 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); codedIS.popLimit(old); } - searchRouteRegion(req, rs.subregions, toLoad); + searchRouteRegionTree(req, rs.subregions, toLoad); if (rs.shiftToData != 0) { toLoad.add(rs); } } } + return toLoad; } } diff --git a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java index ff2c08b056..a207ba09bb 100644 --- a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java +++ b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java @@ -515,7 +515,8 @@ public class BinaryRoutePlanner { public void printDebugMemoryInformation(RoutingContext ctx, PriorityQueue graphDirectSegments, PriorityQueue graphReverseSegments, TLongObjectHashMap visitedDirectSegments,TLongObjectHashMap 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("Loaded tiles " + ctx.loadedTiles + " (distinct "+ctx.distinctLoadedTiles+ "), unloaded tiles " + ctx.unloadedTiles + " (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) { + final RoutingTile tile = ctx.getRoutingTile(tile31X, tile31Y); if (tile.isLoaded()) { tile.access++; @@ -552,6 +555,11 @@ public class BinaryRoutePlanner { float mb = (1 << 20); 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); + } 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); diff --git a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java index 0e203be97c..1fc143f151 100644 --- a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java +++ b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java @@ -11,9 +11,11 @@ import gnu.trove.set.hash.TLongHashSet; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import net.osmand.NativeLibrary; import net.osmand.NativeLibrary.NativeRouteSearchResult; @@ -59,6 +61,7 @@ public class RoutingContext { // 5. debug information (package accessor) long timeToLoad = 0; + long timeToLoadHeaders = 0; long timeToCalculate = 0; public int loadedTiles = 0; int distinctLoadedTiles = 0; @@ -70,6 +73,8 @@ public class RoutingContext { public int relaxedSegments = 0; // callback of processing segments RouteSegmentVisitor visitor = null; + public int routingSubregionLoaded = 0; + public Set routingSubregionsSet = new LinkedHashSet(); private TileStatistics global = new TileStatistics(); @@ -239,12 +244,9 @@ public class RoutingContext { } } - public void loadTileData(final RoutingTile tile, final List toFillIn, NativeLibrary nativeLib, Map> map) { - - long now = System.nanoTime(); final int zoomToLoad = 31 - tile.getZoom(); final int tileX = tile.getTileX(); final int tileY = tile.getTileY(); @@ -325,7 +327,19 @@ public class RoutingContext { } } else { 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 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) { throw new RuntimeException("Loading data exception", e); } @@ -351,7 +365,7 @@ public class RoutingContext { tile.nativeResults = nativeRouteSearchResults; } - timeToLoad += (System.nanoTime() - now); + } diff --git a/DataExtractionOSM/src/net/osmand/router/routing.xml b/DataExtractionOSM/src/net/osmand/router/routing.xml index 25f56997cc..06abd8dd53 100644 --- a/DataExtractionOSM/src/net/osmand/router/routing.xml +++ b/DataExtractionOSM/src/net/osmand/router/routing.xml @@ -5,10 +5,11 @@ - - - - + + + + + diff --git a/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java b/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java index e41a6082e4..dc3bfef706 100644 --- a/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java +++ b/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java @@ -612,7 +612,7 @@ public class MapRouterLayer implements MapPanelLayer { String m = DataExtractionSettings.getSettings().getRouteMode(); String[] props = m.split("\\,"); 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.ZOOM_TO_LOAD_TILES = 14; RoutingContext ctx = new RoutingContext(config);