Skip to content

Commit

Permalink
Add a commande line option to osrm-routed for max locations supported…
Browse files Browse the repository at this point in the history
… in distance table query
  • Loading branch information
frodrigo committed Nov 27, 2014
1 parent ef8706b commit d2b1376
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Library/OSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OSRM
std::unique_ptr<OSRM_impl> 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);
};
Expand Down
8 changes: 4 additions & 4 deletions Library/OSRM_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace boost { namespace interprocess { class named_mutex; } }
#include <utility>
#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)
{
Expand All @@ -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<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade, max_locations_distance_table));
RegisterPlugin(new HelloWorldPlugin());
RegisterPlugin(new LocatePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
Expand Down Expand Up @@ -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<OSRM_impl>(paths, 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, max_locations_distance_table))
{
}

Expand Down
2 changes: 1 addition & 1 deletion Library/OSRM_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OSRM_impl
using PluginMap = std::unordered_map<std::string, BasePlugin *>;

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);
Expand Down
9 changes: 6 additions & 3 deletions Plugins/DistanceTablePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
{
private:
std::unique_ptr<SearchEngine<DataFacadeT>> 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<SearchEngine<DataFacadeT>>(facade);
}
Expand All @@ -72,8 +74,9 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
}

const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum());
unsigned max_locations =
std::min(100u, static_cast<unsigned>(route_parameters.coordinates.size()));
unsigned max_locations = std::min(static_cast<unsigned>(max_locations_distance_table),
static_cast<unsigned>(route_parameters.coordinates.size()));

PhantomNodeArray phantom_node_vector(max_locations);
for (const auto i : osrm::irange(1u, max_locations))
{
Expand Down
5 changes: 3 additions & 2 deletions Tools/simpleclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
13 changes: 11 additions & 2 deletions Util/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -198,7 +199,10 @@ inline unsigned GenerateServerProgramOptions(const int argc,
"Number of threads to use")(
"sharedmemory,s",
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
// file, but will not be shown to the user
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions routed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d2b1376

Please sign in to comment.