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

fixed CostMatrix shapes for routes against trivial oneways #4633

Merged
merged 2 commits into from Mar 18, 2024
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
Expand Up @@ -42,6 +42,7 @@
* FIXED: CostMatrix for trivial routes with oneways [#4626](https://github.com/valhalla/valhalla/pull/4626)
* FIXED: some entry points to creating geotiff isochrones output did not register the geotiff driver before attempting to use it [#4628](https://github.com/valhalla/valhalla/pull/4628)
* FIXED: libgdal wasn't installed in docker image, so it never worked in docker [#4629](https://github.com/valhalla/valhalla/pull/4629)
* FIXED: CostMatrix shapes for routes against trivial oneways [#4633](https://github.com/valhalla/valhalla/pull/4633)
* **Enhancement**
* UPDATED: French translations, thanks to @xlqian [#4159](https://github.com/valhalla/valhalla/pull/4159)
* CHANGED: -j flag for multithreaded executables to override mjolnir.concurrency [#4168](https://github.com/valhalla/valhalla/pull/4168)
Expand Down
7 changes: 4 additions & 3 deletions src/thor/costmatrix.cc
Expand Up @@ -1243,9 +1243,10 @@ std::string CostMatrix::RecostFormPath(GraphReader& graphreader,
auto source_vertex = PointLL{source_edge.ll().lng(), source_edge.ll().lat()};
auto target_vertex = PointLL{target_edge.ll().lng(), target_edge.ll().lat()};
std::vector<PointLL> points;
for (const auto& path_edge : path_edges) {
auto is_first_edge = path_edge == path_edges.front();
auto is_last_edge = path_edge == path_edges.back();
Comment on lines -1247 to -1248
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the case of seemingly trivial routes which go against the oneway, both of these are true and then further down it'd trim the shape according to a trivial route which is not doing the right thing to do. we have to do this index based to really tell if it's the first/last edge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah these needed to be pointer comparison not equality operator

for (uint32_t i = 0; i < path_edges.size(); i++) {
auto& path_edge = path_edges[i];
auto is_first_edge = i == 0;
auto is_last_edge = i == (path_edges.size() - 1);

const auto* de = graphreader.directededge(path_edge, tile);
auto edge_shp = tile->edgeinfo(de).shape();
Expand Down
26 changes: 21 additions & 5 deletions test/gurka/test_matrix.cc
Expand Up @@ -504,8 +504,9 @@ TEST(StandAlone, CostMatrixShapes) {
/*
EXPECT_EQ(result.matrix().shapes(0), encoded);
EXPECT_EQ(res_doc.Parse(res.c_str())["sources_to_targets"].GetArray()[0].GetArray()[0].GetObject()["shape"],
encoded); res.erase();
encoded);
*/
res.erase();

// trivial route reverse
// has a bug: https://github.com/valhalla/valhalla/issues/4433, but it's band-aided for now
Expand All @@ -517,8 +518,9 @@ TEST(StandAlone, CostMatrixShapes) {
/*
EXPECT_EQ(result.matrix().shapes(0), encoded);
EXPECT_EQ(res_doc.Parse(res.c_str())["sources_to_targets"].GetArray()[0].GetArray()[0].GetObject()["shape"],
encoded); res.erase();
encoded);
*/
res.erase();

// timedistancematrix

Expand Down Expand Up @@ -788,19 +790,33 @@ TEST(StandAlone, CostMatrixTrivialRoutes) {
{"CD", {{"highway", "residential"}}}, {"BE", {{"highway", "residential"}}},
{"EF", {{"highway", "residential"}}}, {"FC", {{"highway", "residential"}}},
};
const auto layout = gurka::detail::map_to_coordinates(ascii_map, 100);
auto layout = gurka::detail::map_to_coordinates(ascii_map, 100);
auto map =
gurka::buildtiles(layout, ways, {}, {}, VALHALLA_BUILD_DIR "test/data/costmatrix_trivial");

std::unordered_map<std::string, std::string> options = {{"/shape_format", "polyline6"}};

// test the against-oneway case
{
auto matrix = gurka::do_action(valhalla::Options::sources_to_targets, map, {"1"}, {"2"}, "auto");
auto matrix =
gurka::do_action(valhalla::Options::sources_to_targets, map, {"1"}, {"2"}, "auto", options);
EXPECT_EQ(matrix.matrix().distances(0), 2200);

std::vector<PointLL> oneway_vertices;
for (auto& node : {"1", "C", "F", "E", "B", "2"}) {
oneway_vertices.push_back(layout[node]);
}
auto encoded = encode<std::vector<PointLL>>(oneway_vertices, 1e6);
EXPECT_EQ(matrix.matrix().shapes(0), encoded);
}

// test the normal trivial case
{
auto matrix = gurka::do_action(valhalla::Options::sources_to_targets, map, {"3"}, {"4"}, "auto");
auto matrix =
gurka::do_action(valhalla::Options::sources_to_targets, map, {"3"}, {"4"}, "auto", options);
EXPECT_EQ(matrix.matrix().distances(0), 400);

auto encoded = encode<std::vector<PointLL>>({layout["3"], layout["4"]}, 1e6);
EXPECT_EQ(matrix.matrix().shapes(0), encoded);
}
}