diff --git a/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java index 1b6077cbb1..5c0f38f4a5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java @@ -65,13 +65,11 @@ public class BinaryRoutePlanner { * Calculate route between start.segmentEnd and end.segmentStart (using A* algorithm) * return list of segments */ - @SuppressWarnings("unused") FinalRouteSegment searchRouteInternal(final RoutingContext ctx, RouteSegmentPoint start, RouteSegmentPoint end, RouteSegment recalculationEnd ) throws InterruptedException, IOException { // measure time ctx.timeToLoad = 0; ctx.memoryOverhead = 1000; - ctx.visitedSegments = 0; // Initializing priority queue to visit way segments Comparator nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator(); @@ -166,8 +164,12 @@ public class BinaryRoutePlanner { throw new InterruptedException("Route calculation interrupted"); } } - ctx.visitedSegments = visitedDirectSegments.size() + visitedOppositeSegments.size(); - printDebugMemoryInformation(ctx, graphDirectSegments, graphReverseSegments, visitedDirectSegments, visitedOppositeSegments); + ctx.visitedSegments += visitedDirectSegments.size() + visitedOppositeSegments.size(); + ctx.visitedDirectSegments += visitedDirectSegments.size(); + ctx.visitedOppositeSegments += visitedOppositeSegments.size(); + ctx.directQueueSize = graphDirectSegments.size(); // Math.max(ctx.directQueueSize, graphDirectSegments.size()); + ctx.oppositeQueueSize = graphReverseSegments.size(); + ctx.visitedOppositeSegments += visitedOppositeSegments.size(); return finalSegment; } @@ -368,8 +370,7 @@ public class BinaryRoutePlanner { log.warn(logMsg); } - public void printDebugMemoryInformation(RoutingContext ctx, PriorityQueue graphDirectSegments, PriorityQueue graphReverseSegments, - TLongObjectHashMap visitedDirectSegments,TLongObjectHashMap visitedOppositeSegments) { + public static void printDebugMemoryInformation(RoutingContext ctx) { printInfo(String.format("Time. Total: %.2f, to load: %.2f, to load headers: %.2f, to calc dev: %.2f ", (System.nanoTime() - ctx.timeToCalculate) / 1e6, ctx.timeToLoad / 1e6, ctx.timeToLoadHeaders / 1e6, ctx.timeNanoToCalcDeviation / 1e6)); @@ -380,12 +381,8 @@ public class BinaryRoutePlanner { ", loaded more than once same tiles " + ctx.loadedPrevUnloadedTiles); printInfo("Visited segments " + ctx.visitedSegments + ", relaxed roads " + ctx.relaxedSegments); - if (graphDirectSegments != null && graphReverseSegments != null) { - printInfo("Priority queues sizes : " + graphDirectSegments.size() + "/" + graphReverseSegments.size()); - } - if (visitedDirectSegments != null && visitedOppositeSegments != null) { - printInfo("Visited interval sizes: " + visitedDirectSegments.size() + "/" + visitedOppositeSegments.size()); - } + printInfo("Priority queues sizes : " + ctx.directQueueSize + "/" + ctx.oppositeQueueSize); + printInfo("Visited interval sizes: " + ctx.visitedDirectSegments + "/" + ctx.visitedOppositeSegments); } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index ba500a9471..60dc5add01 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -203,23 +203,24 @@ public class RoutePlannerFrontEnd { useSmartRouteRecalculation = use; } - // TODO native matches less roads - // TODO fix progress - next iteration - // TODO fix timings and remove logging every iteration public GpxRouteApproximation searchGpxRoute(GpxRouteApproximation gctx, List points) throws IOException, InterruptedException { gctx.ctx.timeToCalculate = System.nanoTime(); if (gctx.ctx.calculationProgress == null) { gctx.ctx.calculationProgress = new RouteCalculationProgress(); } List gpxPoints = generageGpxPoints(points, gctx); - GpxPoint start = gpxPoints.size() > 0 ? gpxPoints.get(0) : null; + GpxPoint start = null; GpxPoint prev = null; + if(gpxPoints.size() > 0) { + gctx.ctx.calculationProgress.totalIterations = (int) (gpxPoints.get(gpxPoints.size() - 1).cumDist / gctx.MAXIMUM_STEP_APPROXIMATION + 1); + start = gpxPoints.get(0); + } while (start != null) { double routeDist = gctx.MAXIMUM_STEP_APPROXIMATION; GpxPoint next = findNextGpxPointWithin(gctx, gpxPoints, start, routeDist); boolean routeFound = false; - + gctx.ctx.calculationProgress.nextIteration(); if (next != null && initRoutingPoint(start, gctx, gctx.MINIMUM_POINT_APPROXIMATION)) { while (routeDist >= gctx.MINIMUM_STEP_APPROXIMATION && !routeFound) { routeFound = initRoutingPoint(next, gctx, gctx.MINIMUM_POINT_APPROXIMATION); @@ -267,9 +268,8 @@ public class RoutePlannerFrontEnd { } start = next; } - + BinaryRoutePlanner.printDebugMemoryInformation(gctx.ctx); calculateGpxRoute(gctx, gpxPoints); - if (!gctx.res.isEmpty()) { new RouteResultPreparation().printResults(gctx.ctx, points.get(0), points.get(points.size() - 1), gctx.res); System.out.println(gctx); @@ -504,6 +504,7 @@ public class RoutePlannerFrontEnd { gctx.routeDistCalculations += (target.cumDist - start.cumDist); gctx.routeCalculations++; res = searchRouteInternalPrepare(gctx.ctx, start.pnt, target.pnt, null); + //BinaryRoutePlanner.printDebugMemoryInformation(gctx.ctx); routeIsCorrect = res != null && !res.isEmpty(); for (int k = start.ind + 1; routeIsCorrect && k < target.ind; k++) { GpxPoint ipoint = gpxPoints.get(k); @@ -859,6 +860,7 @@ public class RoutePlannerFrontEnd { } pringGC(ctx, true); List res = searchRouteInternalPrepare(ctx, points.get(0), points.get(1), routeDirection); + BinaryRoutePlanner.printDebugMemoryInformation(ctx); pringGC(ctx, false); makeStartEndPointsPrecise(res, points.get(0).getPreciseLatLon(), points.get(1).getPreciseLatLon(), null); return res; diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java index 2c44940dff..e3c233b4d4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java @@ -98,11 +98,17 @@ public class RoutingContext { public int loadedTiles = 0; public int visitedSegments = 0; public int relaxedSegments = 0; + public int visitedDirectSegments = 0; + public int visitedOppositeSegments = 0; + public int directQueueSize = 0; + public int oppositeQueueSize = 0; // callback of processing segments RouteSegmentVisitor visitor = null; // old planner public FinalRouteSegment finalRouteSegment; + + RoutingContext(RoutingContext cp) { this.config = cp.config; @@ -252,18 +258,6 @@ public class RoutingContext { return ind; } - public void newRoutingPoints() { - int middleX = startX / 2 + targetX / 2; - int middleY = startY / 2 + targetY; - List dataObjects = new ArrayList(); - loadTileData(middleX, middleY, 17, dataObjects); - - - System.out.println("Size of data objects " + dataObjects.size()); - } - - - public RouteSegment loadRouteSegment(int x31, int y31, long memoryLimit) { long tileId = getRoutingTile(x31, y31, memoryLimit);