From 3fc759ef1c9e7b1a724b524fa7e391ad2d9489bc Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 17 Jan 2014 00:29:41 +0100 Subject: [PATCH] Small changes --- .../net/osmand/router/BinaryRoutePlanner.java | 61 ++++++++++++++++++- .../osmand/router/RouteResultPreparation.java | 21 +++++++ .../src/net/osmand/router/RoutingContext.java | 17 ++++-- 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index da60045966..a06ab6bec2 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -14,6 +14,7 @@ import net.osmand.PlatformUtil; import net.osmand.binary.RouteDataBorderLinePoint; import net.osmand.binary.RouteDataObject; import net.osmand.osm.MapRenderingTypes; +import net.osmand.router.RoutingContext.RoutingSubregionTile; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -81,6 +82,8 @@ public class BinaryRoutePlanner { } } + + newSearchRoute(ctx, start, end); // Initializing priority queue to visit way segments Comparator nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator(); @@ -196,6 +199,61 @@ public class BinaryRoutePlanner { } + private void newSearchRoute(RoutingContext ctx, RouteSegment start, RouteSegment end) { + int sx31 = start.getRoad().getPoint31XTile(start.getSegmentStart()); + int sy31 = start.getRoad().getPoint31YTile(start.getSegmentStart()); + int ex31 = end.getRoad().getPoint31XTile(end.getSegmentStart()); + int ey31 = end.getRoad().getPoint31YTile(end.getSegmentStart()); + int zoom = 11; + int sz = 31 - zoom; + int sx = sx31 >> sz; + int ex = ex31 >> sz; + int sy = sy31 >> sz; + int ey = ey31 >> sz; + + int h = Math.abs(sy - ey); + int w = Math.abs(sx - ex); + int dh = (h + w)/ 6; + int dw = (h + w)/ 6; + System.out.println("Bbox : (" + sx +", " + sy +" - " +ex +", " + ey+ ") - " + + (w + dw * 2) + " x " + (h + dh * 2)); + System.out.println("Load tiles " + ((w + dw * 2)*(h + dh * 2))); + int total = 0; + for(int x = -dw; x <= w + dw; x ++) { + for(int y = -dh; y <= h + dh; y++) { + int tileX = Math.min(sx, ex) + x; + int tileY = Math.min(sy, ey) + y; + float lat = (float) MapUtils.getLatitudeFromTile(zoom, tileY); + float lon = (float) MapUtils.getLongitudeFromTile(zoom, tileX); + if((x == -dw && y == -dh)) { + System.out.println("LeftTop : " + lat + ", " + lon); + } + if((x == w + dw && y == h + dh)){ + System.out.println("RightBottom : " + lat + ", " + lon); + } + List ts = ctx.loadTileHeaders(sz, tileX, tileY); + if(ts != null) { + total += ts.size(); + } + } + } + System.out.println("Total loaded " + total + " "+ ctx.subregionTiles.size()); + List ls = new ArrayList(); + TLongObjectHashMap dup = new TLongObjectHashMap(); + long time = System.currentTimeMillis(); + for(RoutingSubregionTile st : ctx.subregionTiles) { + ctx.loadSubregionTile(st, true); + st.loadAllObjects(ls, ctx, dup); + } + System.out.println("Total obj to check " + ls.size()); + System.out.println("Time " + ctx.timeToLoadHeaders / 1e6 + " " + (System.currentTimeMillis() - time)); + + +// ctx.loadTileHeaders(zoom, tileX, tileY) + + } + + private void printMemoryConsumption( String string) { long h1 = RoutingContext.runGCUsedMemory(); float mb = (1 << 20); @@ -212,7 +270,7 @@ public class BinaryRoutePlanner { ctx.calculationProgress.distanceFromBegin = Math.max(graphDirectSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin); } - if(graphDirectSegments.size() > 0) { + if(graphReverseSegments.size() > 0) { ctx.calculationProgress.distanceFromEnd = Math.max(graphReverseSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin); } @@ -328,6 +386,7 @@ public class BinaryRoutePlanner { } double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed(); +// result *= 0.8; return (float) result; } diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index e288b74a17..6f9fb67efc 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -13,6 +13,7 @@ import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment; import net.osmand.router.BinaryRoutePlanner.RouteSegment; +import net.osmand.router.RoutingContext.RoutingSubregionTile; import net.osmand.util.MapUtils; public class RouteResultPreparation { @@ -279,6 +280,26 @@ public class RouteResultPreparation { } private void newRoutingAnalyzeDiff(RoutingContext ctx, LatLon start, LatLon end, List result, int d) { + System.out.println(); + System.out.println("------------"); + long id = -2; + long[] ids = ctx.indexedSubregions.keys(); + for(long idt : ids) { + long x = idt >> 16; + long y = idt - (x<<16); +// double l = MapUtils.get31LongitudeX((int) (x<<15)); +// double t = MapUtils.get31LatitudeY((int) (y<< 15)); +// double r = MapUtils.get31LongitudeX((int) ((x+1)<<15)); +// double b = MapUtils.get31LatitudeY((int) ((y+1)<<15)); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); +// System.out.println(""); +// System.out.println(); + } for(int k = 0; k < result.size() - d; k+=d){ RouteSegmentResult res1 = result.get(k); RouteSegmentResult res2 = result.get(k + d); diff --git a/OsmAnd-java/src/net/osmand/router/RoutingContext.java b/OsmAnd-java/src/net/osmand/router/RoutingContext.java index 663fdd84b6..1d8d51e945 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingContext.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingContext.java @@ -419,7 +419,7 @@ public class RoutingContext { return original; } - private void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory) { + public void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory) { boolean wasUnloaded = ts.isUnloaded(); int ucount = ts.getUnloadCont(); if (nativeLib == null) { @@ -465,9 +465,12 @@ public class RoutingContext { final int zoomToLoad = 31 - config.ZOOM_TO_LOAD_TILES; int tileX = x31 >> zoomToLoad; int tileY = y31 >> zoomToLoad; - - SearchRequest request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoad, - (tileX + 1) << zoomToLoad, tileY << zoomToLoad, (tileY + 1) << zoomToLoad, null); + return loadTileHeaders(zoomToLoad, tileX, tileY); + } + + public List loadTileHeaders(final int zoomToLoadM31, int tileX, int tileY) { + SearchRequest request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoadM31, + (tileX + 1) << zoomToLoadM31, tileY << zoomToLoadM31, (tileY + 1) << zoomToLoadM31, null); List collection = null; for (Entry> r : map.entrySet()) { // NOTE: load headers same as we do in non-native (it is not native optimized) @@ -693,7 +696,11 @@ public class RoutingContext { this.subregion = subregion; } - private void loadAllObjects(final List toFillIn, RoutingContext ctx, TLongObjectHashMap excludeDuplications) { + public TLongObjectMap getRoutes() { + return routes; + } + + public void loadAllObjects(final List toFillIn, RoutingContext ctx, TLongObjectHashMap excludeDuplications) { if(routes != null) { Iterator it = routes.valueCollection().iterator(); while(it.hasNext()){