From 195655dc193274619ce7051cacd08abbe6260373 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 11 Jun 2012 22:28:57 +0200 Subject: [PATCH] Update router --- .../src/net/osmand/router/BicycleRouter.java | 18 ++- .../net/osmand/router/BinaryRoutePlanner.java | 140 ++++++++++++------ .../src/net/osmand/router/CarRouter.java | 42 ++---- .../net/osmand/router/PedestrianRouter.java | 25 ++-- .../net/osmand/router/RouteSegmentResult.java | 53 ++++++- .../src/net/osmand/router/RoutingContext.java | 4 +- .../src/net/osmand/router/VehicleRouter.java | 25 +--- .../osmand/router/test/RouterTestsSuite.java | 12 +- .../src/net/osmand/swing/MapRouterLayer.java | 27 ++-- .../swing/OsmExtractionPreferencesDialog.java | 4 +- .../osmand/plus/routing/RouteProvider.java | 11 +- 11 files changed, 218 insertions(+), 143 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/router/BicycleRouter.java b/DataExtractionOSM/src/net/osmand/router/BicycleRouter.java index 6501cd41e9..aa94e8bcbc 100644 --- a/DataExtractionOSM/src/net/osmand/router/BicycleRouter.java +++ b/DataExtractionOSM/src/net/osmand/router/BicycleRouter.java @@ -5,7 +5,6 @@ import gnu.trove.list.array.TIntArrayList; import java.util.LinkedHashMap; import java.util.Map; -import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteDataObject; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; @@ -99,9 +98,9 @@ public class BicycleRouter extends VehicleRouter { } @Override - public double getRoadPriorityToCalculateRoute(RouteDataObject road) { + public double getFutureRoadPriority(RouteDataObject road) { String highway = getHighway(road); - double priority = highway != null && bicyclePriorityValues.containsKey(highway) ? bicyclePriorityValues.get(highway) : 1d; + double priority = bicyclePriorityValues.containsKey(highway) ? bicyclePriorityValues.get(highway) : 1d; return priority; } @@ -110,13 +109,18 @@ public class BicycleRouter extends VehicleRouter { */ @Override public double defineSpeed(RouteDataObject road) { - String highway = getHighway(road); - double priority = highway != null && bicyclePriorityValues.containsKey(highway) ? bicyclePriorityValues.get(highway) : 0.5d; - Double value = bicycleNotDefinedValues.get(highway); + Double value = bicycleNotDefinedValues.get(getHighway(road)); if (value == null) { value = 4d; } - return value / 3.6d * priority; + return value / 3.6d ; + } + + @Override + public double defineSpeedPriority(RouteDataObject road) { + String highway = getHighway(road); + double priority = bicyclePriorityValues.containsKey(highway) ? bicyclePriorityValues.get(highway) : 0.5d; + return priority; } diff --git a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java index b24cc5b659..5e08e283a9 100644 --- a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java +++ b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java @@ -22,7 +22,6 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteDataObject; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion; -import net.osmand.osm.LatLon; import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapUtils; @@ -36,7 +35,7 @@ public class BinaryRoutePlanner { - private static final Log log = LogUtil.getLog(BinaryRoutePlanner.class); + protected static final Log log = LogUtil.getLog(BinaryRoutePlanner.class); public BinaryRoutePlanner(BinaryMapIndexReader... map) { for (BinaryMapIndexReader mr : map) { @@ -146,7 +145,7 @@ public class BinaryRoutePlanner { * return list of segments */ public List searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end) throws IOException { - + boolean relaxingStrategy = true; // measure time ctx.timeToLoad = 0; ctx.visitedSegments = 0; @@ -197,6 +196,10 @@ public class BinaryRoutePlanner { } while (!graphSegments.isEmpty()) { RouteSegment segment = graphSegments.poll(); + + if(relaxingStrategy) { + relaxNotNeededSegments(ctx, graphSegments, segment); + } ctx.visitedSegments++; // for debug purposes @@ -219,10 +222,12 @@ public class BinaryRoutePlanner { init = true; } else if (ctx.planRouteIn2Directions()) { inverse = nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) > 0; - if (graphDirectSegments.size() * 1.3 > graphReverseSegments.size()) { - inverse = true; - } else if (graphDirectSegments.size() < 1.3 * graphReverseSegments.size()) { - inverse = false; + if (!relaxingStrategy) { + if (graphDirectSegments.size() * 1.3 > graphReverseSegments.size()) { + inverse = true; + } else if (graphDirectSegments.size() < 1.3 * graphReverseSegments.size()) { + inverse = false; + } } } else { // different strategy : use onedirectional graph @@ -234,7 +239,7 @@ public class BinaryRoutePlanner { graphSegments = graphDirectSegments; } } - + printDebugMemoryInformation(ctx, graphDirectSegments, graphReverseSegments, visitedDirectSegments, visitedOppositeSegments); // 4. Route is found : collect all segments and prepare result return prepareResult(ctx, startNanoTime); @@ -242,6 +247,34 @@ public class BinaryRoutePlanner { } + private void relaxNotNeededSegments(RoutingContext ctx, PriorityQueue graphSegments, RouteSegment currentSegment) { + int before = graphSegments.size(); + if(before > 100) { + double maxd = currentSegment.distanceFromStart; + double mine = currentSegment.distanceToEnd; + Iterator iterator = graphSegments.iterator(); + while(iterator.hasNext()){ + RouteSegment s = iterator.next(); + if(s.distanceToEnd < mine){ + maxd = s.distanceFromStart; + mine = s.distanceToEnd; + } + } + double d = maxd / 2; + iterator = graphSegments.iterator(); + while(iterator.hasNext()){ + RouteSegment s = iterator.next(); + if(s.distanceFromStart < d){ + ctx.relaxedSegments++; + iterator.remove(); + } + } + int after = graphSegments.size(); + println("Relaxing : before " + before +" after " + after); + } + } + + private double h(final RoutingContext ctx, int targetEndX, int targetEndY, int startX, int startY) { double distance = squareRootDist(startX, startY, targetEndX, targetEndY); @@ -251,7 +284,7 @@ public class BinaryRoutePlanner { protected static double h(RoutingContext ctx, double distToFinalPoint, RouteSegment next) { double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed(); if(ctx.isUseDynamicRoadPrioritising() && next != null){ - double priority = ctx.getRouter().getRoadPriorityToCalculateRoute(next.road); + double priority = ctx.getRouter().getFutureRoadPriority(next.road); result /= priority; } return result; @@ -295,6 +328,26 @@ public class BinaryRoutePlanner { } } + private static void println(String logMsg) { +// log.info(logMsg); + System.out.println(logMsg); + } + + public void printDebugMemoryInformation(RoutingContext ctx, + PriorityQueue graphDirectSegments, PriorityQueue graphReverseSegments, + TLongObjectHashMap visitedDirectSegments, TLongObjectHashMap visitedOppositeSegments){ + println("Time to calculate : " + ctx.timeToCalculate / 1e6 +", time to load : " + ctx.timeToLoad / 1e6 ); + println("Loaded tiles : " + ctx.loadedTiles.size() + ", visited roads " + ctx.visitedSegments); + println("Relaxed roads: " + ctx.relaxedSegments); + if(graphDirectSegments != null && graphReverseSegments != null) { + println("Priority queues sizes : " + graphDirectSegments.size() +"/" + graphReverseSegments.size()); + } + if(visitedDirectSegments != null && visitedOppositeSegments != null) { + println("Visited segments sizes: " + visitedDirectSegments.size() +"/" + visitedOppositeSegments.size()); + } + + } + public void loadRoutes(final RoutingContext ctx, int tile31X, int tile31Y, final List toFillIn) { int zoomToLoad = 31 - ctx.getZoomToLoadTileWithRoads(); int tileX = tile31X >> zoomToLoad; @@ -424,9 +477,10 @@ public class BinaryRoutePlanner { // Using A* routing algorithm // g(x) - calculate distance to that point and calculate time double distOnRoadToPass = squareRootDist(x, y, middlex, middley); - double speed = ctx.getRouter().defineSpeed(road); + double priority = ctx.getRouter().defineSpeedPriority(road); + double speed = ctx.getRouter().defineSpeed(road) * priority; if (speed == 0) { - speed = ctx.getRouter().getMinDefaultSpeed(); + speed = ctx.getRouter().getMinDefaultSpeed() * priority; } double distanceFromStart = segment.distanceFromStart + distOnRoadToPass / speed; distanceFromStart += d > 0? obstaclePlusTime : obstacleMinusTime; @@ -589,7 +643,6 @@ public class BinaryRoutePlanner { // next.distanceFromStart = gDistFromStart; // next.parentRoute = segment; // next.parentSegmentEnd = segmentEnd; -// // if (ctx.visitor != null) { // ctx.visitor.visitSegment(next, false); // } @@ -643,7 +696,7 @@ public class BinaryRoutePlanner { return String.format("s%.2f e%.2f", ((float)distanceFromStart), ((float)distanceToEnd)); } } - + /** * Helper method to prepare final result */ @@ -652,40 +705,44 @@ public class BinaryRoutePlanner { RouteSegment segment = ctx.finalReverseRoute; int parentSegmentStart = ctx.finalReverseEndSegment; - while(segment != null){ - RouteSegmentResult res = new RouteSegmentResult(); - res.object = segment.road; - res.startPointIndex = segment.segmentStart; - res.endPointIndex = parentSegmentStart; + while (segment != null) { + RouteSegmentResult res = new RouteSegmentResult(segment.road, parentSegmentStart, segment.segmentStart); parentSegmentStart = segment.parentSegmentEnd; segment = segment.parentRoute; - // do not add segments consists from 1 point - if(res.startPointIndex != res.endPointIndex) { - result.add(res); - } - res.startPoint = convertPoint(res.object, res.startPointIndex); - res.endPoint = convertPoint(res.object, res.endPointIndex); + result.add(res); } Collections.reverse(result); segment = ctx.finalDirectRoute; int parentSegmentEnd = ctx.finalDirectEndSegment; - while(segment != null){ - RouteSegmentResult res = new RouteSegmentResult(); - res.object = segment.road; - res.startPointIndex = parentSegmentEnd; - res.endPointIndex = segment.segmentStart; + while (segment != null) { + RouteSegmentResult res = new RouteSegmentResult(segment.road, segment.segmentStart, parentSegmentEnd); parentSegmentEnd = segment.parentSegmentEnd; - segment = segment.parentRoute; - // do not add segments consists from 1 point - if(res.startPointIndex != res.endPointIndex) { - result.add(res); - } - res.startPoint = convertPoint(res.object, res.startPointIndex); - res.endPoint = convertPoint(res.object, res.endPointIndex); + result.add(res); + } + Collections.reverse(result); + // calculate time + for (int i = 0; i < result.size(); i++) { + RouteSegmentResult rr = result.get(i); + RouteDataObject road = rr.getObject(); + double distOnRoadToPass = 0; + double speed = ctx.getRouter().defineSpeed(road); + if (speed == 0) { + speed = ctx.getRouter().getMinDefaultSpeed(); + } + boolean plus = rr.getStartPointIndex() < rr.getEndPointIndex(); + int next; + for (int j = rr.getStartPointIndex(); j != rr.getEndPointIndex(); j = next) { + next = plus ? j + 1 : j - 1; + double d = squareRootDist(road.getPoint31XTile(j), road.getPoint31YTile(j), road.getPoint31XTile(next), + road.getPoint31YTile(next)); + distOnRoadToPass += d / speed + ctx.getRouter().defineObstacle(road, j); + } + // last point turn time can be added + // if(i + 1 < result.size()) { distOnRoadToPass += ctx.getRouter().calculateTurnTime(); } + rr.setSegmentTime((float) distOnRoadToPass); } - if (PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST) { System.out.println("ROUTE : "); @@ -702,21 +759,16 @@ public class BinaryRoutePlanner { if(ref != null) { name += " " + ref; } - System.out.println(MessageFormat.format("\t", - (res.object.getId())+"", res.startPointIndex, res.endPointIndex, name)); + System.out.println(MessageFormat.format("\t", + (res.getObject().getId())+"", res.getStartPointIndex()+"", res.getEndPointIndex()+"", name, res.getSegmentTime())); } System.out.println(""); } ctx.timeToCalculate = (System.nanoTime() - startNanoTime); - log.info("Time to calculate : " + ctx.timeToCalculate / 1e6 +", time to load : " + ctx.timeToLoad / 1e6 + ", loaded tiles : " + ctx.loadedTiles.size() + - ", visited segments " + ctx.visitedSegments ); return result; } - private LatLon convertPoint(RouteDataObject o, int ind){ - return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind))); - } public interface RouteSegmentVisitor { diff --git a/DataExtractionOSM/src/net/osmand/router/CarRouter.java b/DataExtractionOSM/src/net/osmand/router/CarRouter.java index 6793c6f52f..478d3c4ba6 100644 --- a/DataExtractionOSM/src/net/osmand/router/CarRouter.java +++ b/DataExtractionOSM/src/net/osmand/router/CarRouter.java @@ -74,36 +74,17 @@ public class CarRouter extends VehicleRouter { for(int i=0; i= 1){ - return 1; - } else if(priority >= 0.7){ - return 0.7; - } else if(priority >= 0.5){ - return 0.5; - } else { - return 0.3; - } - } @Override - public double getRoadPriorityToCalculateRoute(RouteDataObject road) { + public double getFutureRoadPriority(RouteDataObject road) { String highway = getHighway(road); double priority = highway != null && autoPriorityValues.containsKey(highway) ? autoPriorityValues.get(highway) : 0.5d; // keep it in boundaries otherwise @@ -133,12 +114,19 @@ public class CarRouter extends VehicleRouter { highway = r.highwayRoad(); } } - double priority = highway != null && autoPriorityValues.containsKey(highway) ? autoPriorityValues.get(highway) : 0.5d; + Double value = autoNotDefinedValues.get(highway); if (value == null) { - value = 50d; + value = 45d; } - return value / 3.6d * priority; + return value / 3.6d; + } + + @Override + public double defineSpeedPriority(RouteDataObject road) { + String highway = road.getHighway(); + double priority = highway != null && autoPriorityValues.containsKey(highway) ? autoPriorityValues.get(highway) : 0.5d; + return priority; } /** @@ -148,7 +136,7 @@ public class CarRouter extends VehicleRouter { */ @Override public double getMinDefaultSpeed() { - return 9; + return 12; } /** @@ -203,7 +191,7 @@ public class CarRouter extends VehicleRouter { double a2 = directionRoute(next, next.segmentStart, true); double diff = Math.abs(a1 - a2); if (diff > Math.PI / 2 && diff < 3 * Math.PI / 2) { - return 25; + return 20; } } return 0; diff --git a/DataExtractionOSM/src/net/osmand/router/PedestrianRouter.java b/DataExtractionOSM/src/net/osmand/router/PedestrianRouter.java index d4b09721d5..a653e8e429 100644 --- a/DataExtractionOSM/src/net/osmand/router/PedestrianRouter.java +++ b/DataExtractionOSM/src/net/osmand/router/PedestrianRouter.java @@ -5,7 +5,6 @@ import gnu.trove.list.array.TIntArrayList; import java.util.LinkedHashMap; import java.util.Map; -import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteDataObject; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; @@ -70,14 +69,21 @@ public class PedestrianRouter extends VehicleRouter { pedestrianPriorityValues.put("services", 1d); pedestrianPriorityValues.put("steps", 1.2d); } + + @Override + public double getFutureRoadPriority(RouteDataObject road) { + String highway = getHighway(road); + double priority = pedestrianPriorityValues.containsKey(highway) ? pedestrianPriorityValues.get(highway) : 1d; + return priority; + } - @Override - public double getRoadPriorityToCalculateRoute(RouteDataObject road) { - String highway = getHighway(road); - double priority = highway!= null && pedestrianPriorityValues.containsKey(highway) ? pedestrianPriorityValues.get(highway) : 1d; - return priority; - } - + @Override + public double defineSpeedPriority(RouteDataObject road) { + String highway = getHighway(road); + double priority = pedestrianPriorityValues.containsKey(highway) ? pedestrianPriorityValues.get(highway) : 1d; + return priority; + } + @Override public int isOneWay(RouteDataObject road) { return 0; @@ -122,14 +128,13 @@ public class PedestrianRouter extends VehicleRouter { public double defineSpeed(RouteDataObject road) { double speed = 1.5d; String highway = getHighway(road); - double priority = highway != null && pedestrianPriorityValues.containsKey(highway) ? pedestrianPriorityValues.get(highway) : 1d; if (highway != null) { Double value = pedestrianNotDefinedValues.get(highway); if (value != null) { speed = value; } } - return speed * priority; + return speed; } /** diff --git a/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java b/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java index 922e775d58..c4900d46c3 100644 --- a/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java +++ b/DataExtractionOSM/src/net/osmand/router/RouteSegmentResult.java @@ -2,12 +2,55 @@ package net.osmand.router; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteDataObject; import net.osmand.osm.LatLon; +import net.osmand.osm.MapUtils; public class RouteSegmentResult { - public LatLon startPoint; - public LatLon endPoint; - public RouteDataObject object; - public int startPointIndex; - public int endPointIndex; + private RouteDataObject object; + private int startPointIndex; + private int endPointIndex; + private float segmentTime; + + public RouteSegmentResult(RouteDataObject object, int startPointIndex, int endPointIndex) { + this.object = object; + this.startPointIndex = startPointIndex; + this.endPointIndex = endPointIndex; + + } + + public RouteDataObject getObject() { + return object; + } + + public float getSegmentTime() { + return segmentTime; + } + + public void setSegmentTime(float segmentTime) { + this.segmentTime = segmentTime; + } + + public LatLon getStartPoint() { + return convertPoint(object, startPointIndex); + } + + public int getStartPointIndex() { + return startPointIndex; + } + + public int getEndPointIndex() { + return endPointIndex; + } + + public LatLon getPoint(int i) { + return convertPoint(object, i); + } + + public LatLon getEndPoint() { + return convertPoint(object, endPointIndex); + } + + private LatLon convertPoint(RouteDataObject o, int ind){ + return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind))); + } } \ No newline at end of file diff --git a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java index b3cd7c9a02..eee616e865 100644 --- a/DataExtractionOSM/src/net/osmand/router/RoutingContext.java +++ b/DataExtractionOSM/src/net/osmand/router/RoutingContext.java @@ -30,7 +30,7 @@ public class RoutingContext { private boolean usingShortestWay = false; - // 2. Routing memory cache + // 2. Routing memory cache (big objects) TLongObjectMap routes = new TLongObjectHashMap(); TIntSet loadedTiles = new TIntHashSet(); // TODO delete this object ? @@ -52,12 +52,12 @@ public class RoutingContext { RouteSegment finalReverseRoute = null; int finalReverseEndSegment = 0; - // 3. debug information (package accessor) long timeToLoad = 0; long timeToCalculate = 0; int visitedSegments = 0; + int relaxedSegments = 0; // callback of processing segments RouteSegmentVisitor visitor = null; diff --git a/DataExtractionOSM/src/net/osmand/router/VehicleRouter.java b/DataExtractionOSM/src/net/osmand/router/VehicleRouter.java index 20a5e6bf79..03ffd3d377 100644 --- a/DataExtractionOSM/src/net/osmand/router/VehicleRouter.java +++ b/DataExtractionOSM/src/net/osmand/router/VehicleRouter.java @@ -34,25 +34,11 @@ public abstract class VehicleRouter { return road.getHighway(); } - /** - * Used for algorithm of increasing road priorities (actually make sense only for car routing) - * other routers can increase/decrease road priorities in the middle of route - * @param road - * @return - */ - public double getRoadPriorityHeuristicToIncrease(RouteDataObject road) { - return 1; - } - /** - * Used for algorithm to estimate end distance - * @param road - * @return + * Used for algorithm to multiply h(x) part A* based on current road */ - public double getRoadPriorityToCalculateRoute(RouteDataObject road) { - return 1; - } + public abstract double getFutureRoadPriority(RouteDataObject road); /** * return delay in seconds @@ -63,9 +49,14 @@ public abstract class VehicleRouter { } /** - * return speed in m/s for vehicle + * return speed in m/s for vehicle for specified road */ public abstract double defineSpeed(RouteDataObject road); + + /** + * define priority to multiply the speed for g(x) A* + */ + public abstract double defineSpeedPriority(RouteDataObject road); /** * Used for A* routing to calculate g(x) diff --git a/DataExtractionOSM/src/net/osmand/router/test/RouterTestsSuite.java b/DataExtractionOSM/src/net/osmand/router/test/RouterTestsSuite.java index b03f6568d7..f8175f14a7 100644 --- a/DataExtractionOSM/src/net/osmand/router/test/RouterTestsSuite.java +++ b/DataExtractionOSM/src/net/osmand/router/test/RouterTestsSuite.java @@ -119,17 +119,17 @@ public class RouterTestsSuite { int expectedStart = Integer.parseInt(segment.getAttribute("start")); int expectedEnd = Integer.parseInt(segment.getAttribute("end")); RouteSegmentResult segmentResult = route.get(i); - if (expectedId != segmentResult.object.getId() >> 1) { + if (expectedId != segmentResult.getObject().getId() >> 1) { throw new IllegalArgumentException("Test : '" + testDescription + "' on segment " + (i + 1) + " : " + "\n" - + "(expected route id) " + expectedId + " != " + (segmentResult.object.getId() >> 1) + " (actual route id)"); + + "(expected route id) " + expectedId + " != " + (segmentResult.getObject().getId() >> 1) + " (actual route id)"); } - if (expectedStart != segmentResult.startPointIndex) { + if (expectedStart != segmentResult.getStartPointIndex()) { throw new IllegalArgumentException("Test : '" + testDescription + "' on segment " + (i + 1) + " : " + "\n" - + "(expected start index) " + expectedStart + " != " + segmentResult.startPointIndex + " (actual start index)"); + + "(expected start index) " + expectedStart + " != " + segmentResult.getStartPointIndex() + " (actual start index)"); } - if (expectedEnd != segmentResult.endPointIndex) { + if (expectedEnd != segmentResult.getEndPointIndex()) { throw new IllegalArgumentException("Test : '" + testDescription + "' on segment " + (i + 1) + " : " + "\n" - + "(expected end index) " + expectedEnd + " != " + segmentResult.endPointIndex + " (actual end index)"); + + "(expected end index) " + expectedEnd + " != " + segmentResult.getEndPointIndex() + " (actual end index)"); } i++; diff --git a/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java b/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java index 2f28701b24..3219d7c129 100644 --- a/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java +++ b/DataExtractionOSM/src/net/osmand/swing/MapRouterLayer.java @@ -42,7 +42,6 @@ import net.osmand.router.CarRouter; import net.osmand.router.PedestrianRouter; import net.osmand.router.RouteSegmentResult; import net.osmand.router.RoutingContext; -import net.osmand.router.VehicleRouter; import net.osmand.router.BinaryRoutePlanner.RouteSegment; import net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor; @@ -546,7 +545,7 @@ public class MapRouterLayer implements MapPanelLayer { playPauseButton.setText("Play"); } stop = false; - if(files == null){ + if(files.isEmpty()){ JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE); return null; @@ -647,18 +646,10 @@ public class MapRouterLayer implements MapPanelLayer { } }); - // TODO delete this block after - net.osmand.osm.Node ns = createNode(st, st.getSegmentStart()); - points.registerObject(ns.getLatitude(), ns.getLongitude(), ns); - ns = createNode(e, e.getSegmentStart()); - points.registerObject(ns.getLatitude(), ns.getLongitude(), ns); - if (pause && animateRoutingCalculation) { - waitNextPress(); - } - // TODO delete this block after List searchRoute = router.searchRoute(ctx, st, e); - if (pause && animateRoutingCalculation) { + if (animateRoutingCalculation) { + playPauseButton.setVisible(false); nextTurn.setText("FINISH"); waitNextPress(); nextTurn.setText(">>"); @@ -667,20 +658,20 @@ public class MapRouterLayer implements MapPanelLayer { for (RouteSegmentResult s : searchRoute) { // double dist = MapUtils.getDistance(s.startPoint, s.endPoint); Way way = new Way(-1); - boolean plus = s.startPointIndex < s.endPointIndex; - int i = s.startPointIndex; + boolean plus = s.getStartPointIndex() < s.getEndPointIndex(); + int i = s.getStartPointIndex(); while (true) { - net.osmand.osm.Node n = new net.osmand.osm.Node(MapUtils.get31LatitudeY(s.object.getPoint31YTile(i)), MapUtils - .get31LongitudeX(s.object.getPoint31XTile(i)), -1); + LatLon l = s.getPoint(i); + net.osmand.osm.Node n = new net.osmand.osm.Node(l.getLatitude(), l.getLongitude(), -1); if (prevWayNode != null) { if (MapUtils.getDistance(prevWayNode, n) > 0) { - System.out.println("Warning not connected road " + " " + s.object.getHighway() + " dist " + System.out.println("Warning not connected road " + " " + s.getObject().getHighway() + " dist " + MapUtils.getDistance(prevWayNode, n)); } prevWayNode = null; } way.addNode(n); - if (i == s.endPointIndex) { + if (i == s.getEndPointIndex()) { break; } if (plus) { diff --git a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionPreferencesDialog.java b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionPreferencesDialog.java index d5a70501d8..f66a92de0b 100644 --- a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionPreferencesDialog.java +++ b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionPreferencesDialog.java @@ -57,7 +57,7 @@ public class OsmExtractionPreferencesDialog extends JDialog { } public void showDialog(){ - setSize(700, 500); + setSize(700, 570); double x = getParent().getBounds().getCenterX(); double y = getParent().getBounds().getCenterY(); setLocation((int) x - getWidth() / 2, (int) y - getHeight() / 2); @@ -161,7 +161,7 @@ public class OsmExtractionPreferencesDialog extends JDialog { constr.ipadx = 5; constr.gridx = 1; constr.gridy = gridY++; - l.setConstraints(directionPlanRoute, constr); + l.setConstraints(routingMode, constr); label = new JLabel("Direction to plan route (0 - both, 1 - forward, -1 - backward) : "); panel.add(label); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 9a5c2d58dd..15d4c85c07 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -637,14 +637,15 @@ public class RouteProvider { try { List result = router.searchRoute(ctx, st, en); for (RouteSegmentResult s : result) { - boolean plus = s.startPointIndex < s.endPointIndex; - int i = s.startPointIndex; + boolean plus = s.getStartPointIndex() < s.getEndPointIndex(); + int i = s.getStartPointIndex(); while (true) { Location n = new Location(""); //$NON-NLS-1$ - n.setLatitude(MapUtils.get31LatitudeY(s.object.getPoint31YTile(i))); - n.setLongitude(MapUtils.get31LongitudeX(s.object.getPoint31XTile(i))); + LatLon point = s.getPoint(i); + n.setLatitude(point.getLatitude()); + n.setLongitude(point.getLongitude()); res.add(n); - if (i == s.endPointIndex) { + if (i == s.getEndPointIndex()) { break; } if (plus) {