diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index b798c78fca..4a222c8acb 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -371,15 +371,23 @@ public class BinaryRoutePlanner { // long nt = System.nanoTime(); // float devDistance = ctx.precalculatedRouteDirection.getDeviationDistance(x, y); // // 1. linear method -// // segmentDist = segmentDist * (1 + ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.config.DEVIATION_RADIUS); +// segmentDist = segmentDist * (1 + devDistance / ctx.config.DEVIATION_RADIUS); // // 2. exponential method // segmentDist = segmentDist * (float) Math.pow(1.5, devDistance / 500); + // 3. next by method +// segmentDist = devDistance ; // ctx.timeNanoToCalcDeviation += (System.nanoTime() - nt); } // could be expensive calculation // 3. get intersected ways final RouteSegment roadNext = ctx.loadRouteSegment(x, y, ctx.config.memoryLimitation - ctx.memoryOverhead); float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime); + if(ctx.precalculatedRouteDirection != null && ctx.precalculatedRouteDirection.isFollowNext()) { + // reset to f + distStartObstacles = 0; + // more precise but slower + //distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMinDefaultSpeed(); + } // We don't check if there are outgoing connections previous = processIntersections(ctx, graphSegments, visitedSegments, distStartObstacles, @@ -557,7 +565,7 @@ public class BinaryRoutePlanner { private RouteSegment processIntersections(RoutingContext ctx, PriorityQueue graphSegments, - TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, + TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections, boolean[] processFurther) { boolean thereAreRestrictions ; diff --git a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java index 68bcc8195e..17a5eb5314 100644 --- a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java +++ b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java @@ -19,6 +19,7 @@ public class PrecalculatedRouteDirection { private float minSpeed; private float maxSpeed; private float[] tms; + private boolean followNext; private static final int SHIFT = (1 << (31 - 17)); private static final int[] SHIFTS = new int[]{1 << (31 - 15), 1 << (31 - 13), 1 << (31 - 12), 1 << (31 - 11), 1 << (31 - 7)}; @@ -240,6 +241,15 @@ public class PrecalculatedRouteDirection { return ((long) x31) << 32l + ((long)y31); } + public void setFollowNext(boolean followNext) { + this.followNext = followNext; + } + + public boolean isFollowNext() { + return followNext; + } + + public PrecalculatedRouteDirection adopt(RoutingContext ctx) { int ind1 = getIndex(ctx.startX, ctx.startY); int ind2 = getIndex(ctx.targetX, ctx.targetY); @@ -258,6 +268,7 @@ public class PrecalculatedRouteDirection { // routeDirection.startY31 = ctx.startY; routeDirection.endPoint = calc(ctx.targetX, ctx.targetX); routeDirection.endFinishTime = (float) BinaryRoutePlanner.squareRootDist(pointsX[ind2], pointsY[ind2], ctx.targetX, ctx.targetY) / maxSpeed; + routeDirection.followNext = followNext; // routeDirection.endX31 = ctx.targetX; // routeDirection.endY31 = ctx.targetY; diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index b466cb0dcf..8d7f61e3ae 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -84,13 +84,17 @@ public class RoutePlannerFrontEnd { } - public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates) throws IOException, InterruptedException { + return searchRoute(ctx, start, end, intermediates, null); + } + + + public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates, + PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException { if(ctx.calculationProgress == null) { ctx.calculationProgress = new RouteCalculationProgress(); } boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty(); - PrecalculatedRouteDirection routeDirection = null; double maxDistance = MapUtils.getDistance(start, end); if(!intermediatesEmpty) { LatLon b = start; @@ -99,7 +103,8 @@ public class RoutePlannerFrontEnd { b = l; } } - if(ctx.calculationMode == RouteCalculationMode.COMPLEX && maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) { + if(ctx.calculationMode == RouteCalculationMode.COMPLEX && routeDirection == null + && maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) { RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE); nctx.calculationProgress = ctx.calculationProgress ; List ls = searchRoute(nctx, start, end, intermediates); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index e8cbf61d0e..61cc068e36 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -451,7 +451,8 @@ public class RouteProvider { latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude()); } precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed()); - cf.planRoadDirection = 1; + precalculated.setFollowNext(true); + //cf.planRoadDirection = 1; } // BUILD context RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, @@ -466,9 +467,6 @@ public class RouteProvider { complexCtx.calculationProgress = params.calculationProgress; complexCtx.leftSideNavigation = params.leftSide; } - if(precalculated != null) { - ctx.precalculatedRouteDirection = precalculated.adopt(ctx); - } ctx.leftSideNavigation = params.leftSide; ctx.calculationProgress = params.calculationProgress; if(params.previousToRecalculate != null) { @@ -481,7 +479,7 @@ public class RouteProvider { if (params.intermediates != null) { inters = new ArrayList(params.intermediates); } - return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters); + return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated); } @@ -547,12 +545,12 @@ public class RouteProvider { private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params, RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en, - List inters) throws IOException { + List inters, PrecalculatedRouteDirection precalculated) throws IOException { try { List result ; if(complexCtx != null) { try { - result = router.searchRoute(complexCtx, st, en, inters); + result = router.searchRoute(complexCtx, st, en, inters, precalculated); // discard ctx and replace with calculated ctx = complexCtx; } catch(final RuntimeException e) {