Merge branch 'master' into sf-ankerl
This commit is contained in:
@@ -54,14 +54,10 @@ namespace osrm::engine
|
||||
*
|
||||
* In addition, shared memory can be used for datasets loaded with osrm-datastore.
|
||||
*
|
||||
* You can chose between three algorithms:
|
||||
* You can chose between two algorithms:
|
||||
* - Algorithm::CH
|
||||
* Contraction Hierarchies, extremely fast queries but slow pre-processing. The default right
|
||||
* now.
|
||||
* - Algorithm::CoreCH
|
||||
* Deprecated, to be removed in v6.0
|
||||
* Contraction Hierachies with partial contraction for faster pre-processing but slower
|
||||
* queries.
|
||||
* - Algorithm::MLD
|
||||
* Multi Level Dijkstra, moderately fast in both pre-processing and query.
|
||||
*
|
||||
@@ -74,7 +70,6 @@ struct EngineConfig final
|
||||
enum class Algorithm
|
||||
{
|
||||
CH,
|
||||
CoreCH, // Deprecated, will be removed in v6.0
|
||||
MLD
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
namespace osrm::engine::map_matching
|
||||
{
|
||||
@@ -21,10 +21,8 @@ struct NormalDistribution
|
||||
// FIXME implement log-probability version since it's faster
|
||||
double Density(const double val) const
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
|
||||
const double x = val - mean;
|
||||
return 1.0 / (std::sqrt(two_pi<double>()) * standard_deviation) *
|
||||
return 1.0 / (std::sqrt(2 * std::numbers::pi) * standard_deviation) *
|
||||
std::exp(-x * x / (standard_deviation * standard_deviation));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "util/integer_range.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace osrm::engine::map_matching
|
||||
{
|
||||
|
||||
static const double log_2_pi = std::log(2. * boost::math::constants::pi<double>());
|
||||
static const double log_2_pi = std::log(2. * std::numbers::pi);
|
||||
static const double IMPOSSIBLE_LOG_PROB = -std::numeric_limits<double>::infinity();
|
||||
static const double MINIMAL_LOG_PROB = std::numeric_limits<double>::lowest();
|
||||
static const std::size_t INVALID_STATE = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define ENGINE_MAP_MATCHING_CONFIDENCE_HPP
|
||||
|
||||
#include "engine/map_matching/bayes_classifier.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <cmath>
|
||||
|
||||
namespace osrm::engine::map_matching
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace osrm::engine
|
||||
|
||||
// Algorithm-dependent heaps
|
||||
// - CH algorithms use CH heaps
|
||||
// - CoreCH algorithms use CH
|
||||
// - MLD algorithms use MLD heaps
|
||||
|
||||
template <typename Algorithm> struct SearchEngineData
|
||||
|
||||
@@ -296,24 +296,19 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
||||
{
|
||||
engine_config->algorithm = osrm::EngineConfig::Algorithm::CH;
|
||||
}
|
||||
else if (algorithm_str == "CoreCH")
|
||||
{
|
||||
engine_config->algorithm = osrm::EngineConfig::Algorithm::CH;
|
||||
}
|
||||
else if (algorithm_str == "MLD")
|
||||
{
|
||||
engine_config->algorithm = osrm::EngineConfig::Algorithm::MLD;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowError(args.Env(), "algorithm option must be one of 'CH', 'CoreCH', or 'MLD'.");
|
||||
ThrowError(args.Env(), "algorithm option must be one of 'CH', or 'MLD'.");
|
||||
return engine_config_ptr();
|
||||
}
|
||||
}
|
||||
else if (!algorithm.IsUndefined())
|
||||
{
|
||||
ThrowError(args.Env(),
|
||||
"algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'.");
|
||||
ThrowError(args.Env(), "algorithm option must be a string and one of 'CH', or 'MLD'.");
|
||||
return engine_config_ptr();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
@@ -37,7 +38,7 @@ class CheapRuler
|
||||
static constexpr double FE = 1.0 / 298.257223563; // flattening
|
||||
|
||||
static constexpr double E2 = FE * (2 - FE);
|
||||
static constexpr double RAD = M_PI / 180.0;
|
||||
static constexpr double RAD = std::numbers::pi / 180.0;
|
||||
|
||||
public:
|
||||
explicit CheapRuler(double latitude)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -23,17 +23,9 @@ const constexpr double RAD_TO_DEGREE = 1. / DEGREE_TO_RAD;
|
||||
// The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
|
||||
const constexpr long double EARTH_RADIUS = 6372797.560856;
|
||||
|
||||
inline double degToRad(const double degree)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
return degree * (pi<double>() / 180.0);
|
||||
}
|
||||
inline double degToRad(const double degree) { return degree * (std::numbers::pi / 180.0); }
|
||||
|
||||
inline double radToDeg(const double radian)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
return radian * (180.0 * (1. / pi<double>()));
|
||||
}
|
||||
inline double radToDeg(const double radian) { return radian * (180.0 * std::numbers::inv_pi); }
|
||||
} // namespace detail
|
||||
|
||||
const constexpr static double METERS_PER_DEGREE_LAT = 110567.0;
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
@@ -126,8 +124,7 @@ inline bool requiresNameAnnounced(const StringView &from_name,
|
||||
|
||||
// check similarity of names
|
||||
const auto names_are_empty = from_name.empty() && to_name.empty();
|
||||
const auto name_is_contained =
|
||||
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
|
||||
const auto name_is_contained = from_name.starts_with(to_name) || to_name.starts_with(from_name);
|
||||
|
||||
const auto checkForPrefixOrSuffixChange = [](const std::string_view first,
|
||||
const std::string_view second,
|
||||
|
||||
@@ -156,7 +156,20 @@ template <typename NodeID,
|
||||
class QueryHeap
|
||||
{
|
||||
private:
|
||||
using HeapData = std::pair<Weight, Key>;
|
||||
struct HeapData
|
||||
{
|
||||
Weight weight;
|
||||
Key index;
|
||||
|
||||
bool operator>(const HeapData &other) const
|
||||
{
|
||||
if (weight == other.weight)
|
||||
{
|
||||
return index > other.index;
|
||||
}
|
||||
return weight > other.weight;
|
||||
}
|
||||
};
|
||||
using HeapContainer = boost::heap::d_ary_heap<HeapData,
|
||||
boost::heap::arity<4>,
|
||||
boost::heap::mutable_<true>,
|
||||
@@ -195,7 +208,7 @@ class QueryHeap
|
||||
{
|
||||
BOOST_ASSERT(node < std::numeric_limits<NodeID>::max());
|
||||
const auto index = static_cast<Key>(inserted_nodes.size());
|
||||
const auto handle = heap.push(std::make_pair(weight, index));
|
||||
const auto handle = heap.emplace(HeapData{weight, index});
|
||||
inserted_nodes.emplace_back(HeapNode{handle, node, weight, data});
|
||||
node_index[node] = index;
|
||||
}
|
||||
@@ -278,19 +291,19 @@ class QueryHeap
|
||||
NodeID Min() const
|
||||
{
|
||||
BOOST_ASSERT(!heap.empty());
|
||||
return inserted_nodes[heap.top().second].node;
|
||||
return inserted_nodes[heap.top().index].node;
|
||||
}
|
||||
|
||||
Weight MinKey() const
|
||||
{
|
||||
BOOST_ASSERT(!heap.empty());
|
||||
return heap.top().first;
|
||||
return heap.top().weight;
|
||||
}
|
||||
|
||||
NodeID DeleteMin()
|
||||
{
|
||||
BOOST_ASSERT(!heap.empty());
|
||||
const Key removedIndex = heap.top().second;
|
||||
const Key removedIndex = heap.top().index;
|
||||
heap.pop();
|
||||
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end());
|
||||
return inserted_nodes[removedIndex].node;
|
||||
@@ -299,7 +312,7 @@ class QueryHeap
|
||||
HeapNode &DeleteMinGetHeapNode()
|
||||
{
|
||||
BOOST_ASSERT(!heap.empty());
|
||||
const Key removedIndex = heap.top().second;
|
||||
const Key removedIndex = heap.top().index;
|
||||
heap.pop();
|
||||
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end());
|
||||
return inserted_nodes[removedIndex];
|
||||
@@ -320,13 +333,13 @@ class QueryHeap
|
||||
const auto index = node_index.peek_index(node);
|
||||
auto &reference = inserted_nodes[index];
|
||||
reference.weight = weight;
|
||||
heap.increase(reference.handle, std::make_pair(weight, index));
|
||||
heap.increase(reference.handle, HeapData{weight, static_cast<Key>(index)});
|
||||
}
|
||||
|
||||
void DecreaseKey(const HeapNode &heapNode)
|
||||
{
|
||||
BOOST_ASSERT(!WasRemoved(heapNode.node));
|
||||
heap.increase(heapNode.handle, std::make_pair(heapNode.weight, (*heapNode.handle).second));
|
||||
heap.increase(heapNode.handle, HeapData{heapNode.weight, (*heapNode.handle).index});
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef STRING_UTIL_HPP
|
||||
#define STRING_UTIL_HPP
|
||||
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
|
||||
#include <cstddef>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -10,26 +11,30 @@
|
||||
namespace osrm::util
|
||||
{
|
||||
|
||||
// implements Lemire's table-based escape needs check
|
||||
// cf. https://lemire.me/blog/2024/05/31/quickly-checking-whether-a-string-needs-escaping/
|
||||
inline static constexpr std::array<uint8_t, 256> json_quotable_character = []() constexpr
|
||||
{
|
||||
std::array<uint8_t, 256> result{};
|
||||
for (auto i = 0; i < 32; i++)
|
||||
{
|
||||
result[i] = 1;
|
||||
}
|
||||
for (auto i : {'"', '\\'})
|
||||
{
|
||||
result[i] = 1;
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
|
||||
inline bool RequiresJSONStringEscaping(const std::string &string)
|
||||
{
|
||||
for (const char letter : string)
|
||||
uint8_t needs = 0;
|
||||
for (uint8_t c : string)
|
||||
{
|
||||
switch (letter)
|
||||
{
|
||||
case '\\':
|
||||
case '"':
|
||||
case '/':
|
||||
case '\b':
|
||||
case '\f':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
return true;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
needs |= json_quotable_character[c];
|
||||
}
|
||||
return false;
|
||||
return needs;
|
||||
}
|
||||
|
||||
inline void EscapeJSONString(const std::string &input, std::string &output)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
namespace osrm::util
|
||||
{
|
||||
@@ -356,25 +356,21 @@ constexpr unsigned short atan_table[4096] = {
|
||||
0xffe0, 0xffea, 0xfff4, 0xffff};
|
||||
|
||||
// max value is pi/4
|
||||
#ifdef _MSC_VER // TODO: remove as soon as boost allows C++14 features with Visual Studio
|
||||
const constexpr double SCALING_FACTOR = 4. / M_PI * 0xFFFF;
|
||||
#else
|
||||
const constexpr double SCALING_FACTOR = 4. / boost::math::constants::pi<double>() * 0xFFFF;
|
||||
#endif
|
||||
const constexpr double SCALING_FACTOR = 4. * std::numbers::inv_pi * 0xFFFF;
|
||||
|
||||
inline double atan2_lookup(double y, double x)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
static constexpr auto half_pi = std::numbers::pi * 0.5;
|
||||
|
||||
if (std::abs(x) < std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
if (y >= 0.)
|
||||
{
|
||||
return half_pi<double>();
|
||||
return half_pi;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -half_pi<double>();
|
||||
return -half_pi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,25 +401,25 @@ inline double atan2_lookup(double y, double x)
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
angle = pi<double>() - angle;
|
||||
angle = std::numbers::pi - angle;
|
||||
break;
|
||||
case 2:
|
||||
angle = -angle;
|
||||
break;
|
||||
case 3:
|
||||
angle = -pi<double>() + angle;
|
||||
angle = -std::numbers::pi + angle;
|
||||
break;
|
||||
case 4:
|
||||
angle = half_pi<double>() - angle;
|
||||
angle = half_pi - angle;
|
||||
break;
|
||||
case 5:
|
||||
angle = half_pi<double>() + angle;
|
||||
angle = half_pi + angle;
|
||||
break;
|
||||
case 6:
|
||||
angle = -half_pi<double>() + angle;
|
||||
angle = -half_pi + angle;
|
||||
break;
|
||||
case 7:
|
||||
angle = -half_pi<double>() - angle;
|
||||
angle = -half_pi - angle;
|
||||
break;
|
||||
}
|
||||
return angle;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <numbers>
|
||||
|
||||
namespace osrm::util::web_mercator
|
||||
{
|
||||
@@ -14,7 +14,7 @@ const constexpr double RAD_TO_DEGREE = 1. / DEGREE_TO_RAD;
|
||||
// radius used by WGS84
|
||||
const constexpr double EARTH_RADIUS_WGS84 = 6378137.0;
|
||||
// earth circumference devided by 2
|
||||
const constexpr double MAXEXTENT = EARTH_RADIUS_WGS84 * boost::math::constants::pi<double>();
|
||||
const constexpr double MAXEXTENT = EARTH_RADIUS_WGS84 * std::numbers::pi;
|
||||
// ^ math functions are not constexpr since they have side-effects (setting errno) :(
|
||||
const constexpr double EPSG3857_MAX_LATITUDE = 85.051128779806592378; // 90(4*atan(exp(pi))/pi-1)
|
||||
const constexpr double MAX_LONGITUDE = 180.0;
|
||||
@@ -103,8 +103,8 @@ inline void pixelToDegree(const double shift, double &x, double &y)
|
||||
const double b = shift / 2.0;
|
||||
x = (x - b) / shift * 360.0;
|
||||
// FIXME needs to be simplified
|
||||
const double g = (y - b) / -(shift / (2 * M_PI)) / detail::DEGREE_TO_RAD;
|
||||
static_assert(detail::DEGREE_TO_RAD / (2 * M_PI) - 1 / 360. < 0.0001, "");
|
||||
const double g = (y - b) / -(shift * 0.5 * std::numbers::inv_pi) / detail::DEGREE_TO_RAD;
|
||||
static_assert(detail::DEGREE_TO_RAD * 0.5 * std::numbers::inv_pi - 1 / 360. < 0.0001, "");
|
||||
y = static_cast<double>(yToLat(g));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user