Update route planer for transport progress bar
This commit is contained in:
parent
21a4075260
commit
6a6426265a
1 changed files with 28 additions and 3 deletions
|
@ -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();
|
ctx.startCalcTime = System.currentTimeMillis();
|
||||||
List<TransportRouteSegment> startStops = ctx.getTransportStops(start);
|
List<TransportRouteSegment> startStops = ctx.getTransportStops(start);
|
||||||
List<TransportRouteSegment> endStops = ctx.getTransportStops(end);
|
List<TransportRouteSegment> endStops = ctx.getTransportStops(end);
|
||||||
|
@ -45,7 +45,7 @@ public class TransportRoutePlanner {
|
||||||
}
|
}
|
||||||
double finishTime = ctx.cfg.maxRouteTime;
|
double finishTime = ctx.cfg.maxRouteTime;
|
||||||
List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>();
|
List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>();
|
||||||
|
initProgressBar(ctx, start, end);
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
TransportRouteSegment segment = queue.poll();
|
TransportRouteSegment segment = queue.poll();
|
||||||
TransportRouteSegment ex = ctx.visitedSegments.get(segment.getId());
|
TransportRouteSegment ex = ctx.visitedSegments.get(segment.getId());
|
||||||
|
@ -56,7 +56,6 @@ public class TransportRoutePlanner {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ctx.visitedRoutesCount++;
|
ctx.visitedRoutesCount++;
|
||||||
System.out.println(segment);
|
|
||||||
ctx.visitedSegments.put(segment.getId(), segment);
|
ctx.visitedSegments.put(segment.getId(), segment);
|
||||||
if (segment.getDepth() > ctx.cfg.maxNumberOfChanges) {
|
if (segment.getDepth() > ctx.cfg.maxNumberOfChanges) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -137,11 +136,37 @@ public class TransportRoutePlanner {
|
||||||
results.add(finish);
|
results.add(finish);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
|
||||||
|
throw new InterruptedException("Route calculation interrupted");
|
||||||
|
}
|
||||||
|
updateCalculationProgress(ctx, queue);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return prepareResults(ctx, results);
|
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) {
|
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
|
||||||
Collections.sort(results, new SegmentsComparator(ctx));
|
Collections.sort(results, new SegmentsComparator(ctx));
|
||||||
List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>();
|
List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>();
|
||||||
|
|
Loading…
Reference in a new issue