Merge pull request #1335 from Project-OSRM/feature/frodrigo-max_locations_distance_table
Feature/frodrigo max locations distance table
This commit is contained in:
		
						commit
						0e5a448d04
					
				
							
								
								
									
										52
									
								
								Include/osrm/libosrm_config.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Include/osrm/libosrm_config.hpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| /*
 | ||||
| 
 | ||||
| Copyright (c) 2015, Project OSRM, Dennis Luxen, others | ||||
| All rights reserved. | ||||
| 
 | ||||
| Redistribution and use in source and binary forms, with or without modification, | ||||
| are permitted provided that the following conditions are met: | ||||
| 
 | ||||
| Redistributions of source code must retain the above copyright notice, this list | ||||
| of conditions and the following disclaimer. | ||||
| Redistributions in binary form must reproduce the above copyright notice, this | ||||
| list of conditions and the following disclaimer in the documentation and/or | ||||
| other materials provided with the distribution. | ||||
| 
 | ||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| 
 | ||||
| */ | ||||
| 
 | ||||
| #ifndef SERVER_CONFIG_HPP | ||||
| #define SERVER_CONFIG_HPP | ||||
| 
 | ||||
| #include <osrm/server_paths.hpp> | ||||
| 
 | ||||
| struct libosrm_config | ||||
| { | ||||
|     libosrm_config(const libosrm_config&) = delete; | ||||
|     libosrm_config() | ||||
|         : max_locations_distance_table(100) | ||||
|         , use_shared_memory(false) | ||||
|     {} | ||||
| 
 | ||||
|     libosrm_config(const ServerPaths &paths, const bool flag, const int max) | ||||
|         : server_paths(paths) | ||||
|         , max_locations_distance_table(max) | ||||
|         , use_shared_memory(flag) | ||||
|     {} | ||||
| 
 | ||||
|     ServerPaths server_paths; | ||||
|     int max_locations_distance_table; | ||||
|     bool use_shared_memory; | ||||
| }; | ||||
| 
 | ||||
| #endif // SERVER_CONFIG_HPP
 | ||||
