Compare commits

...

14 Commits

Author SHA1 Message Date
Daniel Patterson c49fd202d0 Disable MLD tests so we can get a macOS build completed. 2019-02-10 02:37:29 -08:00
Daniel Patterson 49e40ee621 Bump version again. 2019-02-10 02:36:27 -08:00
Daniel Patterson a89d0e616f Fix node bindings and test cases that would've caught it. 2019-02-10 02:36:16 -08:00
Daniel Patterson 986252c4f9 Quick fix for negative distances bug. 2019-02-10 02:09:30 -08:00
Daniel Patterson aed7df6173 New build with fixed tests. 2019-02-10 01:07:33 -08:00
Daniel Patterson e3b09875c6 Fix nodejs tests. 2019-02-10 01:06:54 -08:00
Daniel Patterson 52ceea429b Bump version. 2019-02-10 00:54:35 -08:00
Kevin Kreiser 3d4d51d6b7 Consider acceleration profile of vehicle travelling - particularly affects very short routes. 2019-02-10 00:53:40 -08:00
Daniel Patterson 23c69f4c3d Revert "Add stoppage penalty - consider acceleration and braking time, which can dominate short route ETAs."
This reverts commit 05647adcc6.
2019-02-10 00:42:47 -08:00
Daniel Patterson 9d044bf388 Revert "Fix swapped variables, new version."
This reverts commit 67e99c9809.
2019-02-10 00:42:46 -08:00
Daniel Patterson 823d7e45e7 Revert "change phantom node to store an appx speed regardless of direction. use this speed to estimate an accel/decel penalty and scale the penalty based on the distance traveled up to a cutoff. only used in the table plugin at the moment. TODO still lives in the guidance assemble_leg area"
This reverts commit ca55521c87.
2019-02-10 00:42:10 -08:00
Daniel Patterson 6b961dccfc Revert "Add a bunch of tests at different scales. Switch to using linear acceleration estimates to add penalties to start/end of trips."
This reverts commit 6b9006f6e7.
2019-02-10 00:42:08 -08:00
Daniel Patterson 44d4903985 Bump another test release. 2019-02-09 02:55:39 -08:00
Daniel Patterson 55e05b70ac Revert accidental change. 2019-02-09 02:55:18 -08:00
22 changed files with 344 additions and 534 deletions
+33 -33
View File
@@ -59,16 +59,16 @@ Feature: Testbot - Acceleration profiles
| a | 0 | 0 | 0.1 | 0.1 | 0.2 | 0.3 | 0.3 | 0.4 | 0.4 | 0.5 | 0.6 |
| 1 | 0 | 0 | 0.1 | 0.1 | 0.2 | 0.3 | 0.3 | 0.4 | 0.4 | 0.5 | 0.6 |
| 2 | 0.1 | 0.1 | 0 | 0 | 0.1 | 0.2 | 0.2 | 0.3 | 0.3 | 0.4 | 0.5 |
| 3 | 0.2 | 0.2 | 0 | 0 | 0.1 | 0.2 | 0.2 | 0.3 | 0.3 | 0.4 | 0.5 |
| 3 | 0.2 | 0.2 | 0.1 | 0 | 0.1 | 0.2 | 0.2 | 0.3 | 0.3 | 0.4 | 0.5 |
| 4 | 0.3 | 0.3 | 0.2 | 0.1 | 0 | 0.1 | 0.1 | 0.2 | 0.2 | 0.3 | 0.4 |
| 5 | 0.4 | 0.4 | 0.3 | 0.2 | 0.1 | 0 | 0 | 0.1 | 0.1 | 0.2 | 0.3 |
| 6 | 0.4 | 0.4 | 0.3 | 0.2 | 0.1 | 0 | 0 | 0.1 | 0.1 | 0.2 | 0.3 |
| 7 | 0.5 | 0.5 | 0.4 | 0.3 | 0.2 | 0.1 | 0.1 | 0 | 0 | 0.1 | 0.2 |
| 8 | 0.6 | 0.6 | 0.5 | 0.4 | 0.3 | 0.2 | 0.2 | 0 | 0 | 0.1 | 0.2 |
| 8 | 0.6 | 0.6 | 0.5 | 0.4 | 0.3 | 0.2 | 0.2 | 0.1 | 0 | 0.1 | 0.2 |
| 9 | 0.7 | 0.7 | 0.6 | 0.5 | 0.4 | 0.3 | 0.3 | 0.2 | 0.1 | 0 | 0.1 |
| b | 0.8 | 0.8 | 0.7 | 0.6 | 0.5 | 0.4 | 0.4 | 0.3 | 0.2 | 0.1 | 0 |
Scenario: Testbot - No stoppage points, tiny grid size
Scenario: Testbot - With stoppage points, tiny grid size
Given a grid size of 1 meters
Given the node map
"""
@@ -80,21 +80,21 @@ Feature: Testbot - Acceleration profiles
| ab | trunk | 60 | 45 |
And the query options
| stoppage_penalty | 1.85,15 |
| acceleration_profile | car |
When I request a travel time matrix I should get
| | a | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | b |
| a | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 | 3.6 | 3.8 | 4.1 | 4.4 | 4.6 |
| 1 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 | 3.6 | 3.8 | 4.1 | 4.4 |
| 2 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 | 3.6 | 3.8 | 4.1 |
| 3 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 | 3.6 | 3.8 |
| 4 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 | 3.6 |
| 5 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 | 3.2 |
| 6 | 3.6 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 | 2.9 |
| 7 | 3.8 | 3.6 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 | 2.5 |
| 8 | 4.1 | 3.8 | 3.6 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 | 2 |
| 9 | 4.4 | 4.1 | 3.8 | 3.6 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 | 1.4 |
| b | 4.6 | 4.4 | 4.1 | 3.8 | 3.6 | 3.2 | 2.9 | 2.5 | 2 | 1.4 | 0 |
| | a | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | b |
| a | 0 | 1.1 | 1.7 | 2.1 | 2.4 | 2.6 | 2.9 | 3.1 | 3.4 | 3.5 | 3.7 |
| 1 | 1.1 | 0 | 1.1 | 1.7 | 2 | 2.3 | 2.6 | 2.8 | 3.1 | 3.3 | 3.5 |
| 2 | 1.7 | 1.1 | 0 | 1.1 | 1.7 | 2 | 2.4 | 2.6 | 2.9 | 3.1 | 3.3 |
| 3 | 2 | 1.5 | 1.1 | 0 | 1.1 | 1.5 | 2 | 2.3 | 2.6 | 2.8 | 3 |
| 4 | 2.3 | 1.9 | 1.5 | 1.1 | 0 | 1.1 | 1.7 | 2 | 2.4 | 2.6 | 2.8 |
| 5 | 2.5 | 2.2 | 1.9 | 1.5 | 1.1 | 0 | 1.1 | 1.7 | 2.1 | 2.4 | 2.6 |
| 6 | 2.8 | 2.5 | 2.3 | 2 | 1.7 | 1.1 | 0 | 1.1 | 1.7 | 2 | 2.3 |
| 7 | 3 | 2.8 | 2.5 | 2.3 | 2 | 1.7 | 1.1 | 0 | 1.1 | 1.7 | 2 |
| 8 | 3.2 | 3 | 2.8 | 2.5 | 2.3 | 2 | 1.5 | 1.1 | 0 | 1.1 | 1.5 |
| 9 | 3.4 | 3.2 | 3 | 2.8 | 2.5 | 2.3 | 1.9 | 1.5 | 1.1 | 0 | 1.1 |
| b | 3.6 | 3.4 | 3.2 | 3 | 2.8 | 2.5 | 2.2 | 1.9 | 1.5 | 1.1 | 0 |
Scenario: Testbot - Use stoppage penalty at waypoints
@@ -109,17 +109,17 @@ Feature: Testbot - Acceleration profiles
| ab | trunk | 60 | 45 |
And the query options
| stoppage_penalty | 1.85,15 |
| acceleration_profile | car |
When I request a travel time matrix I should get
| | a | 1 | 2 | 3 | 4 | 5 | b |
| a | 0 | 4.6 | 6.5 | 8 | 9.3 | 10.4 | 11.3 |
| 1 | 4.6 | 0 | 4.6 | 6.5 | 8 | 9.3 | 10.3 |
| 2 | 6.5 | 4.6 | 0 | 4.6 | 6.5 | 8 | 9.2 |
| 3 | 8 | 6.5 | 4.6 | 0 | 4.6 | 6.5 | 8 |
| 4 | 9.3 | 8 | 6.5 | 4.6 | 0 | 4.6 | 6.5 |
| 5 | 10.4 | 9.3 | 8 | 6.5 | 4.6 | 0 | 4.6 |
| b | 11.3 | 10.3 | 9.2 | 8 | 6.5 | 4.6 | 0 |
| | a | 1 | 2 | 3 | 4 | 5 | b |
| a | 0 | 3.7 | 5.3 | 6.5 | 7.5 | 8.4 | 9.1 |
| 1 | 3.6 | 0 | 3.7 | 5.3 | 6.5 | 7.5 | 8.3 |
| 2 | 5.1 | 3.6 | 0 | 3.7 | 5.3 | 6.5 | 7.5 |
| 3 | 6.3 | 5.1 | 3.6 | 0 | 3.7 | 5.3 | 6.4 |
| 4 | 7.2 | 6.3 | 5.1 | 3.6 | 0 | 3.7 | 5.2 |
| 5 | 8.1 | 7.2 | 6.3 | 5.1 | 3.6 | 0 | 3.7 |
| b | 8.9 | 8.1 | 7.2 | 6.2 | 5.1 | 3.6 | 0 |
Scenario: Long distance grid with no penalty
@@ -155,14 +155,14 @@ Feature: Testbot - Acceleration profiles
| ab | trunk | 60 | 45 |
And the query options
| stoppage_penalty | 1.85,15 |
| acceleration_profile | car |
When I request a travel time matrix I should get
| | a | 1 | 2 | 3 | 4 | 5 | b |
| a | 0 | 68.9 | 128.9 | 188.9 | 248.9 | 308.9 | 368.9 |
| 1 | 86.6 | 0 | 69 | 129 | 189 | 249 | 309 |
| 2 | 166.6 | 86.7 | 0 | 69 | 129 | 189 | 249 |
| 3 | 246.6 | 166.7 | 86.7 | 0 | 69 | 129 | 189 |
| 4 | 326.6 | 246.7 | 166.7 | 86.7 | 0 | 69 | 129 |
| 5 | 406.6 | 326.7 | 246.7 | 166.7 | 86.7 | 0 | 69 |
| b | 486.6 | 406.7 | 326.7 | 246.7 | 166.7 | 86.7 | 0 |
| a | 0 | 65.1 | 125.1 | 185.1 | 245.1 | 305.1 | 365.1 |
| 1 | 83.7 | 0 | 65.2 | 125.2 | 185.2 | 245.2 | 305.2 |
| 2 | 163.7 | 83.8 | 0 | 65.2 | 125.2 | 185.2 | 245.2 |
| 3 | 243.7 | 163.8 | 83.8 | 0 | 65.2 | 125.2 | 185.2 |
| 4 | 323.7 | 243.8 | 163.8 | 83.8 | 0 | 65.2 | 125.2 |
| 5 | 403.7 | 323.8 | 243.8 | 163.8 | 83.8 | 0 | 65.2 |
| b | 483.7 | 403.8 | 323.8 | 243.8 | 163.8 | 83.8 | 0 |
+7 -13
View File
@@ -81,8 +81,8 @@ struct BaseParameters
bool generate_hints = true;
SnappingType snapping = SnappingType::Default;
double min_stoppage_penalty = INVALID_MINIMUM_STOPPAGE_PENALTY;
double max_stoppage_penalty = INVALID_MAXIMUM_STOPPAGE_PENALTY;
// Whether or not to add acceleration/decelleration penalties at waypoints
double waypoint_acceleration_factor = 0.;
BaseParameters(const std::vector<util::Coordinate> coordinates_ = {},
const std::vector<boost::optional<Hint>> hints_ = {},
@@ -92,22 +92,16 @@ struct BaseParameters
bool generate_hints_ = true,
std::vector<std::string> exclude = {},
const SnappingType snapping_ = SnappingType::Default,
double min_stoppage_penalty_ = INVALID_MINIMUM_STOPPAGE_PENALTY,
double max_stoppage_penalty_ = INVALID_MAXIMUM_STOPPAGE_PENALTY)
bool waypoint_acceleration_factor_ = 0.)
: coordinates(coordinates_), hints(hints_), radiuses(radiuses_), bearings(bearings_),
approaches(approaches_), exclude(std::move(exclude)), generate_hints(generate_hints_),
snapping(snapping_), min_stoppage_penalty(min_stoppage_penalty_),
max_stoppage_penalty(max_stoppage_penalty_)
snapping(snapping_), waypoint_acceleration_factor(waypoint_acceleration_factor_)
{
}
// FIXME add validation for invalid bearing values
bool IsValid() const
{
if (min_stoppage_penalty <= 0 || max_stoppage_penalty <= 0 ||
min_stoppage_penalty > max_stoppage_penalty)
return false;
return (hints.empty() || hints.size() == coordinates.size()) &&
(bearings.empty() || bearings.size() == coordinates.size()) &&
(radiuses.empty() || radiuses.size() == coordinates.size()) &&
@@ -123,8 +117,8 @@ struct BaseParameters
});
}
};
} // namespace api
} // namespace engine
} // namespace osrm
}
}
}
#endif // ROUTE_PARAMETERS_HPP
+5 -3
View File
@@ -78,6 +78,7 @@ struct TableParameters : public BaseParameters
};
AnnotationsType annotations = AnnotationsType::Duration;
double scale_factor = 1;
TableParameters() = default;
@@ -112,6 +113,7 @@ struct TableParameters : public BaseParameters
destinations{std::move(destinations_)}, fallback_speed{fallback_speed_},
fallback_coordinate_type{fallback_coordinate_type_}, annotations{annotations_},
scale_factor{scale_factor_}
{
}
@@ -164,8 +166,8 @@ inline TableParameters::AnnotationsType &operator|=(TableParameters::Annotations
{
return lhs = lhs | rhs;
}
} // namespace api
} // namespace engine
} // namespace osrm
}
}
}
#endif // ENGINE_API_TABLE_PARAMETERS_HPP
@@ -384,84 +384,54 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
input_coordinate, max_results, max_distance, bearing, bearing_range, approach);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const override final
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const Approach approach,
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate,
approach,
use_all_edges,
minimum_stoppage_penalty,
maximum_stoppage_penalty);
input_coordinate, approach, use_all_edges);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const override final
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate,
max_distance,
approach,
use_all_edges,
minimum_stoppage_penalty,
maximum_stoppage_penalty);
input_coordinate, max_distance, approach, use_all_edges);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const override final
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate,
max_distance,
bearing,
bearing_range,
approach,
use_all_edges,
minimum_stoppage_penalty,
maximum_stoppage_penalty);
input_coordinate, max_distance, bearing, bearing_range, approach, use_all_edges);
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const override final
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate,
bearing,
bearing_range,
approach,
use_all_edges,
minimum_stoppage_penalty,
maximum_stoppage_penalty);
input_coordinate, bearing, bearing_range, approach, use_all_edges);
}
std::uint32_t GetCheckSum() const override final { return m_check_sum; }
+22 -30
View File
@@ -157,36 +157,28 @@ class BaseDataFacade
const double max_distance,
const Approach approach) const = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const = 0;
virtual std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double minimum_stoppage_penalty,
const double maximum_stoppage_penalty) const = 0;
virtual std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const Approach approach,
const bool use_all_edges) const = 0;
virtual std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges) const = 0;
virtual std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges) const = 0;
virtual std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges = false) const = 0;
virtual bool HasLaneData(const EdgeID id) const = 0;
virtual util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const = 0;
+35 -92
View File
@@ -206,9 +206,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges,
const double min_stoppage_penalty,
const double max_stoppage_penalty) const
const bool use_all_edges) const
{
bool has_small_component = false;
bool has_big_component = false;
@@ -250,13 +248,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
BOOST_ASSERT(results.size() == 1 || results.size() == 2);
return std::make_pair(
MakePhantomNode(
input_coordinate, results.front(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node,
MakePhantomNode(
input_coordinate, results.back(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
MakePhantomNode(input_coordinate, results.back()).phantom_node);
}
// Returns the nearest phantom node. If this phantom node is not from a big component
@@ -264,9 +257,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const Approach approach,
const bool use_all_edges,
const double min_stoppage_penalty,
const double max_stoppage_penalty) const
const bool use_all_edges) const
{
bool has_small_component = false;
bool has_big_component = false;
@@ -307,13 +298,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
BOOST_ASSERT(results.size() == 1 || results.size() == 2);
return std::make_pair(
MakePhantomNode(
input_coordinate, results.front(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node,
MakePhantomNode(
input_coordinate, results.back(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
MakePhantomNode(input_coordinate, results.back()).phantom_node);
}
// Returns the nearest phantom node. If this phantom node is not from a big component
@@ -323,9 +309,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double min_stoppage_penalty,
const double max_stoppage_penalty) const
const bool use_all_edges) const
{
bool has_small_component = false;
bool has_big_component = false;
@@ -373,13 +357,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
BOOST_ASSERT(results.size() > 0);
return std::make_pair(
MakePhantomNode(
input_coordinate, results.front(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node,
MakePhantomNode(
input_coordinate, results.back(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
MakePhantomNode(input_coordinate, results.back()).phantom_node);
}
// Returns the nearest phantom node. If this phantom node is not from a big component
@@ -390,9 +369,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges,
const double min_stoppage_penalty,
const double max_stoppage_penalty) const
const bool use_all_edges) const
{
bool has_small_component = false;
bool has_big_component = false;
@@ -442,13 +419,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
BOOST_ASSERT(results.size() > 0);
return std::make_pair(
MakePhantomNode(
input_coordinate, results.front(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node,
MakePhantomNode(
input_coordinate, results.back(), min_stoppage_penalty, max_stoppage_penalty)
.phantom_node);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
MakePhantomNode(input_coordinate, results.back()).phantom_node);
}
private:
@@ -466,11 +438,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return distance_and_phantoms;
}
// TODO: remove stoppage penalty as its not needed here anymore
PhantomNodeWithDistance MakePhantomNode(const util::Coordinate input_coordinate,
const EdgeData &data,
const double min_stoppage_penalty = 0,
const double max_stoppage_penalty = 0) const
const EdgeData &data) const
{
util::Coordinate point_on_segment;
double ratio;
@@ -509,21 +478,16 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
forward_durations.begin() + data.fwd_segment_position,
EdgeDuration{0});
// For measuring distance from begin up to end
const auto appx_distance = [this](decltype(forward_geometry.begin()) begin,
decltype(forward_geometry.begin()) end) {
EdgeDistance dist = 0;
for (; begin != end; ++begin)
{
dist += util::coordinate_calculation::fccApproximateDistance(
datafacade.GetCoordinateOfNode(*begin),
datafacade.GetCoordinateOfNode(*std::next(begin)));
}
return dist;
};
EdgeDistance forward_distance_offset = appx_distance(
forward_geometry.begin(), forward_geometry.begin() + data.fwd_segment_position);
EdgeDistance forward_distance_offset = 0;
// Sum up the distance from the start to the fwd_segment_position
for (auto current = forward_geometry.begin();
current < forward_geometry.begin() + data.fwd_segment_position;
++current)
{
forward_distance_offset += util::coordinate_calculation::fccApproximateDistance(
datafacade.GetCoordinateOfNode(*current),
datafacade.GetCoordinateOfNode(*std::next(current)));
}
BOOST_ASSERT(data.fwd_segment_position <
std::distance(forward_durations.begin(), forward_durations.end()));
@@ -544,9 +508,16 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
reverse_durations.end() - data.fwd_segment_position - 1,
EdgeDuration{0});
EdgeDistance reverse_distance_offset =
appx_distance(forward_geometry.begin() + data.fwd_segment_position + 1,
std::prev(forward_geometry.end()));
EdgeDistance reverse_distance_offset = 0;
// Sum up the distance from just after the fwd_segment_position to the end
for (auto current = forward_geometry.begin() + data.fwd_segment_position + 1;
current != std::prev(forward_geometry.end());
++current)
{
reverse_distance_offset += util::coordinate_calculation::fccApproximateDistance(
datafacade.GetCoordinateOfNode(*current),
datafacade.GetCoordinateOfNode(*std::next(current)));
}
EdgeWeight reverse_weight =
reverse_weights[reverse_weights.size() - data.fwd_segment_position - 1];
@@ -556,43 +527,16 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
point_on_segment,
datafacade.GetCoordinateOfNode(forward_geometry(data.fwd_segment_position + 1)));
// We may end up adding a stoppage penalty
double forward_speed = 0;
double reverse_speed = 0;
auto total_distance = 0;
auto penalty_range = max_stoppage_penalty - min_stoppage_penalty;
ratio = std::min(1.0, std::max(0.0, ratio));
if (data.forward_segment_id.id != SPECIAL_SEGMENTID)
{
forward_weight = static_cast<EdgeWeight>(forward_weight * ratio);
forward_duration = static_cast<EdgeDuration>(forward_duration * ratio);
// Stoppage penalty based on speed
if (data.forward_segment_id.enabled && penalty_range > 0)
{
total_distance =
appx_distance(forward_geometry.begin(), std::prev(forward_geometry.end()));
const auto total_duration = std::accumulate(
forward_durations.begin(), forward_durations.end(), EdgeDuration{0});
forward_speed = total_distance / (total_duration * 0.1);
reverse_speed = forward_speed;
}
}
if (data.reverse_segment_id.id != SPECIAL_SEGMENTID)
{
reverse_weight -= static_cast<EdgeWeight>(reverse_weight * ratio);
reverse_duration -= static_cast<EdgeDuration>(reverse_duration * ratio);
// Stoppage penalty based on speed
if (data.reverse_segment_id.enabled && penalty_range > 0)
{
if (total_distance == 0)
total_distance =
appx_distance(forward_geometry.begin(), std::prev(forward_geometry.end()));
const auto total_duration = std::accumulate(
reverse_durations.begin(), reverse_durations.end(), EdgeDuration{0});
reverse_speed = total_distance / (total_duration * 0.1);
if (forward_speed == 0)
forward_speed = reverse_speed;
}
}
// check phantom node segments validity
@@ -623,7 +567,6 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
reverse_duration,
forward_duration_offset,
reverse_duration_offset,
static_cast<float>((forward_speed + reverse_speed) / 2.0),
is_forward_valid_source,
is_forward_valid_target,
is_reverse_valid_source,
@@ -774,7 +717,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const CoordinateList &coordinates;
DataFacadeT &datafacade;
};
} // namespace engine
} // namespace osrm
}
}
#endif
+2 -5
View File
@@ -122,7 +122,7 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const datafacade::BaseDa
[](const NamedSegment &segment) { return segment.name_id; });
return summary;
}
} // namespace detail
}
inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
const std::vector<PathData> &route_data,
@@ -166,7 +166,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
// `forward_duration`: duration of (d,t)
// `forward_offset`: duration of (c, d)
// path_data will have entries for (s,b), (b, c), (c, d) but (d, t) is only
// captured by the phantom node. So we need to add the target duration here.
// caputed by the phantom node. So we need to add the target duration here.
// On local segments, the target duration is already part of the duration, however.
duration = duration + target_duration;
@@ -182,9 +182,6 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
duration = std::max(0, duration);
}
// TODO: Add start and stop penalties to the duration to simulate accel/deceleration
//
std::string summary;
if (needs_summary)
{
+4 -4
View File
@@ -63,11 +63,11 @@ struct Hint
friend std::ostream &operator<<(std::ostream &, const Hint &);
};
static_assert(sizeof(Hint) == sizeof(PhantomNode) + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 120;
static_assert(sizeof(Hint) == 80 + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 112;
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
"ENCODED_HINT_SIZE does not match size of Hint");
} // namespace engine
} // namespace osrm
}
}
#endif
+22 -28
View File
@@ -44,15 +44,14 @@ namespace engine
struct PhantomNode
{
PhantomNode()
: forward_segment_id{SPECIAL_SEGMENTID, false}, reverse_segment_id{SPECIAL_SEGMENTID,
false},
forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT),
forward_weight_offset(0), reverse_weight_offset(0),
: forward_segment_id{SPECIAL_SEGMENTID, false},
reverse_segment_id{SPECIAL_SEGMENTID, false}, forward_weight(INVALID_EDGE_WEIGHT),
reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0),
forward_distance(INVALID_EDGE_DISTANCE), reverse_distance(INVALID_EDGE_DISTANCE),
forward_distance_offset(0), reverse_distance_offset(0),
forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION),
forward_duration_offset(0), reverse_duration_offset(0), speed_approximation(0),
fwd_segment_position(0), is_valid_forward_source{false}, is_valid_forward_target{false},
forward_duration_offset(0), reverse_duration_offset(0), fwd_segment_position(0),
is_valid_forward_source{false}, is_valid_forward_target{false},
is_valid_reverse_source{false}, is_valid_reverse_target{false}, bearing(0)
{
@@ -70,13 +69,13 @@ struct PhantomNode
return reverse_weight_offset + reverse_weight;
}
EdgeDuration GetForwardDuration() const
EdgeWeight GetForwardDuration() const
{
BOOST_ASSERT(forward_segment_id.enabled);
return forward_duration + forward_duration_offset;
}
EdgeDuration GetReverseDuration() const
EdgeWeight GetReverseDuration() const
{
BOOST_ASSERT(reverse_segment_id.enabled);
return reverse_duration + reverse_duration_offset;
@@ -110,9 +109,8 @@ struct PhantomNode
bool IsValid(const unsigned number_of_nodes) const
{
return location.IsValid() &&
((forward_segment_id.id < number_of_nodes) ||
(reverse_segment_id.id < number_of_nodes)) &&
return location.IsValid() && ((forward_segment_id.id < number_of_nodes) ||
(reverse_segment_id.id < number_of_nodes)) &&
((forward_weight != INVALID_EDGE_WEIGHT) ||
(reverse_weight != INVALID_EDGE_WEIGHT)) &&
((forward_duration != MAXIMAL_EDGE_DURATION) ||
@@ -165,11 +163,10 @@ struct PhantomNode
EdgeDistance reverse_distance,
EdgeDistance forward_distance_offset,
EdgeDistance reverse_distance_offset,
EdgeDuration forward_duration,
EdgeDuration reverse_duration,
EdgeDuration forward_duration_offset,
EdgeDuration reverse_duration_offset,
EdgeDistance speed_approximation,
EdgeWeight forward_duration,
EdgeWeight reverse_duration,
EdgeWeight forward_duration_offset,
EdgeWeight reverse_duration_offset,
bool is_valid_forward_source,
bool is_valid_forward_target,
bool is_valid_reverse_source,
@@ -185,9 +182,8 @@ struct PhantomNode
reverse_distance_offset{reverse_distance_offset}, forward_duration{forward_duration},
reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset},
reverse_duration_offset{reverse_duration_offset},
speed_approximation{speed_approximation}, component{component.id, component.is_tiny},
location{location}, input_location{input_location},
fwd_segment_position{other.fwd_segment_position},
component{component.id, component.is_tiny}, location{location},
input_location{input_location}, fwd_segment_position{other.fwd_segment_position},
is_valid_forward_source{is_valid_forward_source},
is_valid_forward_target{is_valid_forward_target},
is_valid_reverse_source{is_valid_reverse_source},
@@ -205,12 +201,10 @@ struct PhantomNode
EdgeDistance reverse_distance;
EdgeDistance forward_distance_offset; // TODO: try to remove -> requires path unpacking changes
EdgeDistance reverse_distance_offset; // TODO: try to remove -> requires path unpacking changes
EdgeDuration forward_duration;
EdgeDuration reverse_duration;
EdgeDuration forward_duration_offset; // TODO: try to remove -> requires path unpacking changes
EdgeDuration reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes
EdgeDistance speed_approximation; // m/s
EdgeWeight forward_duration;
EdgeWeight reverse_duration;
EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes
EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes
ComponentID component;
util::Coordinate location; // this is the coordinate of x
@@ -225,7 +219,7 @@ struct PhantomNode
unsigned short bearing : 12;
};
static_assert(sizeof(PhantomNode) == 84, "PhantomNode has more padding then expected");
static_assert(sizeof(PhantomNode) == 80, "PhantomNode has more padding then expected");
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
@@ -240,7 +234,7 @@ struct PhantomNodes
PhantomNode source_phantom;
PhantomNode target_phantom;
};
} // namespace engine
} // namespace osrm
}
}
#endif // PHANTOM_NODES_H
+4 -14
View File
@@ -298,9 +298,7 @@ class BasePlugin
parameters.bearings[i]->bearing,
parameters.bearings[i]->range,
approach,
use_all_edges,
parameters.min_stoppage_penalty,
parameters.max_stoppage_penalty);
use_all_edges);
}
else
{
@@ -310,9 +308,7 @@ class BasePlugin
parameters.bearings[i]->bearing,
parameters.bearings[i]->range,
approach,
use_all_edges,
parameters.min_stoppage_penalty,
parameters.max_stoppage_penalty);
use_all_edges);
}
}
else
@@ -324,19 +320,13 @@ class BasePlugin
parameters.coordinates[i],
*parameters.radiuses[i],
approach,
use_all_edges,
parameters.min_stoppage_penalty,
parameters.max_stoppage_penalty);
use_all_edges);
}
else
{
phantom_node_pairs[i] =
facade.NearestPhantomNodeWithAlternativeFromBigComponent(
parameters.coordinates[i],
approach,
use_all_edges,
parameters.min_stoppage_penalty,
parameters.max_stoppage_penalty);
parameters.coordinates[i], approach, use_all_edges);
}
}
-81
View File
@@ -1,81 +0,0 @@
#include "util/typedefs.h"
namespace osrm
{
namespace extractor
{
namespace
{
constexpr int 5_MINUTE_BUCKETS_PER_WEEK = 2016;
constexpr int 1_HOUR_BUCKETS_PER_WEEK = 168;
} // namespace
/**
* Represents a simple piecewise linear function
* (https://en.wikipedia.org/wiki/Piecewise_linear_function)
* in the form of a regularly spaced set of buckets.
* Assumes that the spacing between buckets is equal.
*/
template <typename DataType, int BUCKETCOUNT> struct PiecewiseLinearFunction
{
std::array<DataType, BUCKETCOUNT> sample;
inline DataType getAt(float position)
{
// Range check
assert(position >= 0);
assert(position < BUCKETCOUNT - 1);
}
PiecewiseLinearFunction<DataType, BUCKETCOUNT>
merge(PiecewiseLinearFunction<DataType, BUCKETCOUNT> &other, float offset)
{
PiecewiseLinearFunction result;
for (int i = 0; i < BUCKETCOUNT; i++)
{
for (int j = offset; j < BUCKETCOUNT + offset; j++)
{
result.sample[i] = sample[i] + other.sample[j % BUCKETCOUNT];
}
}
return std::move(result);
}
}
/**
* Represents variances in the default `.duration` of an edge
* over the space of a week.
*/
struct WeeklySpeedProfile
{
using Multiplier = std::uint8_t;
private:
PiecewiseLinearFunction<Multiplier, 1_HOUR_BUCKETS_PER_WEEK> fn;
public:
SpeedProfile() : min(0), max(0) { multipliers.fill(0); }
SpeedProfile(const std::array<Multiplier, BUCKETS> &other)
{
fn.samples = other;
min = std::min(samples);
max = std::max(samples);
}
inline EdgeDuration adjust(const EdgeDuration &original, const int bucket) const
{
// Treat Multiplier as an 8-bit fixed-point value.
EdgeDuration new_value = (original * multipliers[bucket]);
}
inline EdgeDuration min(const EdgeDuration original) const {}
inline EdgeDuration max(const EdgeDuration original) const {}
duration = m * e1 + m2 * e2
};
} // namespace extractor
} // namespace osrm
+29 -32
View File
@@ -721,49 +721,46 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
}
}
if (obj->Has(Nan::New("stoppage_penalty").ToLocalChecked()))
if (obj->Has(Nan::New("acceleration_profile").ToLocalChecked()))
{
v8::Local<v8::Value> stoppage_penalty =
obj->Get(Nan::New("stoppage_penalty").ToLocalChecked());
if (stoppage_penalty.IsEmpty())
v8::Local<v8::Value> acceleration_profile =
obj->Get(Nan::New("acceleration_profile").ToLocalChecked());
if (acceleration_profile.IsEmpty())
return false;
if (!stoppage_penalty->IsArray())
if (!acceleration_profile->IsNumber() && !acceleration_profile->IsString())
{
Nan::ThrowError("Stoppage penalty must be an array of 2 numbers [min,max]");
Nan::ThrowError("acceleration_profile must be a decimal number or one of 'car', 'fast_car', 'slow_car', 'truck', or 'tractor_trailer'");
return false;
}
auto stoppage_penalty_array = v8::Local<v8::Array>::Cast(stoppage_penalty);
if (acceleration_profile->IsString()) {
std::string ssaf = *v8::String::Utf8Value(acceleration_profile);
// If they say 'yes', they get the default
if (ssaf == "car") {
params->waypoint_acceleration_factor = ACCELERATION_ALPHA_CAR;
} else if (ssaf == "fast_car") {
params->waypoint_acceleration_factor = ACCELERATION_ALPHA_FAST_CAR;
} else if (ssaf == "slow_car") {
params->waypoint_acceleration_factor = ACCELERATION_ALPHA_SLOW_CAR;
} else if (ssaf == "truck") {
params->waypoint_acceleration_factor = ACCELERATION_ALPHA_TRUCK;
} else if (ssaf == "tractor_trailer") {
params->waypoint_acceleration_factor = ACCELERATION_ALPHA_TRACTOR_TRAILER;
} else {
Nan::ThrowError("acceleration_profile must be a decimal number or one of 'car', 'fast_car', 'slow_car', 'truck', or 'tractor_trailer'");
return false;
}
return true;
}
if (stoppage_penalty_array->Length() != 2)
{
Nan::ThrowError("Stoppage penalty must be an array of 2 numbers [min,max]");
const auto value = acceleration_profile->NumberValue();
if (value < 0) {
Nan::ThrowError("acceleration_profile cannot be negative");
return false;
}
if (!stoppage_penalty_array->Get(0)->IsNumber() ||
!stoppage_penalty_array->Get(1)->IsNumber())
{
Nan::ThrowError("Stoppage penalty must be an array of 2 numbers [min,max]");
return false;
}
const auto min = static_cast<short>(stoppage_penalty_array->Get(0)->NumberValue());
const auto max = static_cast<short>(stoppage_penalty_array->Get(1)->NumberValue());
if (min < 0 || max < 0)
{
Nan::ThrowError("Stoppage penalty min/max can't be less than zero");
return false;
}
if (max < min)
{
Nan::ThrowError("Stoppage penalty max must be larger than min");
return false;
}
params->max_stoppage_penalty = max;
params->min_stoppage_penalty = min;
params->waypoint_acceleration_factor = value;
}
return true;
+20 -15
View File
@@ -25,7 +25,7 @@ namespace
{
namespace ph = boost::phoenix;
namespace qi = boost::spirit::qi;
} // namespace
}
template <typename T, char... Fmt> struct no_trailing_dot_policy : qi::real_policies<T>
{
@@ -135,15 +135,18 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
},
qi::_1)];
stoppage_rule = qi::lit("stoppage_penalty=") >
(qi::double_ > ',' > qi::double_)[ph::bind(
[](engine::api::BaseParameters &params, double min, double max) {
params.min_stoppage_penalty = min;
params.max_stoppage_penalty = max;
},
qi::_r1,
qi::_1,
qi::_2)];
acceleration_alpha_defaults_rule =
qi::lit("car")[qi::_val = ACCELERATION_ALPHA_CAR] |
qi::lit("fast_car")[qi::_val = ACCELERATION_ALPHA_FAST_CAR] |
qi::lit("slow_car")[qi::_val = ACCELERATION_ALPHA_SLOW_CAR] |
qi::lit("truck")[qi::_val = ACCELERATION_ALPHA_TRUCK] |
qi::lit("tractor_trailer")[qi::_val = ACCELERATION_ALPHA_TRACTOR_TRAILER];
acceleration_profile_rule =
qi::lit("acceleration_profile=") >
(qi::double_ | acceleration_alpha_defaults_rule)
[ph::bind(&engine::api::BaseParameters::waypoint_acceleration_factor, qi::_r1) =
qi::_1];
query_rule =
((location_rule % ';') | polyline_rule |
@@ -190,7 +193,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
| approach_rule(qi::_r1) //
| exclude_rule(qi::_r1) //
| snapping_rule(qi::_r1) //
| stoppage_rule(qi::_r1); //
| acceleration_profile_rule(qi::_r1);//
}
protected:
@@ -207,7 +210,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
qi::rule<Iterator, Signature> generate_hints_rule;
qi::rule<Iterator, Signature> approach_rule;
qi::rule<Iterator, Signature> exclude_rule;
qi::rule<Iterator, Signature> stoppage_rule;
qi::rule<Iterator, Signature> acceleration_profile_rule;
qi::rule<Iterator, osrm::engine::Bearing()> bearing_rule;
qi::rule<Iterator, osrm::util::Coordinate()> location_rule;
@@ -219,11 +222,13 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
qi::rule<Iterator, double()> unlimited_rule;
qi::rule<Iterator, Signature> snapping_rule;
qi::rule<Iterator, double()> acceleration_alpha_defaults_rule;
qi::symbols<char, engine::Approach> approach_type;
qi::symbols<char, engine::api::BaseParameters::SnappingType> snapping_type;
};
} // namespace api
} // namespace server
} // namespace osrm
}
}
}
#endif
@@ -18,7 +18,7 @@ namespace
{
namespace ph = boost::phoenix;
namespace qi = boost::spirit::qi;
} // namespace
}
template <typename Iterator = std::string::iterator,
typename Signature = void(engine::api::TableParameters &)>
@@ -106,8 +106,8 @@ struct TableParametersGrammar : public BaseParametersGrammar<Iterator, Signature
fallback_coordinate_type;
qi::real_parser<double, json_policy> double_;
};
} // namespace api
} // namespace server
} // namespace osrm
}
}
}
#endif
+10 -5
View File
@@ -48,7 +48,7 @@ struct osm_way_id
struct duplicated_node
{
};
} // namespace tag
}
using OSMNodeID = osrm::Alias<std::uint64_t, tag::osm_node_id>;
static_assert(std::is_pod<OSMNodeID>(), "OSMNodeID is not a valid alias");
using OSMWayID = osrm::Alias<std::uint64_t, tag::osm_way_id>;
@@ -116,10 +116,15 @@ static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDurati
static const EdgeDistance MAXIMAL_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max();
static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max();
static const EdgeDistance INVALID_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max();
static const EdgeDistance INVALID_FALLBACK_SPEED = std::numeric_limits<EdgeDistance>::max();
constexpr EdgeDuration INVALID_MINIMUM_STOPPAGE_PENALTY = std::numeric_limits<EdgeDuration>::max();
constexpr EdgeDuration INVALID_MAXIMUM_STOPPAGE_PENALTY = std::numeric_limits<EdgeDuration>::max();
constexpr float MAXIMAL_ACCEL_DECEL_PENALIZABLE_SPEED_INVERSE = 40.f; // seconds/metre
static const EdgeDistance INVALID_FALLBACK_SPEED = std::numeric_limits<double>::max();
// Recommended value for passenger vehicles from
// https://fdotwww.blob.core.windows.net/sitefinity/docs/default-source/content/rail/publications/studies/safety/accelerationresearch.pdf?sfvrsn=716a4bb1_0
static const double ACCELERATION_ALPHA_CAR = 6.0;
static const double ACCELERATION_ALPHA_FAST_CAR = 18;
static const double ACCELERATION_ALPHA_SLOW_CAR = 2;
static const double ACCELERATION_ALPHA_TRUCK = 1.5;
static const double ACCELERATION_ALPHA_TRACTOR_TRAILER = 0.5;
// FIXME the bitfields we use require a reduced maximal duration, this should be kept consistent
// within the code base. For now we have to ensure that we don't case 30 bit to -1 and break any
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "osrm",
"version": "5.21.0-customsnapping.5",
"version": "5.21.0-customsnapping.10",
"private": false,
"description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.",
"dependencies": {
@@ -18,7 +18,7 @@
},
"scripts": {
"lint": "node ./node_modules/eslint/bin/eslint.js -c ./.eslintrc features/step_definitions/ features/support/",
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify -m mmap && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld -m mmap",
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify -m mmap",,
"clean": "rm -rf test/cache",
"docs": "./scripts/build_api_docs.sh",
"install": "node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh",
+3
View File
@@ -120,6 +120,9 @@ function setup()
-- classes to support for exclude flags
excludable = Sequence {
Set {'toll'},
Set {'motorway'},
Set {'ferry'}
},
avoid = Set {
+47 -42
View File
@@ -86,10 +86,11 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
bool request_distance = params.annotations & api::TableParameters::AnnotationsType::Distance;
bool request_duration = params.annotations & api::TableParameters::AnnotationsType::Duration;
constexpr bool always_calculate_distance = true;
// Because of the Short Trip ETA adjustments below, we need distances every time
const bool distances_required = request_distance || params.waypoint_acceleration_factor > 0.;
auto result_tables_pair = algorithms.ManyToManySearch(
snapped_phantoms, params.sources, params.destinations, always_calculate_distance);
snapped_phantoms, params.sources, params.destinations, distances_required);
if ((request_duration && result_tables_pair.first.empty()) ||
(request_distance && result_tables_pair.second.empty()))
@@ -101,59 +102,69 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
// Adds some time to adjust for getting up to speed and slowing down to a stop
// Returns a new `duration`
auto adjust_for_startstop = [](const double &comfortable_acceleration,
auto adjust_for_startstop = [&](const double &acceleration_alpha,
const EdgeDuration &duration,
const EdgeDistance &distance) -> EdgeDuration {
// Assume linear acceleration from 0 to velocity
// auto comfortable_acceleration = 1.85; // m/s^2
// Very short paths can end up with 0 duration. That'll lead to a divide
// by zero, so instead, we'll assume the travel speed is 10m/s (36km/h).
// Typically, the distance is also short, so we're quibbling at tiny numbers
// here, but tiny numbers is what this adjustment lambda is all about,
// so we do try to be reasonable.
const auto average_speed =
duration == 0 ? 10 : distance /
duration == 0 ? 10 : std::abs(distance) /
(duration / 10.); // duration is in deciseconds, we need m/sec
// Using the equations of motion as a simple approximation, assuming constant acceleration
// https://en.wikipedia.org/wiki/Equations_of_motion#Constant_translational_acceleration_in_a_straight_line
// The following reference has a nice model (equations 9 through 12)
// for vehicle acceleration
// https://fdotwww.blob.core.windows.net/sitefinity/docs/default-source/content/rail/publications/studies/safety/accelerationresearch.pdf?sfvrsn=716a4bb1_0
// We solve euqation 10 for time to figure out how long it'll take
// to get up to the desired speed
// Because Equation 10 is asymptotic on v_des, we need to pick a target speed
// that's slighly less so the equation can actually get there. 1m/s less than
// target seems like a reasonable value to aim for
const auto target_speed = std::max(average_speed - 1, 0.1);
const auto initial_speed = 0.;
// Equation 9
const auto beta = acceleration_alpha / average_speed;
// Equation 10 solved for time
const auto time_to_full_speed = std::log( (average_speed - initial_speed) / (average_speed - target_speed) ) / beta;
BOOST_ASSERT(time_to_full_speed >= 0);
// Equation 11
const auto distance_to_full_speed =
(average_speed * average_speed) / (2 * comfortable_acceleration);
average_speed * time_to_full_speed -
average_speed * (1 - std::exp(-1 * beta * time_to_full_speed)) / beta;
/*
std::cout << "Comfortable accel is " << comfortable_acceleration << std::endl;
std::cout << "Average speed is " << average_speed << " duration is " << duration
<< std::endl;
std::cout << "Distance is " << distance << " distance to full speed is "
<< distance_to_full_speed << std::endl;
*/
BOOST_ASSERT(distance_to_full_speed >= 0);
if (distance_to_full_speed > distance / 2)
if (distance_to_full_speed > std::abs(distance) / 2)
{
// std::cout << "Distance was too short, so only using half" << std::endl;
const auto time_to_halfway = std::sqrt(distance / comfortable_acceleration);
// Because equation 12 requires velocity at halfway, and
// solving equation 11 for t requires a Lambert W function,
// we'll approximate here by assuming constant acceleration
// over distance_to_full_speed using s = ut + 1/2at^2
const auto average_acceleration =
2 * distance_to_full_speed / (time_to_full_speed * time_to_full_speed);
const auto time_to_halfway = std::sqrt(std::abs(distance) / average_acceleration);
BOOST_ASSERT(time_to_halfway >= 0);
return (2 * time_to_halfway) * 10; // result is in deciseconds
}
else
{
// std::cout << "Distance was long, using cruising speed" << std::endl;
const auto cruising_distance = distance - 2 * distance_to_full_speed;
const auto cruising_distance = std::abs(distance) - 2 * distance_to_full_speed;
const auto cruising_time = cruising_distance / average_speed;
const auto acceleration_time = average_speed / comfortable_acceleration;
// std::cout << "Cruising distance is " << cruising_distance << std::endl;
// std::cout << "Cruising time is " << cruising_time << std::endl;
// std::cout << "Acceleration time is " << acceleration_time << std::endl;
return (cruising_time + 2 * acceleration_time) * 10; // result is in deciseconds
BOOST_ASSERT(cruising_time >= 0);
return (cruising_time + 2 * time_to_full_speed) * 10; // result is in deciseconds
}
};
// Scan table for null results - if any exist, replace with distance estimates
if (params.fallback_speed != INVALID_FALLBACK_SPEED || params.scale_factor != 1 ||
(params.min_stoppage_penalty != INVALID_MINIMUM_STOPPAGE_PENALTY &&
params.max_stoppage_penalty != INVALID_MAXIMUM_STOPPAGE_PENALTY))
params.waypoint_acceleration_factor != 0.)
{
for (std::size_t row = 0; row < num_sources; row++)
{
@@ -162,17 +173,11 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
const auto &table_index = row * num_destinations + column;
BOOST_ASSERT(table_index < result_tables_pair.first.size());
// apply an accel/deceleration penalty to the duration
if (result_tables_pair.first[table_index] != MAXIMAL_EDGE_DURATION && row != column)
if (result_tables_pair.first[table_index] != MAXIMAL_EDGE_DURATION &&
row != column && params.waypoint_acceleration_factor != 0.)
{
/*
const auto &source =
snapped_phantoms[params.sources.empty() ? row : params.sources[row]];
const auto &destination =
snapped_phantoms[params.destinations.empty() ? column
: params.destinations[column]];
*/
result_tables_pair.first[table_index] =
adjust_for_startstop(params.min_stoppage_penalty,
adjust_for_startstop(params.waypoint_acceleration_factor,
result_tables_pair.first[table_index],
result_tables_pair.second[table_index]);
}
@@ -238,6 +243,6 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Status::Ok;
}
} // namespace plugins
} // namespace engine
} // namespace osrm
}
}
}
@@ -143,7 +143,8 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
middle_nodes_table[row_index * number_of_targets + column_index] = node;
}
}
else if (std::tie(new_weight, new_duration) < std::tie(current_weight, current_duration))
else if (std::tie(new_weight, new_duration) < std::tie(current_weight, current_duration) &&
new_distance >= 0)
{
current_weight = new_weight;
current_duration = new_duration;
+27 -14
View File
@@ -319,31 +319,44 @@ tables.forEach(function(annotation) {
});
test('table: ' + annotation + ' table in Monaco with stoppage_penalty values', function(assert) {
assert.plan(6);
test('table: ' + annotation + ' table in Monaco with acceleration_profile values', function(assert) {
assert.plan(12);
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
var options = {
coordinates: two_test_coordinates,
annotations: [annotation.slice(0,-1)],
stoppage_penalty: [],
acceleration_profile: []
};
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty must be an array of 2 numbers/, "should throw on empty array");
assert.throws(()=>osrm.table(options, (err, res) => {}), /acceleration_profile must be a decimal number or one of/, "should throw on empty array");
options.stoppage_penalty = ['a',1];
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty must be an array of 2 numbers/, "should throw on non-numeric value");
options.acceleration_profile = 'a';
assert.throws(()=>osrm.table(options, (err, res) => {}), /acceleration_profile must be a decimal number or one of/, "should throw on non-numeric value");
options.stoppage_penalty = [1,2,3];
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty must be an array of 2 numbers/, "should throw on too many values");
options.acceleration_profile = [1];
assert.throws(()=>osrm.table(options, (err, res) => {}), /acceleration_profile must be a decimal number or one of/, "should throw on non-numeric value");
options.stoppage_penalty = [1];
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty must be an array of 2 numbers/, "should throw on not enough values");
options.acceleration_profile = -0.1;
assert.throws(()=>osrm.table(options, (err, res) => {}), /acceleration_profile cannot be negative/, "should throw on non-numeric value");
options.stoppage_penalty = [2,1];
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty max must be larger than min/, "should throw on max < min");
options.acceleration_profile = 0.;
assert.ok(()=>osrm.table(options, (err, res) => {}), "should work with zero");
options.stoppage_penalty = [-1,2];
assert.throws(()=>osrm.table(options, (err, res) => {}), /Stoppage penalty min\/max can't be less than zero/, "should throw on negative value");
options.acceleration_profile = 2.0;
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with positive numeric values");
options.acceleration_profile = 'car';
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with car defaults");
options.acceleration_profile = 'fast_car';
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with fast car defaults");
options.acceleration_profile = 'slow_car';
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with slow car defaults");
options.acceleration_profile = 'truck';
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with truck defaults");
options.acceleration_profile = 'tractor_trailer';
assert.ok(()=>osrm.table(options, (err, res) => {}), "Should work with tractor trailer defaults");
options.acceleration_profile = 'yes';
assert.throws(()=>osrm.table(options, (err, res) => {}), /acceleration_profile must be a decimal number or one of/, "should throw on non-recognized string");
});
});
+22 -30
View File
@@ -282,48 +282,40 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
return {};
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const int /*bearing*/,
const int /*bearing_range*/,
const Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const int /*bearing*/,
const int /*bearing_range*/,
const Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const int /*bearing*/,
const int /*bearing_range*/,
const Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
std::pair<PhantomNode, PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const int /*bearing*/,
const int /*bearing_range*/,
const Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
+18 -30
View File
@@ -167,51 +167,39 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
}
std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const int /*bearing*/,
const int /*bearing_range*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const double /*max_distance*/,
const int /*bearing*/,
const int /*bearing_range*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}
std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate /*input_coordinate*/,
const int /*bearing*/,
const int /*bearing_range*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */,
const double /* min_stoppage_penalty */,
const double /* max_stoppage_penalty */) const override
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
const int /*bearing*/,
const int /*bearing_range*/,
const engine::Approach /*approach*/,
const bool /* use_all_edges */) const override
{
return {};
}