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,
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class RoutePlannerFrontEnd {
|
|||
RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
|
||||
nctx.calculationProgress = ctx.calculationProgress;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue