Skip to content

Commit 9c08add

Browse files
committed
Merge pull request #39 from valhalla/dwn
Use meters for distance.
2 parents ea71b1d + a975183 commit 9c08add

7 files changed

+55
-59
lines changed

src/thor/astarheuristic.cc

+28-28
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
using namespace valhalla::midgard;
44

5-
namespace valhalla{
6-
namespace thor{
7-
8-
// Default constructor
9-
AStarHeuristic::AStarHeuristic()
10-
: costfactor_(1.0f) {
11-
}
12-
13-
// Initializes the AStar heuristic
14-
void AStarHeuristic::Init(const PointLL& ll, const float factor) {
15-
distapprox_.SetTestPoint(ll);
16-
costfactor_ = factor;
17-
}
18-
19-
// Ge tthe distance to the destination
20-
float AStarHeuristic::GetDistance(const midgard::PointLL& ll) {
21-
return sqrtf(distapprox_.DistanceSquared(ll));
22-
}
23-
24-
// Get the A* heuristic given the lat,lng.
25-
float AStarHeuristic::Get(const midgard::PointLL& ll) {
26-
return sqrtf(distapprox_.DistanceSquared(ll)) * costfactor_;
27-
}
28-
29-
// Get the A* heuristic given the distance to the destination.
30-
float AStarHeuristic::Get(const float dist) {
31-
return dist * costfactor_;
32-
}
5+
namespace valhalla {
6+
namespace thor {
7+
8+
// Default constructor
9+
AStarHeuristic::AStarHeuristic()
10+
: costfactor_(1.0f) {
11+
}
12+
13+
// Initializes the AStar heuristic
14+
void AStarHeuristic::Init(const PointLL& ll, const float factor) {
15+
distapprox_.SetTestPoint(ll);
16+
costfactor_ = factor;
17+
}
18+
19+
// Ge tthe distance to the destination
20+
float AStarHeuristic::GetDistance(const midgard::PointLL& ll) {
21+
return sqrtf(distapprox_.DistanceSquared(ll));
22+
}
23+
24+
// Get the A* heuristic given the lat,lng.
25+
float AStarHeuristic::Get(const midgard::PointLL& ll) {
26+
return sqrtf(distapprox_.DistanceSquared(ll)) * costfactor_;
27+
}
28+
29+
// Get the A* heuristic given the distance to the destination.
30+
float AStarHeuristic::Get(const float dist) {
31+
return dist * costfactor_;
32+
}
3333

3434
}
3535
}

src/thor/autocost.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ AutoCost::AutoCost()
8585
// Create speed cost table
8686
speedfactor_[0] = kSecPerHour; // TODO - what to make speed=0?
8787
for (uint32_t s = 1; s < 255; s++) {
88-
speedfactor_[s] = kSecPerHour / static_cast<float>(s);
88+
speedfactor_[s] = (kSecPerHour * 0.001f) / static_cast<float>(s);
8989
}
9090
}
9191

@@ -100,25 +100,25 @@ bool AutoCost::Allowed(const baldr::DirectedEdge* edge, const bool uturn,
100100
// Allow upward transitions except when close to the destination
101101
if (edge->trans_up()) {
102102
return (edge->endnode().level() == 0) ?
103-
dist2dest > 50.0f : dist2dest > 10.0f;
103+
dist2dest > 50000.0f : dist2dest > 10000.0f;
104104
}
105105

106106
// Allow downward transitions only when near the destination
107107
if (edge->trans_down()) {
108108
return (edge->endnode().level() == 1) ?
109-
dist2dest < 50.0f : dist2dest < 10.0f;
109+
dist2dest < 50000.0f : dist2dest < 10000.0f;
110110
}
111111

112112
// Skip shortcut edges when near the destination
113-
if (edge->shortcut() && dist2dest < 10.0f)
113+
if (edge->shortcut() && dist2dest < 10000.0f)
114114
return false;
115115

116116
// Do not allow Uturns or entering no-thru edges.
117117
// TODO - evaluate later!
118118
// TODO - until the opp_index is set in the new hierarchies do not test
119119
// for uturn!
120-
// if (uturn || (edge->not_thru() && dist2dest > 5.0))
121-
if ((edge->not_thru() && dist2dest > 5.0)) {
120+
// if (uturn || (edge->not_thru() && dist2dest > 5000.0))
121+
if ((edge->not_thru() && dist2dest > 5000.0)) {
122122
return false;
123123
}
124124
return (edge->forwardaccess() & kAutoAccess);

src/thor/pathalgorithm.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ std::vector<GraphId> PathAlgorithm::GetBestPath(const PathLocation& origin,
127127
}
128128

129129
// Stop expanding the local level once 50 transitions have been made
130-
if (dist2dest > 10.0f && node.level() == 2 && upto1count > 50) {
130+
if (dist2dest > 10000.0f && node.level() == 2 && upto1count > 50) {
131131
continue;
132132
}
133133

134134
// Stop expanding arterial level once 250 transitions have been made
135-
if (dist2dest > 50.0f && node.level() == 1 && upto0count > 250) {
135+
if (dist2dest > 50000.0f && node.level() == 1 && upto0count > 250) {
136136
continue;
137137
}
138138

src/thor/pedestriancost.cc

+9-13
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@ class PedestrianCost : public DynamicCost {
7272
private:
7373
// Walking speed (default to 5.1 km / hour)
7474
float walkingspeed_;
75-
// Favor walkways and paths? (default to 0.95f)
75+
76+
// Favor walkways and paths? (default to 0.9f)
7677
float favorwalkways_;
7778
};
7879

7980
// Constructor
8081
PedestrianCost::PedestrianCost()
8182
: DynamicCost(),
8283
walkingspeed_(5.1f),
83-
favorwalkways_(0.90f) {
84-
84+
favorwalkways_(0.9f) {
8585
//TODO: load up stuff from ptree config
86-
//We want to use walkways
87-
favorwalkways_ = .5f;
8886
}
8987

9088
// Destructor
@@ -122,7 +120,8 @@ float PedestrianCost::Get(const DirectedEdge* edge) const {
122120

123121
// Returns the time (in seconds) to traverse the edge.
124122
float PedestrianCost::Seconds(const baldr::DirectedEdge* edge) const {
125-
return edge->length() / walkingspeed_;
123+
// meters * 3600 sec/hr / 1000 m/km)
124+
return (edge->length() * 3.6f) / walkingspeed_;
126125
}
127126

128127
/**
@@ -134,16 +133,13 @@ float PedestrianCost::Seconds(const baldr::DirectedEdge* edge) const {
134133
* estimate is less than the least possible time along roads.
135134
*/
136135
float PedestrianCost::AStarCostFactor() const {
137-
// Multiplied by the factor used to favor walkways/paths if < 1.0f
138-
if (favorwalkways_ < 1.0f)
139-
return 1.0f * favorwalkways_;
140-
141-
return 1.0f;
136+
// Use the factor to favor walkways/paths if < 1.0f
137+
return (favorwalkways_ < 1.0f) ? favorwalkways_ : 1.0f;
142138
}
143139

144140
float PedestrianCost::UnitSize() const {
145-
// Consider anything within 5 m to be same cost
146-
return 0.005f;
141+
// Consider anything within 2 m to be same cost
142+
return 2.0f;
147143
}
148144

149145
cost_ptr_t CreatePedestrianCost(/*pt::ptree const& config*/){

src/thor/trippathbuilder.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace valhalla {
1010
namespace thor {
1111

12-
// Kilometers offset from start/end of shape for finding heading
13-
constexpr float kKmOffsetForHeading = 0.03f;
12+
// Meters offset from start/end of shape for finding heading
13+
constexpr float kMetersOffsetForHeading =30.0f;
1414

1515
// Default constructor
1616
TripPathBuilder::TripPathBuilder() {
@@ -79,10 +79,10 @@ TripPath TripPathBuilder::Build(GraphReader& graphreader,
7979

8080
trip_edge->set_begin_heading(
8181
std::round(
82-
PointLL::HeadingAlongPolyline(edgeinfo->shape(), kKmOffsetForHeading)));
82+
PointLL::HeadingAlongPolyline(edgeinfo->shape(), kMetersOffsetForHeading)));
8383
trip_edge->set_end_heading(
8484
std::round(
85-
PointLL::HeadingAtEndOfPolyline(edgeinfo->shape(), kKmOffsetForHeading)));
85+
PointLL::HeadingAtEndOfPolyline(edgeinfo->shape(), kMetersOffsetForHeading)));
8686

8787
} else {
8888

@@ -95,13 +95,13 @@ TripPath TripPathBuilder::Build(GraphReader& graphreader,
9595
std::round(
9696
fmod(
9797
(PointLL::HeadingAtEndOfPolyline(edgeinfo->shape(),
98-
kKmOffsetForHeading) + 180.0f), 360)));
98+
kMetersOffsetForHeading) + 180.0f), 360)));
9999

100100
trip_edge->set_end_heading(
101101
std::round(
102102
fmod(
103103
(PointLL::HeadingAlongPolyline(edgeinfo->shape(),
104-
kKmOffsetForHeading) + 180.0f), 360)));
104+
kMetersOffsetForHeading) + 180.0f), 360)));
105105
}
106106
trip_edge->set_end_shape_index(trip_shape.size());
107107

