Fix out of memory for public transport and make maximum public transport route 3 hours

This commit is contained in:
Victor Shcherb 2019-03-05 23:49:48 +01:00
parent 5992090cbd
commit 457dd18854
3 changed files with 19 additions and 4 deletions

View file

@ -22,7 +22,7 @@ public class TransportRoute extends MapObject {
private String color; private String color;
private List<Way> forwardWays; private List<Way> forwardWays;
private TransportSchedule schedule; private TransportSchedule schedule;
public static final double SAME_STOP = 25; public static final double SAME_STOP = 40;
public TransportRoute() { public TransportRoute() {
} }

View file

@ -26,7 +26,7 @@ import gnu.trove.map.hash.TLongObjectHashMap;
public class TransportRoutePlanner { public class TransportRoutePlanner {
private static final boolean MEASURE_TIME = false;
public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException { public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException {
ctx.startCalcTime = System.currentTimeMillis(); ctx.startCalcTime = System.currentTimeMillis();
@ -47,6 +47,7 @@ public class TransportRoutePlanner {
List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>(); List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>();
initProgressBar(ctx, start, end); initProgressBar(ctx, start, end);
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
long beginMs = MEASURE_TIME ? System.currentTimeMillis() : 0;
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
return null; return null;
} }
@ -60,6 +61,7 @@ public class TransportRoutePlanner {
} }
ctx.visitedRoutesCount++; ctx.visitedRoutesCount++;
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;
} }
@ -90,6 +92,9 @@ public class TransportRoutePlanner {
} else { } else {
travelTime += ctx.cfg.stopTime + segmentDist / ctx.cfg.travelSpeed; travelTime += ctx.cfg.stopTime + segmentDist / ctx.cfg.travelSpeed;
} }
if(travelDist > finishTime + ctx.cfg.finishTimeSeconds) {
break;
}
sgms.clear(); sgms.clear();
sgms = ctx.getTransportStops(stop.x31, stop.y31, true, sgms); sgms = ctx.getTransportStops(stop.x31, stop.y31, true, sgms);
for (TransportRouteSegment sgm : sgms) { for (TransportRouteSegment sgm : sgms) {
@ -149,6 +154,13 @@ public class TransportRoutePlanner {
if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) {
throw new InterruptedException("Route calculation interrupted"); throw new InterruptedException("Route calculation interrupted");
} }
if (MEASURE_TIME) {
long time = System.currentTimeMillis() - beginMs;
if (time > 10) {
System.out.println(String.format("%d ms ref - %s id - %d", time, segment.road.getRef(),
segment.road.getId()));
}
}
updateCalculationProgress(ctx, queue); updateCalculationProgress(ctx, queue);
} }
@ -748,7 +760,10 @@ public class TransportRoutePlanner {
lst.add(segment); lst.add(segment);
} }
} else { } else {
System.err.println("Routing error: missing stop in route"); // MapUtils.getDistance(s.getLocation(), route.getForwardStops().get(158).getLocation());
System.err.println(
String.format("Routing error: missing stop '%s' in route '%s' id: %d",
s.toString(), route.getRef(), route.getId() / 2));
} }
} }
} }

View file

@ -22,7 +22,7 @@ public class TransportRoutingConfiguration {
public int finishTimeSeconds = 1200; public int finishTimeSeconds = 1200;
public int maxRouteTime = 60 * 60 * 1000; // 1000 hours public int maxRouteTime = 60 * 60 * 10; // 10 hours
public boolean useSchedule; public boolean useSchedule;