Skip to content

Commit 3e11d15

Browse files
committed
Modify arterial hierarchy distance from destination based on route lenght
and (later) density at the destination.
1 parent d88b963 commit 3e11d15

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

src/thor/pathalgorithm.cc

+42-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,36 @@ void PathAlgorithm::Init(const PointLL& origll, const PointLL& destll,
156156
hierarchy_limits_ = costing->GetHierarchyLimits();
157157
}
158158

159-
// Calculate best path. This method is single mode, no time dependency.
159+
// Modulate the hierarchy expansion within distance based on density at
160+
// the destination (increase distance for lower densities and decrease
161+
// for higher densities) and the distance between origin and destination
162+
// (increase for shorter distances).
163+
void PathAlgorithm::ModifyHierarchyLimits(const float dist,
164+
const uint32_t density) {
165+
// TODO - default distance below which we increase expansion within
166+
// distance. This is somewhat temporary to address route quality on shorter
167+
// routes - hopefully we will mark the data somehow to indicate how to
168+
// use the hierarchy when approaching the destination (or use a
169+
// bi-directional search without hierarchies for shorter routes).
170+
float factor = 1.0f;
171+
if (25000.0f < dist && dist < 100000.0f) {
172+
factor = std::min(3.0f, 100000.0f / dist);
173+
}
174+
/* TODO - need a reliable density factor near the destination (e.g. tile level?)
175+
// Low density - increase expansion within distance.
176+
// High density - decrease expansion within distance.
177+
if (density < 8) {
178+
float f = 1.0f + (8.0f - density) * 0.125f;
179+
factor *= f;
180+
} else if (density > 8) {
181+
float f = 0.5f + (15.0f - density) * 0.0625;
182+
factor *= f;
183+
}*/
184+
// TODO - just arterial for now...investigate whether to alter local as well
185+
hierarchy_limits_[1].expansion_within_dist *= factor;
186+
}
187+
188+
// Calculate best path. This method is single mode, not time-dependent.
160189
std::vector<PathInfo> PathAlgorithm::GetBestPath(const PathLocation& origin,
161190
const PathLocation& destination, GraphReader& graphreader,
162191
const std::shared_ptr<DynamicCost>& costing) {
@@ -183,7 +212,12 @@ std::vector<PathInfo> PathAlgorithm::GetBestPath(const PathLocation& origin,
183212

184213
// Initialize the origin and destination locations
185214
SetOrigin(graphreader, origin, costing, loop_edge_info);
186-
SetDestination(graphreader, dest, costing);
215+
uint32_t density = SetDestination(graphreader, dest, costing);
216+
217+
// Update hierarchy limits
218+
if (allow_transitions_) {
219+
ModifyHierarchyLimits(mindist, density);
220+
}
187221

188222
// Find shortest path
189223
uint32_t nc = 0; // Count of iterations with no convergence
@@ -706,16 +740,21 @@ void PathAlgorithm::SetOrigin(GraphReader& graphreader,
706740
}
707741

708742
// Add a destination edge
709-
void PathAlgorithm::SetDestination(GraphReader& graphreader,
743+
uint32_t PathAlgorithm::SetDestination(GraphReader& graphreader,
710744
const PathLocation& dest,
711745
const std::shared_ptr<DynamicCost>& costing) {
712746
// For each edge
747+
uint32_t density = 0;
713748
float seconds = 0.0f;
714749
for (const auto& edge : dest.edges()) {
715750
// Keep the id and the cost to traverse the partial distance
716751
const GraphTile* tile = graphreader.GetGraphTile(edge.id);
717752
destinations_[edge.id] = (costing->EdgeCost(tile->directededge(edge.id), 0.0f) * edge.dist);
753+
754+
// Get the tile relative density
755+
density = tile->header()->density();
718756
}
757+
return density;
719758
}
720759

721760
// Test is the shortest path has been found.

valhalla/thor/pathalgorithm.h

+20-4
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,33 @@ class PathAlgorithm {
136136
const baldr::DirectedEdge* edge,
137137
const sif::EdgeLabel& pred, const uint32_t predindex);
138138

139+
/**
140+
* Modify hierarchy limits.
141+
*/
142+
void ModifyHierarchyLimits(const float dist, const uint32_t density);
143+
139144
/**
140145
* Add edges at the origin to the adjacency list
146+
* @param graphreader Graph tile reader.
147+
* @param dest Location information of the destination
148+
* @param costing Dynamic costing
149+
* @param loop_edge Loop edge information
141150
*/
142-
void SetOrigin(baldr::GraphReader& graphreader, const baldr::PathLocation& origin,
143-
const std::shared_ptr<sif::DynamicCost>& costing, const PathInfo& loop_edge);
151+
void SetOrigin(baldr::GraphReader& graphreader,
152+
const baldr::PathLocation& origin,
153+
const std::shared_ptr<sif::DynamicCost>& costing,
154+
const PathInfo& loop_edge);
144155

145156
/**
146157
* Set the destination edge(s).
158+
* @param graphreader Graph tile reader.
159+
* @param dest Location information of the destination
160+
* @param costing Dynamic costing
161+
* @return Returns the relative density near the destination (0-15)
147162
*/
148-
void SetDestination(baldr::GraphReader& graphreader, const baldr::PathLocation& dest,
149-
const std::shared_ptr<sif::DynamicCost>& costing);
163+
uint32_t SetDestination(baldr::GraphReader& graphreader,
164+
const baldr::PathLocation& dest,
165+
const std::shared_ptr<sif::DynamicCost>& costing);
150166

151167
/**
152168
* Return a valid edge id if we've found the destination edge

0 commit comments

Comments
 (0)