Add support for a default_bearing_radius flag (#6575)
This commit is contained in:
parent
d6afe91d8f
commit
d51631401e
@ -1,5 +1,7 @@
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
- Changes from 5.27.1
|
- Changes from 5.27.1
|
||||||
|
- Features
|
||||||
|
- ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575)
|
||||||
- Build:
|
- Build:
|
||||||
- ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455)
|
- ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455)
|
||||||
- CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439)
|
- CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439)
|
||||||
|
@ -38,6 +38,7 @@ var osrm = new OSRM('network.osrm');
|
|||||||
- `options.max_radius_map_matching` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. radius size supported in map matching query (default: 5).
|
- `options.max_radius_map_matching` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. radius size supported in map matching query (default: 5).
|
||||||
- `options.max_results_nearest` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. results supported in nearest query (default: unlimited).
|
- `options.max_results_nearest` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. results supported in nearest query (default: unlimited).
|
||||||
- `options.max_alternatives` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. number of alternatives supported in alternative routes query (default: 3).
|
- `options.max_alternatives` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Max. number of alternatives supported in alternative routes query (default: 3).
|
||||||
|
- `options.default_radius` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Default radius for queries (default: unlimited).
|
||||||
|
|
||||||
### route
|
### route
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "--max-trip-size"
|
And stdout should contain "--max-trip-size"
|
||||||
And stdout should contain "--max-table-size"
|
And stdout should contain "--max-table-size"
|
||||||
And stdout should contain "--max-matching-size"
|
And stdout should contain "--max-matching-size"
|
||||||
|
And stdout should contain "--default-radius"
|
||||||
And it should exit successfully
|
And it should exit successfully
|
||||||
|
|
||||||
Scenario: osrm-routed - Help, short
|
Scenario: osrm-routed - Help, short
|
||||||
@ -42,6 +43,7 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "--max-trip-size"
|
And stdout should contain "--max-trip-size"
|
||||||
And stdout should contain "--max-table-size"
|
And stdout should contain "--max-table-size"
|
||||||
And stdout should contain "--max-matching-size"
|
And stdout should contain "--max-matching-size"
|
||||||
|
And stdout should contain "--default-radius"
|
||||||
And it should exit successfully
|
And it should exit successfully
|
||||||
|
|
||||||
Scenario: osrm-routed - Help, long
|
Scenario: osrm-routed - Help, long
|
||||||
@ -62,4 +64,5 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "--max-table-size"
|
And stdout should contain "--max-table-size"
|
||||||
And stdout should contain "--max-table-size"
|
And stdout should contain "--max-table-size"
|
||||||
And stdout should contain "--max-matching-size"
|
And stdout should contain "--max-matching-size"
|
||||||
|
And stdout should contain "--default-radius"
|
||||||
And it should exit successfully
|
And it should exit successfully
|
||||||
|
@ -43,11 +43,15 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Engine(const EngineConfig &config)
|
explicit Engine(const EngineConfig &config)
|
||||||
: route_plugin(config.max_locations_viaroute, config.max_alternatives), //
|
: route_plugin(config.max_locations_viaroute,
|
||||||
table_plugin(config.max_locations_distance_table), //
|
config.max_alternatives,
|
||||||
nearest_plugin(config.max_results_nearest), //
|
config.default_radius), //
|
||||||
trip_plugin(config.max_locations_trip), //
|
table_plugin(config.max_locations_distance_table, config.default_radius), //
|
||||||
match_plugin(config.max_locations_map_matching, config.max_radius_map_matching), //
|
nearest_plugin(config.max_results_nearest, config.default_radius), //
|
||||||
|
trip_plugin(config.max_locations_trip, config.default_radius), //
|
||||||
|
match_plugin(config.max_locations_map_matching,
|
||||||
|
config.max_radius_map_matching,
|
||||||
|
config.default_radius), //
|
||||||
tile_plugin() //
|
tile_plugin() //
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -83,6 +83,7 @@ struct EngineConfig final
|
|||||||
int max_locations_map_matching = -1;
|
int max_locations_map_matching = -1;
|
||||||
double max_radius_map_matching = -1.0;
|
double max_radius_map_matching = -1.0;
|
||||||
int max_results_nearest = -1;
|
int max_results_nearest = -1;
|
||||||
|
boost::optional<double> default_radius;
|
||||||
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
|
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
|
||||||
bool use_shared_memory = true;
|
bool use_shared_memory = true;
|
||||||
boost::filesystem::path memory_file;
|
boost::filesystem::path memory_file;
|
||||||
|
@ -20,8 +20,10 @@ class MatchPlugin : public BasePlugin
|
|||||||
using CandidateLists = routing_algorithms::CandidateLists;
|
using CandidateLists = routing_algorithms::CandidateLists;
|
||||||
static const constexpr double RADIUS_MULTIPLIER = 3;
|
static const constexpr double RADIUS_MULTIPLIER = 3;
|
||||||
|
|
||||||
MatchPlugin(const int max_locations_map_matching, const double max_radius_map_matching)
|
MatchPlugin(const int max_locations_map_matching,
|
||||||
: max_locations_map_matching(max_locations_map_matching),
|
const double max_radius_map_matching,
|
||||||
|
const boost::optional<double> default_radius)
|
||||||
|
: BasePlugin(default_radius), max_locations_map_matching(max_locations_map_matching),
|
||||||
max_radius_map_matching(max_radius_map_matching)
|
max_radius_map_matching(max_radius_map_matching)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace osrm::engine::plugins
|
|||||||
class NearestPlugin final : public BasePlugin
|
class NearestPlugin final : public BasePlugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NearestPlugin(const int max_results);
|
explicit NearestPlugin(const int max_results, const boost::optional<double> default_radius);
|
||||||
|
|
||||||
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||||
const api::NearestParameters ¶ms,
|
const api::NearestParameters ¶ms,
|
||||||
|
@ -27,6 +27,10 @@ namespace osrm::engine::plugins
|
|||||||
class BasePlugin
|
class BasePlugin
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
BasePlugin() = default;
|
||||||
|
|
||||||
|
BasePlugin(const boost::optional<double> default_radius_) : default_radius(default_radius_) {}
|
||||||
|
|
||||||
bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates) const
|
bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates) const
|
||||||
{
|
{
|
||||||
return !std::any_of(
|
return !std::any_of(
|
||||||
@ -237,7 +241,7 @@ class BasePlugin
|
|||||||
phantom_nodes[i] = facade.NearestPhantomNodes(
|
phantom_nodes[i] = facade.NearestPhantomNodes(
|
||||||
parameters.coordinates[i],
|
parameters.coordinates[i],
|
||||||
number_of_results,
|
number_of_results,
|
||||||
use_radiuses ? parameters.radiuses[i] : boost::none,
|
use_radiuses ? parameters.radiuses[i] : default_radius,
|
||||||
use_bearings ? parameters.bearings[i] : boost::none,
|
use_bearings ? parameters.bearings[i] : boost::none,
|
||||||
use_approaches && parameters.approaches[i] ? parameters.approaches[i].get()
|
use_approaches && parameters.approaches[i] ? parameters.approaches[i].get()
|
||||||
: engine::Approach::UNRESTRICTED);
|
: engine::Approach::UNRESTRICTED);
|
||||||
@ -279,7 +283,7 @@ class BasePlugin
|
|||||||
|
|
||||||
alternatives[i] = facade.NearestCandidatesWithAlternativeFromBigComponent(
|
alternatives[i] = facade.NearestCandidatesWithAlternativeFromBigComponent(
|
||||||
parameters.coordinates[i],
|
parameters.coordinates[i],
|
||||||
use_radiuses ? parameters.radiuses[i] : boost::none,
|
use_radiuses ? parameters.radiuses[i] : default_radius,
|
||||||
use_bearings ? parameters.bearings[i] : boost::none,
|
use_bearings ? parameters.bearings[i] : boost::none,
|
||||||
use_approaches && parameters.approaches[i] ? parameters.approaches[i].get()
|
use_approaches && parameters.approaches[i] ? parameters.approaches[i].get()
|
||||||
: engine::Approach::UNRESTRICTED,
|
: engine::Approach::UNRESTRICTED,
|
||||||
@ -320,6 +324,8 @@ class BasePlugin
|
|||||||
return std::string("Could not find a matching segment for coordinate ") +
|
return std::string("Could not find a matching segment for coordinate ") +
|
||||||
std::to_string(missing_index);
|
std::to_string(missing_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const boost::optional<double> default_radius;
|
||||||
};
|
};
|
||||||
} // namespace osrm::engine::plugins
|
} // namespace osrm::engine::plugins
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ namespace osrm::engine::plugins
|
|||||||
class TablePlugin final : public BasePlugin
|
class TablePlugin final : public BasePlugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TablePlugin(const int max_locations_distance_table);
|
explicit TablePlugin(const int max_locations_distance_table,
|
||||||
|
const boost::optional<double> default_radius);
|
||||||
|
|
||||||
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||||
const api::TableParameters ¶ms,
|
const api::TableParameters ¶ms,
|
||||||
|
@ -32,7 +32,10 @@ class TripPlugin final : public BasePlugin
|
|||||||
const bool roundtrip) const;
|
const bool roundtrip) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TripPlugin(const int max_locations_trip_) : max_locations_trip(max_locations_trip_) {}
|
explicit TripPlugin(const int max_locations_trip_, boost::optional<double> default_radius)
|
||||||
|
: BasePlugin(default_radius), max_locations_trip(max_locations_trip_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||||
const api::TripParameters ¶meters,
|
const api::TripParameters ¶meters,
|
||||||
|
@ -25,7 +25,9 @@ class ViaRoutePlugin final : public BasePlugin
|
|||||||
const int max_alternatives;
|
const int max_alternatives;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ViaRoutePlugin(int max_locations_viaroute, int max_alternatives);
|
explicit ViaRoutePlugin(int max_locations_viaroute,
|
||||||
|
int max_alternatives,
|
||||||
|
boost::optional<double> default_radius);
|
||||||
|
|
||||||
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
Status HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||||
const api::RouteParameters &route_parameters,
|
const api::RouteParameters &route_parameters,
|
||||||
|
@ -285,6 +285,7 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
|||||||
auto max_results_nearest = params.Get("max_results_nearest");
|
auto max_results_nearest = params.Get("max_results_nearest");
|
||||||
auto max_alternatives = params.Get("max_alternatives");
|
auto max_alternatives = params.Get("max_alternatives");
|
||||||
auto max_radius_map_matching = params.Get("max_radius_map_matching");
|
auto max_radius_map_matching = params.Get("max_radius_map_matching");
|
||||||
|
auto default_radius = params.Get("default_radius");
|
||||||
|
|
||||||
if (!max_locations_trip.IsUndefined() && !max_locations_trip.IsNumber())
|
if (!max_locations_trip.IsUndefined() && !max_locations_trip.IsNumber())
|
||||||
{
|
{
|
||||||
@ -316,6 +317,11 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
|||||||
ThrowError(args.Env(), "max_alternatives must be an integral number");
|
ThrowError(args.Env(), "max_alternatives must be an integral number");
|
||||||
return engine_config_ptr();
|
return engine_config_ptr();
|
||||||
}
|
}
|
||||||
|
if (!default_radius.IsUndefined() && !default_radius.IsNumber())
|
||||||
|
{
|
||||||
|
ThrowError(args.Env(), "default_radius must be an integral number");
|
||||||
|
return engine_config_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
if (max_locations_trip.IsNumber())
|
if (max_locations_trip.IsNumber())
|
||||||
engine_config->max_locations_trip = max_locations_trip.ToNumber().Int32Value();
|
engine_config->max_locations_trip = max_locations_trip.ToNumber().Int32Value();
|
||||||
@ -333,6 +339,8 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args)
|
|||||||
engine_config->max_alternatives = max_alternatives.ToNumber().Int32Value();
|
engine_config->max_alternatives = max_alternatives.ToNumber().Int32Value();
|
||||||
if (max_radius_map_matching.IsNumber())
|
if (max_radius_map_matching.IsNumber())
|
||||||
engine_config->max_radius_map_matching = max_radius_map_matching.ToNumber().DoubleValue();
|
engine_config->max_radius_map_matching = max_radius_map_matching.ToNumber().DoubleValue();
|
||||||
|
if (default_radius.IsNumber())
|
||||||
|
engine_config->default_radius = default_radius.ToNumber().DoubleValue();
|
||||||
|
|
||||||
return engine_config;
|
return engine_config;
|
||||||
}
|
}
|
||||||
|
@ -181,22 +181,27 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
|||||||
if (tidied.parameters.radiuses.empty())
|
if (tidied.parameters.radiuses.empty())
|
||||||
{
|
{
|
||||||
search_radiuses.resize(tidied.parameters.coordinates.size(),
|
search_radiuses.resize(tidied.parameters.coordinates.size(),
|
||||||
routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER);
|
default_radius.has_value()
|
||||||
|
? *default_radius
|
||||||
|
: routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
search_radiuses.resize(tidied.parameters.coordinates.size());
|
search_radiuses.resize(tidied.parameters.coordinates.size());
|
||||||
std::transform(tidied.parameters.radiuses.begin(),
|
std::transform(
|
||||||
|
tidied.parameters.radiuses.begin(),
|
||||||
tidied.parameters.radiuses.end(),
|
tidied.parameters.radiuses.end(),
|
||||||
search_radiuses.begin(),
|
search_radiuses.begin(),
|
||||||
[](const boost::optional<double> &maybe_radius) {
|
[default_radius = this->default_radius](const boost::optional<double> &maybe_radius) {
|
||||||
if (maybe_radius)
|
if (maybe_radius)
|
||||||
{
|
{
|
||||||
return *maybe_radius * RADIUS_MULTIPLIER;
|
return *maybe_radius * RADIUS_MULTIPLIER;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER;
|
return default_radius.has_value()
|
||||||
|
? *default_radius
|
||||||
|
: routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
namespace osrm::engine::plugins
|
namespace osrm::engine::plugins
|
||||||
{
|
{
|
||||||
|
|
||||||
NearestPlugin::NearestPlugin(const int max_results_) : max_results{max_results_} {}
|
NearestPlugin::NearestPlugin(const int max_results_, const boost::optional<double> default_radius_)
|
||||||
|
: BasePlugin(default_radius_), max_results{max_results_}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
Status NearestPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
|
||||||
const api::NearestParameters ¶ms,
|
const api::NearestParameters ¶ms,
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
namespace osrm::engine::plugins
|
namespace osrm::engine::plugins
|
||||||
{
|
{
|
||||||
|
|
||||||
TablePlugin::TablePlugin(const int max_locations_distance_table)
|
TablePlugin::TablePlugin(const int max_locations_distance_table,
|
||||||
: max_locations_distance_table(max_locations_distance_table)
|
const boost::optional<double> default_radius)
|
||||||
|
: BasePlugin(default_radius), max_locations_distance_table(max_locations_distance_table)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,11 @@
|
|||||||
namespace osrm::engine::plugins
|
namespace osrm::engine::plugins
|
||||||
{
|
{
|
||||||
|
|
||||||
ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute, int max_alternatives)
|
ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute,
|
||||||
: max_locations_viaroute(max_locations_viaroute), max_alternatives(max_alternatives)
|
int max_alternatives,
|
||||||
|
boost::optional<double> default_radius)
|
||||||
|
: BasePlugin(default_radius), max_locations_viaroute(max_locations_viaroute),
|
||||||
|
max_alternatives(max_alternatives)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ Napi::Object Engine::Init(Napi::Env env, Napi::Object exports)
|
|||||||
* @param {Number} [options.max_radius_map_matching] Max. radius size supported in map matching query (default: 5).
|
* @param {Number} [options.max_radius_map_matching] Max. radius size supported in map matching query (default: 5).
|
||||||
* @param {Number} [options.max_results_nearest] Max. results supported in nearest query (default: unlimited).
|
* @param {Number} [options.max_results_nearest] Max. results supported in nearest query (default: unlimited).
|
||||||
* @param {Number} [options.max_alternatives] Max. number of alternatives supported in alternative routes query (default: 3).
|
* @param {Number} [options.max_alternatives] Max. number of alternatives supported in alternative routes query (default: 3).
|
||||||
|
* @param {Number} [options.default_radius] Default radius for queries (default: unlimited).
|
||||||
*
|
*
|
||||||
* @class OSRM
|
* @class OSRM
|
||||||
*
|
*
|
||||||
|
@ -147,7 +147,10 @@ inline unsigned generateServerProgramOptions(const int argc,
|
|||||||
"Max. number of alternatives supported in the MLD route query") //
|
"Max. number of alternatives supported in the MLD route query") //
|
||||||
("max-matching-radius",
|
("max-matching-radius",
|
||||||
value<double>(&config.max_radius_map_matching)->default_value(-1.0),
|
value<double>(&config.max_radius_map_matching)->default_value(-1.0),
|
||||||
"Max. radius size supported in map matching query. Default: unlimited.");
|
"Max. radius size supported in map matching query. Default: unlimited.") //
|
||||||
|
("default-radius",
|
||||||
|
value<boost::optional<double>>(&config.default_radius),
|
||||||
|
"Default radius size for queries. Default: unlimited.");
|
||||||
|
|
||||||
// hidden options, will be allowed on command line, but will not be shown to the user
|
// hidden options, will be allowed on command line, but will not be shown to the user
|
||||||
boost::program_options::options_description hidden_options("Hidden options");
|
boost::program_options::options_description hidden_options("Hidden options");
|
||||||
|
@ -112,6 +112,18 @@ test('constructor: throws if dataset_name is not a string', function(assert) {
|
|||||||
assert.throws(function() { new OSRM({dataset_name: "unsued_name___", shared_memory: true}); }, /Could not find shared memory region/, 'Does not accept wrong name');
|
assert.throws(function() { new OSRM({dataset_name: "unsued_name___", shared_memory: true}); }, /Could not find shared memory region/, 'Does not accept wrong name');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('constructor: takes a default_radius argument', function(assert) {
|
||||||
|
assert.plan(1);
|
||||||
|
var osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1});
|
||||||
|
assert.ok(osrm);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('constructor: throws if default_radius is not a number', function(assert) {
|
||||||
|
assert.plan(2);
|
||||||
|
assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 'abc'}); }, /default_radius must be an integral number/, 'Does not accept string');
|
||||||
|
assert.ok(new OSRM({algorithm: 'MLD', path: monaco_mld_path, default_radius: 1}), 'Does accept number');
|
||||||
|
});
|
||||||
|
|
||||||
test('constructor: parses custom limits', function(assert) {
|
test('constructor: parses custom limits', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
var osrm = new OSRM({
|
var osrm = new OSRM({
|
||||||
|
Loading…
Reference in New Issue
Block a user