Update calculation
This commit is contained in:
parent
f965160876
commit
5dd8c35988
3 changed files with 43 additions and 22 deletions
|
@ -14,7 +14,6 @@ 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;
|
||||
|
@ -82,12 +81,6 @@ public class BinaryRoutePlanner {
|
|||
}
|
||||
|
||||
}
|
||||
if(ctx.precalculatedRouteDirection != null) {
|
||||
ctx.precalculatedRouteDirection.prereg(ctx.startX, ctx.startY);
|
||||
ctx.precalculatedRouteDirection.prereg(ctx.targetX, ctx.targetY);
|
||||
}
|
||||
|
||||
//newSearchRoute(ctx, start, end);
|
||||
|
||||
// Initializing priority queue to visit way segments
|
||||
Comparator<RouteSegment> nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator();
|
||||
|
|
|
@ -15,7 +15,6 @@ public class PrecalculatedRouteDirection {
|
|||
private TIntArrayList pointsX = new TIntArrayList();
|
||||
private TIntArrayList pointsY = new TIntArrayList();
|
||||
private float avgSpeed;
|
||||
private float[] tmsReverse;
|
||||
private float[] tms;
|
||||
private static final int SHIFT = (1 << (31 - 18));
|
||||
private static final int[] SHIFTS = new int[]{(1 << (31 - 17)), (1 << (31 - 15)), (1 << (31 - 13)), (1 << (31 - 12)),
|
||||
|
@ -26,7 +25,6 @@ public class PrecalculatedRouteDirection {
|
|||
private float[] ct2 = new float[2];
|
||||
|
||||
private Map<Long, Integer> prereg = new TreeMap<Long, Integer>();
|
||||
|
||||
private DataTileManager<Integer> indexedPoints = new DataTileManager<Integer>(17);
|
||||
|
||||
private PrecalculatedRouteDirection(List<RouteSegmentResult> ls, float avgSpeed) {
|
||||
|
@ -34,6 +32,16 @@ public class PrecalculatedRouteDirection {
|
|||
init(ls);
|
||||
}
|
||||
|
||||
private PrecalculatedRouteDirection(PrecalculatedRouteDirection parent, int s1, int s2) {
|
||||
this.avgSpeed = parent.avgSpeed;
|
||||
tms = new float[s2 - s1 + 1];
|
||||
for (int i = s1; i <= s2; i++) {
|
||||
pointsX.add(parent.pointsX.get(i));
|
||||
pointsY.add(parent.pointsY.get(i));
|
||||
tms[i - s1] = parent.tms[i] - parent.tms[s2];
|
||||
}
|
||||
}
|
||||
|
||||
public static PrecalculatedRouteDirection build(List<RouteSegmentResult> ls, float cutoffDistance, float avgSpeed){
|
||||
int begi = 0;
|
||||
float d = cutoffDistance;
|
||||
|
@ -82,14 +90,10 @@ public class PrecalculatedRouteDirection {
|
|||
}
|
||||
}
|
||||
tms = new float[times.size()];
|
||||
tmsReverse = new float[times.size()];
|
||||
float totInc = 0;
|
||||
float totDec = totaltm;
|
||||
for(int i = 0; i < times.size(); i++) {
|
||||
totInc += times.get(i);
|
||||
totDec -= times.get(i);
|
||||
tms[i] = totDec;
|
||||
tmsReverse[i] = totInc;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,8 +140,20 @@ public class PrecalculatedRouteDirection {
|
|||
ct[1] = (float) (ds / avgSpeed);
|
||||
return ind;
|
||||
}
|
||||
|
||||
public PrecalculatedRouteDirection adopt(RoutingContext ctx) {
|
||||
int ind1 = getIndex(ctx.startX, ctx.startY, ct1);
|
||||
int ind2 = getIndex(ctx.startX, ctx.startY, ct2);
|
||||
if (ind1 < ind2) {
|
||||
PrecalculatedRouteDirection routeDirection = new PrecalculatedRouteDirection(this, ind1, ind2);
|
||||
routeDirection.preRegisterPoint(ctx.startX, ctx.startY);
|
||||
routeDirection.preRegisterPoint(ctx.targetX, ctx.targetY);
|
||||
return routeDirection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void prereg(int x31, int y31) {
|
||||
private void preRegisterPoint(int x31, int y31) {
|
||||
int ind = getIndex(x31, y31, ct1);
|
||||
long l = ((long) x31) << 32l + ((long)y31);
|
||||
if(ind == -1){
|
||||
|
@ -146,4 +162,6 @@ public class PrecalculatedRouteDirection {
|
|||
prereg.put(l, ind);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -91,10 +91,11 @@ public class RoutePlannerFrontEnd {
|
|||
}
|
||||
boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty();
|
||||
// TODO complex, progress, native, empty route, intermediates...
|
||||
PrecalculatedRouteDirection routeDirection = null;
|
||||
if(ctx.calculationMode == RouteCalculationMode.COMPLEX && intermediatesEmpty) {
|
||||
RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
|
||||
List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);
|
||||
ctx.precalculatedRouteDirection = PrecalculatedRouteDirection.build(ls,
|
||||
routeDirection = PrecalculatedRouteDirection.build(ls,
|
||||
5000, ctx.getRouter().getMaxDefaultSpeed() / 2);
|
||||
}
|
||||
// remove fast recalculation
|
||||
|
@ -103,6 +104,9 @@ public class RoutePlannerFrontEnd {
|
|||
ctx.startY = MapUtils.get31TileNumberY(start.getLatitude());
|
||||
ctx.targetX = MapUtils.get31TileNumberX(end.getLongitude());
|
||||
ctx.targetY = MapUtils.get31TileNumberY(end.getLatitude());
|
||||
if(routeDirection != null) {
|
||||
ctx.precalculatedRouteDirection = routeDirection.adopt(ctx);
|
||||
}
|
||||
List<RouteSegmentResult> res = runNativeRouting(ctx);
|
||||
if(res != null) {
|
||||
new RouteResultPreparation().printResults(ctx, start, end, res);
|
||||
|
@ -124,7 +128,7 @@ public class RoutePlannerFrontEnd {
|
|||
if(!addSegment(end, ctx, indexNotFound++, points)){
|
||||
return null;
|
||||
}
|
||||
List<RouteSegmentResult> res = searchRoute(ctx, points);
|
||||
List<RouteSegmentResult> res = searchRoute(ctx, points, routeDirection);
|
||||
if(res != null) {
|
||||
new RouteResultPreparation().printResults(ctx, start, end, res);
|
||||
}
|
||||
|
@ -144,11 +148,15 @@ public class RoutePlannerFrontEnd {
|
|||
|
||||
}
|
||||
|
||||
private List<RouteSegmentResult> searchRouteInternalPrepare(final RoutingContext ctx, RouteSegment start, RouteSegment end) throws IOException, InterruptedException {
|
||||
private List<RouteSegmentResult> searchRouteInternalPrepare(final RoutingContext ctx, RouteSegment start, RouteSegment end,
|
||||
PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException {
|
||||
ctx.targetX = end.road.getPoint31XTile(end.getSegmentStart());
|
||||
ctx.targetY = end.road.getPoint31YTile(end.getSegmentStart());
|
||||
ctx.startX = start.road.getPoint31XTile(start.getSegmentStart());
|
||||
ctx.startY = start.road.getPoint31YTile(start.getSegmentStart());
|
||||
if(routeDirection != null) {
|
||||
ctx.precalculatedRouteDirection = routeDirection.adopt(ctx);
|
||||
}
|
||||
if (ctx.nativeLib != null && useOldVersion) {
|
||||
return runNativeRouting(ctx);
|
||||
} else {
|
||||
|
@ -190,7 +198,8 @@ public class RoutePlannerFrontEnd {
|
|||
}
|
||||
|
||||
|
||||
private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, List<RouteSegment> points) throws IOException, InterruptedException {
|
||||
private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, List<RouteSegment> points, PrecalculatedRouteDirection routeDirection)
|
||||
throws IOException, InterruptedException {
|
||||
if(points.size() > 2) {
|
||||
ArrayList<RouteSegmentResult> firstPartRecalculatedRoute = null;
|
||||
ArrayList<RouteSegmentResult> restPartRecalculatedRoute = null;
|
||||
|
@ -222,7 +231,7 @@ public class RoutePlannerFrontEnd {
|
|||
}
|
||||
local.visitor = ctx.visitor;
|
||||
local.calculationProgress = ctx.calculationProgress;
|
||||
List<RouteSegmentResult> res = searchRouteInternalPrepare(local, points.get(i), points.get(i + 1));
|
||||
List<RouteSegmentResult> res = searchRouteInternalPrepare(local, points.get(i), points.get(i + 1), routeDirection);
|
||||
|
||||
results.addAll(res);
|
||||
ctx.distinctLoadedTiles += local.distinctLoadedTiles;
|
||||
|
@ -244,17 +253,18 @@ public class RoutePlannerFrontEnd {
|
|||
ctx.unloadAllData();
|
||||
return results;
|
||||
}
|
||||
return searchRoute(ctx, points.get(0), points.get(1));
|
||||
return searchRoute(ctx, points.get(0), points.get(1), routeDirection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end) throws IOException, InterruptedException {
|
||||
private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end, PrecalculatedRouteDirection routeDirection)
|
||||
throws IOException, InterruptedException {
|
||||
if(ctx.SHOW_GC_SIZE){
|
||||
long h1 = ctx.runGCUsedMemory();
|
||||
float mb = (1 << 20);
|
||||
log.warn("Used before routing " + h1 / mb+ " actual");
|
||||
}
|
||||
List<RouteSegmentResult> result = searchRouteInternalPrepare(ctx, start, end);
|
||||
List<RouteSegmentResult> result = searchRouteInternalPrepare(ctx, start, end, routeDirection);
|
||||
if (RoutingContext.SHOW_GC_SIZE) {
|
||||
int sz = ctx.global.size;
|
||||
log.warn("Subregion size " + ctx.subregionTiles.size() + " " + " tiles " + ctx.indexedSubregions.size());
|
||||
|
|
Loading…
Reference in a new issue