Update route planer for transport progress bar

This commit is contained in:
Victor Shcherb 2019-01-09 17:13:49 +01:00
parent 21a4075260
commit 6a6426265a

View file

@ -28,7 +28,7 @@ public class TransportRoutePlanner {
public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException {
public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException {
ctx.startCalcTime = System.currentTimeMillis();
List<TransportRouteSegment> startStops = ctx.getTransportStops(start);
List<TransportRouteSegment> endStops = ctx.getTransportStops(end);
@ -45,7 +45,7 @@ public class TransportRoutePlanner {
}
double finishTime = ctx.cfg.maxRouteTime;
List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>();
initProgressBar(ctx, start, end);
while (!queue.isEmpty()) {
TransportRouteSegment segment = queue.poll();
TransportRouteSegment ex = ctx.visitedSegments.get(segment.getId());
@ -56,7 +56,6 @@ public class TransportRoutePlanner {
continue;
}
ctx.visitedRoutesCount++;
System.out.println(segment);
ctx.visitedSegments.put(segment.getId(), segment);
if (segment.getDepth() > ctx.cfg.maxNumberOfChanges) {
continue;
@ -137,10 +136,36 @@ public class TransportRoutePlanner {
results.add(finish);
}
}
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
throw new InterruptedException("Route calculation interrupted");
}
updateCalculationProgress(ctx, queue);
}
return prepareResults(ctx, results);
}
private void initProgressBar(TransportRoutingContext ctx, LatLon start, LatLon end) {
ctx.calculationProgress.distanceFromEnd = 0;
ctx.calculationProgress.reverseSegmentQueueSize = 0;
ctx.calculationProgress.directSegmentQueueSize = 0;
float speed = (float) ctx.cfg.travelSpeed + 1; // assume
ctx.calculationProgress.totalEstimatedDistance = (float) (MapUtils.getDistance(start, end)/ speed);
}
private void updateCalculationProgress(TransportRoutingContext ctx, PriorityQueue<TransportRouteSegment> queue) {
if (ctx.calculationProgress != null) {
ctx.calculationProgress.directSegmentQueueSize = queue.size();
if (queue.size() > 0) {
TransportRouteSegment peek = queue.peek();
ctx.calculationProgress.distanceFromBegin = (float) Math.max(peek.distFromStart,
ctx.calculationProgress.distanceFromBegin);
}
}
}
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
Collections.sort(results, new SegmentsComparator(ctx));