@@ -179,7 +179,7 @@ TripPath_Edge* TripPathBuilder::AddTripEdge(const DirectedEdge* directededge,
179179
}
180180

181181
// Set speed and length
182-
trip_edge->set_length(directededge->length());
182+
trip_edge->set_length(directededge->length() * 0.001f); // Convert to km
183183
trip_edge->set_speed(directededge->speed());
184184

185185
// Test whether edge is traversed forward or reverse and set driveability

valhalla/thor/astarheuristic.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AStarHeuristic {
4646

4747
/**
4848
* Get the A* heuristic given the dstance to the destination.
49-
* @param distance Distance (km) to the destination.
49+
* @param distance Distance (meters) to the destination.
5050
* @return Returns an estimate of the cost to the destination.
5151
* For A* shortest path this MUST UNDERESTIMATE the true cost.
5252
*/

valhalla/thor/edgelabel.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EdgeLabel {
2929
* @param endnode End node of the directed edge.
3030
* @param cost True cost to the edge.
3131
* @param sortcost Cost for sorting (includes A* heuristic)
32-
* @param dist Distance (km) to the destination
32+
* @param dist Distance meters to the destination
3333
*/
3434
EdgeLabel(const uint32_t predecessor, const baldr::GraphId& edgeid,
3535
const baldr::DirectedEdge* edge, const float cost,
@@ -92,7 +92,7 @@ class EdgeLabel {
9292

9393
/**
9494
* Get the distance to the destination.
95-
* @return Returns the distance in km.
95+
* @return Returns the distance in meters.
9696
*/
9797
float distance() const;
9898

0 commit comments

Comments
 (0)