From 457dd188541b6566520e4c199ce58777fec4ecdb Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 5 Mar 2019 23:49:48 +0100 Subject: [PATCH] Fix out of memory for public transport and make maximum public transport route 3 hours --- .../java/net/osmand/data/TransportRoute.java | 2 +- .../osmand/router/TransportRoutePlanner.java | 19 +++++++++++++++++-- .../router/TransportRoutingConfiguration.java | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java b/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java index 36b9fb4361..2dd9ff1678 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/TransportRoute.java @@ -22,7 +22,7 @@ public class TransportRoute extends MapObject { private String color; private List forwardWays; private TransportSchedule schedule; - public static final double SAME_STOP = 25; + public static final double SAME_STOP = 40; public TransportRoute() { } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index a981ec1bca..b3bdc75973 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -26,7 +26,7 @@ import gnu.trove.map.hash.TLongObjectHashMap; public class TransportRoutePlanner { - + private static final boolean MEASURE_TIME = false; public List buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException, InterruptedException { ctx.startCalcTime = System.currentTimeMillis(); @@ -47,6 +47,7 @@ public class TransportRoutePlanner { List results = new ArrayList(); initProgressBar(ctx, start, end); while (!queue.isEmpty()) { + long beginMs = MEASURE_TIME ? System.currentTimeMillis() : 0; if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { return null; } @@ -60,6 +61,7 @@ public class TransportRoutePlanner { } ctx.visitedRoutesCount++; ctx.visitedSegments.put(segment.getId(), segment); + if (segment.getDepth() > ctx.cfg.maxNumberOfChanges) { continue; } @@ -90,6 +92,9 @@ public class TransportRoutePlanner { } else { travelTime += ctx.cfg.stopTime + segmentDist / ctx.cfg.travelSpeed; } + if(travelDist > finishTime + ctx.cfg.finishTimeSeconds) { + break; + } sgms.clear(); sgms = ctx.getTransportStops(stop.x31, stop.y31, true, sgms); for (TransportRouteSegment sgm : sgms) { @@ -149,6 +154,13 @@ public class TransportRoutePlanner { if (ctx.calculationProgress != null && ctx.calculationProgress.isCancelled) { 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); } @@ -748,7 +760,10 @@ public class TransportRoutePlanner { lst.add(segment); } } 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)); } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java index c8e26f04eb..01ca4be8d2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java @@ -22,7 +22,7 @@ public class TransportRoutingConfiguration { public int finishTimeSeconds = 1200; - public int maxRouteTime = 60 * 60 * 1000; // 1000 hours + public int maxRouteTime = 60 * 60 * 10; // 10 hours public boolean useSchedule;