Skip to content

Commit

Permalink
Change treatment of pencil point u-turns to ignore situations where t…
Browse files Browse the repository at this point in the history
…wo unnamed roads form the pencil-point (#3084)

* Fixed a problem where the pencil-point u-turn logic is triggered even when the turn transitions between two unnamed roads.  It now checks to see if the connected edges are named before checking for name consistency.

* Added changelog entry

* Added gurka test

* Applied formatting

* Updated comments

Co-authored-by: Greg Knisely <greg@mapzen.com>
  • Loading branch information
Karim Shehadeh and gknisely committed May 20, 2021
1 parent 56788d4 commit 7e67cf9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## Release Date: 2021-??-?? Valhalla 3.1.2
* **Removed**
* **Bug Fix**
* FIXED: Change unnamed road intersections from being treated as penil point u-turns [#3084](https://github.com/valhalla/valhalla/pull/3084)
* FIXED: Fix TimeDepReverse termination and path cost calculation (for arrive_by routing) [#2987](https://github.com/valhalla/valhalla/pull/2987)
* FIXED: Isochrone (::Generalize()) fix to avoid generating self-intersecting polygons [#3026](https://github.com/valhalla/valhalla/pull/3026)
* FIXED: Handle day_on/day_off/hour_on/hour_off restrictions [#3029](https://github.com/valhalla/valhalla/pull/3029)
Expand Down
86 changes: 86 additions & 0 deletions test/gurka/test_unnamed_pencilpoint_uturns.cc
@@ -0,0 +1,86 @@
#include "gurka.h"
#include <gtest/gtest.h>

#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif

using namespace valhalla;

const std::unordered_map<std::string, std::string> build_config{
{"mjolnir.admin", {VALHALLA_SOURCE_DIR "test/data/netherlands_admin.sqlite"}}};

const std::vector<std::string>& costing = {"auto", "hov", "taxi",
"bus", "truck", "bicycle",
"motor_scooter", "motorcycle", "pedestrian"};

TEST(Standalone, UnnamedPencilPointUturns) {
constexpr double gridsize_metres = 10;

const std::string ascii_map = R"(
A---B\
C---D/ E---F---G
| |
I---H
)";

const gurka::ways ways = {
{"ABE", {{"highway", "primary"}, {"name", ""}, {"oneway", "-1"}}},
{"CDE", {{"highway", "primary"}, {"name", ""}, {"oneway", "yes"}}},
{"EFG", {{"highway", "primary"}, {"name", "Silverbrook Road"}}},
{"GHIF", {{"highway", "secondary"}, {"name", "4th Street"}}},
};

const auto layout =
gurka::detail::map_to_coordinates(ascii_map, gridsize_metres, {5.1079374, 52.0887174});
auto map = gurka::buildtiles(layout, ways, {}, {}, "test/data/gurka_avoid_pencil_point_uturns",
build_config);

for (auto& c : costing) {
auto result = gurka::do_action(valhalla::Options::route, map, {"C", "A"}, c);

if (c == "bicycle") {

// Verify maneuver types
gurka::assert::raw::expect_maneuvers(result, {DirectionsLeg_Maneuver_Type_kStart,
DirectionsLeg_Maneuver_Type_kSharpLeft,
DirectionsLeg_Maneuver_Type_kDestination});

int maneuver_index = 1;

// Verify that it takes the sharp left turn
gurka::assert::raw::expect_instructions_at_maneuver_index(
result, maneuver_index, "Make a sharp left.", "Make a sharp left.",
"Make a sharp left. Then You will arrive at your destination.", "Continue for 50 meters.");
} else if (c == "pedestrian") {

// Verify maneuver types
gurka::assert::raw::expect_maneuvers(result, {DirectionsLeg_Maneuver_Type_kStart,
DirectionsLeg_Maneuver_Type_kSharpLeft,
DirectionsLeg_Maneuver_Type_kDestination});

int maneuver_index = 1;

// Verify that it takes the sharp left turn
gurka::assert::raw::expect_instructions_at_maneuver_index(result, maneuver_index,
"Make a sharp left.",
"Make a sharp left.",
"Make a sharp left.",
"Continue for 50 meters.");
} else {

// Verify maneuver types
gurka::assert::raw::expect_maneuvers(result, {DirectionsLeg_Maneuver_Type_kStart,
DirectionsLeg_Maneuver_Type_kSharpLeft,
DirectionsLeg_Maneuver_Type_kDestination});

int maneuver_index = 1;

// Verify that it takes the sharp left turn
gurka::assert::raw::expect_instructions_at_maneuver_index(
result, maneuver_index, "Make a sharp left.", "Make a sharp left.",
"Make a sharp left. Then You will arrive at your destination.", "Continue for 50 meters.");
}
}
}
4 changes: 2 additions & 2 deletions valhalla/sif/dynamiccost.h
Expand Up @@ -624,7 +624,7 @@ class DynamicCost {
seconds += kTCUnfavorableUturn;
// Did we make a pencil point uturn?
else if (edge->turntype(idx) == baldr::Turn::Type::kSharpLeft && edge->edge_to_right(idx) &&
!edge->edge_to_left(idx) && edge->name_consistency(idx))
!edge->edge_to_left(idx) && edge->named() && edge->name_consistency(idx))
seconds *= kTCUnfavorablePencilPointUturn;
} else {
// Did we make a uturn on a short, internal edge or did we make a uturn at a node.
Expand All @@ -633,7 +633,7 @@ class DynamicCost {
seconds += kTCUnfavorableUturn;
// Did we make a pencil point uturn?
else if (edge->turntype(idx) == baldr::Turn::Type::kSharpRight && !edge->edge_to_right(idx) &&
edge->edge_to_left(idx) && edge->name_consistency(idx))
edge->edge_to_left(idx) && edge->named() && edge->name_consistency(idx))
seconds *= kTCUnfavorablePencilPointUturn;
}
}
Expand Down

0 comments on commit 7e67cf9

Please sign in to comment.