| @ -1,6 +1,6 @@ | ||||
| /*
 | ||||
| 
 | ||||
| Copyright (c) 2013, Project OSRM, Dennis Luxen, others | ||||
| Copyright (c) 2015, Project OSRM, Dennis Luxen, others | ||||
| All rights reserved. | ||||
| 
 | ||||
| Redistribution and use in source and binary forms, with or without modification, | ||||
| @ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| #ifndef OSRM_H | ||||
| #define OSRM_H | ||||
| 
 | ||||
| #include <osrm/server_paths.hpp> | ||||
| #include <osrm/libosrm_config.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| 
 | ||||
| @ -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(libosrm_config &lib_config); | ||||
|     ~OSRM(); | ||||
|     int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result); | ||||
| }; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| /*
 | ||||
| 
 | ||||
| Copyright (c) 2014, Project OSRM, Dennis Luxen, others | ||||
| Copyright (c) 2015, Project OSRM, Dennis Luxen, others | ||||
| All rights reserved. | ||||
| 
 | ||||
| Redistribution and use in source and binary forms, with or without modification, | ||||
| @ -49,16 +49,15 @@ namespace boost { namespace interprocess { class named_mutex; } } | ||||
| #include <boost/interprocess/sync/scoped_lock.hpp> | ||||
| 
 | ||||
| #include <osrm/route_parameters.hpp> | ||||
| #include <osrm/server_paths.hpp> | ||||
| 
 | ||||
| #include <algorithm> | ||||
| #include <fstream> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
| 
 | ||||
| OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) | ||||
| OSRM_impl::OSRM_impl(libosrm_config &lib_config) | ||||
| { | ||||
|     if (use_shared_memory) | ||||
|     if (lib_config.use_shared_memory) | ||||
|     { | ||||
|         barrier = osrm::make_unique<SharedBarriers>(); | ||||
|         query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>(); | ||||
| @ -66,12 +65,13 @@ OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) | ||||
|     else | ||||
|     { | ||||
|         // populate base path
 | ||||
|         populate_base_path(server_paths); | ||||
|         query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(server_paths); | ||||
|         populate_base_path(lib_config.server_paths); | ||||
|         query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(lib_config.server_paths); | ||||
|     } | ||||
| 
 | ||||
|     // The following plugins handle all requests.
 | ||||
|     RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade)); | ||||
|     RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade, | ||||
|         lib_config.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)); | ||||
| @ -151,8 +151,8 @@ int OSRM_impl::RunQuery(RouteParameters &route_parameters, JSON::Object &json_re | ||||
| 
 | ||||
| // 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(libosrm_config &lib_config) | ||||
|     : OSRM_pimpl_(osrm::make_unique<OSRM_impl>(lib_config)) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| /*
 | ||||
| 
 | ||||
| Copyright (c) 2013, Project OSRM, Dennis Luxen, others | ||||
| Copyright (c) 2015, Project OSRM, Dennis Luxen, others | ||||
| All rights reserved. | ||||
| 
 | ||||
| Redistribution and use in source and binary forms, with or without modification, | ||||
| @ -32,11 +32,11 @@ class BasePlugin; | ||||
| namespace http { class Reply; } | ||||
| struct RouteParameters; | ||||
| 
 | ||||
| #include <osrm/json_container.hpp> | ||||
| #include <osrm/server_paths.hpp> | ||||
| 
 | ||||
| #include "../data_structures/query_edge.hpp" | ||||
| 
 | ||||
| #include <osrm/json_container.hpp> | ||||
| #include <osrm/libosrm_config.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <unordered_map> | ||||
| #include <string> | ||||
| @ -50,7 +50,7 @@ class OSRM_impl | ||||
|     using PluginMap = std::unordered_map<std::string, BasePlugin *>; | ||||
| 
 | ||||
|   public: | ||||
|     OSRM_impl(ServerPaths paths, const bool use_shared_memory); | ||||
|     OSRM_impl(libosrm_config &lib_config); | ||||
|     OSRM_impl(const OSRM_impl &) = delete; | ||||
|     virtual ~OSRM_impl(); | ||||
|     int RunQuery(RouteParameters &route_parameters, JSON::Object &json_result); | ||||
|  | ||||
| @ -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<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
 | ||||
| @ -272,6 +276,11 @@ inline unsigned GenerateServerProgramOptions(const int argc, | ||||
|     { | ||||
|         return INIT_OK_START_ENGINE; | ||||
|     } | ||||
|     if (1 > max_locations_distance_table) | ||||
|     { | ||||
|         throw osrm::exception("Max location for distance table must be a positive number"); | ||||
|     } | ||||
| 
 | ||||
|     SimpleLogger().Write() << visible_options; | ||||
|     return INIT_OK_DO_NOT_START_ENGINE; | ||||
| } | ||||
|  | ||||
| @ -25,7 +25,8 @@ Feature: osrm-routed command line options: help | ||||
|         And stdout should contain "--port" | ||||
|         And stdout should contain "--threads" | ||||
|         And stdout should contain "--sharedmemory" | ||||
|         And stdout should contain 22 lines | ||||
|         And stdout should contain "--max_locations_distance_table" | ||||
|         And stdout should contain 25 lines | ||||
|         And it should exit with code 0 | ||||
| 
 | ||||
|     Scenario: osrm-routed - Help, short | ||||
| @ -49,7 +50,8 @@ Feature: osrm-routed command line options: help | ||||
|         And stdout should contain "--port" | ||||
|         And stdout should contain "--threads" | ||||
|         And stdout should contain "--sharedmemory" | ||||
|         And stdout should contain 22 lines | ||||
|         And stdout should contain "--max_locations_distance_table" | ||||
|         And stdout should contain 25 lines | ||||
|         And it should exit with code 0 | ||||
| 
 | ||||
|     Scenario: osrm-routed - Help, long | ||||
| @ -73,5 +75,6 @@ Feature: osrm-routed command line options: help | ||||
|         And stdout should contain "--port" | ||||
|         And stdout should contain "--threads" | ||||
|         And stdout should contain "--sharedmemory" | ||||
|         And stdout should contain 22 lines | ||||
|         And stdout should contain "--max_locations_distance_table" | ||||
|         And stdout should contain 25 lines | ||||
|         And it should exit with code 0 | ||||
|  | ||||
| @ -53,9 +53,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); | ||||
|     } | ||||
| @ -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(0u, max_locations)) | ||||
|         { | ||||
|  | ||||
							
								
								
									
										15
									
								
								routed.cpp
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								routed.cpp
									
									
									
									
									
								
							| @ -69,20 +69,21 @@ int main(int argc, const char *argv[]) | ||||
|     { | ||||
|         LogPolicy::GetInstance().Unmute(); | ||||
| 
 | ||||
|         bool use_shared_memory = false, trial_run = false; | ||||
|         bool trial_run = false; | ||||
|         std::string ip_address; | ||||
|         int ip_port, requested_thread_num; | ||||
| 
 | ||||
|         ServerPaths server_paths; | ||||
|         libosrm_config lib_config; | ||||
| 
 | ||||
|         const unsigned init_result = GenerateServerProgramOptions(argc, | ||||
|                                                                   argv, | ||||
|                                                                   server_paths, | ||||
|                                                                   lib_config.server_paths, | ||||
|                                                                   ip_address, | ||||
|                                                                   ip_port, | ||||
|                                                                   requested_thread_num, | ||||
|                                                                   use_shared_memory, | ||||
|                                                                   trial_run); | ||||
|                                                                   lib_config.use_shared_memory, | ||||
|                                                                   trial_run, | ||||
|                                                                   lib_config.max_locations_distance_table); | ||||
|         if (init_result == INIT_OK_DO_NOT_START_ENGINE) | ||||
|         { | ||||
|             return 0; | ||||
| @ -101,7 +102,7 @@ int main(int argc, const char *argv[]) | ||||
| #endif | ||||
|         SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION; | ||||
| 
 | ||||
|         if (use_shared_memory) | ||||
|         if (lib_config.use_shared_memory) | ||||
|         { | ||||
|             SimpleLogger().Write(logDEBUG) << "Loading from shared memory"; | ||||
|         } | ||||
| @ -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(lib_config); | ||||
|         auto routing_server = | ||||
|             Server::CreateServer(ip_address, ip_port, requested_thread_num); | ||||
| 
 | ||||
|  | ||||
| @ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| #include "../Util/simple_logger.hpp" | ||||
| 
 | ||||
| #include <osrm/json_container.hpp> | ||||
| #include <osrm/libosrm_config.hpp> | ||||
| #include <osrm/route_parameters.hpp> | ||||
| #include <osrm/server_paths.hpp> | ||||
| 
 | ||||
| #include <string> | ||||
| 
 | ||||
| @ -44,16 +44,17 @@ int main(int argc, const char *argv[]) | ||||
|     { | ||||
|         std::string ip_address; | ||||
|         int ip_port, requested_thread_num; | ||||
|         bool use_shared_memory = false, trial_run = false; | ||||
|         ServerPaths server_paths; | ||||
|         bool trial_run = false; | ||||
|         libosrm_config lib_config; | ||||
|         const unsigned init_result = GenerateServerProgramOptions(argc, | ||||
|                                                                   argv, | ||||
|                                                                   server_paths, | ||||
|                                                                   lib_config.server_paths, | ||||
|                                                                   ip_address, | ||||
|                                                                   ip_port, | ||||
|                                                                   requested_thread_num, | ||||
|                                                                   use_shared_memory, | ||||
|                                                                   trial_run); | ||||
|                                                                   lib_config.use_shared_memory, | ||||
|                                                                   trial_run, | ||||
|                                                                   lib_config.max_locations_distance_table); | ||||
| 
 | ||||
|         if (init_result == INIT_OK_DO_NOT_START_ENGINE) | ||||
|         { | ||||
| @ -65,7 +66,7 @@ int main(int argc, const char *argv[]) | ||||
|         } | ||||
|         SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION; | ||||
| 
 | ||||
|         OSRM routing_machine(server_paths, use_shared_memory); | ||||
|         OSRM routing_machine(lib_config); | ||||
| 
 | ||||
|         RouteParameters route_parameters; | ||||
|         route_parameters.zoom_level = 18;           // no generalization
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user