From b067b66aa6099a6f1511879c080c4a47dfda2130 Mon Sep 17 00:00:00 2001 From: crimean Date: Mon, 24 Jun 2019 15:03:53 +0300 Subject: [PATCH] Working on min/max/def speed --- .../net/osmand/router/BinaryRoutePlanner.java | 12 +++--- .../java/net/osmand/router/GeneralRouter.java | 41 ++++++++++++------- .../router/PrecalculatedRouteDirection.java | 4 +- .../osmand/router/RoutePlannerFrontEnd.java | 4 +- .../osmand/router/RouteResultPreparation.java | 2 +- .../java/net/osmand/router/VehicleRouter.java | 11 ++++- .../osmand/plus/routing/RouteProvider.java | 3 +- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java index 60a1abaf99..2790a3b678 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/BinaryRoutePlanner.java @@ -343,12 +343,12 @@ public class BinaryRoutePlanner { private float estimatedDistance(final RoutingContext ctx, int targetEndX, int targetEndY, int startX, int startY) { double distance = squareRootDist(startX, startY, targetEndX, targetEndY); - return (float) (distance / ctx.getRouter().getMaxDefaultSpeed()); + return (float) (distance / ctx.getRouter().getMaxSpeed()); } protected static float h(RoutingContext ctx, int begX, int begY, int endX, int endY) { double distToFinalPoint = squareRootDist(begX, begY, endX, endY); - double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed(); + double result = distToFinalPoint / ctx.getRouter().getMaxSpeed(); if (ctx.precalculatedRouteDirection != null) { float te = ctx.precalculatedRouteDirection.timeEstimate(begX, begY, endX, endY); if (te > 0) { @@ -480,7 +480,7 @@ public class BinaryRoutePlanner { // reset to f // distStartObstacles = 0; // more precise but slower - distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMaxDefaultSpeed(); + distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMaxSpeed(); } // We don't check if there are outgoing connections @@ -584,11 +584,11 @@ public class BinaryRoutePlanner { float priority = ctx.getRouter().defineSpeedPriority(road); float speed = (ctx.getRouter().defineRoutingSpeed(road) * priority); if (speed == 0) { - speed = (ctx.getRouter().getMinDefaultSpeed() * priority); + speed = (ctx.getRouter().getDefaultSpeed() * priority); } // speed can not exceed max default speed according to A* - if (speed > ctx.getRouter().getMaxDefaultSpeed()) { - speed = ctx.getRouter().getMaxDefaultSpeed(); + if (speed > ctx.getRouter().getMaxSpeed()) { + speed = ctx.getRouter().getMaxSpeed(); } return obstaclesTime + distOnRoadToPass / speed; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index 1f5f9bdb99..b355264201 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -55,10 +55,12 @@ public class GeneralRouter implements VehicleRouter { private float roundaboutTurn; private float rightTurn; // speed in m/s - private float minDefaultSpeed = 10; + private float defaultSpeed = 0.28f; // speed in m/s - private float maxDefaultSpeed = 10; - + private float minSpeed = 1f; + // speed in m/s + private float maxSpeed = 10f; + private TLongHashSet impassableRoads; private GeneralRouterProfile profile; @@ -161,7 +163,7 @@ public class GeneralRouter implements VehicleRouter { shortestRoute = params.containsKey(USE_SHORTEST_WAY) && parseSilentBoolean(params.get(USE_SHORTEST_WAY), false); heightObstacles = params.containsKey(USE_HEIGHT_OBSTACLES) && parseSilentBoolean(params.get(USE_HEIGHT_OBSTACLES), false); if(shortestRoute) { - maxDefaultSpeed = Math.min(CAR_SHORTEST_DEFAULT_SPEED, maxDefaultSpeed); + maxSpeed = Math.min(CAR_SHORTEST_DEFAULT_SPEED, maxSpeed); } } @@ -188,10 +190,15 @@ public class GeneralRouter implements VehicleRouter { rightTurn = parseSilentFloat(v, rightTurn); } else if(k.equals("roundaboutTurn")) { roundaboutTurn = parseSilentFloat(v, roundaboutTurn); - } else if(k.equals("minDefaultSpeed")) { - minDefaultSpeed = parseSilentFloat(v, minDefaultSpeed * 3.6f) / 3.6f; - } else if(k.equals("maxDefaultSpeed")) { - maxDefaultSpeed = parseSilentFloat(v, maxDefaultSpeed * 3.6f) / 3.6f; + } else if(k.equals("defaultSpeed")) { + defaultSpeed = parseSilentFloat(v, defaultSpeed * 3.6f) / 3.6f; + } else if(k.equals("minDefaultSpeed") || k.equals("minSpeed")) { + minSpeed = parseSilentFloat(v, minSpeed * 3.6f) / 3.6f; + if (k.equals("minDefaultSpeed")) { + defaultSpeed = minSpeed; + } + } else if(k.equals("maxDefaultSpeed") || k.equals("maxSpeed")) { + maxSpeed = parseSilentFloat(v, maxSpeed * 3.6f) / 3.6f; } } @@ -377,13 +384,13 @@ public class GeneralRouter implements VehicleRouter { @Override public float defineRoutingSpeed(RouteDataObject road) { - return Math.min(defineVehicleSpeed(road), maxDefaultSpeed); + return Math.min(defineVehicleSpeed(road), maxSpeed); } @Override public float defineVehicleSpeed(RouteDataObject road) { - return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getMinDefaultSpeed()); + return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getDefaultSpeed()); } @Override @@ -392,16 +399,20 @@ public class GeneralRouter implements VehicleRouter { } @Override - public float getMinDefaultSpeed() { - return minDefaultSpeed; + public float getDefaultSpeed() { + return defaultSpeed; } @Override - public float getMaxDefaultSpeed() { - return maxDefaultSpeed; + public float getMinSpeed() { + return minSpeed; + } + + @Override + public float getMaxSpeed() { + return maxSpeed; } - public double getLeftTurn() { return leftTurn; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/PrecalculatedRouteDirection.java b/OsmAnd-java/src/main/java/net/osmand/router/PrecalculatedRouteDirection.java index d11044f0fd..d5fbae4cc2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/PrecalculatedRouteDirection.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/PrecalculatedRouteDirection.java @@ -260,8 +260,8 @@ public class PrecalculatedRouteDirection { public PrecalculatedRouteDirection adopt(RoutingContext ctx) { int ind1 = getIndex(ctx.startX, ctx.startY); int ind2 = getIndex(ctx.targetX, ctx.targetY); - minSpeed = ctx.getRouter().getMinDefaultSpeed(); - maxSpeed = ctx.getRouter().getMaxDefaultSpeed(); + minSpeed = ctx.getRouter().getDefaultSpeed(); + maxSpeed = ctx.getRouter().getMaxSpeed(); if(ind1 == -1) { return null; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index 65637ca190..e76bf02fd6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -196,7 +196,7 @@ public class RoutePlannerFrontEnd { RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE); nctx.calculationProgress = ctx.calculationProgress; List ls = searchRoute(nctx, start, end, intermediates); - routeDirection = PrecalculatedRouteDirection.build(ls, ctx.config.DEVIATION_RADIUS, ctx.getRouter().getMaxDefaultSpeed()); + routeDirection = PrecalculatedRouteDirection.build(ls, ctx.config.DEVIATION_RADIUS, ctx.getRouter().getMaxSpeed()); } if (intermediatesEmpty && ctx.nativeLib != null) { ctx.startX = MapUtils.get31TileNumberX(start.getLongitude()); @@ -426,7 +426,7 @@ public class RoutePlannerFrontEnd { ctx.calculationProgress.reverseSegmentQueueSize = 0; ctx.calculationProgress.directSegmentQueueSize = 0; float rd = (float) MapUtils.squareRootDist31(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY); - float speed = 0.9f * ctx.config.router.getMaxDefaultSpeed(); + float speed = 0.9f * ctx.config.router.getMaxSpeed(); ctx.calculationProgress.totalEstimatedDistance = (float) (rd / speed); } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index 94522fc57c..ffb9ffb5c2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -237,7 +237,7 @@ public class RouteResultPreparation { double distOnRoadToPass = 0; double speed = ctx.getRouter().defineVehicleSpeed(road); if (speed == 0) { - speed = ctx.getRouter().getMinDefaultSpeed(); + speed = ctx.getRouter().getDefaultSpeed(); } else { if (speed > SLOW_DOWN_SPEED_THRESHOLD) { speed = speed - (speed / SLOW_DOWN_SPEED_THRESHOLD - 1) * SLOW_DOWN_SPEED; diff --git a/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java index c2b5f5f970..6797de0848 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/VehicleRouter.java @@ -62,14 +62,21 @@ public interface VehicleRouter { * * @return minimal speed at road in m/s */ - public float getMinDefaultSpeed(); + public float getDefaultSpeed(); + + /** + * Used as minimal threshold of default speed + * + * @return minimal speed at road in m/s + */ + public float getMinSpeed(); /** * Used for A* routing to predict h(x) : it should be great any g(x) * * @return maximum speed to calculate shortest distance */ - public float getMaxDefaultSpeed(); + public float getMaxSpeed(); /** * aware of road restrictions diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 79e745be1b..5463e3bb2b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -29,7 +29,6 @@ import net.osmand.plus.Version; import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.router.GeneralRouter; -import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameterType; import net.osmand.router.PrecalculatedRouteDirection; @@ -612,7 +611,7 @@ public class RouteProvider { for(int k = 0; k < latLon.length; k ++) { latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude()); } - precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed()); + precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxSpeed()); precalculated.setFollowNext(true); //cf.planRoadDirection = 1; }