Working on min/max/def speed
This commit is contained in:
parent
3ad51ba267
commit
b067b66aa6
7 changed files with 47 additions and 30 deletions
|
@ -343,12 +343,12 @@ public class BinaryRoutePlanner {
|
||||||
private float estimatedDistance(final RoutingContext ctx, int targetEndX, int targetEndY,
|
private float estimatedDistance(final RoutingContext ctx, int targetEndX, int targetEndY,
|
||||||
int startX, int startY) {
|
int startX, int startY) {
|
||||||
double distance = squareRootDist(startX, startY, targetEndX, targetEndY);
|
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) {
|
protected static float h(RoutingContext ctx, int begX, int begY, int endX, int endY) {
|
||||||
double distToFinalPoint = squareRootDist(begX, begY, endX, endY);
|
double distToFinalPoint = squareRootDist(begX, begY, endX, endY);
|
||||||
double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed();
|
double result = distToFinalPoint / ctx.getRouter().getMaxSpeed();
|
||||||
if (ctx.precalculatedRouteDirection != null) {
|
if (ctx.precalculatedRouteDirection != null) {
|
||||||
float te = ctx.precalculatedRouteDirection.timeEstimate(begX, begY, endX, endY);
|
float te = ctx.precalculatedRouteDirection.timeEstimate(begX, begY, endX, endY);
|
||||||
if (te > 0) {
|
if (te > 0) {
|
||||||
|
@ -480,7 +480,7 @@ public class BinaryRoutePlanner {
|
||||||
// reset to f
|
// reset to f
|
||||||
// distStartObstacles = 0;
|
// distStartObstacles = 0;
|
||||||
// more precise but slower
|
// 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
|
// We don't check if there are outgoing connections
|
||||||
|
@ -584,11 +584,11 @@ public class BinaryRoutePlanner {
|
||||||
float priority = ctx.getRouter().defineSpeedPriority(road);
|
float priority = ctx.getRouter().defineSpeedPriority(road);
|
||||||
float speed = (ctx.getRouter().defineRoutingSpeed(road) * priority);
|
float speed = (ctx.getRouter().defineRoutingSpeed(road) * priority);
|
||||||
if (speed == 0) {
|
if (speed == 0) {
|
||||||
speed = (ctx.getRouter().getMinDefaultSpeed() * priority);
|
speed = (ctx.getRouter().getDefaultSpeed() * priority);
|
||||||
}
|
}
|
||||||
// speed can not exceed max default speed according to A*
|
// speed can not exceed max default speed according to A*
|
||||||
if (speed > ctx.getRouter().getMaxDefaultSpeed()) {
|
if (speed > ctx.getRouter().getMaxSpeed()) {
|
||||||
speed = ctx.getRouter().getMaxDefaultSpeed();
|
speed = ctx.getRouter().getMaxSpeed();
|
||||||
}
|
}
|
||||||
return obstaclesTime + distOnRoadToPass / speed;
|
return obstaclesTime + distOnRoadToPass / speed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,12 @@ public class GeneralRouter implements VehicleRouter {
|
||||||
private float roundaboutTurn;
|
private float roundaboutTurn;
|
||||||
private float rightTurn;
|
private float rightTurn;
|
||||||
// speed in m/s
|
// speed in m/s
|
||||||
private float minDefaultSpeed = 10;
|
private float defaultSpeed = 0.28f;
|
||||||
// speed in m/s
|
// speed in m/s
|
||||||
private float maxDefaultSpeed = 10;
|
private float minSpeed = 1f;
|
||||||
|
// speed in m/s
|
||||||
|
private float maxSpeed = 10f;
|
||||||
|
|
||||||
private TLongHashSet impassableRoads;
|
private TLongHashSet impassableRoads;
|
||||||
private GeneralRouterProfile profile;
|
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);
|
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);
|
heightObstacles = params.containsKey(USE_HEIGHT_OBSTACLES) && parseSilentBoolean(params.get(USE_HEIGHT_OBSTACLES), false);
|
||||||
if(shortestRoute) {
|
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);
|
rightTurn = parseSilentFloat(v, rightTurn);
|
||||||
} else if(k.equals("roundaboutTurn")) {
|
} else if(k.equals("roundaboutTurn")) {
|
||||||
roundaboutTurn = parseSilentFloat(v, roundaboutTurn);
|
roundaboutTurn = parseSilentFloat(v, roundaboutTurn);
|
||||||
} else if(k.equals("minDefaultSpeed")) {
|
} else if(k.equals("defaultSpeed")) {
|
||||||
minDefaultSpeed = parseSilentFloat(v, minDefaultSpeed * 3.6f) / 3.6f;
|
defaultSpeed = parseSilentFloat(v, defaultSpeed * 3.6f) / 3.6f;
|
||||||
} else if(k.equals("maxDefaultSpeed")) {
|
} else if(k.equals("minDefaultSpeed") || k.equals("minSpeed")) {
|
||||||
maxDefaultSpeed = parseSilentFloat(v, maxDefaultSpeed * 3.6f) / 3.6f;
|
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
|
@Override
|
||||||
public float defineRoutingSpeed(RouteDataObject road) {
|
public float defineRoutingSpeed(RouteDataObject road) {
|
||||||
return Math.min(defineVehicleSpeed(road), maxDefaultSpeed);
|
return Math.min(defineVehicleSpeed(road), maxSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float defineVehicleSpeed(RouteDataObject road) {
|
public float defineVehicleSpeed(RouteDataObject road) {
|
||||||
return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getMinDefaultSpeed());
|
return getObjContext(RouteDataObjectAttribute.ROAD_SPEED) .evaluateFloat(road, getDefaultSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -392,16 +399,20 @@ public class GeneralRouter implements VehicleRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMinDefaultSpeed() {
|
public float getDefaultSpeed() {
|
||||||
return minDefaultSpeed;
|
return defaultSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxDefaultSpeed() {
|
public float getMinSpeed() {
|
||||||
return maxDefaultSpeed;
|
return minSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxSpeed() {
|
||||||
|
return maxSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public double getLeftTurn() {
|
public double getLeftTurn() {
|
||||||
return leftTurn;
|
return leftTurn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,8 +260,8 @@ public class PrecalculatedRouteDirection {
|
||||||
public PrecalculatedRouteDirection adopt(RoutingContext ctx) {
|
public PrecalculatedRouteDirection adopt(RoutingContext ctx) {
|
||||||
int ind1 = getIndex(ctx.startX, ctx.startY);
|
int ind1 = getIndex(ctx.startX, ctx.startY);
|
||||||
int ind2 = getIndex(ctx.targetX, ctx.targetY);
|
int ind2 = getIndex(ctx.targetX, ctx.targetY);
|
||||||
minSpeed = ctx.getRouter().getMinDefaultSpeed();
|
minSpeed = ctx.getRouter().getDefaultSpeed();
|
||||||
maxSpeed = ctx.getRouter().getMaxDefaultSpeed();
|
maxSpeed = ctx.getRouter().getMaxSpeed();
|
||||||
if(ind1 == -1) {
|
if(ind1 == -1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ public class RoutePlannerFrontEnd {
|
||||||
RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
|
RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
|
||||||
nctx.calculationProgress = ctx.calculationProgress;
|
nctx.calculationProgress = ctx.calculationProgress;
|
||||||
List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);
|
List<RouteSegmentResult> 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) {
|
if (intermediatesEmpty && ctx.nativeLib != null) {
|
||||||
ctx.startX = MapUtils.get31TileNumberX(start.getLongitude());
|
ctx.startX = MapUtils.get31TileNumberX(start.getLongitude());
|
||||||
|
@ -426,7 +426,7 @@ public class RoutePlannerFrontEnd {
|
||||||
ctx.calculationProgress.reverseSegmentQueueSize = 0;
|
ctx.calculationProgress.reverseSegmentQueueSize = 0;
|
||||||
ctx.calculationProgress.directSegmentQueueSize = 0;
|
ctx.calculationProgress.directSegmentQueueSize = 0;
|
||||||
float rd = (float) MapUtils.squareRootDist31(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY);
|
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);
|
ctx.calculationProgress.totalEstimatedDistance = (float) (rd / speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ public class RouteResultPreparation {
|
||||||
double distOnRoadToPass = 0;
|
double distOnRoadToPass = 0;
|
||||||
double speed = ctx.getRouter().defineVehicleSpeed(road);
|
double speed = ctx.getRouter().defineVehicleSpeed(road);
|
||||||
if (speed == 0) {
|
if (speed == 0) {
|
||||||
speed = ctx.getRouter().getMinDefaultSpeed();
|
speed = ctx.getRouter().getDefaultSpeed();
|
||||||
} else {
|
} else {
|
||||||
if (speed > SLOW_DOWN_SPEED_THRESHOLD) {
|
if (speed > SLOW_DOWN_SPEED_THRESHOLD) {
|
||||||
speed = speed - (speed / SLOW_DOWN_SPEED_THRESHOLD - 1) * SLOW_DOWN_SPEED;
|
speed = speed - (speed / SLOW_DOWN_SPEED_THRESHOLD - 1) * SLOW_DOWN_SPEED;
|
||||||
|
|
|
@ -62,14 +62,21 @@ public interface VehicleRouter {
|
||||||
*
|
*
|
||||||
* @return minimal speed at road in m/s
|
* @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)
|
* Used for A* routing to predict h(x) : it should be great any g(x)
|
||||||
*
|
*
|
||||||
* @return maximum speed to calculate shortest distance
|
* @return maximum speed to calculate shortest distance
|
||||||
*/
|
*/
|
||||||
public float getMaxDefaultSpeed();
|
public float getMaxSpeed();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* aware of road restrictions
|
* aware of road restrictions
|
||||||
|
|
|
@ -29,7 +29,6 @@ import net.osmand.plus.Version;
|
||||||
import net.osmand.plus.activities.SettingsNavigationActivity;
|
import net.osmand.plus.activities.SettingsNavigationActivity;
|
||||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
||||||
import net.osmand.router.PrecalculatedRouteDirection;
|
import net.osmand.router.PrecalculatedRouteDirection;
|
||||||
|
@ -612,7 +611,7 @@ public class RouteProvider {
|
||||||
for(int k = 0; k < latLon.length; k ++) {
|
for(int k = 0; k < latLon.length; k ++) {
|
||||||
latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude());
|
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);
|
precalculated.setFollowNext(true);
|
||||||
//cf.planRoadDirection = 1;
|
//cf.planRoadDirection = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue