From 0b867183a32d62ccb0aae2c0f974298883df8e37 Mon Sep 17 00:00:00 2001 From: Henadzi Klimuk Date: Thu, 2 Sep 2021 16:35:53 +0300 Subject: [PATCH 1/5] Replace piecewise constant function for sharing with a continuous one --- src/thor/alternates.cc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/thor/alternates.cc b/src/thor/alternates.cc index 876fa843ca..1589dff5c8 100644 --- a/src/thor/alternates.cc +++ b/src/thor/alternates.cc @@ -28,24 +28,18 @@ namespace thor { float get_max_sharing(const valhalla::Location& origin, const valhalla::Location& destination) { PointLL from(origin.path_edges(0).ll().lng(), origin.path_edges(0).ll().lat()); PointLL to(destination.path_edges(0).ll().lng(), destination.path_edges(0).ll().lat()); - auto distance = from.Distance(to); + float distance = from.Distance(to); // 10km - if (distance < 10000.) { - return 0.50; - } - // 20km - else if (distance < 20000.) { - return 0.60; - } - // 50km - else if (distance < 50000.) { - return 0.65; - } + if (distance < 10000.f) + return 0.6f; // 100km - else if (distance < 100000.) { - return 0.70; + if (distance < 100000.f) { + // Uniformly increase 'at_most_shared' value from 0.6 to 0.75 for routes + // from 10km to 100km + return 0.6f + (kAtMostShared - 0.6f) * (distance - 10000.f) / (100000.f - 10000.f); } + // > 100km return kAtMostShared; } From c800b23ed582516d61bd5cb1c10e7d2c233b182a Mon Sep 17 00:00:00 2001 From: Henadzi Klimuk Date: Thu, 2 Sep 2021 16:40:21 +0300 Subject: [PATCH 2/5] Change 'sharing' coefficient calculation Before 'sharing' was defined as a part of shared edges of an alternative candidate. Now it's a part of shared edges of already chosen route. It prevents from getting alternatives with artificial detours. --- src/thor/alternates.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/thor/alternates.cc b/src/thor/alternates.cc index 1589dff5c8..68f9507f44 100644 --- a/src/thor/alternates.cc +++ b/src/thor/alternates.cc @@ -169,20 +169,19 @@ bool validate_alternate_by_sharing(std::vector>& sha // if an edge on the candidate_path is encountered that is also on one of the existing paths, // we count it as a "shared" edge - float shared_length = 0.f, total_length = 0.f; + float shared_length = 0.f; for (const auto& cpi : candidate_path) { const auto length = &cpi == &candidate_path.front() ? cpi.path_distance : cpi.path_distance - (&cpi - 1)->path_distance; - total_length += length; if (shared.find(cpi.edgeid) != shared.end()) { shared_length += length; } } - // throw this alternate away if it shares more than at_most_shared with any of the chosen paths - assert(total_length > 0); - if ((shared_length / total_length) > at_most_shared) { + // throw this alternate away if any of the chosen paths shares more than at_most_shared with it + assert(paths[i].back().path_distance > 0); + if ((shared_length / paths[i].back().path_distance) > at_most_shared) { LOG_DEBUG("Candidate alternate rejected by sharing"); return false; } From 2db88b6f90c42dcb7878d4b4f2691665f95a6469 Mon Sep 17 00:00:00 2001 From: Henadzi Klimuk Date: Thu, 2 Sep 2021 16:49:59 +0300 Subject: [PATCH 3/5] Extend alternatives search to get more routes Changed alternative_cost_extend coefficient from 1.1 to 1.2 --- src/thor/bidirectional_astar.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thor/bidirectional_astar.cc b/src/thor/bidirectional_astar.cc index f312e840dd..cbda27c947 100644 --- a/src/thor/bidirectional_astar.cc +++ b/src/thor/bidirectional_astar.cc @@ -28,7 +28,7 @@ constexpr float kThresholdDelta = 420.0f; // an upper bound value cost for alternative routes we're looking for. Due to the fact that // we can't estimate route cost that goes through some particular edge very precisely, we // can find alternatives with costs greater than the threshold. -constexpr float kAlternativeCostExtend = 1.1f; +constexpr float kAlternativeCostExtend = 1.2f; // Maximum number of additional iterations allowed once the first connection has been found. // For alternative routes we use bigger cost extension than in the case with one route. This // may lead to a significant increase in the number of iterations (~time). So, we should limit From 8483dba2674225da67a25826f6f1c157e0f7fa51 Mon Sep 17 00:00:00 2001 From: Henadzi Klimuk Date: Thu, 2 Sep 2021 18:11:22 +0300 Subject: [PATCH 4/5] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf4dc11fb0..12e2a837c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * ADDED: Add `preferred_layer` as a parameter of loki requests. [#3270](https://github.com/valhalla/valhalla/pull/3270) * ADDED: Exposing service area names in passive maneuvers. [#3277](https://github.com/valhalla/valhalla/pull/3277) * ADDED: Added traffic signal and stop sign check for stop impact. These traffic signals and stop sign are located on edges. [#3279](https://github.com/valhalla/valhalla/pull/3279) + * CHANGED: Improved sharing criterion to obtain more reasonable alternatives; extended alternatives search [#3302](https://github.com/valhalla/valhalla/pull/3302) ## Release Date: 2021-07-20 Valhalla 3.1.3 * **Removed** From 63d3689f414ef6847e4f1dc43d1781123ca09ca3 Mon Sep 17 00:00:00 2001 From: Henadzi Klimuk Date: Mon, 6 Sep 2021 11:45:01 +0300 Subject: [PATCH 5/5] Replace division by path_length with multiplication --- src/thor/alternates.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/thor/alternates.cc b/src/thor/alternates.cc index 68f9507f44..42b2e746ef 100644 --- a/src/thor/alternates.cc +++ b/src/thor/alternates.cc @@ -180,8 +180,7 @@ bool validate_alternate_by_sharing(std::vector>& sha } // throw this alternate away if any of the chosen paths shares more than at_most_shared with it - assert(paths[i].back().path_distance > 0); - if ((shared_length / paths[i].back().path_distance) > at_most_shared) { + if (shared_length > at_most_shared * paths[i].back().path_distance) { LOG_DEBUG("Candidate alternate rejected by sharing"); return false; }