Skip to content

Commit

Permalink
Redesign the new commands
Browse files Browse the repository at this point in the history
- Allow to set both the maxslope and the maxslopecost in the way context separately for uphill and downhill
- New names for the new commands that better reflect what they actually do
  • Loading branch information
quaelnix committed Jan 16, 2024
1 parent 213de56 commit 7ce187e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
38 changes: 18 additions & 20 deletions brouter-core/src/main/java/btools/router/StdPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ final class StdPath extends OsmPath {
private float elevation_buffer; // just another elevation buffer (for travel time)

private int uphillcostdiv;
private int uphillmaxbuffercostdiv;
private int downhillcostdiv;
private int downhillmaxbuffercostdiv;

// Gravitational constant, g
private static final double GRAVITY = 9.81; // in meters per second^(-2)
Expand All @@ -41,9 +39,7 @@ protected void resetState() {
totalTime = 0.f;
totalEnergy = 0.f;
uphillcostdiv = 0;
uphillmaxbuffercostdiv = 0;
downhillcostdiv = 0;
downhillmaxbuffercostdiv = 0;
elevation_buffer = 0.f;
}

Expand All @@ -53,6 +49,8 @@ protected double processWaySection(RoutingContext rc, double distance, double de
float turncostbase = rc.expctxWay.getTurncost();
float uphillcutoff = rc.expctxWay.getUphillcutoff() * 10000;
float downhillcutoff = rc.expctxWay.getDownhillcutoff() * 10000;
float uphillmaxslope = rc.expctxWay.getUphillmaxslope() * 10000;
float downhillmaxslope = rc.expctxWay.getDownhillmaxslope() * 10000;
float cfup = rc.expctxWay.getUphillCostfactor();
float cfdown = rc.expctxWay.getDownhillCostfactor();
float cf = rc.expctxWay.getCostfactor();
Expand All @@ -64,25 +62,25 @@ protected double processWaySection(RoutingContext rc, double distance, double de
downhillcostdiv = 1000000 / downhillcostdiv;
}

downhillmaxbuffercostdiv = (int) rc.expctxWay.getDownhillmaxbuffercost();
if (downhillmaxbuffercostdiv > 0) {
downhillmaxbuffercostdiv = 1000000 / downhillmaxbuffercostdiv;
int downhillmaxslopecostdiv = (int) rc.expctxWay.getDownhillmaxslopecost();
if (downhillmaxslopecostdiv > 0) {
downhillmaxslopecostdiv = 1000000 / downhillmaxslopecostdiv;
} else {
// if not given, use legacy behavior
downhillmaxbuffercostdiv = downhillcostdiv;
downhillmaxslopecostdiv = downhillcostdiv;
}

uphillcostdiv = (int) rc.expctxWay.getUphillcost();
if (uphillcostdiv > 0) {
uphillcostdiv = 1000000 / uphillcostdiv;
}

uphillmaxbuffercostdiv = (int) rc.expctxWay.getUphillmaxbuffercost();
if (uphillmaxbuffercostdiv > 0) {
uphillmaxbuffercostdiv = 1000000 / uphillmaxbuffercostdiv;
int uphillmaxslopecostdiv = (int) rc.expctxWay.getUphillmaxslopecost();
if (uphillmaxslopecostdiv > 0) {
uphillmaxslopecostdiv = 1000000 / uphillmaxslopecostdiv;
} else {
// if not given, use legacy behavior
uphillmaxbuffercostdiv = uphillcostdiv;
uphillmaxslopecostdiv = uphillcostdiv;
}

int dist = (int) distance; // legacy arithmetics needs int
Expand Down Expand Up @@ -119,12 +117,12 @@ protected double processWaySection(RoutingContext rc, double distance, double de
reduce = excess;
}
ehbd -= reduce;
int elevationCost = 0;
float elevationCost = 0.f;
if (downhillcostdiv > 0) {
elevationCost += Math.min(reduce, dist * rc.elevationbufferreduce) / downhillcostdiv;
elevationCost += Math.min(reduce, dist * downhillmaxslope) / downhillcostdiv;
}
if (downhillmaxbuffercostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * rc.elevationbufferreduce) / downhillmaxbuffercostdiv;
if (downhillmaxslopecostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * downhillmaxslope) / downhillmaxslopecostdiv;
}
if (elevationCost > 0) {
sectionCost += elevationCost;
Expand All @@ -151,12 +149,12 @@ protected double processWaySection(RoutingContext rc, double distance, double de
reduce = excess;
}
ehbu -= reduce;
int elevationCost = 0;
float elevationCost = 0.f;
if (uphillcostdiv > 0) {
elevationCost += Math.min(reduce, dist * rc.elevationbufferreduce) / uphillcostdiv;
elevationCost += Math.min(reduce, dist * uphillmaxslope) / uphillcostdiv;
}
if (uphillmaxbuffercostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * rc.elevationbufferreduce) / uphillmaxbuffercostdiv;
if (uphillmaxslopecostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * uphillmaxslope) / uphillmaxslopecostdiv;
}
if (elevationCost > 0) {
sectionCost += elevationCost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class BExpressionContextWay extends BExpressionContext implements T
private boolean decodeForbidden = true;

private static String[] buildInVariables =
{"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed", "uphillcost", "downhillcost", "uphillcutoff", "downhillcutoff", "uphillmaxbuffercost", "downhillmaxbuffercost"};
{"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed", "uphillcost", "downhillcost", "uphillcutoff", "downhillcutoff", "uphillmaxslope", "downhillmaxslope", "uphillmaxslopecost", "downhillmaxslopecost"};

protected String[] getBuildInVariableNames() {
return buildInVariables;
Expand Down Expand Up @@ -82,14 +82,22 @@ public float getDownhillcutoff() {
return getBuildInVariable(15);
}

public float getUphillmaxbuffercost() {
public float getUphillmaxslope() {
return getBuildInVariable(16);
}

public float getDownhillmaxbuffercost() {
public float getDownhillmaxslope() {
return getBuildInVariable(17);
}

public float getUphillmaxslopecost() {
return getBuildInVariable(18);
}

public float getDownhillmaxslopecost() {
return getBuildInVariable(19);
}

public BExpressionContextWay(BExpressionMetaData meta) {
super("way", meta);
}
Expand Down

0 comments on commit 7ce187e

Please sign in to comment.