Skip to content

Commit

Permalink
highway=path and bicycle=yes should not get speed for pushing section (
Browse files Browse the repository at this point in the history
…#1892)

* highway=pathPath and bicycle=yes should not get speed for pushing section
See https://discuss.graphhopper.com/t/bike-profil-highway-pathpath-and-bicycle-yes-should-not-get-speed-for-pushing-section/5148

* Reduce speed for bicycle=yes on a pushing section part from 14km/h to 10km/h.

* Indentations fixed.

* indentation

Co-authored-by: Peter <graphhopper@gmx.de>
  • Loading branch information
ratrun and karussell committed Feb 23, 2020
1 parent 55408ce commit b56ae1d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,13 @@ int getSpeed(ReaderWay way) {
// Under certain conditions we need to increase the speed of pushing sections to the speed of a "highway=cycleway"
if (way.hasTag("highway", pushingSectionsHighways)
&& ((way.hasTag("foot", "yes") && way.hasTag("segregated", "yes"))
|| way.hasTag("bicycle", "designated") || way.hasTag("bicycle", "official")))
|| (way.hasTag("bicycle", intendedValues))))
highwaySpeed = getHighwaySpeed("cycleway");

String s = way.getTag("surface");
Integer surfaceSpeed = 0;
if (!Helper.isEmpty(s)) {
Integer surfaceSpeed = surfaceSpeeds.get(s);
surfaceSpeed = surfaceSpeeds.get(s);
if (surfaceSpeed != null) {
speed = surfaceSpeed;
// boost handling for good surfaces but avoid boosting if pushing section
Expand All @@ -366,24 +367,24 @@ int getSpeed(ReaderWay way) {
}

// Until now we assumed that the way is no pushing section
// Now we check that, but only in case that our speed is bigger compared to the PUSHING_SECTION_SPEED
// Now we check that, but only in case that our speed computed so far is bigger compared to the PUSHING_SECTION_SPEED
if (speed > PUSHING_SECTION_SPEED
&& (way.hasTag("highway", pushingSectionsHighways) || way.hasTag("bicycle", "dismount"))) {
if (!way.hasTag("bicycle", intendedValues)) {
// Here we set the speed for pushing sections and set speed for steps as even lower:
if (way.hasTag("highway", "steps"))
speed = PUSHING_SECTION_SPEED / 2;
else
speed = PUSHING_SECTION_SPEED;
} else if (way.hasTag("bicycle", "designated") || way.hasTag("bicycle", "official")) {
speed = way.hasTag("highway", "steps") ? PUSHING_SECTION_SPEED / 2 : PUSHING_SECTION_SPEED;
} else if (way.hasTag("bicycle", "designated") || way.hasTag("bicycle", "official") ||
way.hasTag("segregated", "yes") || way.hasTag("bicycle", "yes")) {
// Here we handle the cases where the OSM tagging results in something similar to "highway=cycleway"
speed = highwaySpeeds.get("cycleway");
} else {
speed = PUSHING_SECTION_SPEED;
if (way.hasTag("segregated", "yes"))
speed = highwaySpeeds.get("cycleway");
else
speed = way.hasTag("bicycle", "yes") ? 10 : highwaySpeeds.get("cycleway");

// overwrite our speed again in case we have a valid surface speed and if it is smaller as computed so far
if ((surfaceSpeed > 0) && (surfaceSpeed < speed))
speed = surfaceSpeed;
}
// Increase speed in case of segregated
if (speed <= PUSHING_SECTION_SPEED && way.hasTag("segregated", "yes"))
speed = PUSHING_SECTION_SPEED * 2;
}
return speed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public void testGetSpeed() {
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertPriority(AVOID_IF_POSSIBLE.getValue(), way);

way.clearTags();
way.setTag("highway", "path");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));

way.clearTags();
way.setTag("highway", "secondary");
way.setTag("bicycle", "dismount");
Expand All @@ -74,33 +78,36 @@ public void testGetSpeed() {
way.clearTags();
way.setTag("highway", "footway");
way.setTag("bicycle", "yes");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertEquals(10, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);
way.setTag("segregated", "no");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertEquals(10 , encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);
way.setTag("segregated", "yes");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
assertEquals(18, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);

way.clearTags();
way.setTag("highway", "footway");
way.setTag("surface", "paved");
way.setTag("bicycle", "yes");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertEquals(10, encoder.getSpeed(way));
way.setTag("surface", "cobblestone");
assertEquals(8, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);
way.setTag("segregated", "yes");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
way.setTag("surface", "paved");
assertEquals(18, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);

way.clearTags();
way.setTag("highway", "platform");
way.setTag("surface", "paved");
way.setTag("bicycle", "yes");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertEquals(10, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);
way.setTag("segregated", "yes");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
assertEquals(18, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);

way.clearTags();
Expand Down Expand Up @@ -140,18 +147,18 @@ public void testGetSpeed() {
assertPriority(VERY_NICE.getValue(), way);

way.setTag("bicycle", "yes");
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertEquals(10, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);

way.setTag("segregated", "yes");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
assertEquals(cyclewaySpeed, encoder.getSpeed(way));
assertPriority(PREFER.getValue(), way);

way.setTag("surface", "unpaved");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
assertEquals(14, encoder.getSpeed(way));

way.setTag("surface", "paved");
assertEquals(PUSHING_SECTION_SPEED * 2, encoder.getSpeed(way));
assertEquals(cyclewaySpeed, encoder.getSpeed(way));

way.clearTags();
way.setTag("highway", "path");
Expand Down Expand Up @@ -238,7 +245,7 @@ public void testGetSpeed() {
way.clearTags();
way.setTag("highway", "path");
way.setTag("surface", "ground");
assertEquals(4, encoder.getSpeed(way));
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
assertPriority(AVOID_IF_POSSIBLE.getValue(), way);

way.clearTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ public void testMonacoRacingBike() {
public void testKremsBikeRelation() {
List<OneRun> list = new ArrayList<>();
list.add(new OneRun(48.409523, 15.602394, 48.375466, 15.72916, 12491, 159));
// 3109m is better as cyclepath is used
list.add(new OneRun(48.410061, 15.63951, 48.411386, 15.604899, 3112, 87));
list.add(new OneRun(48.410061, 15.63951, 48.411386, 15.604899, 3077, 79));
list.add(new OneRun(48.412294, 15.62007, 48.398306, 15.609667, 3965, 94));

runAlgo(testCollector, DIR + "/krems.osm.gz", "target/krems-gh",
Expand Down

0 comments on commit b56ae1d

Please sign in to comment.