Merge branch 'abrensch:master' into fix-nogos

This commit is contained in:
afischerdev 2023-03-28 09:33:04 +02:00 committed by GitHub
commit 4147405362
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 33 deletions

View file

@ -247,12 +247,12 @@ final class KinematicPath extends OsmPath {
@Override @Override
public int elevationCorrection(RoutingContext rc) { public int elevationCorrection() {
return 0; return 0;
} }
@Override @Override
public boolean definitlyWorseThan(OsmPath path, RoutingContext rc) { public boolean definitlyWorseThan(OsmPath path) {
KinematicPath p = (KinematicPath) path; KinematicPath p = (KinematicPath) path;
int c = p.cost; int c = p.cost;

View file

@ -427,9 +427,9 @@ abstract class OsmPath implements OsmLinkHolder {
protected void computeKinematic(RoutingContext rc, double dist, double delta_h, boolean detailMode) { protected void computeKinematic(RoutingContext rc, double dist, double delta_h, boolean detailMode) {
} }
public abstract int elevationCorrection(RoutingContext rc); public abstract int elevationCorrection();
public abstract boolean definitlyWorseThan(OsmPath p, RoutingContext rc); public abstract boolean definitlyWorseThan(OsmPath p);
public OsmNode getSourceNode() { public OsmNode getSourceNode() {
return sourceNode; return sourceNode;

View file

@ -53,10 +53,6 @@ public final class RoutingContext {
public int memoryclass = 64; public int memoryclass = 64;
public int downhillcostdiv;
public int downhillcutoff;
public int uphillcostdiv;
public int uphillcutoff;
public boolean carMode; public boolean carMode;
public boolean bikeMode; public boolean bikeMode;
public boolean footMode; public boolean footMode;
@ -124,12 +120,6 @@ public final class RoutingContext {
setModel(expctxGlobal._modelClass); setModel(expctxGlobal._modelClass);
downhillcostdiv = (int) expctxGlobal.getVariableValue("downhillcost", 0.f);
downhillcutoff = (int) (expctxGlobal.getVariableValue("downhillcutoff", 0.f) * 10000);
uphillcostdiv = (int) expctxGlobal.getVariableValue("uphillcost", 0.f);
uphillcutoff = (int) (expctxGlobal.getVariableValue("uphillcutoff", 0.f) * 10000);
if (downhillcostdiv != 0) downhillcostdiv = 1000000 / downhillcostdiv;
if (uphillcostdiv != 0) uphillcostdiv = 1000000 / uphillcostdiv;
carMode = 0.f != expctxGlobal.getVariableValue("validForCars", 0.f); carMode = 0.f != expctxGlobal.getVariableValue("validForCars", 0.f);
bikeMode = 0.f != expctxGlobal.getVariableValue("validForBikes", 0.f); bikeMode = 0.f != expctxGlobal.getVariableValue("validForBikes", 0.f);
footMode = 0.f != expctxGlobal.getVariableValue("validForFoot", 0.f); footMode = 0.f != expctxGlobal.getVariableValue("validForFoot", 0.f);

View file

@ -1242,7 +1242,7 @@ public class RoutingEngine extends Thread {
if (parentcost < firstMatchCost) firstMatchCost = parentcost; if (parentcost < firstMatchCost) firstMatchCost = parentcost;
int costEstimate = path.cost int costEstimate = path.cost
+ path.elevationCorrection(routingContext) + path.elevationCorrection()
+ (costCuttingTrack.cost - pe.cost); + (costCuttingTrack.cost - pe.cost);
if (costEstimate <= maxTotalCost) { if (costEstimate <= maxTotalCost) {
matchPath = OsmPathElement.create(path, routingContext.countTraffic); matchPath = OsmPathElement.create(path, routingContext.countTraffic);
@ -1375,7 +1375,7 @@ public class RoutingEngine extends Thread {
OsmLinkHolder dominator = link.getFirstLinkHolder(currentNode); OsmLinkHolder dominator = link.getFirstLinkHolder(currentNode);
while (!trafficSim && dominator != null) { while (!trafficSim && dominator != null) {
OsmPath dp = (OsmPath) dominator; OsmPath dp = (OsmPath) dominator;
if (dp.airdistance != -1 && bestPath.definitlyWorseThan(dp, routingContext)) { if (dp.airdistance != -1 && bestPath.definitlyWorseThan(dp)) {
break; break;
} }
dominator = dominator.getNextForLink(); dominator = dominator.getNextForLink();

View file

@ -18,6 +18,9 @@ final class StdPath extends OsmPath {
private float totalEnergy; // total route energy (Joule) private float totalEnergy; // total route energy (Joule)
private float elevation_buffer; // just another elevation buffer (for travel time) private float elevation_buffer; // just another elevation buffer (for travel time)
private int uphillcostdiv;
private int downhillcostdiv;
// Gravitational constant, g // Gravitational constant, g
private static final double GRAVITY = 9.81; // in meters per second^(-2) private static final double GRAVITY = 9.81; // in meters per second^(-2)
@ -37,6 +40,8 @@ final class StdPath extends OsmPath {
ehbu = 0; ehbu = 0;
totalTime = 0.f; totalTime = 0.f;
totalEnergy = 0.f; totalEnergy = 0.f;
uphillcostdiv = 0;
downhillcostdiv = 0;
elevation_buffer = 0.f; elevation_buffer = 0.f;
} }
@ -44,12 +49,24 @@ final class StdPath extends OsmPath {
protected double processWaySection(RoutingContext rc, double distance, double delta_h, double elevation, double angle, double cosangle, boolean isStartpoint, int nsection, int lastpriorityclassifier) { protected double processWaySection(RoutingContext rc, double distance, double delta_h, double elevation, double angle, double cosangle, boolean isStartpoint, int nsection, int lastpriorityclassifier) {
// calculate the costfactor inputs // calculate the costfactor inputs
float turncostbase = rc.expctxWay.getTurncost(); float turncostbase = rc.expctxWay.getTurncost();
float uphillcutoff = rc.expctxWay.getUphillcutoff() * 10000;
float downhillcutoff = rc.expctxWay.getDownhillcutoff() * 10000;
float cfup = rc.expctxWay.getUphillCostfactor(); float cfup = rc.expctxWay.getUphillCostfactor();
float cfdown = rc.expctxWay.getDownhillCostfactor(); float cfdown = rc.expctxWay.getDownhillCostfactor();
float cf = rc.expctxWay.getCostfactor(); float cf = rc.expctxWay.getCostfactor();
cfup = cfup == 0.f ? cf : cfup; cfup = cfup == 0.f ? cf : cfup;
cfdown = cfdown == 0.f ? cf : cfdown; cfdown = cfdown == 0.f ? cf : cfdown;
downhillcostdiv = (int) rc.expctxWay.getDownhillcost();
if (downhillcostdiv > 0) {
downhillcostdiv = 1000000 / downhillcostdiv;
}
uphillcostdiv = (int) rc.expctxWay.getUphillcost();
if (uphillcostdiv > 0) {
uphillcostdiv = 1000000 / uphillcostdiv;
}
int dist = (int) distance; // legacy arithmetics needs int int dist = (int) distance; // legacy arithmetics needs int
// penalty for turning angle // penalty for turning angle
@ -66,8 +83,8 @@ final class StdPath extends OsmPath {
// leads to an immediate penalty // leads to an immediate penalty
int delta_h_micros = (int) (1000000. * delta_h); int delta_h_micros = (int) (1000000. * delta_h);
ehbd += -delta_h_micros - dist * rc.downhillcutoff; ehbd += -delta_h_micros - dist * downhillcutoff;
ehbu += delta_h_micros - dist * rc.uphillcutoff; ehbu += delta_h_micros - dist * uphillcutoff;
float downweight = 0.f; float downweight = 0.f;
if (ehbd > rc.elevationpenaltybuffer) { if (ehbd > rc.elevationpenaltybuffer) {
@ -84,8 +101,8 @@ final class StdPath extends OsmPath {
reduce = excess; reduce = excess;
} }
ehbd -= reduce; ehbd -= reduce;
if (rc.downhillcostdiv > 0) { if (downhillcostdiv > 0) {
int elevationCost = reduce / rc.downhillcostdiv; int elevationCost = reduce / downhillcostdiv;
sectionCost += elevationCost; sectionCost += elevationCost;
if (message != null) { if (message != null) {
message.linkelevationcost += elevationCost; message.linkelevationcost += elevationCost;
@ -110,8 +127,8 @@ final class StdPath extends OsmPath {
reduce = excess; reduce = excess;
} }
ehbu -= reduce; ehbu -= reduce;
if (rc.uphillcostdiv > 0) { if (uphillcostdiv > 0) {
int elevationCost = reduce / rc.uphillcostdiv; int elevationCost = reduce / uphillcostdiv;
sectionCost += elevationCost; sectionCost += elevationCost;
if (message != null) { if (message != null) {
message.linkelevationcost += elevationCost; message.linkelevationcost += elevationCost;
@ -153,23 +170,23 @@ final class StdPath extends OsmPath {
} }
@Override @Override
public int elevationCorrection(RoutingContext rc) { public int elevationCorrection() {
return (rc.downhillcostdiv > 0 ? ehbd / rc.downhillcostdiv : 0) return (downhillcostdiv > 0 ? ehbd / downhillcostdiv : 0)
+ (rc.uphillcostdiv > 0 ? ehbu / rc.uphillcostdiv : 0); + (uphillcostdiv > 0 ? ehbu / uphillcostdiv : 0);
} }
@Override @Override
public boolean definitlyWorseThan(OsmPath path, RoutingContext rc) { public boolean definitlyWorseThan(OsmPath path) {
StdPath p = (StdPath) path; StdPath p = (StdPath) path;
int c = p.cost; int c = p.cost;
if (rc.downhillcostdiv > 0) { if (p.downhillcostdiv > 0) {
int delta = p.ehbd - ehbd; int delta = p.ehbd / p.downhillcostdiv - (downhillcostdiv > 0 ? ehbd / downhillcostdiv : 0);
if (delta > 0) c += delta / rc.downhillcostdiv; if (delta > 0) c += delta;
} }
if (rc.uphillcostdiv > 0) { if (p.uphillcostdiv > 0) {
int delta = p.ehbu - ehbu; int delta = p.ehbu / p.uphillcostdiv - (uphillcostdiv > 0 ? ehbu / uphillcostdiv : 0);
if (delta > 0) c += delta / rc.uphillcostdiv; if (delta > 0) c += delta;
} }
return cost > c; return cost > c;

View file

@ -12,7 +12,7 @@ public final class BExpressionContextWay extends BExpressionContext implements T
private boolean decodeForbidden = true; private boolean decodeForbidden = true;
private static String[] buildInVariables = private static String[] buildInVariables =
{"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed"}; {"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed", "uphillcost", "downhillcost", "uphillcutoff", "downhillcutoff"};
protected String[] getBuildInVariableNames() { protected String[] getBuildInVariableNames() {
return buildInVariables; return buildInVariables;
@ -66,6 +66,22 @@ public final class BExpressionContextWay extends BExpressionContext implements T
return getBuildInVariable(11); return getBuildInVariable(11);
} }
public float getUphillcost() {
return getBuildInVariable(12);
}
public float getDownhillcost() {
return getBuildInVariable(13);
}
public float getUphillcutoff() {
return getBuildInVariable(14);
}
public float getDownhillcutoff() {
return getBuildInVariable(15);
}
public BExpressionContextWay(BExpressionMetaData meta) { public BExpressionContextWay(BExpressionMetaData meta) {
super("way", meta); super("way", meta);
} }