Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change treatment of pencil point u-turns to ignore situations where two unnamed roads form the pencil-point #3084

Merged
merged 7 commits into from May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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