Add a commande line option to osrm-routed for max locations supported in distance table query

This commit is contained in:
Frédéric Rodrigo 2014-11-27 12:09:07 +01:00 committed by Frederic Rodrigo
parent 1d2f06df6d
commit e2605c2838
7 changed files with 30 additions and 16 deletions

View File

@ -46,7 +46,7 @@ class OSRM
std::unique_ptr<OSRM_impl> OSRM_pimpl_; std::unique_ptr<OSRM_impl> OSRM_pimpl_;
public: 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(); ~OSRM();
void RunQuery(RouteParameters &route_parameters, http::Reply &reply); void RunQuery(RouteParameters &route_parameters, http::Reply &reply);
}; };

View File

@ -57,7 +57,7 @@ namespace boost { namespace interprocess { class named_mutex; } }
#include <utility> #include <utility>
#include <vector> #include <vector>
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) if (use_shared_memory)
{ {
@ -72,7 +72,7 @@ OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory)
} }
// The following plugins handle all requests. // The following plugins handle all requests.
RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade)); RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade, max_locations_distance_table));
RegisterPlugin(new HelloWorldPlugin()); RegisterPlugin(new HelloWorldPlugin());
RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade)); RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade)); RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
@ -152,8 +152,8 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply)
// proxy code for compilation firewall // proxy code for compilation firewall
OSRM::OSRM(ServerPaths paths, const bool use_shared_memory) OSRM::OSRM(ServerPaths paths, const bool use_shared_memory, const int max_locations_distance_table)
: OSRM_pimpl_(osrm::make_unique<OSRM_impl>(paths, use_shared_memory)) : OSRM_pimpl_(osrm::make_unique<OSRM_impl>(paths, use_shared_memory, max_locations_distance_table))
{ {
} }

View File

@ -49,7 +49,7 @@ class OSRM_impl
using PluginMap = std::unordered_map<std::string, BasePlugin *>; using PluginMap = std::unordered_map<std::string, BasePlugin *>;
public: 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; OSRM_impl(const OSRM_impl &) = delete;
virtual ~OSRM_impl(); virtual ~OSRM_impl();
void RunQuery(RouteParameters &route_parameters, http::Reply &reply); void RunQuery(RouteParameters &route_parameters, http::Reply &reply);

View File

@ -151,7 +151,8 @@ inline unsigned GenerateServerProgramOptions(const int argc,
int &ip_port, int &ip_port,
int &requested_num_threads, int &requested_num_threads,
bool &use_shared_memory, 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 // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
@ -198,7 +199,10 @@ inline unsigned GenerateServerProgramOptions(const int argc,
"Number of threads to use")( "Number of threads to use")(
"sharedmemory,s", "sharedmemory,s",
boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true), boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true),
"Load data from shared memory"); "Load data from shared memory")(
"max_locations_distance_table",
boost::program_options::value<int>(&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 // hidden options, will be allowed both on command line and in config
// file, but will not be shown to the user // file, but will not be shown to the user
@ -272,6 +276,11 @@ inline unsigned GenerateServerProgramOptions(const int argc,
{ {
return INIT_OK_START_ENGINE; 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; SimpleLogger().Write() << visible_options;
return INIT_OK_DO_NOT_START_ENGINE; return INIT_OK_DO_NOT_START_ENGINE;
} }

View File

@ -52,9 +52,11 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
{ {
private: private:
std::unique_ptr<SearchEngine<DataFacadeT>> search_engine_ptr; std::unique_ptr<SearchEngine<DataFacadeT>> search_engine_ptr;
int max_locations_distance_table;
public: 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<SearchEngine<DataFacadeT>>(facade); search_engine_ptr = osrm::make_unique<SearchEngine<DataFacadeT>>(facade);
} }
@ -72,8 +74,9 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
} }
const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum()); const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum());
unsigned max_locations = unsigned max_locations = std::min(static_cast<unsigned>(max_locations_distance_table),
std::min(100u, static_cast<unsigned>(route_parameters.coordinates.size())); static_cast<unsigned>(route_parameters.coordinates.size()));
PhantomNodeArray phantom_node_vector(max_locations); PhantomNodeArray phantom_node_vector(max_locations);
for (const auto i : osrm::irange(0u, max_locations)) for (const auto i : osrm::irange(0u, max_locations))
{ {

View File

@ -71,7 +71,7 @@ int main(int argc, const char *argv[])
bool use_shared_memory = false, trial_run = false; bool use_shared_memory = false, trial_run = false;
std::string ip_address; std::string ip_address;
int ip_port, requested_thread_num; int ip_port, requested_thread_num, max_locations_distance_table;
ServerPaths server_paths; ServerPaths server_paths;
@ -82,7 +82,8 @@ int main(int argc, const char *argv[])
ip_port, ip_port,
requested_thread_num, requested_thread_num,
use_shared_memory, use_shared_memory,
trial_run); trial_run,
max_locations_distance_table);
if (init_result == INIT_OK_DO_NOT_START_ENGINE) if (init_result == INIT_OK_DO_NOT_START_ENGINE)
{ {
return 0; return 0;
@ -117,7 +118,7 @@ int main(int argc, const char *argv[])
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
#endif #endif
OSRM osrm_lib(server_paths, use_shared_memory); OSRM osrm_lib(server_paths, use_shared_memory, max_locations_distance_table);
auto routing_server = auto routing_server =
Server::CreateServer(ip_address, ip_port, requested_thread_num); Server::CreateServer(ip_address, ip_port, requested_thread_num);

View File

@ -65,7 +65,7 @@ int main(int argc, const char *argv[])
try try
{ {
std::string ip_address; 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_run = false; bool use_shared_memory = false, trial_run = false;
ServerPaths server_paths; ServerPaths server_paths;
@ -76,7 +76,8 @@ int main(int argc, const char *argv[])
ip_port, ip_port,
requested_thread_num, requested_thread_num,
use_shared_memory, use_shared_memory,
trial_run); trial_run,
max_locations_distance_table);
if (init_result == INIT_FAILED) if (init_result == INIT_FAILED)
{ {