Fix route preparation

This commit is contained in:
Victor Shcherb 2020-07-07 18:52:40 +02:00
parent 109eb77f88
commit ede816431d
3 changed files with 24 additions and 31 deletions

View file

@ -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<RouteSegment> 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<RouteSegment> graphDirectSegments, PriorityQueue<RouteSegment> graphReverseSegments,
TLongObjectHashMap<RouteSegment> visitedDirectSegments,TLongObjectHashMap<RouteSegment> 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);
}

View file

@ -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<LatLon> points) throws IOException, InterruptedException {
gctx.ctx.timeToCalculate = System.nanoTime();
if (gctx.ctx.calculationProgress == null) {
gctx.ctx.calculationProgress = new RouteCalculationProgress();
}
List<GpxPoint> 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<RouteSegmentResult> 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;

View file

@ -98,12 +98,18 @@ 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;
this.map.putAll(cp.map);
@ -252,18 +258,6 @@ public class RoutingContext {
return ind;
}
public void newRoutingPoints() {
int middleX = startX / 2 + targetX / 2;
int middleY = startY / 2 + targetY;
List<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
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);