Fix route preparation
This commit is contained in:
parent
109eb77f88
commit
ede816431d
3 changed files with 24 additions and 31 deletions
|
@ -65,13 +65,11 @@ public class BinaryRoutePlanner {
|
||||||
* Calculate route between start.segmentEnd and end.segmentStart (using A* algorithm)
|
* Calculate route between start.segmentEnd and end.segmentStart (using A* algorithm)
|
||||||
* return list of segments
|
* return list of segments
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
FinalRouteSegment searchRouteInternal(final RoutingContext ctx, RouteSegmentPoint start, RouteSegmentPoint end,
|
FinalRouteSegment searchRouteInternal(final RoutingContext ctx, RouteSegmentPoint start, RouteSegmentPoint end,
|
||||||
RouteSegment recalculationEnd ) throws InterruptedException, IOException {
|
RouteSegment recalculationEnd ) throws InterruptedException, IOException {
|
||||||
// measure time
|
// measure time
|
||||||
ctx.timeToLoad = 0;
|
ctx.timeToLoad = 0;
|
||||||
ctx.memoryOverhead = 1000;
|
ctx.memoryOverhead = 1000;
|
||||||
ctx.visitedSegments = 0;
|
|
||||||
|
|
||||||
// Initializing priority queue to visit way segments
|
// Initializing priority queue to visit way segments
|
||||||
Comparator<RouteSegment> nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator();
|
Comparator<RouteSegment> nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator();
|
||||||
|
@ -166,8 +164,12 @@ public class BinaryRoutePlanner {
|
||||||
throw new InterruptedException("Route calculation interrupted");
|
throw new InterruptedException("Route calculation interrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.visitedSegments = visitedDirectSegments.size() + visitedOppositeSegments.size();
|
ctx.visitedSegments += visitedDirectSegments.size() + visitedOppositeSegments.size();
|
||||||
printDebugMemoryInformation(ctx, graphDirectSegments, graphReverseSegments, visitedDirectSegments, visitedOppositeSegments);
|
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;
|
return finalSegment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,8 +370,7 @@ public class BinaryRoutePlanner {
|
||||||
log.warn(logMsg);
|
log.warn(logMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printDebugMemoryInformation(RoutingContext ctx, PriorityQueue<RouteSegment> graphDirectSegments, PriorityQueue<RouteSegment> graphReverseSegments,
|
public static void printDebugMemoryInformation(RoutingContext ctx) {
|
||||||
TLongObjectHashMap<RouteSegment> visitedDirectSegments,TLongObjectHashMap<RouteSegment> visitedOppositeSegments) {
|
|
||||||
printInfo(String.format("Time. Total: %.2f, to load: %.2f, to load headers: %.2f, to calc dev: %.2f ",
|
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,
|
(System.nanoTime() - ctx.timeToCalculate) / 1e6, ctx.timeToLoad / 1e6,
|
||||||
ctx.timeToLoadHeaders / 1e6, ctx.timeNanoToCalcDeviation / 1e6));
|
ctx.timeToLoadHeaders / 1e6, ctx.timeNanoToCalcDeviation / 1e6));
|
||||||
|
@ -380,12 +381,8 @@ public class BinaryRoutePlanner {
|
||||||
", loaded more than once same tiles "
|
", loaded more than once same tiles "
|
||||||
+ ctx.loadedPrevUnloadedTiles);
|
+ ctx.loadedPrevUnloadedTiles);
|
||||||
printInfo("Visited segments " + ctx.visitedSegments + ", relaxed roads " + ctx.relaxedSegments);
|
printInfo("Visited segments " + ctx.visitedSegments + ", relaxed roads " + ctx.relaxedSegments);
|
||||||
if (graphDirectSegments != null && graphReverseSegments != null) {
|
printInfo("Priority queues sizes : " + ctx.directQueueSize + "/" + ctx.oppositeQueueSize);
|
||||||
printInfo("Priority queues sizes : " + graphDirectSegments.size() + "/" + graphReverseSegments.size());
|
printInfo("Visited interval sizes: " + ctx.visitedDirectSegments + "/" + ctx.visitedOppositeSegments);
|
||||||
}
|
|
||||||
if (visitedDirectSegments != null && visitedOppositeSegments != null) {
|
|
||||||
printInfo("Visited interval sizes: " + visitedDirectSegments.size() + "/" + visitedOppositeSegments.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,23 +203,24 @@ public class RoutePlannerFrontEnd {
|
||||||
useSmartRouteRecalculation = use;
|
useSmartRouteRecalculation = use;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO native matches less roads
|
// 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 {
|
public GpxRouteApproximation searchGpxRoute(GpxRouteApproximation gctx, List<LatLon> points) throws IOException, InterruptedException {
|
||||||
gctx.ctx.timeToCalculate = System.nanoTime();
|
gctx.ctx.timeToCalculate = System.nanoTime();
|
||||||
if (gctx.ctx.calculationProgress == null) {
|
if (gctx.ctx.calculationProgress == null) {
|
||||||
gctx.ctx.calculationProgress = new RouteCalculationProgress();
|
gctx.ctx.calculationProgress = new RouteCalculationProgress();
|
||||||
}
|
}
|
||||||
List<GpxPoint> gpxPoints = generageGpxPoints(points, gctx);
|
List<GpxPoint> gpxPoints = generageGpxPoints(points, gctx);
|
||||||
GpxPoint start = gpxPoints.size() > 0 ? gpxPoints.get(0) : null;
|
GpxPoint start = null;
|
||||||
GpxPoint prev = 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) {
|
while (start != null) {
|
||||||
double routeDist = gctx.MAXIMUM_STEP_APPROXIMATION;
|
double routeDist = gctx.MAXIMUM_STEP_APPROXIMATION;
|
||||||
GpxPoint next = findNextGpxPointWithin(gctx, gpxPoints, start, routeDist);
|
GpxPoint next = findNextGpxPointWithin(gctx, gpxPoints, start, routeDist);
|
||||||
boolean routeFound = false;
|
boolean routeFound = false;
|
||||||
|
gctx.ctx.calculationProgress.nextIteration();
|
||||||
if (next != null && initRoutingPoint(start, gctx, gctx.MINIMUM_POINT_APPROXIMATION)) {
|
if (next != null && initRoutingPoint(start, gctx, gctx.MINIMUM_POINT_APPROXIMATION)) {
|
||||||
while (routeDist >= gctx.MINIMUM_STEP_APPROXIMATION && !routeFound) {
|
while (routeDist >= gctx.MINIMUM_STEP_APPROXIMATION && !routeFound) {
|
||||||
routeFound = initRoutingPoint(next, gctx, gctx.MINIMUM_POINT_APPROXIMATION);
|
routeFound = initRoutingPoint(next, gctx, gctx.MINIMUM_POINT_APPROXIMATION);
|
||||||
|
@ -267,9 +268,8 @@ public class RoutePlannerFrontEnd {
|
||||||
}
|
}
|
||||||
start = next;
|
start = next;
|
||||||
}
|
}
|
||||||
|
BinaryRoutePlanner.printDebugMemoryInformation(gctx.ctx);
|
||||||
calculateGpxRoute(gctx, gpxPoints);
|
calculateGpxRoute(gctx, gpxPoints);
|
||||||
|
|
||||||
if (!gctx.res.isEmpty()) {
|
if (!gctx.res.isEmpty()) {
|
||||||
new RouteResultPreparation().printResults(gctx.ctx, points.get(0), points.get(points.size() - 1), gctx.res);
|
new RouteResultPreparation().printResults(gctx.ctx, points.get(0), points.get(points.size() - 1), gctx.res);
|
||||||
System.out.println(gctx);
|
System.out.println(gctx);
|
||||||
|
@ -504,6 +504,7 @@ public class RoutePlannerFrontEnd {
|
||||||
gctx.routeDistCalculations += (target.cumDist - start.cumDist);
|
gctx.routeDistCalculations += (target.cumDist - start.cumDist);
|
||||||
gctx.routeCalculations++;
|
gctx.routeCalculations++;
|
||||||
res = searchRouteInternalPrepare(gctx.ctx, start.pnt, target.pnt, null);
|
res = searchRouteInternalPrepare(gctx.ctx, start.pnt, target.pnt, null);
|
||||||
|
//BinaryRoutePlanner.printDebugMemoryInformation(gctx.ctx);
|
||||||
routeIsCorrect = res != null && !res.isEmpty();
|
routeIsCorrect = res != null && !res.isEmpty();
|
||||||
for (int k = start.ind + 1; routeIsCorrect && k < target.ind; k++) {
|
for (int k = start.ind + 1; routeIsCorrect && k < target.ind; k++) {
|
||||||
GpxPoint ipoint = gpxPoints.get(k);
|
GpxPoint ipoint = gpxPoints.get(k);
|
||||||
|
@ -859,6 +860,7 @@ public class RoutePlannerFrontEnd {
|
||||||
}
|
}
|
||||||
pringGC(ctx, true);
|
pringGC(ctx, true);
|
||||||
List<RouteSegmentResult> res = searchRouteInternalPrepare(ctx, points.get(0), points.get(1), routeDirection);
|
List<RouteSegmentResult> res = searchRouteInternalPrepare(ctx, points.get(0), points.get(1), routeDirection);
|
||||||
|
BinaryRoutePlanner.printDebugMemoryInformation(ctx);
|
||||||
pringGC(ctx, false);
|
pringGC(ctx, false);
|
||||||
makeStartEndPointsPrecise(res, points.get(0).getPreciseLatLon(), points.get(1).getPreciseLatLon(), null);
|
makeStartEndPointsPrecise(res, points.get(0).getPreciseLatLon(), points.get(1).getPreciseLatLon(), null);
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -98,11 +98,17 @@ public class RoutingContext {
|
||||||
public int loadedTiles = 0;
|
public int loadedTiles = 0;
|
||||||
public int visitedSegments = 0;
|
public int visitedSegments = 0;
|
||||||
public int relaxedSegments = 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
|
// callback of processing segments
|
||||||
RouteSegmentVisitor visitor = null;
|
RouteSegmentVisitor visitor = null;
|
||||||
|
|
||||||
// old planner
|
// old planner
|
||||||
public FinalRouteSegment finalRouteSegment;
|
public FinalRouteSegment finalRouteSegment;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RoutingContext(RoutingContext cp) {
|
RoutingContext(RoutingContext cp) {
|
||||||
this.config = cp.config;
|
this.config = cp.config;
|
||||||
|
@ -252,18 +258,6 @@ public class RoutingContext {
|
||||||
return ind;
|
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) {
|
public RouteSegment loadRouteSegment(int x31, int y31, long memoryLimit) {
|
||||||
long tileId = getRoutingTile(x31, y31, memoryLimit);
|
long tileId = getRoutingTile(x31, y31, memoryLimit);
|
||||||
|
|
Loading…
Reference in a new issue