Improve gpx route calculation
This commit is contained in:
parent
159dc51197
commit
05e763f60c
4 changed files with 34 additions and 12 deletions
|
@ -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<RouteSegment> graphSegments,
|
||||
TLongObjectHashMap<RouteSegment> visitedSegments, float distFromStart, RouteSegment segment,
|
||||
TLongObjectHashMap<RouteSegment> visitedSegments, float distFromStart, RouteSegment segment,
|
||||
short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections,
|
||||
boolean[] processFurther) {
|
||||
boolean thereAreRestrictions ;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -84,13 +84,17 @@ public class RoutePlannerFrontEnd {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List<LatLon> intermediates) throws IOException, InterruptedException {
|
||||
return searchRoute(ctx, start, end, intermediates, null);
|
||||
}
|
||||
|
||||
|
||||
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List<LatLon> 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<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);
|
||||
|
|
|
@ -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<LatLon>(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<LatLon> inters) throws IOException {
|
||||
List<LatLon> inters, PrecalculatedRouteDirection precalculated) throws IOException {
|
||||
try {
|
||||
List<RouteSegmentResult> 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) {
|
||||
|
|
Loading…
Reference in a new issue