Add "DIVIDE" command and new "maxslope" and "maxslopecost" parameters (#642)

* Added 'DIV' expression for profiles

* Added 'uphillmaxbuffercost' and 'downhillmaxbuffercost' parameter. This makes it possible to penalize very steep path sections

* Added 'div by zero' check in BExpression.java DIV command

* Simplify maxbuffercostdiv logic

* Added documentation about new features

* Fix typo

* Rename new DIV command

* Redesign the new commands
- 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

* Adapt the profile developers guide to the latest changes

* Improve wording

---------

Co-authored-by: quaelnix <122357328+quaelnix@users.noreply.github.com>
This commit is contained in:
simdens 2024-01-17 16:34:52 +01:00 committed by GitHub
parent d2e183c625
commit 2f1422352e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 84 additions and 19 deletions

View file

@ -49,6 +49,8 @@ final class StdPath extends OsmPath {
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();
@ -60,11 +62,27 @@ final class StdPath extends OsmPath {
downhillcostdiv = 1000000 / downhillcostdiv;
}
int downhillmaxslopecostdiv = (int) rc.expctxWay.getDownhillmaxslopecost();
if (downhillmaxslopecostdiv > 0) {
downhillmaxslopecostdiv = 1000000 / downhillmaxslopecostdiv;
} else {
// if not given, use legacy behavior
downhillmaxslopecostdiv = downhillcostdiv;
}
uphillcostdiv = (int) rc.expctxWay.getUphillcost();
if (uphillcostdiv > 0) {
uphillcostdiv = 1000000 / uphillcostdiv;
}
int uphillmaxslopecostdiv = (int) rc.expctxWay.getUphillmaxslopecost();
if (uphillmaxslopecostdiv > 0) {
uphillmaxslopecostdiv = 1000000 / uphillmaxslopecostdiv;
} else {
// if not given, use legacy behavior
uphillmaxslopecostdiv = uphillcostdiv;
}
int dist = (int) distance; // legacy arithmetics needs int
// penalty for turning angle
@ -99,8 +117,14 @@ final class StdPath extends OsmPath {
reduce = excess;
}
ehbd -= reduce;
float elevationCost = 0.f;
if (downhillcostdiv > 0) {
int elevationCost = reduce / downhillcostdiv;
elevationCost += Math.min(reduce, dist * downhillmaxslope) / downhillcostdiv;
}
if (downhillmaxslopecostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * downhillmaxslope) / downhillmaxslopecostdiv;
}
if (elevationCost > 0) {
sectionCost += elevationCost;
if (message != null) {
message.linkelevationcost += elevationCost;
@ -125,8 +149,14 @@ final class StdPath extends OsmPath {
reduce = excess;
}
ehbu -= reduce;
float elevationCost = 0.f;
if (uphillcostdiv > 0) {
int elevationCost = reduce / uphillcostdiv;
elevationCost += Math.min(reduce, dist * uphillmaxslope) / uphillcostdiv;
}
if (uphillmaxslopecostdiv > 0) {
elevationCost += Math.max(0, reduce - dist * uphillmaxslope) / uphillmaxslopecostdiv;
}
if (elevationCost > 0) {
sectionCost += elevationCost;
if (message != null) {
message.linkelevationcost += elevationCost;