From d2b1376558cd7487a9190449d2e5484f46e2e718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Thu, 27 Nov 2014 12:09:07 +0100 Subject: [PATCH] Add a commande line option to osrm-routed for max locations supported in distance table query --- Library/OSRM.h | 2 +- Library/OSRM_impl.cpp | 8 ++++---- Library/OSRM_impl.h | 2 +- Plugins/DistanceTablePlugin.h | 9 ++++++--- Tools/simpleclient.cpp | 5 +++-- Util/ProgramOptions.h | 13 +++++++++++-- routed.cpp | 7 ++++--- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index 372e82c3919..6bfa845a66e 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -46,7 +46,7 @@ class OSRM std::unique_ptr OSRM_pimpl_; public: - explicit OSRM(ServerPaths paths, const bool use_shared_memory = false); + explicit OSRM(ServerPaths paths, const bool use_shared_memory = false, const int max_locations_distance_table = 100); ~OSRM(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); }; diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 44547cd42db..f3acae4212b 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -58,7 +58,7 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) +OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory, const int max_locations_distance_table) { if (use_shared_memory) { @@ -73,7 +73,7 @@ OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) } // The following plugins handle all requests. - RegisterPlugin(new DistanceTablePlugin>(query_data_facade)); + RegisterPlugin(new DistanceTablePlugin>(query_data_facade, max_locations_distance_table)); RegisterPlugin(new HelloWorldPlugin()); RegisterPlugin(new LocatePlugin>(query_data_facade)); RegisterPlugin(new NearestPlugin>(query_data_facade)); @@ -153,8 +153,8 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) // proxy code for compilation firewall -OSRM::OSRM(ServerPaths paths, const bool use_shared_memory) - : OSRM_pimpl_(osrm::make_unique(paths, use_shared_memory)) +OSRM::OSRM(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table) + : OSRM_pimpl_(osrm::make_unique(paths, use_shared_memory, max_locations_distance_table)) { } diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index a4af62cb65a..12b0f2ae0f0 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -49,7 +49,7 @@ class OSRM_impl using PluginMap = std::unordered_map; public: - OSRM_impl(ServerPaths paths, const bool use_shared_memory); + OSRM_impl(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table); OSRM_impl(const OSRM_impl &) = delete; virtual ~OSRM_impl(); void RunQuery(RouteParameters &route_parameters, http::Reply &reply); diff --git a/Plugins/DistanceTablePlugin.h b/Plugins/DistanceTablePlugin.h index 329936fcd39..d384b4039e9 100644 --- a/Plugins/DistanceTablePlugin.h +++ b/Plugins/DistanceTablePlugin.h @@ -52,9 +52,11 @@ template class DistanceTablePlugin final : public BasePlugin { private: std::unique_ptr> search_engine_ptr; + int max_locations_distance_table; public: - explicit DistanceTablePlugin(DataFacadeT *facade) : descriptor_string("table"), facade(facade) + explicit DistanceTablePlugin(DataFacadeT *facade, const int max_locations_distance_table) : + max_locations_distance_table(max_locations_distance_table), descriptor_string("table"), facade(facade) { search_engine_ptr = osrm::make_unique>(facade); } @@ -72,8 +74,9 @@ template class DistanceTablePlugin final : public BasePlugin } const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum()); - unsigned max_locations = - std::min(100u, static_cast(route_parameters.coordinates.size())); + unsigned max_locations = std::min(static_cast(max_locations_distance_table), + static_cast(route_parameters.coordinates.size())); + PhantomNodeArray phantom_node_vector(max_locations); for (const auto i : osrm::irange(1u, max_locations)) { diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index b6714566a21..be86df5854e 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -65,7 +65,7 @@ int main(int argc, const char *argv[]) try { std::string ip_address; - int ip_port, requested_thread_num; + int ip_port, requested_thread_num, max_locations_distance_table; bool use_shared_memory = false, trial = false; ServerPaths server_paths; if (!GenerateServerProgramOptions(argc, @@ -75,7 +75,8 @@ int main(int argc, const char *argv[]) ip_port, requested_thread_num, use_shared_memory, - trial)) + trial, + max_locations_distance_table)) { return 0; } diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index bde9766a65c..b9e2ca403a8 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -151,7 +151,8 @@ inline unsigned GenerateServerProgramOptions(const int argc, int &ip_port, int &requested_num_threads, bool &use_shared_memory, - bool &trial) + bool &trial, + int &max_locations_distance_table) { // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); @@ -198,7 +199,10 @@ inline unsigned GenerateServerProgramOptions(const int argc, "Number of threads to use")( "sharedmemory,s", boost::program_options::value(&use_shared_memory)->implicit_value(true), - "Load data from shared memory"); + "Load data from shared memory")( + "max_locations_distance_table", + boost::program_options::value(&max_locations_distance_table)->default_value(100), + "Max locations supported in distance table query"); // hidden options, will be allowed both on command line and in config // file, but will not be shown to the user @@ -272,6 +276,11 @@ inline unsigned GenerateServerProgramOptions(const int argc, { return INIT_OK_START_ENGINE; } + if (1 > max_locations_distance_table) + { + throw OSRMException("Max location for distance table must be a positive number"); + } + SimpleLogger().Write() << visible_options; return INIT_OK_DO_NOT_START_ENGINE; } diff --git a/routed.cpp b/routed.cpp index 98e45a7a620..32e860c3f4c 100644 --- a/routed.cpp +++ b/routed.cpp @@ -71,7 +71,7 @@ int main(int argc, const char *argv[]) bool use_shared_memory = false, trial_run = false; std::string ip_address; - int ip_port, requested_thread_num; + int ip_port, requested_thread_num, max_locations_distance_table; ServerPaths server_paths; @@ -82,7 +82,8 @@ int main(int argc, const char *argv[]) ip_port, requested_thread_num, use_shared_memory, - trial_run); + trial_run, + max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return 0; @@ -117,7 +118,7 @@ int main(int argc, const char *argv[]) pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - OSRM osrm_lib(server_paths, use_shared_memory); + OSRM osrm_lib(server_paths, use_shared_memory, max_locations_distance_table); auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num);