From 92e52f1a5d668d25388462bd113db308c9a654e8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 31 Jul 2013 13:04:04 +0200 Subject: [PATCH 01/80] Updateing Readme to display build status --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..a690eae6f --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Readme + +For instructions on how to compile and run OSRM, please consult the Wiki at + +https://github.com/DennisOSRM/Project-OSRM/wiki + +or use our free and daily updated online service at + +http://map.project-osrm.org + +## Current build status + +| build config | branch | status | +|:-------------|:--------|:------------| +| Project OSRM | master | [![Build Status](https://travis-ci.org/DennisOSRM/Project-OSRM.png?branch=master)](https://travis-ci.org/DennisOSRM/Project-OSRM) | +| Project OSRM | develop | [![Build Status](https://travis-ci.org/DennisOSRM/Project-OSRM.png?branch=develop)](https://travis-ci.org/DennisOSRM/Project-OSRM) | +| LUAbind fork | master | [![Build Status](https://travis-ci.org/DennisOSRM/luabind.png?branch=master)](https://travis-ci.org/DennisOSRM/luabind) | From d4ea5fc74f48a0b528045f64740b48681caaba09 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 31 Jul 2013 13:09:25 +0200 Subject: [PATCH 02/80] Updateing Readme to give proper reference --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index a690eae6f..2b51aaf1e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,27 @@ or use our free and daily updated online service at http://map.project-osrm.org +## References in publications + +When using the code in a (scientific) publication, please cite + +@inproceedings{luxen-vetter-2011, + author = {Luxen, Dennis and Vetter, Christian}, + title = {Real-time routing with OpenStreetMap data}, + booktitle = {Proceedings of the 19th ACM SIGSPATIAL International Conference on Advances in Geographic Information Systems}, + series = {GIS '11}, + year = {2011}, + isbn = {978-1-4503-1031-4}, + location = {Chicago, Illinois}, + pages = {513--516}, + numpages = {4}, + url = {http://doi.acm.org/10.1145/2093973.2094062}, + doi = {10.1145/2093973.2094062}, + acmid = {2094062}, + publisher = {ACM}, + address = {New York, NY, USA}, +} + ## Current build status | build config | branch | status | From c9a756eddc57cab55579950f0972f0a6fe500af3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 31 Jul 2013 13:12:25 +0200 Subject: [PATCH 03/80] Updateing Readme to give proper reference (again) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2b51aaf1e..1c77f7202 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ http://map.project-osrm.org When using the code in a (scientific) publication, please cite +``` @inproceedings{luxen-vetter-2011, author = {Luxen, Dennis and Vetter, Christian}, title = {Real-time routing with OpenStreetMap data}, @@ -28,6 +29,7 @@ When using the code in a (scientific) publication, please cite publisher = {ACM}, address = {New York, NY, USA}, } +``` ## Current build status From 3067ba60aef36ecccde29d7343c6f8186591526e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 31 Jul 2013 22:05:44 +0200 Subject: [PATCH 04/80] convert relative path in server.ini to absolute paths --- Library/OSRM.cpp | 45 ++++++++++++++++++++++++++++++++++++++------- Library/OSRM.h | 1 + 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index e656a605c..67fe7500d 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -26,14 +26,45 @@ OSRM::OSRM(const char * server_ini_path) { } BaseConfiguration serverConfig(server_ini_path); + + boost::system::error_code ec; + + boost::filesystem::path base_path = + boost::filesystem::complete(server_ini_path).parent_path(); + objects = new QueryObjectsStorage( - serverConfig.GetParameter("hsgrData"), - serverConfig.GetParameter("ramIndex"), - serverConfig.GetParameter("fileIndex"), - serverConfig.GetParameter("nodesData"), - serverConfig.GetParameter("edgesData"), - serverConfig.GetParameter("namesData"), - serverConfig.GetParameter("timestamp") + boost::filesystem::canonical( + serverConfig.GetParameter("hsgrData"), + base_path, ec ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("ramIndex"), + base_path, + ec + ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("fileIndex"), + base_path, + ec + ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("nodesData"), + base_path, + ec ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("edgesData"), + base_path, + ec + ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("namesData"), + base_path, + ec + ).string(), + boost::filesystem::canonical( + serverConfig.GetParameter("timestamp"), + base_path, + ec + ).string() ); RegisterPlugin(new HelloWorldPlugin()); diff --git a/Library/OSRM.h b/Library/OSRM.h index 9a4c601d5..4f505f387 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -35,6 +35,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Server/BasicDatastructures.h" #include +#include #include #include From 960b55fd6c80fd9b85e6f9688e30e23664976a13 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 31 Jul 2013 22:55:20 +0200 Subject: [PATCH 05/80] accidentially called deprecated boost filesystem function --- Library/OSRM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 67fe7500d..40bb3eabf 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -30,7 +30,7 @@ OSRM::OSRM(const char * server_ini_path) { boost::system::error_code ec; boost::filesystem::path base_path = - boost::filesystem::complete(server_ini_path).parent_path(); + boost::filesystem::absolute(server_ini_path).parent_path(); objects = new QueryObjectsStorage( boost::filesystem::canonical( From ec7d3a988545cf2ca352836e9a1b837938bd73cc Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 1 Aug 2013 15:56:18 +0200 Subject: [PATCH 06/80] Fixing boost filesystem to work on old installations, too --- Library/OSRM.cpp | 75 ++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 40bb3eabf..2da379901 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -27,44 +27,49 @@ OSRM::OSRM(const char * server_ini_path) { BaseConfiguration serverConfig(server_ini_path); - boost::system::error_code ec; - boost::filesystem::path base_path = - boost::filesystem::absolute(server_ini_path).parent_path(); + boost::filesystem::absolute(server_ini_path).parent_path(); + + boost::filesystem::path hsgr_path = boost::filesystem::absolute( + serverConfig.GetParameter("hsgrData"), + base_path + ); + + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("ramIndex"), + base_path + ); + + boost::filesystem::path file_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("fileIndex"), + base_path + ); + + boost::filesystem::path node_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("nodesData"), + base_path + ); + boost::filesystem::path edge_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("edgesData"), + base_path + ); + boost::filesystem::path name_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("namesData"), + base_path + ); + boost::filesystem::path timestamp_path = boost::filesystem::absolute( + serverConfig.GetParameter("timestamp"), + base_path + ); objects = new QueryObjectsStorage( - boost::filesystem::canonical( - serverConfig.GetParameter("hsgrData"), - base_path, ec ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("ramIndex"), - base_path, - ec - ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("fileIndex"), - base_path, - ec - ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("nodesData"), - base_path, - ec ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("edgesData"), - base_path, - ec - ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("namesData"), - base_path, - ec - ).string(), - boost::filesystem::canonical( - serverConfig.GetParameter("timestamp"), - base_path, - ec - ).string() + hsgr_path.string(), + ram_index_path.string(), + file_index_path.string(), + node_data_path.string(), + edge_data_path.string(), + name_data_path.string(), + timestamp_path.string() ); RegisterPlugin(new HelloWorldPlugin()); From 63059cfab35191bd4e425a8721062c310cf1e687 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Fri, 2 Aug 2013 09:34:58 +0200 Subject: [PATCH 07/80] make cuke tests work with ruby 2.x --- features/support/env.rb | 2 +- features/support/hash.rb | 13 ++++++++----- features/support/osm_parser.rb | 14 ++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index 13a0b0c5e..a6a99b9f5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,7 +4,7 @@ DEFAULT_PORT = 5000 puts "Ruby version #{RUBY_VERSION}" -unless RUBY_VERSION =~ /^1.9/ +unless RUBY_VERSION.to_f >= 1.9 raise "*** Please upgrade to Ruby 1.9.x to run the OSRM cucumber tests" end diff --git a/features/support/hash.rb b/features/support/hash.rb index e37a6f2df..7639364fb 100644 --- a/features/support/hash.rb +++ b/features/support/hash.rb @@ -1,5 +1,8 @@ require 'digest/sha1' +bin_extract_hash = nil +profile_hashes = nil + def hash_of_files paths paths = [paths] unless paths.is_a? Array hash = Digest::SHA1.new @@ -16,8 +19,8 @@ end def profile_hash - @@profile_hashes ||= {} - @@profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua" + profile_hashes ||= {} + profile_hashes[@profile] ||= hash_of_files "#{PROFILES_PATH}/#{@profile}.lua" end def osm_hash @@ -29,15 +32,15 @@ def lua_lib_hash end def bin_extract_hash - @@bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract" + bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract" end def bin_prepare_hash - @@bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare" + bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare" end def bin_routed_hash - @@bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed" + bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed" end #combine state of data, profile and binaries into a hash that identifies the exact test scenario diff --git a/features/support/osm_parser.rb b/features/support/osm_parser.rb index ea4e9bd16..3331a70bc 100644 --- a/features/support/osm_parser.rb +++ b/features/support/osm_parser.rb @@ -1,23 +1,25 @@ require 'OSM/StreamParser' +locations = nil + class OSMTestParserCallbacks < OSM::Callbacks - @@locations = nil + locations = nil def self.locations - if @@locations - @@locations + if locations + locations else #parse the test file, so we can later reference nodes and ways by name in tests - @@locations = {} + locations = {} file = 'test/data/test.osm' callbacks = OSMTestParserCallbacks.new parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks) parser.parse - puts @@locations + puts locations end end def node(node) - @@locations[node.name] = [node.lat,node.lon] + locations[node.name] = [node.lat,node.lon] end end \ No newline at end of file From 54302a53e130ec0466608db0ea17b9d533422ad1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 17:28:57 +0200 Subject: [PATCH 08/80] use exceptions instead of hard abort --- Contractor/Contractor.h | 3 +- Contractor/TemporaryStorage.cpp | 29 +++---- Contractor/TemporaryStorage.h | 7 +- DataStructures/ImportEdge.h | 32 ++++++- DataStructures/NodeInformationHelpDesk.h | 13 ++- Extractor/BaseParser.cpp | 46 ++++------ Extractor/BaseParser.h | 1 + Extractor/ExtractionContainers.h | 8 +- Extractor/PBFParser.cpp | 8 +- Extractor/PBFParser.h | 1 + Extractor/ScriptingEnvironment.cpp | 85 +++++++++---------- Extractor/ScriptingEnvironment.h | 1 + Library/OSRM.h | 12 +-- Server/DataStructures/QueryObjectsStorage.cpp | 8 +- Server/DataStructures/QueryObjectsStorage.h | 1 + Server/ServerFactory.h | 18 ++-- Util/BaseConfiguration.h | 36 ++++---- Util/GraphLoader.h | 26 ++++-- Util/StringUtil.h | 14 +-- Util/UUID.cpp.in | 10 +-- Util/UUID.h | 1 + createHierarchy.cpp | 56 +++++++++--- extractor.cpp | 25 ++++-- 23 files changed, 248 insertions(+), 193 deletions(-) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 18bee5de6..bbc3ad58e 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -434,8 +434,9 @@ public: p.printStatus(numberOfContractedNodes); } - BOOST_FOREACH(_ThreadData * data, threadData) + BOOST_FOREACH(_ThreadData * data, threadData) { delete data; + } threadData.clear(); } diff --git a/Contractor/TemporaryStorage.cpp b/Contractor/TemporaryStorage.cpp index dbd86e3e5..2f8691066 100644 --- a/Contractor/TemporaryStorage.cpp +++ b/Contractor/TemporaryStorage.cpp @@ -21,11 +21,7 @@ #include "TemporaryStorage.h" TemporaryStorage::TemporaryStorage() { - try { - tempDirectory = boost::filesystem::temp_directory_path(); - } catch(boost::filesystem::filesystem_error & e) { - ERR("could not retrieve location of temporary path: " << e.what()); - } + tempDirectory = boost::filesystem::temp_directory_path(); } TemporaryStorage & TemporaryStorage::GetInstance(){ @@ -39,12 +35,8 @@ TemporaryStorage::~TemporaryStorage() { void TemporaryStorage::removeAll() { boost::mutex::scoped_lock lock(mutex); - try { - for(unsigned slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID) - deallocateSlot(slotID); - - } catch(boost::filesystem::filesystem_error & e) { - ERR("could not retrieve location of temporary path: " << e.what()); + for(unsigned slot_id = 0; slot_id < vectorOfStreamDatas.size(); ++slot_id) { + deallocateSlot(slot_id); } vectorOfStreamDatas.clear(); } @@ -64,13 +56,13 @@ void TemporaryStorage::deallocateSlot(int slotID) { try { StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); - if(!boost::filesystem::exists(data.pathToTemporaryFile)) { + if(!boost::filesystem::exists(data.pathToTemporaryFile)) { return; } - if(data.streamToTemporaryFile->is_open()) + if(data.streamToTemporaryFile->is_open()) { data.streamToTemporaryFile->close(); + } - //INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile); boost::filesystem::remove(data.pathToTemporaryFile); } catch(boost::filesystem::filesystem_error & e) { abort(e); @@ -81,8 +73,10 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s try { StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); - if(!data.writeMode) - ERR("Writing after first read is not allowed"); + BOOST_ASSERT_MSG( + data.writeMode, + "Writing after first read is not allowed" + ); data.streamToTemporaryFile->write(pointer, size); } catch(boost::filesystem::filesystem_error & e) { abort(e); @@ -121,13 +115,11 @@ boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) { } catch(boost::filesystem::filesystem_error & e) { abort(e); } -// INFO("telling position: " << position); return position; } void TemporaryStorage::abort(boost::filesystem::filesystem_error& ) { removeAll(); -// ERR("I/O Error occured: " << e.what()); } void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) { @@ -135,7 +127,6 @@ void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type pos StreamData & data = vectorOfStreamDatas[slotID]; boost::mutex::scoped_lock lock(*data.readWriteMutex); data.streamToTemporaryFile->seekg(position); -// INFO("seeking to position: " << position); } catch(boost::filesystem::filesystem_error & e) { abort(e); } diff --git a/Contractor/TemporaryStorage.h b/Contractor/TemporaryStorage.h index 84004c71c..066d22de5 100644 --- a/Contractor/TemporaryStorage.h +++ b/Contractor/TemporaryStorage.h @@ -24,12 +24,14 @@ #include #include +#include #include #include #include #include #include +#include "../Util/OSRMException.h" #include "../typedefs.h" //This is one big workaround for latest boost renaming woes. @@ -102,8 +104,9 @@ private: streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)), readWriteMutex(new boost::mutex) { - if(streamToTemporaryFile->fail()) - ERR("Aborting, because temporary file at " << pathToTemporaryFile << " could not be created"); + if(streamToTemporaryFile->fail()) { + throw OSRMException("temporary file could not be created"); + } } }; //vector of file streams that is used to store temporary data diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 714560ccc..5da516b15 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EDGE_H #define EDGE_H + +#include "../Util/OSRMException.h" #include class NodeBasedEdge { @@ -40,8 +42,34 @@ public: return (source() < e.source()); } - explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar, bool cf) : - _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _contraFlow(cf) { if(ty < 0) {ERR("Type: " << ty);}; } + explicit NodeBasedEdge( + NodeID s, + NodeID t, + NodeID n, + EdgeWeight w, + bool f, + bool b, + short ty, + bool ra, + bool ig, + bool ar, + bool cf + ) : _source(s), + _target(t), + _name(n), + _weight(w), + forward(f), + backward(b), + _type(ty), + _roundabout(ra), + _ignoreInGrid(ig), + _accessRestricted(ar), + _contraFlow(cf) + { + if(ty < 0) { + throw OSRMException("negative edge type"); + } + } NodeID target() const {return _target; } NodeID source() const {return _source; } diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 48bad7879..4ec7ac1f3 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "PhantomNodes.h" #include "StaticRTree.h" #include "../Contractor/EdgeBasedGraphFactory.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include @@ -126,10 +127,14 @@ private: const std::string & nodes_file, const std::string & edges_file ) { - std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); - if(!nodes_input_stream) { ERR(nodes_file << " not found"); } - std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); - if(!edges_input_stream) { ERR(edges_file << " not found"); } + std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); + if(!nodes_input_stream) { + throw OSRMException("nodes file not found"); + } + std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); + if(!edges_input_stream) { + throw OSRMException("edges file not found"); + } DEBUG("Loading node data"); NodeInfo b; diff --git a/Extractor/BaseParser.cpp b/Extractor/BaseParser.cpp index 6981e9570..b5ba3e614 100644 --- a/Extractor/BaseParser.cpp +++ b/Extractor/BaseParser.cpp @@ -29,7 +29,9 @@ extractor_callbacks(ec), scriptingEnvironment(se), luaState(NULL), use_turn_rest void BaseParser::ReadUseRestrictionsSetting() { if( 0 != luaL_dostring( luaState, "return use_turn_restrictions\n") ) { - ERR(lua_tostring( luaState,-1)<< " occured in scripting block"); + throw OSRMException( + /*lua_tostring( luaState, -1 ) + */"ERROR occured in scripting block" + ); } if( lua_isboolean( luaState, -1) ) { use_turn_restrictions = lua_toboolean(luaState, -1); @@ -44,20 +46,14 @@ void BaseParser::ReadUseRestrictionsSetting() { void BaseParser::ReadRestrictionExceptions() { if(lua_function_exists(luaState, "get_exceptions" )) { //get list of turn restriction exceptions - try { - luabind::call_function( - luaState, - "get_exceptions", - boost::ref(restriction_exceptions) - ); - INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); - BOOST_FOREACH(std::string & str, restriction_exceptions) { - INFO(" " << str); - } - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); + luabind::call_function( + luaState, + "get_exceptions", + boost::ref(restriction_exceptions) + ); + INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); + BOOST_FOREACH(const std::string & str, restriction_exceptions) { + INFO(" " << str); } } else { INFO("Found no exceptions to turn restrictions"); @@ -72,37 +68,25 @@ void BaseParser::report_errors(lua_State *L, const int status) const { } void BaseParser::ParseNodeInLua(ImportNode& n, lua_State* localLuaState) { - try { - luabind::call_function( localLuaState, "node_function", boost::ref(n) ); - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); - } + luabind::call_function( localLuaState, "node_function", boost::ref(n) ); } void BaseParser::ParseWayInLua(ExtractionWay& w, lua_State* localLuaState) { if(2 > w.path.size()) { return; } - try { - luabind::call_function( localLuaState, "way_function", boost::ref(w) ); - } catch (const luabind::error &er) { - lua_State* Ler=er.state(); - report_errors(Ler, -1); - ERR(er.what()); - } + luabind::call_function( localLuaState, "way_function", boost::ref(w) ); } bool BaseParser::ShouldIgnoreRestriction(const std::string& except_tag_string) const { //should this restriction be ignored? yes if there's an overlap between: //a) the list of modes in the except tag of the restriction (except_tag_string), ex: except=bus;bicycle //b) the lua profile defines a hierachy of modes, ex: [access, vehicle, bicycle] - + if( "" == except_tag_string ) { return false; } - + //Be warned, this is quadratic work here, but we assume that //only a few exceptions are actually defined. std::vector exceptions; diff --git a/Extractor/BaseParser.h b/Extractor/BaseParser.h index 690f8a247..e65678fe4 100644 --- a/Extractor/BaseParser.h +++ b/Extractor/BaseParser.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorCallbacks.h" #include "ScriptingEnvironment.h" +#include "../Util/OSRMException.h" extern "C" { #include diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index 78c1b2a62..b2cc547d2 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -39,14 +39,10 @@ public: ExtractionContainers() { //Check if another instance of stxxl is already running or if there is a general problem - try { - stxxl::vector testForRunningInstance; - } catch(std::exception & e) { - ERR("Could not instantiate STXXL layer." << std::endl << e.what()); - } - + stxxl::vector testForRunningInstance; nameVector.push_back(""); } + virtual ~ExtractionContainers() { usedNodeIDs.clear(); allNodes.clear(); diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 51b099f98..1ce5a0231 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -28,7 +28,7 @@ PBFParser::PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnv input.open(fileName, std::ios::in | std::ios::binary); if (!input) { - std::cerr << fileName << ": File not found." << std::endl; + throw OSRMException("pbf file not found."); } #ifndef NDEBUG @@ -194,7 +194,9 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) { } inline void PBFParser::parseNode(_ThreadData * ) { - ERR("Parsing of simple nodes not supported. PBF should use dense nodes"); + throw OSRMException( + "Parsing of simple nodes not supported. PBF should use dense nodes" + ); } inline void PBFParser::parseRelation(_ThreadData * threadData) { @@ -475,7 +477,7 @@ bool PBFParser::readNextBlock(std::fstream& stream, _ThreadData * threadData) { } if ( !threadData->PBFprimitiveBlock.ParseFromArray( &(threadData->charBuffer[0]), threadData-> charBuffer.size() ) ) { - ERR("failed to parse PrimitiveBlock"); + std::cerr << "failed to parse PrimitiveBlock" << std::endl; return false; } return true; diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index a1606bb6f..18c28bed1 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -27,6 +27,7 @@ #include "../DataStructures/ConcurrentQueue.h" #include "../Util/MachineInfo.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 6bab21c5f..ab1cc8d00 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -40,59 +40,58 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { // Add our function to the state's global scope luabind::module(myLuaState) [ - luabind::def("print", LUA_print), - luabind::def("parseMaxspeed", parseMaxspeed), - luabind::def("durationIsValid", durationIsValid), - luabind::def("parseDuration", parseDuration) + luabind::def("print", LUA_print), + luabind::def("parseMaxspeed", parseMaxspeed), + luabind::def("durationIsValid", durationIsValid), + luabind::def("parseDuration", parseDuration) ]; luabind::module(myLuaState) [ - luabind::class_ >("keyVals") - .def("Add", &HashTable::Add) - .def("Find", &HashTable::Find) - .def("Holds", &HashTable::Holds) - ]; + luabind::class_ >("keyVals") + .def("Add", &HashTable::Add) + .def("Find", &HashTable::Find) + .def("Holds", &HashTable::Holds) + ]; luabind::module(myLuaState) [ - luabind::class_("Node") - .def(luabind::constructor<>()) - .def_readwrite("lat", &ImportNode::lat) - .def_readwrite("lon", &ImportNode::lon) - .def_readwrite("id", &ImportNode::id) - .def_readwrite("bollard", &ImportNode::bollard) - .def_readwrite("traffic_light", &ImportNode::trafficLight) - .def_readwrite("tags", &ImportNode::keyVals) - ]; + luabind::class_("Node") + .def(luabind::constructor<>()) + .def_readwrite("lat", &ImportNode::lat) + .def_readwrite("lon", &ImportNode::lon) + .def_readwrite("id", &ImportNode::id) + .def_readwrite("bollard", &ImportNode::bollard) + .def_readwrite("traffic_light", &ImportNode::trafficLight) + .def_readwrite("tags", &ImportNode::keyVals) + ]; luabind::module(myLuaState) [ - luabind::class_("Way") - .def(luabind::constructor<>()) - .def_readwrite("name", &ExtractionWay::name) - .def_readwrite("speed", &ExtractionWay::speed) - .def_readwrite("backward_speed", &ExtractionWay::backward_speed) - .def_readwrite("duration", &ExtractionWay::duration) - .def_readwrite("type", &ExtractionWay::type) - .def_readwrite("access", &ExtractionWay::access) - .def_readwrite("roundabout", &ExtractionWay::roundabout) - .def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted) - .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) - .def_readwrite("tags", &ExtractionWay::keyVals) - .def_readwrite("direction", &ExtractionWay::direction) - .enum_("constants") - [ - luabind::value("notSure", 0), - luabind::value("oneway", 1), - luabind::value("bidirectional", 2), - luabind::value("opposite", 3) - ] - ]; + luabind::class_("Way") + .def(luabind::constructor<>()) + .def_readwrite("name", &ExtractionWay::name) + .def_readwrite("speed", &ExtractionWay::speed) + .def_readwrite("backward_speed", &ExtractionWay::backward_speed) + .def_readwrite("duration", &ExtractionWay::duration) + .def_readwrite("type", &ExtractionWay::type) + .def_readwrite("access", &ExtractionWay::access) + .def_readwrite("roundabout", &ExtractionWay::roundabout) + .def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted) + .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) + .def_readwrite("tags", &ExtractionWay::keyVals) + .def_readwrite("direction", &ExtractionWay::direction) + .enum_("constants") [ + luabind::value("notSure", 0), + luabind::value("oneway", 1), + luabind::value("bidirectional", 2), + luabind::value("opposite", 3) + ] + ]; luabind::module(myLuaState) [ - luabind::class_ >("vector") - .def("Add", &std::vector::push_back) - ]; + luabind::class_ >("vector") + .def("Add", &std::vector::push_back) + ]; if(0 != luaL_dofile(myLuaState, fileName) ) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + throw OSRMException("ERROR occured in scripting block"); } } } diff --git a/Extractor/ScriptingEnvironment.h b/Extractor/ScriptingEnvironment.h index efb128100..315d84318 100644 --- a/Extractor/ScriptingEnvironment.h +++ b/Extractor/ScriptingEnvironment.h @@ -26,6 +26,7 @@ #include "../DataStructures/ImportNode.h" #include "../Util/LuaUtil.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../typedefs.h" #include diff --git a/Library/OSRM.h b/Library/OSRM.h index 4f505f387..5f36211c8 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" #include "../Util/BaseConfiguration.h" +#include "../Util/OSRMException.h" #include "../Util/InputFileUtil.h" #include "../Server/BasicDatastructures.h" @@ -39,19 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include #include -class OSRMException: public std::exception { -public: - OSRMException(const char * message) : message(message) {} -private: - virtual const char* what() const throw() { - return message; - } - const char * message; -}; - class OSRM : boost::noncopyable { typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 69142434c..aa8956c1a 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -33,7 +33,9 @@ QueryObjectsStorage::QueryObjectsStorage( ) { INFO("loading graph data"); std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); - if(!hsgrInStream) { ERR(hsgrPath << " not found"); } + if(!hsgrInStream) { + throw OSRMException("hsgr not found"); + } //Deserialize road network graph std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrEdge> edgeList; @@ -79,7 +81,9 @@ QueryObjectsStorage::QueryObjectsStorage( //deserialize street name list INFO("Loading names index"); std::ifstream namesInStream(namesPath.c_str(), std::ios::binary); - if(!namesInStream) { ERR(namesPath << " not found"); } + if(!namesInStream) { + throw OSRMException("names file not found"); + } unsigned size(0); namesInStream.read((char *)&size, sizeof(unsigned)); diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index cd1b63b63..ebf4bef32 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include "../../Util/OSRMException.h" #include "../../DataStructures/NodeInformationHelpDesk.h" #include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index 160e5ac10..8101d78a3 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/BaseConfiguration.h" #include "../Util/InputFileUtil.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/OSRMException.h" #include "../Util/StringUtil.h" #include "../typedefs.h" @@ -40,31 +41,32 @@ struct ServerFactory { static Server * CreateServer(BaseConfiguration& serverConfig) { if(!testDataFile(serverConfig.GetParameter("nodesData"))) { - ERR("nodes file not found"); + throw OSRMException("nodes file not found"); } if(!testDataFile(serverConfig.GetParameter("hsgrData"))) { - ERR("hsgr file not found"); + throw OSRMException("hsgr file not found"); } if(!testDataFile(serverConfig.GetParameter("namesData"))) { - ERR("names file not found"); + throw OSRMException("names file not found"); } if(!testDataFile(serverConfig.GetParameter("ramIndex"))) { - ERR("ram index file not found"); + throw OSRMException("ram index file not found"); } if(!testDataFile(serverConfig.GetParameter("fileIndex"))) { - ERR("file index file not found"); + throw OSRMException("file index file not found"); } int threads = omp_get_num_procs(); - if(serverConfig.GetParameter("IP") == "") + if(serverConfig.GetParameter("IP") == "") { serverConfig.SetParameter("IP", "0.0.0.0"); - if(serverConfig.GetParameter("Port") == "") + } + if(serverConfig.GetParameter("Port") == "") { serverConfig.SetParameter("Port", "5000"); - + } if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads) threads = stringToInt( serverConfig.GetParameter("Threads") ); diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h index a998c6189..0ff634c82 100644 --- a/Util/BaseConfiguration.h +++ b/Util/BaseConfiguration.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASECONFIGURATION_H_ #define BASECONFIGURATION_H_ +#include "OSRMException.h" #include "../DataStructures/HashTable.h" #include @@ -33,26 +34,19 @@ public: BaseConfiguration(const char * configFile) { std::ifstream config( configFile ); if(!config) { - std::cerr << "[config] .ini not found" << std::endl; - return; + throw OSRMException("[config] .ini not found"); } std::string line; - try { - if (config.is_open()) { - while ( config.good() ) { - getline (config,line); - std::vector tokens; - Tokenize(line, tokens); - if(2 == tokens.size() ) - parameters.Add(tokens[0], tokens[1]); - } - config.close(); + if (config.is_open()) { + while ( config.good() ) { + getline (config,line); + std::vector tokens; + Tokenize(line, tokens); + if(2 == tokens.size() ) + parameters.Add(tokens[0], tokens[1]); } - } catch(std::exception& e) { - ERR("[config] " << configFile << " not found -> Exception: " < parameters; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index cd3e0cf7d..0e46db304 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef GRAPHLOADER_H #define GRAPHLOADER_H +#include "OSRMException.h" #include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportEdge.h" #include "../DataStructures/NodeCoords.h" @@ -308,19 +309,25 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s forward = false; } - if(length == 0) { ERR("loaded null length edge"); } + if(length == 0) { + throw OSRMException("loaded null length edge"); + } // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { - ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source); + throw OSRMException("unresolvable source Node ID"); } source = intNodeID->second; intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); } + if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { + throw OSRMException("unresolvable target Node ID"); + } target = intNodeID->second; - if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); } + if(source == UINT_MAX || target == UINT_MAX) { + throw OSRMException("nonexisting source or target" ); + } EdgeT inputEdge(source, target, 0, weight, forward, backward, type ); edgeList.push_back(inputEdge); @@ -351,8 +358,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s in >> source >> target >> weight >> dir; assert(weight > 0); - if(dir <0 || dir > 3) - ERR( "[error] direction bogus: " << dir ); + if(dir <0 || dir > 3) { + throw OSRMException( "[error] direction bogus"); + } assert(0<=dir && dir<=3); bool forward = true; @@ -361,7 +369,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s if (dir == 2) forward = false; if (dir == 3) {backward = true; forward = true;} - if(weight == 0) { ERR("loaded null length edge"); } + if(weight == 0) { + throw OSRMException("loaded null length edge"); + } if( nodeMap.find(source) == nodeMap.end()) { nodeMap.insert(std::make_pair(source, numberOfNodes )); @@ -395,7 +405,7 @@ unsigned readHSGRFromStream( WARN( ".hsgr was prepared with different build.\n" "Reprocess to get rid of this warning." - ) + ); } unsigned number_of_nodes = 0; diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 6945575f4..2b73b806c 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -165,12 +165,12 @@ inline bool StringStartsWith(const std::string & input, const std::string & pref // Function returns a 'random' filename in temporary directors. // May not be platform independent. -inline void GetTemporaryFileName(std::string & filename) { - char buffer[L_tmpnam]; - char * retPointer = tmpnam (buffer); - if(0 == retPointer) - ERR("Could not create temporary file name"); - filename = buffer; -} +// inline void GetTemporaryFileName(std::string & filename) { +// char buffer[L_tmpnam]; +// char * retPointer = tmpnam (buffer); +// if(0 == retPointer) { +// ERR("Could not create temporary file name"); +// filename = buffer; +// } #endif /* STRINGUTIL_H_ */ diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index 36726c4ae..8c2695525 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -61,35 +61,35 @@ const bool UUID::IsMagicNumberOK() const { const bool UUID::TestGraphUtil(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("hsgr input file misses magic number. Check or reprocess the file"); + throw OSRMException("hsgr input file misses magic number. Check or reprocess the file"); } return std::equal(md5_graph, md5_graph+32, other.md5_graph); } const bool UUID::TestPrepare(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("extracted input file misses magic number. Check or reprocess the file"); + throw OSRMException("extracted input file misses magic number. Check or reprocess the file"); } return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare); } const bool UUID::TestRTree(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("r-tree input file misses magic number. Check or reprocess the file"); + throw OSRMException("r-tree input file misses magic number. Check or reprocess the file"); } return std::equal(md5_tree, md5_tree+32, other.md5_tree); } const bool UUID::TestNodeInfo(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("nodes file misses magic number. Check or reprocess the file"); + throw OSRMException("nodes file misses magic number. Check or reprocess the file"); } return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo); } const bool UUID::TestQueryObjects(const UUID & other) const { if(!other.IsMagicNumberOK()) { - ERR("missing magic number. Check or reprocess the file"); + throw OSRMException("missing magic number. Check or reprocess the file"); } return std::equal(md5_objects, md5_objects+32, other.md5_objects); } diff --git a/Util/UUID.h b/Util/UUID.h index 188ab26a1..6647b9764 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef UUID_H #define UUID_H +#include "OSRMException.h" #include "../typedefs.h" #include diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 85cfea942..6dd0f3b86 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/InputFileUtil.h" #include "Util/LuaUtil.h" #include "Util/OpenMPWrapper.h" +#include "Util/OSRMException.h" #include "Util/StringUtil.h" #include "typedefs.h" @@ -59,7 +60,10 @@ std::vector edgeList; int main (int argc, char *argv[]) { try { if(argc < 3) { - ERR("usage: " << std::endl << argv[0] << " []"); + std::cerr << + "usage: \n" << + argv[0] << " []" << std::endl; + return -1; } double startupTime = get_timestamp(); @@ -75,7 +79,9 @@ int main (int argc, char *argv[]) { INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], std::ios::binary); if(!restrictionsInstream.good()) { - ERR("Could not access files"); + std::cerr << + "Could not access files" << std::endl; + } _Restriction restriction; UUID uuid_loaded, uuid_orig; @@ -85,7 +91,7 @@ int main (int argc, char *argv[]) { WARN( ".restrictions was prepared with different build.\n" "Reprocess to get rid of this warning." - ) + ); } restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); @@ -96,7 +102,7 @@ int main (int argc, char *argv[]) { std::ifstream in; in.open (argv[1], std::ifstream::in | std::ifstream::binary); if (!in.is_open()) { - ERR("Cannot open " << argv[1]); + throw OSRMException("Cannot open osrm input file"); } std::string nodeOut(argv[1]); nodeOut += ".nodes"; @@ -107,7 +113,7 @@ int main (int argc, char *argv[]) { /*** Setup Scripting Environment ***/ if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) { - ERR("Need profile.lua to apply traffic signal penalty"); + throw OSRMException("Cannot open profile.lua "); } // Create a new lua state @@ -125,18 +131,29 @@ int main (int argc, char *argv[]) { // Now call our function in a lua script INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") ); if(0 != luaL_dofile(myLuaState, (argc > 3 ? argv[3] : "profile.lua") )) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; } EdgeBasedGraphFactory::SpeedProfileProperties speedProfile; if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; + return -1; } speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1); if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { - ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); + std::cerr << + lua_tostring(myLuaState,-1) << + " occured in scripting block" << + std::endl; + return -1; } speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1); @@ -146,9 +163,13 @@ int main (int argc, char *argv[]) { NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions); in.close(); INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); - if(0 == edgeList.size()) - ERR("The input data is broken. It is impossible to do any turns in this graph"); - + if(0 == edgeList.size()) { + std::cerr << + "The input data is broken. " + "It is impossible to do any turns in this graph" << + std::endl; + return -1; + } /*** * Building an edge-expanded graph from node-based input an turn restrictions @@ -262,7 +283,13 @@ int main (int argc, char *argv[]) { currentEdge.data = contractedEdgeList[edge].data; if(currentEdge.data.distance <= 0) { INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); - ERR("Failed at edges of node " << node << " of " << numberOfNodes); + std::cerr << + "Failed at edges of node " << + node << + " of " << + numberOfNodes << + std::endl; + return -1; } //Serialize edges hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); @@ -278,8 +305,9 @@ int main (int argc, char *argv[]) { //cleanedEdgeList.clear(); _nodes.clear(); INFO("finished preprocessing"); - } catch (std::exception &e) { - ERR("Exception occured: " << e.what()); + } catch ( const std::exception &e ) { + std::cerr << "Exception occured: " << e.what() << std::endl; + return -1; } return 0; } diff --git a/extractor.cpp b/extractor.cpp index 5e580d8e7..221fb6a1e 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/InputFileUtil.h" #include "Util/MachineInfo.h" #include "Util/OpenMPWrapper.h" +#include "Util/OSRMException.h" #include "Util/StringUtil.h" #include "Util/UUID.h" #include "typedefs.h" @@ -45,7 +46,12 @@ int main (int argc, char *argv[]) { double startup_time = get_timestamp(); if(argc < 2) { - ERR("usage: \n" << argv[0] << " []"); + std::cerr << + "usage: \n" << + argv[0] << + " []" << + std::endl; + return -1; } /*** Setup Scripting Environment ***/ @@ -111,7 +117,7 @@ int main (int argc, char *argv[]) { } if(!parser->ReadHeader()) { - ERR("Parser not initialized!"); + throw OSRMException("Parser not initialized!"); } INFO("Parsing in progress.."); double parsing_start_time = get_timestamp(); @@ -128,11 +134,16 @@ int main (int argc, char *argv[]) { INFO("extraction finished after " << get_timestamp() - startup_time << "s"); - std::cout << "\nRun:\n" - << "./osrm-prepare " << output_file_name << " " << restrictionsFileName - << std::endl; - return 0; + std::cout << + "\nRun:\n" << + "./osrm-prepare " << + output_file_name << + " " << + restrictionsFileName << + std::endl; } catch(std::exception & e) { - WARN("unhandled exception: " << e.what()); + INFO("unhandled exception: " << e.what()); + return -1; } + return 0; } From 444bf41fa4071e2526206fbf9fa69f6a1e68f050 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 17:29:34 +0200 Subject: [PATCH 09/80] use exceptions instead of hard abort --- typedefs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/typedefs.h b/typedefs.h index 180e47ca0..bf0c731d0 100644 --- a/typedefs.h +++ b/typedefs.h @@ -35,7 +35,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #define INFO(x) do {std::cout << "[i " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); -#define ERR(x) do {std::cerr << "[! " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl; std::exit(-1);} while(0); #define WARN(x) do {std::cerr << "[? " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); #ifdef NDEBUG From b591aa013d00080b4e616824720bdf167dd6055c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 17:35:16 +0200 Subject: [PATCH 10/80] Remove dead code --- Util/StringUtil.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 2b73b806c..29b125578 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -23,13 +23,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" -#include #include #include #include #include +#include // precision: position after decimal point // length: maximum number of digits including comma and decimals @@ -163,14 +163,4 @@ inline bool StringStartsWith(const std::string & input, const std::string & pref return boost::starts_with(input, prefix); } -// Function returns a 'random' filename in temporary directors. -// May not be platform independent. -// inline void GetTemporaryFileName(std::string & filename) { -// char buffer[L_tmpnam]; -// char * retPointer = tmpnam (buffer); -// if(0 == retPointer) { -// ERR("Could not create temporary file name"); -// filename = buffer; -// } - #endif /* STRINGUTIL_H_ */ From db46a915ccab3a4d6620b71ce2ff3bb42bf17ee9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 17:37:30 +0200 Subject: [PATCH 11/80] simple wrapper around std::exception --- Util/OSRMException.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Util/OSRMException.h diff --git a/Util/OSRMException.h b/Util/OSRMException.h new file mode 100644 index 000000000..dcae24e18 --- /dev/null +++ b/Util/OSRMException.h @@ -0,0 +1,36 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#ifndef OSRM_EXCEPTION_H +#define OSRM_EXCEPTION_H + +#include + +class OSRMException: public std::exception { +public: + OSRMException(const char * message) : message(message) {} +private: + virtual const char* what() const throw() { + return message; + } + const char * message; +}; + +#endif /* OSRM_EXCEPTION_H */ \ No newline at end of file From 23899613c391d64ec3e3619a9f353f7cb30711e6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 18:37:42 +0200 Subject: [PATCH 12/80] Implement #495 --- Algorithms/StronglyConnectedComponents.h | 6 +++--- Contractor/EdgeBasedGraphFactory.cpp | 8 +++---- DataStructures/Coordinate.h | 27 +++++++++++++++--------- DataStructures/HilbertValue.h | 6 ++++-- DataStructures/NodeCoords.h | 5 +++-- DataStructures/StaticRTree.h | 10 ++++----- Descriptors/DescriptionFactory.cpp | 6 +++--- Extractor/ExtractorCallbacks.cpp | 2 +- Extractor/ExtractorCallbacks.h | 2 ++ Extractor/PBFParser.cpp | 4 ++-- Extractor/PBFParser.h | 1 + Extractor/XMLParser.cpp | 4 ++-- Extractor/XMLParser.h | 1 + Plugins/BasePlugin.h | 1 + Plugins/HelloWorldPlugin.h | 2 +- Plugins/LocatePlugin.h | 7 +++++- Plugins/NearestPlugin.h | 7 +++++- Plugins/RouteParameters.h | 5 ++--- Plugins/ViaRoutePlugin.h | 8 +++++-- Tools/simpleclient.cpp | 4 ++-- 20 files changed, 72 insertions(+), 44 deletions(-) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index 4ef81e90f..c688a050b 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -343,10 +343,10 @@ public: //edges that end on bollard nodes may actually be in two distinct components if(std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 10) { - //INFO("(" << inputNodeInfoList[u].lat/100000. << ";" << inputNodeInfoList[u].lon/100000. << ") -> (" << inputNodeInfoList[v].lat/100000. << ";" << inputNodeInfoList[v].lon/100000. << ")"); + //INFO("(" << inputNodeInfoList[u].lat/COORDINATE_PRECISION << ";" << inputNodeInfoList[u].lon/COORDINATE_PRECISION << ") -> (" << inputNodeInfoList[v].lat/COORDINATE_PRECISION << ";" << inputNodeInfoList[v].lon/COORDINATE_PRECISION << ")"); OGRLineString lineString; - lineString.addPoint(inputNodeInfoList[u].lon/100000., inputNodeInfoList[u].lat/100000.); - lineString.addPoint(inputNodeInfoList[v].lon/100000., inputNodeInfoList[v].lat/100000.); + lineString.addPoint(inputNodeInfoList[u].lon/COORDINATE_PRECISION, inputNodeInfoList[u].lat/COORDINATE_PRECISION); + lineString.addPoint(inputNodeInfoList[v].lon/COORDINATE_PRECISION, inputNodeInfoList[v].lat/COORDINATE_PRECISION); OGRFeature *poFeature; poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); poFeature->SetGeometry( &lineString ); diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 13f49ecb7..9443c24e4 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -400,10 +400,10 @@ unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { /* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ template double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const { - const double v1x = (A.lon - C.lon)/100000.; - const double v1y = lat2y(A.lat/100000.) - lat2y(C.lat/100000.); - const double v2x = (B.lon - C.lon)/100000.; - const double v2y = lat2y(B.lat/100000.) - lat2y(C.lat/100000.); + const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION; + const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); + const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION; + const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI; while(angle < 0) diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h index 68219d5a1..47008d65f 100644 --- a/DataStructures/Coordinate.h +++ b/DataStructures/Coordinate.h @@ -29,6 +29,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include +static const double COORDINATE_PRECISION = 1000000.; + struct _Coordinate { int lat; int lon; @@ -43,7 +45,12 @@ struct _Coordinate { return (INT_MIN != lat) && (INT_MIN != lon); } inline bool isValid() const { - if(lat > 90*100000 || lat < -90*100000 || lon > 180*100000 || lon <-180*100000) { + if( + lat > 90*COORDINATE_PRECISION || + lat < -90*COORDINATE_PRECISION || + lon > 180*COORDINATE_PRECISION || + lon < -180*COORDINATE_PRECISION + ) { return false; } return true; @@ -64,10 +71,10 @@ inline double ApproximateDistance( const int lat1, const int lon1, const int lat assert(lat2 != INT_MIN); assert(lon2 != INT_MIN); double RAD = 0.017453292519943295769236907684886; - double lt1 = lat1/100000.; - double ln1 = lon1/100000.; - double lt2 = lat2/100000.; - double ln2 = lon2/100000.; + double lt1 = lat1/COORDINATE_PRECISION; + double ln1 = lon1/COORDINATE_PRECISION; + double lt2 = lat2/COORDINATE_PRECISION; + double ln2 = lon2/COORDINATE_PRECISION; double dlat1=lt1*(RAD); double dlong1=ln1*(RAD); @@ -96,10 +103,10 @@ inline double ApproximateEuclideanDistance(const _Coordinate &c1, const _Coordin assert(c2.lat != INT_MIN); assert(c2.lon != INT_MIN); const double RAD = 0.017453292519943295769236907684886; - const double lat1 = (c1.lat/100000.)*RAD; - const double lon1 = (c1.lon/100000.)*RAD; - const double lat2 = (c2.lat/100000.)*RAD; - const double lon2 = (c2.lon/100000.)*RAD; + const double lat1 = (c1.lat/COORDINATE_PRECISION)*RAD; + const double lon1 = (c1.lon/COORDINATE_PRECISION)*RAD; + const double lat2 = (c2.lat/COORDINATE_PRECISION)*RAD; + const double lon2 = (c2.lon/COORDINATE_PRECISION)*RAD; const double x = (lon2-lon1) * cos((lat1+lat2)/2.); const double y = (lat2-lat1); @@ -111,7 +118,7 @@ inline double ApproximateEuclideanDistance(const _Coordinate &c1, const _Coordin static inline void convertInternalLatLonToString(const int value, std::string & output) { char buffer[100]; buffer[10] = 0; // Nullterminierung - char* string = printInt< 10, 5 >( buffer, value ); + char* string = printInt< 10, 6 >( buffer, value ); output = string; } diff --git a/DataStructures/HilbertValue.h b/DataStructures/HilbertValue.h index 05e2bb15f..8b64a505b 100644 --- a/DataStructures/HilbertValue.h +++ b/DataStructures/HilbertValue.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef HILBERTVALUE_H_ #define HILBERTVALUE_H_ +#include "Coordinate.h" + #include #include @@ -31,8 +33,8 @@ public: static uint64_t GetHilbertNumberForCoordinate( const _Coordinate & current_coordinate) { unsigned location[2]; - location[0] = current_coordinate.lat+( 90*100000); - location[1] = current_coordinate.lon+(180*100000); + location[0] = current_coordinate.lat+( 90*COORDINATE_PRECISION); + location[1] = current_coordinate.lon+(180*COORDINATE_PRECISION); TransposeCoordinate(location); const uint64_t result = BitInterleaving(location[0], location[1]); diff --git a/DataStructures/NodeCoords.h b/DataStructures/NodeCoords.h index 80fda42b8..c2f62430b 100644 --- a/DataStructures/NodeCoords.h +++ b/DataStructures/NodeCoords.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef _NODE_COORDS_H #define _NODE_COORDS_H +#include "Coordinate.h" #include "../typedefs.h" #include @@ -41,10 +42,10 @@ struct NodeCoords { NodeT id; static NodeCoords min_value() { - return NodeCoords(-90*100000,-180*100000,std::numeric_limits::min()); + return NodeCoords(-90*COORDINATE_PRECISION,-180*COORDINATE_PRECISION,std::numeric_limits::min()); } static NodeCoords max_value() { - return NodeCoords(90*100000, 180*100000, std::numeric_limits::max()); + return NodeCoords(90*COORDINATE_PRECISION, 180*COORDINATE_PRECISION, std::numeric_limits::max()); } value_type operator[](std::size_t n) const { diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 3e598f3e4..34f9fd00b 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -220,10 +220,10 @@ private: std::ostream & out, const RectangleInt2D & rect ) { - out << rect.min_lat/100000. << "," - << rect.min_lon/100000. << " " - << rect.max_lat/100000. << "," - << rect.max_lon/100000.; + out << rect.min_lat/COORDINATE_PRECISION << "," + << rect.min_lon/COORDINATE_PRECISION << " " + << rect.max_lat/COORDINATE_PRECISION << "," + << rect.max_lon/COORDINATE_PRECISION; return out; } }; @@ -298,7 +298,7 @@ public: //Get Hilbert-Value for centroid in mercartor projection DataT & current_element = input_data_vector[element_counter]; _Coordinate current_centroid = current_element.Centroid(); - current_centroid.lat = 100000*lat2y(current_centroid.lat/100000.); + current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION); uint64_t current_hilbert_value = HilbertCode::GetHilbertNumberForCoordinate(current_centroid); input_wrapper_vector[element_counter].m_hilbert_value = current_hilbert_value; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 63e8883eb..e027c3704 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -33,10 +33,10 @@ inline double DescriptionFactory::RadianToDegree(const double radian) const { } double DescriptionFactory::GetBearing(const _Coordinate& A, const _Coordinate& B) const { - double deltaLong = DegreeToRadian(B.lon/100000. - A.lon/100000.); + double deltaLong = DegreeToRadian(B.lon/COORDINATE_PRECISION - A.lon/COORDINATE_PRECISION); - double lat1 = DegreeToRadian(A.lat/100000.); - double lat2 = DegreeToRadian(B.lat/100000.); + double lat1 = DegreeToRadian(A.lat/COORDINATE_PRECISION); + double lat2 = DegreeToRadian(B.lat/COORDINATE_PRECISION); double y = sin(deltaLong) * cos(lat2); double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong); diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index db8e8f8f9..8c28f855d 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -31,7 +31,7 @@ ExtractorCallbacks::~ExtractorCallbacks() { } /** warning: caller needs to take care of synchronization! */ void ExtractorCallbacks::nodeFunction(const _Node &n) { - if(n.lat <= 85*100000 && n.lat >= -85*100000) { + if(n.lat <= 85*COORDINATE_PRECISION && n.lat >= -85*COORDINATE_PRECISION) { externalMemory->allNodes.push_back(n); } } diff --git a/Extractor/ExtractorCallbacks.h b/Extractor/ExtractorCallbacks.h index 3e9fcddf5..0ba78c709 100644 --- a/Extractor/ExtractorCallbacks.h +++ b/Extractor/ExtractorCallbacks.h @@ -34,6 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractionHelperFunctions.h" #include "ExtractorStructs.h" +#include "../DataStructures/Coordinate.h" + class ExtractorCallbacks{ private: StringMap * stringMap; diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 1ce5a0231..4f3b40fde 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -166,8 +166,8 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) { m_lastDenseLatitude += dense.lat( i ); m_lastDenseLongitude += dense.lon( i ); extracted_nodes_vector[i].id = m_lastDenseID; - extracted_nodes_vector[i].lat = 100000*( ( double ) m_lastDenseLatitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lat_offset() ) / NANO; - extracted_nodes_vector[i].lon = 100000*( ( double ) m_lastDenseLongitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lon_offset() ) / NANO; + extracted_nodes_vector[i].lat = COORDINATE_PRECISION*( ( double ) m_lastDenseLatitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lat_offset() ) / NANO; + extracted_nodes_vector[i].lon = COORDINATE_PRECISION*( ( double ) m_lastDenseLongitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lon_offset() ) / NANO; while (denseTagIndex < dense.keys_vals_size()) { const int tagValue = dense.keys_vals( denseTagIndex ); if( 0==tagValue ) { diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index 18c28bed1..edf5cd012 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -23,6 +23,7 @@ #include "BaseParser.h" +#include "../DataStructures/Coordinate.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ConcurrentQueue.h" #include "../Util/MachineInfo.h" diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index 90590e5e9..6ce834335 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -217,12 +217,12 @@ ImportNode XMLParser::_ReadXMLNode() { xmlChar* attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lat" ); if ( attribute != NULL ) { - node.lat = static_cast(100000.*atof(( const char* ) attribute ) ); + node.lat = static_cast(COORDINATE_PRECISION*atof(( const char* ) attribute ) ); xmlFree( attribute ); } attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "lon" ); if ( attribute != NULL ) { - node.lon = static_cast(100000.*atof(( const char* ) attribute )); + node.lon = static_cast(COORDINATE_PRECISION*atof(( const char* ) attribute )); xmlFree( attribute ); } attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); diff --git a/Extractor/XMLParser.h b/Extractor/XMLParser.h index d17230dfe..39070f470 100644 --- a/Extractor/XMLParser.h +++ b/Extractor/XMLParser.h @@ -22,6 +22,7 @@ #define XMLPARSER_H_ #include "BaseParser.h" +#include "../DataStructures/Coordinate.h" #include "../Util/StringUtil.h" #include "../typedefs.h" diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index 954edbf8b..034c848a7 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -22,6 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #define BASEPLUGIN_H_ #include "RouteParameters.h" +#include "../DataStructures/Coordinate.h" #include "../Server/BasicDatastructures.h" #include diff --git a/Plugins/HelloWorldPlugin.h b/Plugins/HelloWorldPlugin.h index 6315dad8c..8e755ea8a 100644 --- a/Plugins/HelloWorldPlugin.h +++ b/Plugins/HelloWorldPlugin.h @@ -35,7 +35,7 @@ public: content << "language: " << routeParameters.language << "
"; content << "Number of locations: " << routeParameters.coordinates.size() << "\n"; for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) { - content << " [" << i << "] " << routeParameters.coordinates[i].lat/100000. << "," << routeParameters.coordinates[i].lon/100000. << "\n"; + content << " [" << i << "] " << routeParameters.coordinates[i].lat/COORDINATE_PRECISION << "," << routeParameters.coordinates[i].lon/COORDINATE_PRECISION << "\n"; } content << "Number of hints: " << routeParameters.hints.size() << "\n"; for(unsigned i = 0; i < routeParameters.hints.size(); ++i) { diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index f1c7d60ac..7369390a9 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -101,7 +101,12 @@ public: } private: inline bool checkCoord(const _Coordinate & c) { - if(c.lat > 90*100000 || c.lat < -90*100000 || c.lon > 180*100000 || c.lon <-180*100000) { + if( + c.lat > 90*COORDINATE_PRECISION || + c.lat < -90*COORDINATE_PRECISION || + c.lon > 180*COORDINATE_PRECISION || + c.lon < -180*COORDINATE_PRECISION + ) { return false; } return true; diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 0b60225ef..3fa1b7379 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -109,7 +109,12 @@ public: } private: inline bool checkCoord(const _Coordinate & c) { - if(c.lat > 90*100000 || c.lat < -90*100000 || c.lon > 180*100000 || c.lon <-180*100000) { + if( + c.lat > 90*COORDINATE_PRECISION || + c.lat < -90*COORDINATE_PRECISION || + c.lon > 180*COORDINATE_PRECISION || + c.lon < -180*COORDINATE_PRECISION + ) { return false; } return true; diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index 88fd1c260..6c2b1af3b 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -106,9 +106,8 @@ struct RouteParameters { } void addCoordinate(boost::fusion::vector < double, double > arg_) { - int lat = 100000.*boost::fusion::at_c < 0 > (arg_); - int lon = 100000.*boost::fusion::at_c < 1 > (arg_); - _Coordinate myCoordinate(lat, lon); + int lat = COORDINATE_PRECISION*boost::fusion::at_c < 0 > (arg_); + int lon = COORDINATE_PRECISION*boost::fusion::at_c < 1 > (arg_); coordinates.push_back(_Coordinate(lat, lon)); } }; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 1bd924ece..72d27dc63 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -201,7 +201,6 @@ public: reply.headers[2].name = "Content-Disposition"; reply.headers[2].value = "attachment; filename=\"route.json\""; } - break; } @@ -210,7 +209,12 @@ public: } private: inline bool checkCoord(const _Coordinate & c) { - if(c.lat > 90*100000 || c.lat < -90*100000 || c.lon > 180*100000 || c.lon <-180*100000) { + if( + c.lat > 90*COORDINATE_PRECISION || + c.lat < -90*COORDINATE_PRECISION || + c.lon > 180*COORDINATE_PRECISION || + c.lon < -180*COORDINATE_PRECISION + ) { return false; } return true; diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index 32dc07a76..74aa8c8f3 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -62,8 +62,8 @@ int main (int argc, char * argv[]) { route_parameters.language = ""; //unused atm //route_parameters.hints.push_back(); // see wiki, saves I/O if done properly - _Coordinate start_coordinate(52.519930*100000,13.438640*100000); - _Coordinate target_coordinate(52.513191*100000,13.415852*100000); + _Coordinate start_coordinate(52.519930*1000000,13.438640*1000000); + _Coordinate target_coordinate(52.513191*1000000,13.415852*1000000); route_parameters.coordinates.push_back(start_coordinate); route_parameters.coordinates.push_back(target_coordinate); From 4f5d7f79bdd1070411d414efa04adbd106f488b3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 19:00:09 +0200 Subject: [PATCH 13/80] fixing tests for enhanced coordinate preceision --- features/investigate/weird.feature | 6 +++--- features/testbot/basic.feature | 30 +++++++++++++++--------------- features/testbot/duration.feature | 8 ++++---- features/testbot/opposite.feature | 10 +++++----- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/features/investigate/weird.feature b/features/investigate/weird.feature index f84a07592..932526d59 100644 --- a/features/investigate/weird.feature +++ b/features/investigate/weird.feature @@ -1,9 +1,9 @@ @routing @weird Feature: Weird routings discovered - + Background: Given the profile "testbot" - + Scenario: Routing on a oneway roundabout Given the node map | | d | c | | @@ -36,7 +36,7 @@ Feature: Weird routings discovered | c | b | cd,de,ef,fg,gh,ha,ab | | d | c | de,ef,fg,gh,ha,ab,bc | | e | d | ef,fg,gh,ha,ab,bc,cd | - | f | e | fg,gh,ha,ab,bc,cd,de | + | f | e | | | g | f | gh,ha,ab,bc,cd,de,ef | | h | g | ha,ab,bc,cd,de,ef,fg | | a | h | ab,bc,cd,de,ef,fg,gh | \ No newline at end of file diff --git a/features/testbot/basic.feature b/features/testbot/basic.feature index aabdcaa00..ff2041a6e 100644 --- a/features/testbot/basic.feature +++ b/features/testbot/basic.feature @@ -1,27 +1,27 @@ @routing @basic Feature: Basic Routing - + Background: Given the profile "testbot" - + @smallest Scenario: A single way with two nodes Given the node map | a | b | - + And the ways | nodes | | ab | - + When I route I should get | from | to | route | | a | b | ab | | b | a | ab | - + Scenario: Routing in between two nodes of way Given the node map | a | b | 1 | 2 | c | d | - + And the ways | nodes | | abcd | @@ -57,12 +57,12 @@ Feature: Basic Routing Scenario: Two ways connected in a straight line Given the node map | a | b | c | - + And the ways | nodes | | ab | | bc | - + When I route I should get | from | to | route | | a | c | ab,bc | @@ -71,17 +71,17 @@ Feature: Basic Routing | b | a | ab | | b | c | bc | | c | b | bc | - + Scenario: 2 unconnected parallel ways Given the node map | a | b | c | | d | e | f | - + And the ways | nodes | | abc | | def | - + When I route I should get | from | to | route | | a | b | abc | @@ -122,7 +122,7 @@ Feature: Basic Routing | ab | | bc | | ca | - + When I route I should get | from | to | route | | a | b | ab | @@ -154,7 +154,7 @@ Feature: Basic Routing | cv | | vw | | wc | - + When I route I should get | from | to | route | | a | b | ab | @@ -183,7 +183,7 @@ Feature: Basic Routing | c | a | abc | | c | e | cde | | e | c | cde | - + Scenario: Grid city center Given the node map | a | b | c | d | @@ -266,7 +266,7 @@ Feature: Basic Routing | c | b | cd,de,ef,fg,gh,ha,ab | | d | c | de,ef,fg,gh,ha,ab,bc | | e | d | ef,fg,gh,ha,ab,bc,cd | - | f | e | fg,gh,ha,ab,bc,cd,de | + | f | e | | | g | f | gh,ha,ab,bc,cd,de,ef | | h | g | ha,ab,bc,cd,de,ef,fg | | a | h | ab,bc,cd,de,ef,fg,gh | diff --git a/features/testbot/duration.feature b/features/testbot/duration.feature index ab6571ce5..e653ae9cf 100644 --- a/features/testbot/duration.feature +++ b/features/testbot/duration.feature @@ -3,13 +3,13 @@ Feature: Durations Background: Given the profile "testbot" - + Scenario: Duration of ways Given the node map | a | b | | | | f | | | | | e | | | | | c | | | d | | - + And the ways | nodes | highway | duration | | ab | primary | 0:01 | @@ -23,9 +23,9 @@ Feature: Durations | a | b | ab | 100m +-1 | 60s +-1 | | b | c | bc | 200m +-1 | 600s +-1 | | c | d | cd | 300m +-1 | 3600s +-1 | - | d | e | de | 144m +-2 | 36000s +-1 | + | d | e | de | 141m +-2 | 36000s +-1 | | e | f | ef | 224m +-2 | 3723s +-1 | - + @todo Scenario: Partial duration of ways Given the node map diff --git a/features/testbot/opposite.feature b/features/testbot/opposite.feature index c242c97b1..ee34b786f 100644 --- a/features/testbot/opposite.feature +++ b/features/testbot/opposite.feature @@ -1,18 +1,18 @@ @routing @testbot @opposite Feature: Separate settings for forward/backward direction - + Background: Given the profile "testbot" - + Scenario: Testbot - Going against the flow Given the node map | a | b | c | d | - + And the ways | nodes | highway | | abcd | river | - + When I route I should get | from | to | route | distance | time | - | a | d | abcd | 300 +- 1m | 30s | + | a | d | abcd | 300 +- 1m | 31s | | d | a | abcd | 300 +- 1m | 68s | \ No newline at end of file From 13f5baf6087439af4cd1d247d75a948eb5ec3aee Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 5 Aug 2013 19:35:47 +0200 Subject: [PATCH 14/80] Moving node data structure into more meaningful class name --- Algorithms/StronglyConnectedComponents.h | 2 +- DataStructures/ImportNode.h | 4 +- DataStructures/NodeInformationHelpDesk.h | 2 +- DataStructures/{NodeCoords.h => QueryNode.h} | 41 ++++++++++++-------- Extractor/ExtractorStructs.h | 2 +- Util/GraphLoader.h | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) rename DataStructures/{NodeCoords.h => QueryNode.h} (63%) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index c688a050b..b7d288714 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -28,7 +28,7 @@ Strongly connected components using Tarjan's Algorithm #include "../DataStructures/DeallocatingVector.h" #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/ImportEdge.h" -#include "../DataStructures/NodeCoords.h" +#include "../DataStructures/QueryNode.h" #include "../DataStructures/Percent.h" #include "../DataStructures/Restriction.h" #include "../DataStructures/TurnInstructions.h" diff --git a/DataStructures/ImportNode.h b/DataStructures/ImportNode.h index b9c27beff..28c9341c1 100644 --- a/DataStructures/ImportNode.h +++ b/DataStructures/ImportNode.h @@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef IMPORTNODE_H_ #define IMPORTNODE_H_ -#include "NodeCoords.h" +#include "QueryNode.h" #include "../DataStructures/HashTable.h" @@ -44,7 +44,7 @@ struct _Node : NodeInfo{ struct ImportNode : public _Node { HashTable keyVals; - + inline void Clear() { keyVals.EraseAll(); lat = 0; lon = 0; id = 0; bollard = false; trafficLight = false; diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 4ec7ac1f3..773a29e51 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef NODEINFORMATIONHELPDESK_H_ #define NODEINFORMATIONHELPDESK_H_ -#include "NodeCoords.h" +#include "QueryNode.h" #include "PhantomNodes.h" #include "StaticRTree.h" #include "../Contractor/EdgeBasedGraphFactory.h" diff --git a/DataStructures/NodeCoords.h b/DataStructures/QueryNode.h similarity index 63% rename from DataStructures/NodeCoords.h rename to DataStructures/QueryNode.h index c2f62430b..6e9386efb 100644 --- a/DataStructures/NodeCoords.h +++ b/DataStructures/QueryNode.h @@ -24,31 +24,40 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Coordinate.h" #include "../typedefs.h" -#include +#include + #include #include #include -template -struct NodeCoords { - typedef unsigned key_type; //type of NodeID +struct NodeInfo { + typedef NodeID key_type; //type of NodeID typedef int value_type; //type of lat,lons - NodeCoords(int _lat, int _lon, NodeT _id) : lat(_lat), lon(_lon), id(_id) {} - NodeCoords() : lat(INT_MAX), lon(INT_MAX), id(UINT_MAX) {} + NodeInfo(int _lat, int _lon, NodeID _id) : lat(_lat), lon(_lon), id(_id) {} + NodeInfo() : lat(INT_MAX), lon(INT_MAX), id(UINT_MAX) {} int lat; int lon; - NodeT id; + NodeID id; - static NodeCoords min_value() { - return NodeCoords(-90*COORDINATE_PRECISION,-180*COORDINATE_PRECISION,std::numeric_limits::min()); - } - static NodeCoords max_value() { - return NodeCoords(90*COORDINATE_PRECISION, 180*COORDINATE_PRECISION, std::numeric_limits::max()); + static NodeInfo min_value() { + return NodeInfo( + -90*COORDINATE_PRECISION, + -180*COORDINATE_PRECISION, + std::numeric_limits::min() + ); } - value_type operator[](std::size_t n) const { + static NodeInfo max_value() { + return NodeInfo( + 90*COORDINATE_PRECISION, + 180*COORDINATE_PRECISION, + std::numeric_limits::max() + ); + } + + value_type operator[](const std::size_t n) const { switch(n) { case 1: return lat; @@ -57,15 +66,13 @@ struct NodeCoords { return lon; break; default: - assert(false); + BOOST_ASSERT_MSG(false, "should not happen"); return UINT_MAX; break; } - assert(false); + BOOST_ASSERT_MSG(false, "should not happen"); return UINT_MAX; } }; -typedef NodeCoords NodeInfo; - #endif //_NODE_COORDS_H diff --git a/Extractor/ExtractorStructs.h b/Extractor/ExtractorStructs.h index b481469f6..2d8134264 100644 --- a/Extractor/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -25,7 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/Coordinate.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportNode.h" -#include "../DataStructures/NodeCoords.h" +#include "../DataStructures/QueryNode.h" #include "../DataStructures/Restriction.h" #include "../DataStructures/TimingUtil.h" #include "../typedefs.h" diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 0e46db304..7069e64da 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -24,7 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRMException.h" #include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportEdge.h" -#include "../DataStructures/NodeCoords.h" +#include "../DataStructures/QueryNode.h" #include "../DataStructures/Restriction.h" #include "../Util/UUID.h" #include "../typedefs.h" From 0f8239bc8e8224a4fc635065f5f10d70d1ad1da3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 12:28:19 +0200 Subject: [PATCH 15/80] Fixing build of tools --- Algorithms/StronglyConnectedComponents.h | 7 ++++--- Tools/componentAnalysis.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index b7d288714..264e41b33 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -350,9 +350,10 @@ public: OGRFeature *poFeature; poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); poFeature->SetGeometry( &lineString ); - if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE ) - { - ERR( "Failed to create feature in shapefile.\n" ); + if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE ) { + throw OSRMException( + "Failed to create feature in shapefile." + ); } OGRFeature::DestroyFeature( poFeature ); } diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index 664c58954..af9e76c75 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -28,6 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/BaseConfiguration.h" #include "../Util/InputFileUtil.h" #include "../Util/GraphLoader.h" +#include "../Util/OSRMException.h" #include #include @@ -48,13 +49,14 @@ std::vector traffic_light_node_IDs_vector; int main (int argument_count, char *argument_values[]) { if(argument_count < 3) { - ERR("usage:\n" << argument_values[0] << " "); + std::cerr << "usage:\n" << argument_values[0] << " " << std::endl; + return -1; } INFO("Using restrictions from file: " << argument_values[2]); std::ifstream restriction_ifstream(argument_values[2], std::ios::binary); if(!restriction_ifstream.good()) { - ERR("Could not access files"); + throw OSRMException("Could not access files"); } uint32_t usable_restriction_count = 0; restriction_ifstream.read( @@ -76,7 +78,7 @@ int main (int argument_count, char *argument_values[]) { ); if (!input_stream.is_open()) { - ERR("Cannot open " << argument_values[1]); + throw OSRMException("Cannot open osrm file"); } std::vector edge_list; From b86c3681bb43398322d34e14d051d5d73ae090db Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 13:54:04 +0200 Subject: [PATCH 16/80] reverting premature checkin --- features/investigate/weird.feature | 2 +- features/testbot/basic.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/investigate/weird.feature b/features/investigate/weird.feature index 932526d59..5bf3b9166 100644 --- a/features/investigate/weird.feature +++ b/features/investigate/weird.feature @@ -36,7 +36,7 @@ Feature: Weird routings discovered | c | b | cd,de,ef,fg,gh,ha,ab | | d | c | de,ef,fg,gh,ha,ab,bc | | e | d | ef,fg,gh,ha,ab,bc,cd | - | f | e | | + | f | e | fg,gh,ha,ab,bc,cd,de | | g | f | gh,ha,ab,bc,cd,de,ef | | h | g | ha,ab,bc,cd,de,ef,fg | | a | h | ab,bc,cd,de,ef,fg,gh | \ No newline at end of file diff --git a/features/testbot/basic.feature b/features/testbot/basic.feature index ff2041a6e..a64311c61 100644 --- a/features/testbot/basic.feature +++ b/features/testbot/basic.feature @@ -266,7 +266,7 @@ Feature: Basic Routing | c | b | cd,de,ef,fg,gh,ha,ab | | d | c | de,ef,fg,gh,ha,ab,bc | | e | d | ef,fg,gh,ha,ab,bc,cd | - | f | e | | + | f | e | fg,gh,ha,ab,bc,cd,de | | g | f | gh,ha,ab,bc,cd,de,ef | | h | g | ha,ab,bc,cd,de,ef,fg | | a | h | ab,bc,cd,de,ef,fg,gh | From cabbe70e47f6c6f8cdc740d046429c2fb3225d35 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 14:01:03 +0200 Subject: [PATCH 17/80] reverting premature checkin --- features/investigate/weird.feature | 41 ++++++++++++++++++++++++++++-- features/testbot/basic.feature | 37 --------------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/features/investigate/weird.feature b/features/investigate/weird.feature index 5bf3b9166..33c2d6108 100644 --- a/features/investigate/weird.feature +++ b/features/investigate/weird.feature @@ -1,4 +1,4 @@ -@routing @weird +@routing @weird @todo Feature: Weird routings discovered Background: @@ -39,4 +39,41 @@ Feature: Weird routings discovered | f | e | fg,gh,ha,ab,bc,cd,de | | g | f | gh,ha,ab,bc,cd,de,ef | | h | g | ha,ab,bc,cd,de,ef,fg | - | a | h | ab,bc,cd,de,ef,fg,gh | \ No newline at end of file + | a | h | ab,bc,cd,de,ef,fg,gh | + + Scenario: Routing on a oneway roundabout + Given the node map + | | d | c | | + | e | | | b | + | f | | | a | + | | g | h | | + + And the ways + | nodes | oneway | + | ab | yes | + | bc | yes | + | cd | yes | + | de | yes | + | ef | yes | + | fg | yes | + | gh | yes | + | ha | yes | + + When I route I should get + | from | to | route | + | a | b | ab | + | b | c | bc | + | c | d | cd | + | d | e | de | + | e | f | ef | + | f | g | fg | + | g | h | gh | + | h | a | ha | + | b | a | bc,cd,de,ef,fg,gh,ha | + | c | b | cd,de,ef,fg,gh,ha,ab | + | d | c | de,ef,fg,gh,ha,ab,bc | + | e | d | ef,fg,gh,ha,ab,bc,cd | + | f | e | fg,gh,ha,ab,bc,cd,de | + | g | f | gh,ha,ab,bc,cd,de,ef | + | h | g | ha,ab,bc,cd,de,ef,fg | + | a | h | ab,bc,cd,de,ef,fg,gh | diff --git a/features/testbot/basic.feature b/features/testbot/basic.feature index a64311c61..9ab579f0f 100644 --- a/features/testbot/basic.feature +++ b/features/testbot/basic.feature @@ -233,40 +233,3 @@ Feature: Basic Routing | d | a | abcd | | a | m | aeim | | m | a | aeim | - - Scenario: Routing on a oneway roundabout - Given the node map - | | d | c | | - | e | | | b | - | f | | | a | - | | g | h | | - - And the ways - | nodes | oneway | - | ab | yes | - | bc | yes | - | cd | yes | - | de | yes | - | ef | yes | - | fg | yes | - | gh | yes | - | ha | yes | - - When I route I should get - | from | to | route | - | a | b | ab | - | b | c | bc | - | c | d | cd | - | d | e | de | - | e | f | ef | - | f | g | fg | - | g | h | gh | - | h | a | ha | - | b | a | bc,cd,de,ef,fg,gh,ha | - | c | b | cd,de,ef,fg,gh,ha,ab | - | d | c | de,ef,fg,gh,ha,ab,bc | - | e | d | ef,fg,gh,ha,ab,bc,cd | - | f | e | fg,gh,ha,ab,bc,cd,de | - | g | f | gh,ha,ab,bc,cd,de,ef | - | h | g | ha,ab,bc,cd,de,ef,fg | - | a | h | ab,bc,cd,de,ef,fg,gh | From e5f0ad4f0b84dbaa02b1e111417c45488c93e7b2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 14:27:36 +0200 Subject: [PATCH 18/80] Use boost timer to provide platform independent timing --- CMakeLists.txt | 2 +- DataStructures/StaticRTree.h | 2 +- Extractor/ExtractionContainers.h | 2 +- Extractor/ExtractorStructs.h | 1 - Util/TimingUtil.h | 33 ++++++++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 Util/TimingUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b17f1149a..5c9c5b212 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp ) -set(BOOST_COMPONENTS filesystem regex system thread) +set(BOOST_COMPONENTS filesystem regex system thread timer) file(GLOB ExtractorGlob Extractor/*.cpp) set(ExtractorSources extractor.cpp ${ExtractorGlob}) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 34f9fd00b..2defee25f 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -22,11 +22,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #define STATICRTREE_H_ #include "MercatorUtil.h" -#include "TimingUtil.h" #include "Coordinate.h" #include "PhantomNodes.h" #include "DeallocatingVector.h" #include "HilbertValue.h" +#include "../Util/TimingUtil.h" #include "../typedefs.h" #include diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index b2cc547d2..ded5c3aad 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -22,7 +22,7 @@ #define EXTRACTIONCONTAINERS_H_ #include "ExtractorStructs.h" -#include "../DataStructures/TimingUtil.h" +#include "../Util/TimingUtil.h" #include "../Util/UUID.h" #include diff --git a/Extractor/ExtractorStructs.h b/Extractor/ExtractorStructs.h index 2d8134264..ca8f654ad 100644 --- a/Extractor/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -27,7 +27,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/ImportNode.h" #include "../DataStructures/QueryNode.h" #include "../DataStructures/Restriction.h" -#include "../DataStructures/TimingUtil.h" #include "../typedefs.h" #include diff --git a/Util/TimingUtil.h b/Util/TimingUtil.h new file mode 100644 index 000000000..cd32f4093 --- /dev/null +++ b/Util/TimingUtil.h @@ -0,0 +1,33 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. +*/ + +#ifndef TIMINGUTIL_H_ +#define TIMINGUTIL_H_ + +#include + +static boost::timer my_timer; + +/** Returns a timestamp (now) in seconds (incl. a fractional part). */ +static inline double get_timestamp() { + return my_timer.elapsed(); +} + +#endif /* TIMINGUTIL_H_ */ From e7cec83a4c82ec6fb01bec57566f84f147f25c80 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 14:28:03 +0200 Subject: [PATCH 19/80] Use boost timer to provide platform independent timing --- DataStructures/TimingUtil.h | 50 ------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 DataStructures/TimingUtil.h diff --git a/DataStructures/TimingUtil.h b/DataStructures/TimingUtil.h deleted file mode 100644 index 6e980e26f..000000000 --- a/DataStructures/TimingUtil.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - open source routing machine - Copyright (C) Dennis Luxen, others 2010 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. -*/ - -#ifndef TIMINGUTIL_H_ -#define TIMINGUTIL_H_ - -#include -#include - - -#ifdef _WIN32 - #include - #include - #include - void gettimeofday(struct timeval* t,void* timezone) - { struct _timeb timebuffer; - _ftime( &timebuffer ); - t->tv_sec=timebuffer.time; - t->tv_usec=1000*timebuffer.millitm; - } -#else - #include -#endif - -/** Returns a timestamp (now) in seconds (incl. a fractional part). */ -static inline double get_timestamp() { - struct timeval tp; - gettimeofday(&tp, NULL); - return double(tp.tv_sec) + tp.tv_usec / 1000000.; -} - - -#endif /* TIMINGUTIL_H_ */ From e06fe6935a357c9acf166c189169c0beb288672a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 16:39:04 +0200 Subject: [PATCH 20/80] refactor Hashtable --- DataStructures/HashTable.h | 51 +++++++++--------------------- DataStructures/ImportNode.h | 2 +- Extractor/ExtractorStructs.h | 2 +- Extractor/PBFParser.cpp | 4 +-- Extractor/ScriptingEnvironment.cpp | 4 ++- Plugins/NearestPlugin.h | 4 +-- Plugins/RouteParameters.h | 2 +- Plugins/ViaRoutePlugin.h | 6 ++-- extractor.cpp | 2 ++ 9 files changed, 30 insertions(+), 47 deletions(-) diff --git a/DataStructures/HashTable.h b/DataStructures/HashTable.h index 57c2dde9f..465caca0e 100644 --- a/DataStructures/HashTable.h +++ b/DataStructures/HashTable.h @@ -24,56 +24,35 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef HASHTABLE_H_ #define HASHTABLE_H_ +#include #include template -class HashTable { - typedef boost::unordered_map MyHashTable; +class HashTable : public boost::unordered_map { +private: + typedef boost::unordered_map super; public: - typedef typename boost::unordered_map::const_iterator MyIterator; - typedef MyIterator iterator; - HashTable() { } - HashTable(const unsigned size) { - table.resize(size); - } + HashTable() : super() { } + + HashTable(const unsigned size) : super(size) { } + inline void Add(const keyT& key, const valueT& value){ - table[key] = value; - } - inline void Set(const keyT& key, const valueT& value){ - table[key] = value; + super::insert(std::make_pair(key, value)); } + inline valueT Find(const keyT& key) const { - if(table.find(key) == table.end()) + if(super::find(key) == super::end()) { return valueT(); - return table.find(key)->second; + } + return boost::ref(super::find(key)->second); } inline bool Holds(const keyT& key) const { - if(table.find(key) == table.end()) + if(super::find(key) == super::end()) { return false; + } return true; } - void EraseAll() { - if(table.size() > 0) - table.clear(); - } - - inline valueT operator[] (keyT key) const { - if(table.find(key) == table.end()) - return valueT(); - return table.find(key)->second; - } - inline unsigned Size() const { - return table.size(); - } - MyIterator begin() const { - return table.begin(); - } - MyIterator end() const { - return table.end(); - } -private: - MyHashTable table; }; #endif /* HASHTABLE_H_ */ diff --git a/DataStructures/ImportNode.h b/DataStructures/ImportNode.h index 28c9341c1..d1eb1dd28 100644 --- a/DataStructures/ImportNode.h +++ b/DataStructures/ImportNode.h @@ -46,7 +46,7 @@ struct ImportNode : public _Node { HashTable keyVals; inline void Clear() { - keyVals.EraseAll(); + keyVals.clear(); lat = 0; lon = 0; id = 0; bollard = false; trafficLight = false; } }; diff --git a/Extractor/ExtractorStructs.h b/Extractor/ExtractorStructs.h index ca8f654ad..108acf97d 100644 --- a/Extractor/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -49,7 +49,7 @@ struct ExtractionWay { id = UINT_MAX; nameID = UINT_MAX; path.clear(); - keyVals.EraseAll(); + keyVals.clear(); direction = ExtractionWay::notSure; speed = -1; backward_speed = -1; diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 4f3b40fde..92338e14a 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -177,7 +177,7 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) { const int keyValue = dense.keys_vals ( denseTagIndex+1 ); const std::string & key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).data(); const std::string & value = threadData->PBFprimitiveBlock.stringtable().s(keyValue).data(); - extracted_nodes_vector[i].keyVals.Add(key, value); + extracted_nodes_vector[i].keyVals.insert(std::make_pair(key, value)); denseTagIndex += 2; } } @@ -306,7 +306,7 @@ inline void PBFParser::parseWay(_ThreadData * threadData) { for(int j = 0; j < number_of_keys; ++j) { const std::string & key = threadData->PBFprimitiveBlock.stringtable().s(inputWay.keys(j)); const std::string & val = threadData->PBFprimitiveBlock.stringtable().s(inputWay.vals(j)); - parsed_way_vector[i].keyVals.Add(key, val); + parsed_way_vector[i].keyVals.insert(std::make_pair(key, val)); } } diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index ab1cc8d00..0b76749dd 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -25,8 +25,9 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { INFO("Using script " << fileName); // Create a new lua state - for(int i = 0; i < omp_get_max_threads(); ++i) + for(int i = 0; i < omp_get_max_threads(); ++i) { luaStateVector.push_back(luaL_newstate()); + } // Connect LuaBind to this lua state for all threads #pragma omp parallel @@ -85,6 +86,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { luabind::value("opposite", 3) ] ]; + luabind::module(myLuaState) [ luabind::class_ >("vector") .def("Add", &std::vector::push_back) diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 3fa1b7379..cb29ae002 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -38,8 +38,8 @@ public: NearestPlugin(QueryObjectsStorage * objects) : names(objects->names) { nodeHelpDesk = objects->nodeHelpDesk; - descriptorTable.Set("", 0); //default descriptor - descriptorTable.Set("json", 1); + descriptorTable.insert(std::make_pair("" , 0)); //default descriptor + descriptorTable.insert(std::make_pair("json", 1)); } std::string GetDescriptor() const { return std::string("nearest"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); } diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index 6c2b1af3b..c6dc5c544 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -53,7 +53,7 @@ struct RouteParameters { std::string language; std::vector hints; std::vector<_Coordinate> coordinates; - typedef HashTable::MyIterator OptionsIterator; + typedef HashTable::const_iterator OptionsIterator; void setZoomLevel(const short i) { if (18 > i && 0 < i) diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 72d27dc63..13c9e025d 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -58,9 +58,9 @@ public: searchEnginePtr = new SearchEngine(graph, nodeHelpDesk, names); - descriptorTable.Set("", 0); //default descriptor - descriptorTable.Set("json", 0); - descriptorTable.Set("gpx", 1); + descriptorTable.insert(std::make_pair("" , 0)); //default descriptor + descriptorTable.insert(std::make_pair("json", 0)); + descriptorTable.insert(std::make_pair("gpx" , 1)); } virtual ~ViaRoutePlugin() { diff --git a/extractor.cpp b/extractor.cpp index 221fb6a1e..773914c03 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -60,7 +60,9 @@ int main (int argc, char *argv[]) { unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("extractor.ini")) { BaseConfiguration extractorConfig("extractor.ini"); + INFO("2"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); + INFO("3"); if( rawNumber != 0 && rawNumber <= number_of_threads) { number_of_threads = rawNumber; } From 3151197471e03e00671d22653846fc6ff9589bf9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 16:50:20 +0200 Subject: [PATCH 21/80] boost timer library not needed --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c9c5b212..b17f1149a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp ) -set(BOOST_COMPONENTS filesystem regex system thread timer) +set(BOOST_COMPONENTS filesystem regex system thread) file(GLOB ExtractorGlob Extractor/*.cpp) set(ExtractorSources extractor.cpp ${ExtractorGlob}) From db7d4f56b31a3e75275c3f011a9a324ae6ec89d8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 16:58:31 +0200 Subject: [PATCH 22/80] Fix build with updated hash table --- Util/BaseConfiguration.h | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h index 0ff634c82..8a3d95907 100644 --- a/Util/BaseConfiguration.h +++ b/Util/BaseConfiguration.h @@ -24,6 +24,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRMException.h" #include "../DataStructures/HashTable.h" +#include + #include #include #include @@ -44,26 +46,22 @@ public: std::vector tokens; Tokenize(line, tokens); if(2 == tokens.size() ) - parameters.Add(tokens[0], tokens[1]); + parameters.insert(std::make_pair(tokens[0], tokens[1])); } config.close(); } } - std::string GetParameter(const char * key){ - return GetParameter(std::string(key)); - } - - std::string GetParameter(std::string key) { - return parameters.Find(key); + std::string GetParameter(const std::string & key){ + return parameters.Find(key); } void SetParameter(const char* key, const char* value) { SetParameter(std::string(key), std::string(value)); } - void SetParameter(std::string key, std::string value) { - parameters.Set(key, value); + void SetParameter(const std::string key, std::string value) { + parameters[key] = value; } private: @@ -77,32 +75,13 @@ private: while (std::string::npos != pos || std::string::npos != lastPos) { std::string temp = str.substr(lastPos, pos - lastPos); - TrimStringRight(temp); - TrimStringLeft(temp); + boost::trim(temp); tokens.push_back( temp ); lastPos = str.find_first_not_of(delimiters, pos); pos = str.find_first_of(delimiters, lastPos); } } - void TrimStringRight(std::string& str) { - std::string::size_type pos = str.find_last_not_of(" "); - if (pos != std::string::npos) { - str.erase(pos+1); - } else { - str.erase( str.begin() , str.end() ); - } - } - - void TrimStringLeft(std::string& str) { - std::string::size_type pos = str.find_first_not_of(" "); - if (pos != std::string::npos) { - str.erase(0, pos); - } else { - str.erase( str.begin() , str.end() ); - } - } - HashTable parameters; }; From b405029f0f495e8a9fedfe4fa1def5efb7e5224a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 17:23:40 +0200 Subject: [PATCH 23/80] Refactoring base config class into proper ini file name --- Contractor/EdgeBasedGraphFactory.h | 1 - Library/OSRM.cpp | 2 +- Library/OSRM.h | 2 +- Server/ServerFactory.h | 6 +- Tools/componentAnalysis.cpp | 2 - Tools/simpleclient.cpp | 2 +- Util/BaseConfiguration.h | 88 ------------------------------ Util/IniFile.h | 0 createHierarchy.cpp | 4 +- extractor.cpp | 4 +- routed.cpp | 4 +- 11 files changed, 12 insertions(+), 103 deletions(-) delete mode 100644 Util/BaseConfiguration.h create mode 100644 Util/IniFile.h diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 7949af6ff..d23f93549 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -35,7 +35,6 @@ #include "../DataStructures/QueryEdge.h" #include "../DataStructures/Percent.h" #include "../DataStructures/TurnInstructions.h" -#include "../Util/BaseConfiguration.h" #include "../Util/LuaUtil.h" #include diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 2da379901..f0937c988 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -25,7 +25,7 @@ OSRM::OSRM(const char * server_ini_path) { throw OSRMException("server.ini not found"); } - BaseConfiguration serverConfig(server_ini_path); + IniFile serverConfig(server_ini_path); boost::filesystem::path base_path = boost::filesystem::absolute(server_ini_path).parent_path(); diff --git a/Library/OSRM.h b/Library/OSRM.h index 5f36211c8..a879a1223 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -30,7 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" -#include "../Util/BaseConfiguration.h" +#include "../Util/IniFile.h" #include "../Util/OSRMException.h" #include "../Util/InputFileUtil.h" #include "../Server/BasicDatastructures.h" diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index 8101d78a3..a41253105 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -27,7 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Server.h" -#include "../Util/BaseConfiguration.h" +#include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" #include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" @@ -38,7 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include struct ServerFactory { - static Server * CreateServer(BaseConfiguration& serverConfig) { + static Server * CreateServer(IniFile& serverConfig) { if(!testDataFile(serverConfig.GetParameter("nodesData"))) { throw OSRMException("nodes file not found"); @@ -76,7 +76,7 @@ struct ServerFactory { } static Server * CreateServer(const char * iniFile) { - BaseConfiguration serverConfig(iniFile); + IniFile serverConfig(iniFile); return CreateServer(serverConfig); } }; diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index af9e76c75..b38d980fa 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/TurnInstructions.h" -#include "../Util/BaseConfiguration.h" #include "../Util/InputFileUtil.h" #include "../Util/GraphLoader.h" #include "../Util/OSRMException.h" @@ -40,7 +39,6 @@ or see http://www.gnu.org/licenses/agpl.txt. typedef QueryEdge::EdgeData EdgeData; typedef DynamicGraph::InputEdge InputEdge; -typedef BaseConfiguration ContractorConfiguration; std::vector internal_to_external_node_map; std::vector<_Restriction> restrictions_vector; diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index 74aa8c8f3..361bbce4b 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -46,7 +46,7 @@ void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_ int main (int argc, char * argv[]) { std::cout << "\n starting up engines, compile at " << __DATE__ << ", " __TIME__ << std::endl; - BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + IniFile serverConfig((argc > 1 ? argv[1] : "server.ini")); OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); RouteParameters route_parameters; diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h deleted file mode 100644 index 8a3d95907..000000000 --- a/Util/BaseConfiguration.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - open source routing machine - Copyright (C) Dennis Luxen, 2010 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. - */ - -#ifndef BASECONFIGURATION_H_ -#define BASECONFIGURATION_H_ - -#include "OSRMException.h" -#include "../DataStructures/HashTable.h" - -#include - -#include -#include -#include -#include - -class BaseConfiguration { -public: - BaseConfiguration(const char * configFile) { - std::ifstream config( configFile ); - if(!config) { - throw OSRMException("[config] .ini not found"); - } - - std::string line; - if (config.is_open()) { - while ( config.good() ) { - getline (config,line); - std::vector tokens; - Tokenize(line, tokens); - if(2 == tokens.size() ) - parameters.insert(std::make_pair(tokens[0], tokens[1])); - } - config.close(); - } - } - - std::string GetParameter(const std::string & key){ - return parameters.Find(key); - } - - void SetParameter(const char* key, const char* value) { - SetParameter(std::string(key), std::string(value)); - } - - void SetParameter(const std::string key, std::string value) { - parameters[key] = value; - } - -private: - void Tokenize( - const std::string& str, - std::vector& tokens, - const std::string& delimiters = "=" - ) { - std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); - std::string::size_type pos = str.find_first_of(delimiters, lastPos); - - while (std::string::npos != pos || std::string::npos != lastPos) { - std::string temp = str.substr(lastPos, pos - lastPos); - boost::trim(temp); - tokens.push_back( temp ); - lastPos = str.find_first_not_of(delimiters, pos); - pos = str.find_first_of(delimiters, lastPos); - } - } - - HashTable parameters; -}; - -#endif /* BASECONFIGURATION_H_ */ diff --git a/Util/IniFile.h b/Util/IniFile.h new file mode 100644 index 000000000..e69de29bb diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 6dd0f3b86..035cba63a 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "DataStructures/QueryEdge.h" #include "DataStructures/StaticGraph.h" #include "DataStructures/StaticRTree.h" -#include "Util/BaseConfiguration.h" +#include "Util/IniFile.h" #include "Util/GraphLoader.h" #include "Util/InputFileUtil.h" #include "Util/LuaUtil.h" @@ -49,7 +49,7 @@ or see http://www.gnu.org/licenses/agpl.txt. typedef QueryEdge::EdgeData EdgeData; typedef DynamicGraph::InputEdge InputEdge; typedef StaticGraph::InputEdge StaticEdge; -typedef BaseConfiguration ContractorConfiguration; +typedef IniFile ContractorConfiguration; std::vector internalToExternalNodeMapping; std::vector<_Restriction> inputRestrictions; diff --git a/extractor.cpp b/extractor.cpp index 773914c03..182545029 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Extractor/ScriptingEnvironment.h" #include "Extractor/PBFParser.h" #include "Extractor/XMLParser.h" -#include "Util/BaseConfiguration.h" +#include "Util/IniFile.h" #include "Util/InputFileUtil.h" #include "Util/MachineInfo.h" #include "Util/OpenMPWrapper.h" @@ -59,7 +59,7 @@ int main (int argc, char *argv[]) { unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("extractor.ini")) { - BaseConfiguration extractorConfig("extractor.ini"); + IniFile extractorConfig("extractor.ini"); INFO("2"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); INFO("3"); diff --git a/routed.cpp b/routed.cpp index 1f4e43550..bd916266a 100644 --- a/routed.cpp +++ b/routed.cpp @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Server/ServerFactory.h" -#include "Util/BaseConfiguration.h" +#include "Util/IniFile.h" #include "Util/InputFileUtil.h" #include "Util/OpenMPWrapper.h" #include "Util/UUID.h" @@ -91,7 +91,7 @@ int main (int argc, char * argv[]) { pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + IniFile serverConfig((argc > 1 ? argv[1] : "server.ini")); OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); Server * s = ServerFactory::CreateServer(serverConfig); From a82383d78e0e224de20e61b2055f3151d682399c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 17:33:26 +0200 Subject: [PATCH 24/80] Refactoring base config class into proper ini file name --- Util/IniFile.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/Util/IniFile.h b/Util/IniFile.h index e69de29bb..ec01ade91 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -0,0 +1,88 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#ifndef INI_FILE_H_ +#define INI_FILE_H_ + +#include "OSRMException.h" +#include "../DataStructures/HashTable.h" + +#include + +#include +#include +#include +#include + +class IniFile { +public: + IniFile(const char * configFile) { + std::ifstream config( configFile ); + if(!config) { + throw OSRMException("[config] .ini not found"); + } + + std::string line; + if (config.is_open()) { + while ( config.good() ) { + getline (config,line); + std::vector tokens; + Tokenize(line, tokens); + if(2 == tokens.size() ) + parameters.insert(std::make_pair(tokens[0], tokens[1])); + } + config.close(); + } + } + + std::string GetParameter(const std::string & key){ + return parameters.Find(key); + } + + void SetParameter(const char* key, const char* value) { + SetParameter(std::string(key), std::string(value)); + } + + void SetParameter(const std::string key, std::string value) { + parameters[key] = value; + } + +private: + void Tokenize( + const std::string& str, + std::vector& tokens, + const std::string& delimiters = "=" + ) { + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); + std::string::size_type pos = str.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + std::string temp = str.substr(lastPos, pos - lastPos); + boost::trim(temp); + tokens.push_back( temp ); + lastPos = str.find_first_not_of(delimiters, pos); + pos = str.find_first_of(delimiters, lastPos); + } + } + + HashTable parameters; +}; + +#endif /* INI_FILE_H_ */ \ No newline at end of file From 21ffd441fa835dec81de4a62b11be801fb1ab385 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 6 Aug 2013 17:46:49 +0200 Subject: [PATCH 25/80] Refactoring base config class into proper ini file name --- Tools/componentAnalysis.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index b38d980fa..be7691c39 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -25,8 +25,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/TurnInstructions.h" -#include "../Util/InputFileUtil.h" #include "../Util/GraphLoader.h" +#include "../Util/IniFile.h" +#include "../Util/InputFileUtil.h" #include "../Util/OSRMException.h" #include From f4906a97b9799eac773571e3899e46cf754c650b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 7 Aug 2013 14:01:56 +0200 Subject: [PATCH 26/80] pass const refs instead of copy --- Plugins/RouteParameters.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index c6dc5c544..e4455f839 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -56,8 +56,9 @@ struct RouteParameters { typedef HashTable::const_iterator OptionsIterator; void setZoomLevel(const short i) { - if (18 > i && 0 < i) + if (18 > i && 0 < i) { zoomLevel = i; + } } void setAlternateRouteFlag(const bool b) { @@ -105,12 +106,11 @@ struct RouteParameters { compression = b; } - void addCoordinate(boost::fusion::vector < double, double > arg_) { + void addCoordinate(const boost::fusion::vector < double, double > & arg_) { int lat = COORDINATE_PRECISION*boost::fusion::at_c < 0 > (arg_); int lon = COORDINATE_PRECISION*boost::fusion::at_c < 1 > (arg_); coordinates.push_back(_Coordinate(lat, lon)); } }; - #endif /*ROUTE_PARAMETERS_H*/ From a609a1c6c2f65dbc247a78d9861ae51685474453 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 7 Aug 2013 14:02:10 +0200 Subject: [PATCH 27/80] Move common code into base class --- Plugins/BasePlugin.h | 13 +++++++++++++ Plugins/LocatePlugin.h | 13 +------------ Plugins/NearestPlugin.h | 13 +------------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index 034c848a7..77b133efb 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -36,6 +36,19 @@ public: virtual std::string GetDescriptor() const = 0; virtual std::string GetVersionString() const = 0 ; virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0; + + inline bool checkCoord(const _Coordinate & c) { + if( + c.lat > 90*COORDINATE_PRECISION || + c.lat < -90*COORDINATE_PRECISION || + c.lon > 180*COORDINATE_PRECISION || + c.lon < -180*COORDINATE_PRECISION + ) { + return false; + } + return true; + } + }; #endif /* BASEPLUGIN_H_ */ diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 7369390a9..9fff478dd 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -99,19 +99,8 @@ public: reply.headers[0].value = tmp; return; } -private: - inline bool checkCoord(const _Coordinate & c) { - if( - c.lat > 90*COORDINATE_PRECISION || - c.lat < -90*COORDINATE_PRECISION || - c.lon > 180*COORDINATE_PRECISION || - c.lon < -180*COORDINATE_PRECISION - ) { - return false; - } - return true; - } +private: NodeInformationHelpDesk * nodeHelpDesk; }; diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index cb29ae002..9ea15d32b 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -107,19 +107,8 @@ public: intToString(reply.content.size(), tmp); reply.headers[0].value = tmp; } -private: - inline bool checkCoord(const _Coordinate & c) { - if( - c.lat > 90*COORDINATE_PRECISION || - c.lat < -90*COORDINATE_PRECISION || - c.lon > 180*COORDINATE_PRECISION || - c.lon < -180*COORDINATE_PRECISION - ) { - return false; - } - return true; - } +private: NodeInformationHelpDesk * nodeHelpDesk; HashTable descriptorTable; std::vector & names; From 75cdefa4fee8082f59b0feae0520b4af14c13bee Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Wed, 7 Aug 2013 21:30:27 +0200 Subject: [PATCH 28/80] show name of missing .ini file --- Util/IniFile.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Util/IniFile.h b/Util/IniFile.h index ec01ade91..1ed0ca578 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -36,7 +36,8 @@ public: IniFile(const char * configFile) { std::ifstream config( configFile ); if(!config) { - throw OSRMException("[config] .ini not found"); + std::string str = "[config] " + std::string(configFile) + " not found"; + throw OSRMException(str.c_str()); } std::string line; From ef221e1c6ce9471401cfcdac00f7dc8aaa979f23 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:17:01 +0200 Subject: [PATCH 29/80] Replacing log macros by more sophisticated mechanism --- Algorithms/StronglyConnectedComponents.h | 34 +-- Contractor/ContractionCleanup.h | 261 ------------------ Contractor/Contractor.h | 12 +- Contractor/EdgeBasedGraphFactory.cpp | 28 +- Contractor/EdgeBasedGraphFactory.h | 1 + Contractor/TemporaryStorage.cpp | 2 +- Contractor/TemporaryStorage.h | 1 + DataStructures/NodeInformationHelpDesk.h | 8 +- DataStructures/StaticGraph.h | 10 +- DataStructures/StaticRTree.h | 31 ++- Descriptors/DescriptionFactory.cpp | 14 +- Descriptors/DescriptionFactory.h | 1 + Extractor/BaseParser.cpp | 10 +- Extractor/BaseParser.h | 1 + Extractor/ExtractionContainers.cpp | 4 +- Extractor/ExtractionContainers.h | 1 + Extractor/ExtractorCallbacks.cpp | 7 +- Extractor/PBFParser.cpp | 9 +- Extractor/PBFParser.h | 1 + Extractor/ScriptingEnvironment.cpp | 2 +- Extractor/ScriptingEnvironment.h | 1 + Extractor/XMLParser.cpp | 4 +- Extractor/XMLParser.h | 1 + Plugins/ViaRoutePlugin.h | 17 +- RoutingAlgorithms/AlternativePathRouting.h | 2 +- RoutingAlgorithms/BasicRoutingInterface.h | 3 +- Server/DataStructures/QueryObjectsStorage.cpp | 17 +- Server/DataStructures/QueryObjectsStorage.h | 3 +- Server/RequestHandler.h | 8 +- Tools/componentAnalysis.cpp | 12 +- Util/GraphLoader.h | 45 +-- Util/InputFileUtil.h | 4 +- createHierarchy.cpp | 87 ++++-- extractor.cpp | 30 +- routed.cpp | 5 +- typedefs.h | 11 +- 36 files changed, 242 insertions(+), 446 deletions(-) delete mode 100644 Contractor/ContractionCleanup.h diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index 264e41b33..2377258f8 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -33,6 +33,8 @@ Strongly connected components using Tarjan's Algorithm #include "../DataStructures/Restriction.h" #include "../DataStructures/TurnInstructions.h" +#include "../Util/SimpleLogger.h" + #include #include #include @@ -243,7 +245,7 @@ public: bool beforeRecursion = recursionStack.top().first; TarjanStackFrame currentFrame = recursionStack.top().second; NodeID v = currentFrame.v; -// INFO("popping node " << v << (beforeRecursion ? " before " : " after ") << "recursion"); +// SimpleLogger().Write() << "popping node " << v << (beforeRecursion ? " before " : " after ") << "recursion"; recursionStack.pop(); if(beforeRecursion) { @@ -256,45 +258,45 @@ public: tarjanStack.push(v); tarjanNodes[v].onStack = true; ++index; -// INFO("pushing " << v << " onto tarjan stack, idx[" << v << "]=" << tarjanNodes[v].index << ", lowlink["<< v << "]=" << tarjanNodes[v].lowlink); +// SimpleLogger().Write() << "pushing " << v << " onto tarjan stack, idx[" << v << "]=" << tarjanNodes[v].index << ", lowlink["<< v << "]=" << tarjanNodes[v].lowlink; //Traverse outgoing edges for(TarjanDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { TarjanDynamicGraph::NodeIterator vprime = _nodeBasedGraph->GetTarget(e2); -// INFO("traversing edge (" << v << "," << vprime << ")"); +// SimpleLogger().Write() << "traversing edge (" << v << "," << vprime << ")"; if(UINT_MAX == tarjanNodes[vprime].index) { recursionStack.push(std::make_pair(true,TarjanStackFrame(vprime, v))); } else { -// INFO("Node " << vprime << " is already explored"); +// SimpleLogger().Write() << "Node " << vprime << " is already explored"; if(tarjanNodes[vprime].onStack) { unsigned newLowlink = std::min(tarjanNodes[v].lowlink, tarjanNodes[vprime].index); -// INFO("Setting lowlink[" << v << "] from " << tarjanNodes[v].lowlink << " to " << newLowlink); +// SimpleLogger().Write() << "Setting lowlink[" << v << "] from " << tarjanNodes[v].lowlink << " to " << newLowlink; tarjanNodes[v].lowlink = newLowlink; // } else { -// INFO("But node " << vprime << " is not on stack"); +// SimpleLogger().Write() << "But node " << vprime << " is not on stack"; } } } } else { -// INFO("we are at the end of recursion and checking node " << v); +// SimpleLogger().Write() << "we are at the end of recursion and checking node " << v; { // setting lowlink in its own scope so it does not pollute namespace // NodeID parent = (UINT_MAX == tarjanNodes[v].parent ? v : tarjanNodes[v].parent ); -// INFO("parent=" << currentFrame.parent); -// INFO("tarjanNodes[" << v << "].lowlink=" << tarjanNodes[v].lowlink << ", tarjanNodes[" << currentFrame.parent << "].lowlink=" << tarjanNodes[currentFrame.parent].lowlink); +// SimpleLogger().Write() << "parent=" << currentFrame.parent; +// SimpleLogger().Write() << "tarjanNodes[" << v << "].lowlink=" << tarjanNodes[v].lowlink << ", tarjanNodes[" << currentFrame.parent << "].lowlink=" << tarjanNodes[currentFrame.parent].lowlink; //Note the index shift by 1 compared to the recursive version tarjanNodes[currentFrame.parent].lowlink = std::min(tarjanNodes[currentFrame.parent].lowlink, tarjanNodes[v].lowlink); -// INFO("Setting tarjanNodes[" << currentFrame.parent <<"].lowlink=" << tarjanNodes[currentFrame.parent].lowlink); +// SimpleLogger().Write() << "Setting tarjanNodes[" << currentFrame.parent <<"].lowlink=" << tarjanNodes[currentFrame.parent].lowlink; } -// INFO("tarjanNodes[" << v << "].lowlink=" << tarjanNodes[v].lowlink << ", tarjanNodes[" << v << "].index=" << tarjanNodes[v].index); +// SimpleLogger().Write() << "tarjanNodes[" << v << "].lowlink=" << tarjanNodes[v].lowlink << ", tarjanNodes[" << v << "].index=" << tarjanNodes[v].index; //after recursion, lets do cycle checking //Check if we found a cycle. This is the bottom part of the recursion if(tarjanNodes[v].lowlink == tarjanNodes[v].index) { NodeID vprime; do { -// INFO("identified component " << currentComponent << ": " << tarjanStack.top()); +// SimpleLogger().Write() << "identified component " << currentComponent << ": " << tarjanStack.top(); vprime = tarjanStack.top(); tarjanStack.pop(); tarjanNodes[vprime].onStack = false; componentsIndex[vprime] = currentComponent; @@ -302,7 +304,7 @@ public: } while( v != vprime); vectorOfComponentSizes.push_back(sizeOfCurrentComponent); if(sizeOfCurrentComponent > 1000) - INFO("large component [" << currentComponent << "]=" << sizeOfCurrentComponent); + SimpleLogger().Write() << "large component [" << currentComponent << "]=" << sizeOfCurrentComponent; ++currentComponent; sizeOfCurrentComponent = 0; } @@ -310,14 +312,14 @@ public: } } - INFO("identified: " << vectorOfComponentSizes.size() << " many components, marking small components"); + SimpleLogger().Write() << "identified: " << vectorOfComponentSizes.size() << " many components, marking small components"; int singleCounter = 0; for(unsigned i = 0; i < vectorOfComponentSizes.size(); ++i){ if(1 == vectorOfComponentSizes[i]) ++singleCounter; } - INFO("identified " << singleCounter << " SCCs of size 1"); + SimpleLogger().Write() << "identified " << singleCounter << " SCCs of size 1"; uint64_t total_network_distance = 0; p.reinit(_nodeBasedGraph->GetNumberOfNodes()); for(TarjanDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { @@ -363,7 +365,7 @@ public: OGRDataSource::DestroyDataSource( poDS ); std::vector().swap(vectorOfComponentSizes); std::vector().swap(componentsIndex); - INFO("total network distance: " << total_network_distance/100/1000. << " km"); + SimpleLogger().Write() << "total network distance: " << (uint64_t)total_network_distance/100/1000. << " km"; } private: unsigned CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const { diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h deleted file mode 100644 index e42dad3a7..000000000 --- a/Contractor/ContractionCleanup.h +++ /dev/null @@ -1,261 +0,0 @@ -/* - open source routing machine - Copyright (C) Dennis Luxen, others 2010 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. - */ - -#ifndef CONTRACTIONCLEANUP_H_INCLUDED -#define CONTRACTIONCLEANUP_H_INCLUDED - -#include -#ifndef _WIN32 -#include -#endif -#include "Contractor.h" - -class ContractionCleanup { -private: - - struct _CleanupHeapData { - NodeID parent; - _CleanupHeapData( NodeID p ) { - parent = p; - } - }; - typedef BinaryHeap< NodeID, NodeID, int, _CleanupHeapData > _Heap; - - struct _ThreadData { - _Heap* _heapForward; - _Heap* _heapBackward; - _ThreadData( NodeID nodes ) { - _heapBackward = new _Heap(nodes); - _heapForward = new _Heap(nodes); - } - ~_ThreadData() { - delete _heapBackward; - delete _heapForward; - } - }; - -public: - - struct Edge { - NodeID source; - NodeID target; - struct EdgeData { - NodeID via; - unsigned nameID; - int distance; - TurnInstruction turnInstruction; - bool shortcut:1; - bool forward:1; - bool backward:1; - } data; - bool operator<( const Edge& right ) const { - if ( source != right.source ) - return source < right.source; - return target < right.target; - } - - //sorts by source and other attributes - static bool CompareBySource( const Edge& left, const Edge& right ) { - if ( left.source != right.source ) - return left.source < right.source; - int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 ); - int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 ); - if ( l != r ) - return l < r; - if ( left.target != right.target ) - return left.target < right.target; - return left.data.distance < right.data.distance; - } - - bool operator== ( const Edge& right ) const { - return ( source == right.source && target == right.target && data.distance == right.data.distance && - data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward - && data.via == right.data.via && data.nameID == right.data.nameID - ); - } - }; - - ContractionCleanup( int numNodes, const std::vector< Edge >& edges ) { - _graph = edges; - _numNodes = numNodes; - } - - ~ContractionCleanup() { - - } - - void Run() { - RemoveUselessShortcuts(); - } - - template< class EdgeT > - void GetData( std::vector< EdgeT >& edges ) { - for ( int edge = 0, endEdges = ( int ) _graph.size(); edge != endEdges; ++edge ) { - if(_graph[edge].data.forward || _graph[edge].data.backward) { - EdgeT newEdge; - newEdge.source = _graph[edge].source; - newEdge.target = _graph[edge].target; - newEdge.data = _graph[edge].data; - edges.push_back( newEdge ); - } - } - sort( edges.begin(), edges.end() ); - } - -private: - - double _Timestamp() { - struct timeval tp; - gettimeofday(&tp, NULL); - return double(tp.tv_sec) + tp.tv_usec / 1000000.; - } - - void BuildOutgoingGraph() { - //sort edges by source - sort( _graph.begin(), _graph.end(), Edge::CompareBySource ); - try { - _firstEdge.resize( _numNodes + 1 ); - } catch(...) { - ERR("Not enough RAM on machine"); - return; - } - _firstEdge[0] = 0; - for ( NodeID i = 0, node = 0; i < ( NodeID ) _graph.size(); i++ ) { - while ( _graph[i].source != node ) - _firstEdge[++node] = i; - if ( i == ( NodeID ) _graph.size() - 1 ) - while ( node < _numNodes ) - _firstEdge[++node] = ( int ) _graph.size(); - } - } - - void RemoveUselessShortcuts() { - int maxThreads = omp_get_max_threads(); - std::vector < _ThreadData* > threadData; - for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) { - threadData.push_back( new _ThreadData( _numNodes ) ); - } - - INFO("Scanning for useless shortcuts"); - BuildOutgoingGraph(); -/* - #pragma omp parallel for - for ( int i = 0; i < ( int ) _graph.size(); i++ ) { - //only remove shortcuts - if ( !_graph[i].data.shortcut ) - continue; - - if ( _graph[i].data.forward ) { - int result = _ComputeDistance( _graph[i].source, _graph[i].target, threadData[omp_get_thread_num()] ); - if ( result < _graph[i].data.distance ) { - _graph[i].data.forward = false; - } - } - if ( _graph[i].data.backward ) { - int result = _ComputeDistance( _graph[i].target, _graph[i].source, threadData[omp_get_thread_num()] ); - if ( result < _graph[i].data.distance ) { - _graph[i].data.backward = false; - } - } - } -*/ - INFO("Removing edges"); - int useful = 0; - for ( int i = 0; i < ( int ) _graph.size(); i++ ) { - if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut ) { - continue; - } - _graph[useful] = _graph[i]; - useful++; - } - INFO("Removed " << _graph.size() - useful << " useless shortcuts"); - _graph.resize( useful ); - - for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) { - delete threadData[threadNum]; - } - } - - void _ComputeStep( _Heap* heapForward, _Heap* heapBackward, bool forwardDirection, NodeID* middle, int* targetDistance ) { - - const NodeID node = heapForward->DeleteMin(); - const int distance = heapForward->GetKey( node ); - - if ( distance > *targetDistance ) { - heapForward->DeleteAll(); - return; - } - - if ( heapBackward->WasInserted( node ) ) { - const int newDistance = heapBackward->GetKey( node ) + distance; - if ( newDistance < *targetDistance ) { - *middle = node; - *targetDistance = newDistance; - } - } - - for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) { - const NodeID to = _graph[edge].target; - const int edgeWeight = _graph[edge].data.distance; - assert( edgeWeight > 0 ); - const int toDistance = distance + edgeWeight; - - if ( (forwardDirection ? _graph[edge].data.forward : _graph[edge].data.backward ) ) { - //New Node discovered -> Add to Heap + Node Info Storage - if ( !heapForward->WasInserted( to ) ) - heapForward->Insert( to, toDistance, node ); - - //Found a shorter Path -> Update distance - else if ( toDistance < heapForward->GetKey( to ) ) { - heapForward->DecreaseKey( to, toDistance ); - //new parent - heapForward->GetData( to ) = node; - } - } - } - } - - int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data ) { - data->_heapForward->Clear(); - data->_heapBackward->Clear(); - //insert source into heap - data->_heapForward->Insert( source, 0, source ); - data->_heapBackward->Insert( target, 0, target ); - - int targetDistance = std::numeric_limits< int >::max(); - NodeID middle = std::numeric_limits::max(); - - while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) { - if ( data->_heapForward->Size() > 0 ) { - _ComputeStep( data->_heapForward, data->_heapBackward, true, &middle, &targetDistance ); - } - - if ( data->_heapBackward->Size() > 0 ) { - _ComputeStep( data->_heapBackward, data->_heapForward, false, &middle, &targetDistance ); - } - } - return targetDistance; - } - NodeID _numNodes; - std::vector< Edge > _graph; - std::vector< unsigned > _firstEdge; -}; - -#endif // CONTRACTIONCLEANUP_H_INCLUDED diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index bbc3ad58e..1ffc0435b 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/XORFastHash.h" #include "../DataStructures/XORFastHashStorage.h" #include "../Util/OpenMPWrapper.h" +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include @@ -124,7 +125,8 @@ public: BOOST_ASSERT_MSG( newEdge.data.distance > 0, "edge distance < 1" ); #ifndef NDEBUG if ( newEdge.data.distance > 24 * 60 * 60 * 10 ) { - WARN("Edge weight large -> " << newEdge.data.distance); + SimpleLogger().Write(logWARNING) << + "Edge weight large -> " << newEdge.data.distance; } #endif edges.push_back( newEdge ); @@ -198,9 +200,9 @@ public: // } // } // - // INFO("edges at node with id " << highestNode << " has degree " << maxdegree); + // SimpleLogger().Write() << "edges at node with id " << highestNode << " has degree " << maxdegree; // for(unsigned i = _graph->BeginEdges(highestNode); i < _graph->EndEdges(highestNode); ++i) { - // INFO(" ->(" << highestNode << "," << _graph->GetTarget(i) << "); via: " << _graph->GetEdgeData(i).via); + // SimpleLogger().Write() << " ->(" << highestNode << "," << _graph->GetTarget(i) << "); via: " << _graph->GetEdgeData(i).via; // } //Create temporary file @@ -430,7 +432,7 @@ public: // avgdegree /= std::max((unsigned)1,(unsigned)remainingNodes.size() ); // quaddegree /= std::max((unsigned)1,(unsigned)remainingNodes.size() ); // - // INFO("rest: " << remainingNodes.size() << ", max: " << maxdegree << ", min: " << mindegree << ", avg: " << avgdegree << ", quad: " << quaddegree); + // SimpleLogger().Write() << "rest: " << remainingNodes.size() << ", max: " << maxdegree << ", min: " << mindegree << ", avg: " << avgdegree << ", quad: " << quaddegree; p.printStatus(numberOfContractedNodes); } @@ -443,7 +445,7 @@ public: template< class Edge > inline void GetEdges( DeallocatingVector< Edge >& edges ) { Percent p (_graph->GetNumberOfNodes()); - INFO("Getting edges of minimized graph"); + SimpleLogger().Write() << "Getting edges of minimized graph"; NodeID numberOfNodes = _graph->GetNumberOfNodes(); if(_graph->GetNumberOfNodes()) { for ( NodeID node = 0; node < numberOfNodes; ++node ) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 9443c24e4..7da2e4f67 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -162,7 +162,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned)); - INFO("Identifying small components"); + SimpleLogger().Write() << "Identifying small components"; //Run a BFS on the undirected graph and identify small components std::queue > bfsQueue; std::vector componentsIndex(_nodeBasedGraph->GetNumberOfNodes(), UINT_MAX); @@ -179,7 +179,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State //fetch element from BFS queue std::pair currentQueueItem = bfsQueue.front(); bfsQueue.pop(); - // INFO("sizeof queue: " << bfsQueue.size() << ", sizeOfCurrentComponents: " << sizeOfCurrentComponent << ", settled nodes: " << settledNodes++ << ", max: " << endNodes); + // SimpleLogger().Write() << "sizeof queue: " << bfsQueue.size() << ", sizeOfCurrentComponents: " << sizeOfCurrentComponent << ", settled nodes: " << settledNodes++ << ", max: " << endNodes; const NodeID v = currentQueueItem.first; //current node const NodeID u = currentQueueItem.second; //parent //increment size counter of current component @@ -216,7 +216,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State ++currentComponent; } } - INFO("identified: " << vectorOfComponentSizes.size() << " many components"); + SimpleLogger().Write() << "identified: " << vectorOfComponentSizes.size() << " many components"; p.reinit(_nodeBasedGraph->GetNumberOfNodes()); //loop over all edges and generate new set of nodes. @@ -314,19 +314,19 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned)); originalEdgeDataOutFile.close(); -// INFO("Sorting edge-based Nodes"); -// std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end()); -// INFO("Removing duplicate nodes (if any)"); +// SimpleLogger().Write() <<"Sorting edge-based Nodes"; +// std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end(); +// SimpleLogger().Write() <<"Removing duplicate nodes (if any)"; // edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() ); -// INFO("Applying vector self-swap trick to free up memory"); -// INFO("size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity()); +// SimpleLogger().Write() <<"Applying vector self-swap trick to free up memory"; +// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity(); // std::vector(edgeBasedNodes).swap(edgeBasedNodes); -// INFO("size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity()); - INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges"); - INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges"); -// INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << 2*((double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter)); - INFO("Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions."); - INFO("Generated " << edgeBasedNodes.size() << " edge based nodes"); +// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity(); + SimpleLogger().Write() <<"Node-based graph contains " << nodeBasedEdgeCounter << " edges"; + SimpleLogger().Write() <<"Edge-based graph contains " << edgeBasedEdges.size() << " edges"; +// SimpleLogger().Write() << "Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << 2*((double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter; + SimpleLogger().Write() <<"Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions."; + SimpleLogger().Write() <<"Generated " << edgeBasedNodes.size() << " edge based nodes"; } TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const { diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index d23f93549..2c5360c1c 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -36,6 +36,7 @@ #include "../DataStructures/Percent.h" #include "../DataStructures/TurnInstructions.h" #include "../Util/LuaUtil.h" +#include "../Util/SimpleLogger.h" #include diff --git a/Contractor/TemporaryStorage.cpp b/Contractor/TemporaryStorage.cpp index 2f8691066..6c32ba176 100644 --- a/Contractor/TemporaryStorage.cpp +++ b/Contractor/TemporaryStorage.cpp @@ -45,7 +45,7 @@ int TemporaryStorage::allocateSlot() { boost::mutex::scoped_lock lock(mutex); try { vectorOfStreamDatas.push_back(StreamData()); - //INFO("created new temporary file: " << vectorOfStreamDatas.back().pathToTemporaryFile); + //SimpleLogger().Write() << "created new temporary file: " << vectorOfStreamDatas.back().pathToTemporaryFile; } catch(boost::filesystem::filesystem_error & e) { abort(e); } diff --git a/Contractor/TemporaryStorage.h b/Contractor/TemporaryStorage.h index 066d22de5..feebc3552 100644 --- a/Contractor/TemporaryStorage.h +++ b/Contractor/TemporaryStorage.h @@ -32,6 +32,7 @@ #include #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include "../typedefs.h" //This is one big workaround for latest boost renaming woes. diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 773a29e51..37bead56f 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -136,7 +136,7 @@ private: throw OSRMException("edges file not found"); } - DEBUG("Loading node data"); + SimpleLogger().Write(logDEBUG) << "Loading node data"; NodeInfo b; while(!nodes_input_stream.eof()) { nodes_input_stream.read((char *)&b, sizeof(NodeInfo)); @@ -145,7 +145,7 @@ private: std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); nodes_input_stream.close(); - DEBUG("Loading edge data"); + SimpleLogger().Write(logDEBUG) << "Loading edge data"; unsigned numberOfOrigEdges(0); edges_input_stream.read((char*)&numberOfOrigEdges, sizeof(unsigned)); origEdgeData_viaNode.resize(numberOfOrigEdges); @@ -163,8 +163,8 @@ private: origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction; } edges_input_stream.close(); - DEBUG("Loaded " << numberOfOrigEdges << " orig edges"); - DEBUG("Opening NN indices"); + SimpleLogger().Write(logDEBUG) << "Loaded " << numberOfOrigEdges << " orig edges"; + SimpleLogger().Write(logDEBUG) << "Opening NN indices"; } std::vector<_Coordinate> coordinateVector; diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 7504cbaa9..4e95c1630 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STATICGRAPH_H_INCLUDED #define STATICGRAPH_H_INCLUDED +#include "../Util/SimpleLogger.h" #include "../typedefs.h" #include @@ -99,12 +100,17 @@ public: if(data.shortcut) { unsigned eid2 = FindEdgeInEitherDirection(u, data.id); if(eid2 == UINT_MAX) { - DEBUG("cannot find first segment of edge (" << u << "," << data.id << "," << v << ")"); + SimpleLogger().Write(logWARNING) << + "cannot find first segment of edge (" << + u << "," << data.id << "," << v << ")"; + data.shortcut = false; } eid2 = FindEdgeInEitherDirection(data.id, v); if(eid2 == UINT_MAX) { - DEBUG("cannot find second segment of edge (" << u << "," << data.id << "," << v << ")"); + SimpleLogger().Write(logWARNING) << + "cannot find second segment of edge (" << + u << "," << data.id << "," << v << ")"; data.shortcut = false; } } diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 2defee25f..02b372403 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "PhantomNodes.h" #include "DeallocatingVector.h" #include "HilbertValue.h" +#include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" #include "../typedefs.h" @@ -287,7 +288,10 @@ public: : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) { - INFO("constructing r-tree of " << m_element_count << " elements"); + SimpleLogger().Write() << + "constructing r-tree of " << m_element_count << + " elements"; + double time1 = get_timestamp(); std::vector input_wrapper_vector(m_element_count); @@ -394,7 +398,8 @@ public: //close tree node file. tree_node_file.close(); double time2 = get_timestamp(); - INFO("finished r-tree construction in " << (time2-time1) << " seconds"); + SimpleLogger().Write() << + "finished r-tree construction in " << (time2-time1) << " seconds"; } //Read-only operation for queries @@ -406,7 +411,7 @@ public: std::ifstream tree_node_file(node_filename.c_str(), std::ios::binary); uint32_t tree_size = 0; tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); - //INFO("reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"); + //SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"; m_search_tree.resize(tree_size); tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size); tree_node_file.close(); @@ -416,8 +421,8 @@ public: leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t)); leaf_node_file.close(); - //INFO( tree_size << " nodes in search tree"); - //INFO( m_element_count << " elements in leafs"); + //SimpleLogger().Write() << tree_size << " nodes in search tree"; + //SimpleLogger().Write() << m_element_count << " elements in leafs"; } /* inline void FindKNearestPhantomNodesForCoordinate( @@ -432,7 +437,7 @@ public: uint32_t io_count = 0; uint32_t explored_tree_nodes_count = 0; - INFO("searching for coordinate " << input_coordinate); + SimpleLogger().Write() << "searching for coordinate " << input_coordinate; double min_dist = DBL_MAX; double min_max_dist = DBL_MAX; bool found_a_nearest_edge = false; @@ -561,7 +566,7 @@ public: result_phantom_node.location.lat = input_coordinate.lat; } - INFO("mindist: " << min_distphantom_node.isBidirected() ? "yes" : "no") ); + SimpleLogger().Write() << "mindist: " << min_distphantom_node.isBidirected() ? "yes" : "no"); return found_a_nearest_edge; } @@ -578,7 +583,7 @@ public: uint32_t io_count = 0; uint32_t explored_tree_nodes_count = 0; - //INFO("searching for coordinate " << input_coordinate); + //SimpleLogger().Write() << "searching for coordinate " << input_coordinate; double min_dist = DBL_MAX; double min_max_dist = DBL_MAX; bool found_a_nearest_edge = false; @@ -609,7 +614,7 @@ public: LeafNode current_leaf_node; LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node); ++io_count; - //INFO("checking " << current_leaf_node.object_count << " elements"); + //SimpleLogger().Write() << "checking " << current_leaf_node.object_count << " elements"; for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) { DataT & current_edge = current_leaf_node.objects[i]; if(ignore_tiny_components && current_edge.belongsToTinyComponent) { @@ -664,15 +669,15 @@ public: ) ) { BOOST_ASSERT_MSG(current_edge.id != result_phantom_node.edgeBasedNode, "IDs not different"); - //INFO("found bidirected edge on nodes " << current_edge.id << " and " << result_phantom_node.edgeBasedNode); + //SimpleLogger().Write() << "found bidirected edge on nodes " << current_edge.id << " and " << result_phantom_node.edgeBasedNode; result_phantom_node.weight2 = current_edge.weight; if(current_edge.id < result_phantom_node.edgeBasedNode) { result_phantom_node.edgeBasedNode = current_edge.id; std::swap(result_phantom_node.weight1, result_phantom_node.weight2); std::swap(current_end_coordinate, current_start_coordinate); - // INFO("case 2"); + // SimpleLogger().Write() <<"case 2"; } - //INFO("w1: " << result_phantom_node.weight1 << ", w2: " << result_phantom_node.weight2); + //SimpleLogger().Write() << "w1: " << result_phantom_node.weight1 << ", w2: " << result_phantom_node.weight2; } } } else { @@ -732,7 +737,7 @@ private: } if(!thread_local_rtree_stream->good()) { thread_local_rtree_stream->clear(std::ios::goodbit); - DEBUG("Resetting stale filestream"); + SimpleLogger().Write(logDEBUG) << "Resetting stale filestream"; } uint64_t seek_pos = sizeof(uint64_t) + leaf_id*sizeof(LeafNode); thread_local_rtree_stream->seekg(seek_pos); diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index e027c3704..692dc31cb 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -123,7 +123,7 @@ void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLev // || std::string::npos != string0.find(string1+" ;") // || std::string::npos != string0.find("; "+string1) // ){ -// INFO("->next correct: " << string0 << " contains " << string1); +// SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; // for(; lastTurn != i; ++lastTurn) // pathDescription[lastTurn].nameID = pathDescription[i].nameID; // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; @@ -132,7 +132,7 @@ void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLev // || std::string::npos != string1.find(string0+" ;") // || std::string::npos != string1.find("; "+string0) // ){ -// INFO("->prev correct: " << string1 << " contains " << string0); +// SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; // pathDescription[i].nameID = pathDescription[i-1].nameID; // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; // } @@ -153,24 +153,24 @@ void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLev if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { - //INFO("Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID); + //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; assert(pathDescription[i].necessary); lengthOfSegment = 0; durationOfSegment = 0; indexOfSegmentBegin = i; } } - // INFO("#segs: " << pathDescription.size()); + // SimpleLogger().Write() << "#segs: " << pathDescription.size(); //Post-processing to remove empty or nearly empty path segments if(FLT_EPSILON > pathDescription.back().length) { - // INFO("#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length); + // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; if(pathDescription.size() > 2){ pathDescription.pop_back(); pathDescription.back().necessary = true; pathDescription.back().turnInstruction = TurnInstructions.NoTurn; targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; - // INFO("Deleting last turn instruction"); + // SimpleLogger().Write() << "Deleting last turn instruction"; } } else { pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); @@ -182,7 +182,7 @@ void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLev pathDescription[0].turnInstruction = TurnInstructions.HeadOn; pathDescription[0].necessary = true; startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; - // INFO("Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length); + // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; } } else { pathDescription[0].duration *= startPhantom.ratio; diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index e54752d16..36071e492 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -27,6 +27,7 @@ #include "../DataStructures/SearchEngine.h" #include "../DataStructures/SegmentInformation.h" #include "../DataStructures/TurnInstructions.h" +#include "../Util/SimpleLogger.h" #include "../typedefs.h" #include diff --git a/Extractor/BaseParser.cpp b/Extractor/BaseParser.cpp index b5ba3e614..cf5530a4d 100644 --- a/Extractor/BaseParser.cpp +++ b/Extractor/BaseParser.cpp @@ -37,9 +37,9 @@ void BaseParser::ReadUseRestrictionsSetting() { use_turn_restrictions = lua_toboolean(luaState, -1); } if( use_turn_restrictions ) { - INFO("Using turn restrictions" ); + SimpleLogger().Write() << "Using turn restrictions"; } else { - INFO("Ignoring turn restrictions" ); + SimpleLogger().Write() << "Ignoring turn restrictions"; } } @@ -51,12 +51,12 @@ void BaseParser::ReadRestrictionExceptions() { "get_exceptions", boost::ref(restriction_exceptions) ); - INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); + SimpleLogger().Write() << "Found " << restriction_exceptions.size() << " exceptions to turn restriction"; BOOST_FOREACH(const std::string & str, restriction_exceptions) { - INFO(" " << str); + SimpleLogger().Write() << " " << str; } } else { - INFO("Found no exceptions to turn restrictions"); + SimpleLogger().Write() << "Found no exceptions to turn restrictions"; } } diff --git a/Extractor/BaseParser.h b/Extractor/BaseParser.h index e65678fe4..64228b53d 100644 --- a/Extractor/BaseParser.h +++ b/Extractor/BaseParser.h @@ -24,6 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorCallbacks.h" #include "ScriptingEnvironment.h" #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" extern "C" { #include diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 292e994cf..255d545e4 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -117,7 +117,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con ++restrictionsIT; } std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; - INFO("usable restrictions: " << usableRestrictionsCounter ); + SimpleLogger().Write() << "usable restrictions: " << usableRestrictionsCounter; //serialize restrictions std::ofstream restrictionsOutstream; restrictionsOutstream.open(restrictionsFileName.c_str(), std::ios::binary); @@ -298,7 +298,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con // addressOutFile.close(); // cout << "ok, after " << get_timestamp() - time << "s" << endl; - INFO("Processed " << usedNodeCounter << " nodes and " << usedEdgeCounter << " edges"); + SimpleLogger().Write() << "Processed " << usedNodeCounter << " nodes and " << usedEdgeCounter << " edges"; } catch ( const std::exception& e ) { diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index ded5c3aad..96b8ba357 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -22,6 +22,7 @@ #define EXTRACTIONCONTAINERS_H_ #include "ExtractorStructs.h" +#include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" #include "../Util/UUID.h" diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index 8c28f855d..f2f53a02b 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -45,7 +45,9 @@ bool ExtractorCallbacks::restrictionFunction(const _RawRestrictionContainer &r) void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) { if((0 < parsed_way.speed) || (0 < parsed_way.duration)) { //Only true if the way is specified by the speed profile if(UINT_MAX == parsed_way.id){ - DEBUG("found bogus way with id: " << parsed_way.id << " of size " << parsed_way.path.size()); + SimpleLogger().Write(logDEBUG) << + "found bogus way with id: " << parsed_way.id << + " of size " << parsed_way.path.size(); return; } @@ -55,7 +57,8 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) { } if(FLT_EPSILON >= fabs(-1. - parsed_way.speed)){ - DEBUG("found way with bogus speed, id: " << parsed_way.id); + SimpleLogger().Write(logDEBUG) << + "found way with bogus speed, id: " << parsed_way.id; return; } diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 92338e14a..6221c6f26 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -49,9 +49,10 @@ PBFParser::~PBFParser() { } google::protobuf::ShutdownProtobufLibrary(); -#ifndef NDEBUG - DEBUG("parsed " << blockCount << " blocks from pbf with " << groupCount << " groups"); -#endif + SimpleLogger().Write(logDEBUG) << + "parsed " << blockCount << + " blocks from pbf with " << groupCount << + " groups"; } inline bool PBFParser::ReadHeader() { @@ -108,7 +109,7 @@ inline void PBFParser::ParseData() { _ThreadData *threadData; threadDataQueue->wait_and_pop(threadData); if( NULL==threadData ) { - INFO("Parse Data Thread Finished"); + SimpleLogger().Write() << "Parse Data Thread Finished"; threadDataQueue->push(NULL); // Signal end of data for other threads break; } diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index edf5cd012..ec5035f3d 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -29,6 +29,7 @@ #include "../Util/MachineInfo.h" #include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include "../typedefs.h" #include diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 0b76749dd..fba59f89d 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -22,7 +22,7 @@ ScriptingEnvironment::ScriptingEnvironment() {} ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { - INFO("Using script " << fileName); + SimpleLogger().Write() << "Using script " << fileName; // Create a new lua state for(int i = 0; i < omp_get_max_threads(); ++i) { diff --git a/Extractor/ScriptingEnvironment.h b/Extractor/ScriptingEnvironment.h index 315d84318..fc4b97e1a 100644 --- a/Extractor/ScriptingEnvironment.h +++ b/Extractor/ScriptingEnvironment.h @@ -27,6 +27,7 @@ #include "../Util/LuaUtil.h" #include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include "../typedefs.h" #include diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index 6ce834335..2ab6e7335 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -27,7 +27,9 @@ #include XMLParser::XMLParser(const char * filename, ExtractorCallbacks* ec, ScriptingEnvironment& se) : BaseParser(ec, se) { - WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf"); + SimpleLogger().Write(logWARNING) << + "Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf"; + inputReader = inputReaderFactory(filename); } diff --git a/Extractor/XMLParser.h b/Extractor/XMLParser.h index 39070f470..51b7b1b1e 100644 --- a/Extractor/XMLParser.h +++ b/Extractor/XMLParser.h @@ -23,6 +23,7 @@ #include "BaseParser.h" #include "../DataStructures/Coordinate.h" +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include "../typedefs.h" diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 13c9e025d..cbeae3fe8 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -33,6 +33,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Descriptors/GPXDescriptor.h" #include "../Descriptors/JSONDescriptor.h" #include "../Server/DataStructures/QueryObjectsStorage.h" +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include @@ -90,14 +91,14 @@ public: std::vector phantomNodeVector(rawRoute.rawViaNodeCoordinates.size()); for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); ++i) { if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) { -// INFO("Decoding hint: " << routeParameters.hints[i] << " for location index " << i); +// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i; DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]); if(phantomNodeVector[i].isValid(nodeHelpDesk->getNumberOfNodes())) { -// INFO("Decoded hint " << i << " successfully"); +// SimpleLogger().Write() << "Decoded hint " << i << " successfully"; continue; } } -// INFO("Brute force lookup of coordinate " << i); +// SimpleLogger().Write() << "Brute force lookup of coordinate " << i; searchEnginePtr->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i], routeParameters.zoomLevel); } @@ -108,7 +109,7 @@ public: rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes); } if( ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) { -// INFO("Checking for alternative paths"); +// SimpleLogger().Write() << "Checking for alternative paths"; searchEnginePtr->alternativePaths(rawRoute.segmentEndCoordinates[0], rawRoute); } else { @@ -117,7 +118,7 @@ public: if(INT_MAX == rawRoute.lengthOfShortestPath ) { - DEBUG( "Error occurred, single path not found" ); + SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found"; } reply.status = http::Reply::ok; @@ -152,10 +153,10 @@ public: PhantomNodes phantomNodes; phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom; -// INFO("Start location: " << phantomNodes.startPhantom.location) +// SimpleLogger().Write() << "Start location: " << phantomNodes.startPhantom.location; phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom; -// INFO("TargetLocation: " << phantomNodes.targetPhantom.location); -// INFO("Number of segments: " << rawRoute.segmentEndCoordinates.size()); +// SimpleLogger().Write() << "TargetLocation: " << phantomNodes.targetPhantom.location; +// SimpleLogger().Write() << "Number of segments: " << rawRoute.segmentEndCoordinates.size(); desc->SetConfig(descriptorConfig); desc->Run(reply, rawRoute, phantomNodes, *searchEnginePtr); diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 8c3e53ef3..8b54a3de5 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -307,7 +307,7 @@ private: int aindex = 0; //compute forward sharing while( (packedAlternativePath[aindex] == packedShortestPath[aindex]) && (packedAlternativePath[aindex+1] == packedShortestPath[aindex+1]) ) { - // INFO("retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"); + // SimpleLogger().Write() << "retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"; typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); sharing += search_graph->GetEdgeData(edgeID).distance; ++aindex; diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index caef97a96..67615a89d 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/RawRouteData.h" #include "../Util/ContainerUtils.h" +#include "../Util/SimpleLogger.h" #include @@ -44,7 +45,7 @@ public: inline void RoutingStep(typename QueryDataT::QueryHeap & _forwardHeap, typename QueryDataT::QueryHeap & _backwardHeap, NodeID *middle, int *_upperbound, const int edgeBasedOffset, const bool forwardDirection) const { const NodeID node = _forwardHeap.DeleteMin(); const int distance = _forwardHeap.GetKey(node); - //INFO("Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance); + //SimpleLogger().Write() << "Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance; if(_backwardHeap.WasInserted(node) ){ const int newDistance = _backwardHeap.GetKey(node) + distance; if(newDistance < *_upperbound ){ diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index aa8956c1a..9373a5f9e 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -20,7 +20,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "QueryObjectsStorage.h" -#include "../../Util/GraphLoader.h" QueryObjectsStorage::QueryObjectsStorage( const std::string & hsgrPath, @@ -31,7 +30,7 @@ QueryObjectsStorage::QueryObjectsStorage( const std::string & namesPath, const std::string & timestampPath ) { - INFO("loading graph data"); + SimpleLogger().Write() << "loading graph data"; std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); if(!hsgrInStream) { throw OSRMException("hsgr not found"); @@ -47,15 +46,17 @@ QueryObjectsStorage::QueryObjectsStorage( ); hsgrInStream.close(); - INFO("Data checksum is " << checkSum); + SimpleLogger().Write() << "Data checksum is " << checkSum; graph = new QueryGraph(nodeList, edgeList); assert(0 == nodeList.size()); assert(0 == edgeList.size()); if(timestampPath.length()) { - INFO("Loading Timestamp"); + SimpleLogger().Write() << "Loading Timestamp"; std::ifstream timestampInStream(timestampPath.c_str()); - if(!timestampInStream) { WARN(timestampPath << " not found"); } + if(!timestampInStream) { + SimpleLogger().Write(logWARNING) << timestampPath << " not found"; + } getline(timestampInStream, timestamp); timestampInStream.close(); @@ -67,7 +68,7 @@ QueryObjectsStorage::QueryObjectsStorage( timestamp.resize(25); } - INFO("Loading auxiliary information"); + SimpleLogger().Write() << "Loading auxiliary information"; //Init nearest neighbor data structure nodeHelpDesk = new NodeInformationHelpDesk( ramIndexPath, @@ -79,7 +80,7 @@ QueryObjectsStorage::QueryObjectsStorage( ); //deserialize street name list - INFO("Loading names index"); + SimpleLogger().Write() << "Loading names index"; std::ifstream namesInStream(namesPath.c_str(), std::ios::binary); if(!namesInStream) { throw OSRMException("names file not found"); @@ -97,7 +98,7 @@ QueryObjectsStorage::QueryObjectsStorage( } std::vector(names).swap(names); namesInStream.close(); - INFO("All query data structures loaded"); + SimpleLogger().Write() << "All query data structures loaded"; } QueryObjectsStorage::~QueryObjectsStorage() { diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index ebf4bef32..9d2429c0b 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -24,8 +24,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include - +#include "../../Util/GraphLoader.h" #include "../../Util/OSRMException.h" +#include "../../Util/SimpleLogger.h" #include "../../DataStructures/NodeInformationHelpDesk.h" #include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 0f91601ab..0105703b3 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasicDatastructures.h" #include "../Library/OSRM.h" #include "../Plugins/RouteParameters.h" +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include "../typedefs.h" @@ -53,8 +54,8 @@ public: ltime=time(NULL); Tm=localtime(<ime); - INFO((Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << (Tm->tm_mon+1 < 10 ? "0" : "" ) << (Tm->tm_mon+1) << "-" << 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " << - req.endpoint.to_string() << " " << req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri ); + SimpleLogger().Write() << (Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << (Tm->tm_mon+1 < 10 ? "0" : "" ) << (Tm->tm_mon+1) << "-" << 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " << + req.endpoint.to_string() << " " << req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri; } RouteParameters routeParameters; @@ -84,7 +85,8 @@ public: } } catch(std::exception& e) { rep = http::Reply::stockReply(http::Reply::internalServerError); - WARN("[server error] code: " << e.what() << ", uri: " << req.uri); + SimpleLogger().Write(logWARNING) << + "[server error] code: " << e.what() << ", uri: " << req.uri; return; } }; diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index be7691c39..b196ddca3 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include #include @@ -52,7 +53,7 @@ int main (int argument_count, char *argument_values[]) { return -1; } - INFO("Using restrictions from file: " << argument_values[2]); + SimpleLogger().Write() << "Using restrictions from file: " << argument_values[2]; std::ifstream restriction_ifstream(argument_values[2], std::ios::binary); if(!restriction_ifstream.good()) { throw OSRMException("Could not access files"); @@ -91,17 +92,16 @@ int main (int argument_count, char *argument_values[]) { ); input_stream.close(); - INFO( + SimpleLogger().Write() << restrictions_vector.size() << " restrictions, " << bollard_node_IDs_vector.size() << " bollard nodes, " << - traffic_light_node_IDs_vector.size() << " traffic lights" - ); + traffic_light_node_IDs_vector.size() << " traffic lights"; /*** * Building an edge-expanded graph from node-based input an turn restrictions */ - INFO("Starting SCC graph traversal"); + SimpleLogger().Write() << "Starting SCC graph traversal"; TarjanSCC * tarjan = new TarjanSCC ( node_based_node_count, edge_list, @@ -117,6 +117,6 @@ int main (int argument_count, char *argument_values[]) { std::vector<_Restriction>().swap(restrictions_vector); std::vector().swap(bollard_node_IDs_vector); std::vector().swap(traffic_light_node_IDs_vector); - INFO("finished component analysis"); + SimpleLogger().Write() << "finished component analysis"; return 0; } diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 7069e64da..c3c9a5c44 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/ImportEdge.h" #include "../DataStructures/QueryNode.h" #include "../DataStructures/Restriction.h" +#include "../Util/SimpleLogger.h" #include "../Util/UUID.h" #include "../typedefs.h" @@ -64,10 +65,9 @@ NodeID readBinaryOSRMGraphFromStream( in.read((char *) &uuid_loaded, sizeof(UUID)); if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { - WARN( + SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n" - "Reprocess to get rid of this warning." - ) + "Reprocess to get rid of this warning."; } NodeID n, source, target; @@ -75,7 +75,7 @@ NodeID readBinaryOSRMGraphFromStream( short dir;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; in.read((char*)&n, sizeof(NodeID)); - INFO("Importing n = " << n << " nodes "); + SimpleLogger().Write() << "Importing n = " << n << " nodes "; _Node node; for (NodeID i=0; i(trafficLightNodes).swap(trafficLightNodes); in.read((char*)&m, sizeof(unsigned)); - INFO(" and " << m << " edges "); + SimpleLogger().Write() << " and " << m << " edges "; for(unsigned i = 0; i < inputRestrictions.size(); ++i) { ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped from Node of restriction"); + SimpleLogger().Write(logDEBUG) << "Unmapped from Node of restriction"; continue; } @@ -104,14 +104,14 @@ NodeID readBinaryOSRMGraphFromStream( intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped via node of restriction"); + SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction"; continue; } inputRestrictions[i].viaNode = intNodeID->second; intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode); if( intNodeID == ext2IntNodeMap.end()) { - DEBUG("Unmapped to node of restriction"); + SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction"; continue; } inputRestrictions[i].toNode = intNodeID->second; @@ -152,7 +152,8 @@ NodeID readBinaryOSRMGraphFromStream( ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { #ifndef NDEBUG - WARN(" unresolved source NodeID: " << source ); + SimpleLogger().Write(logWARNING) << + " unresolved source NodeID: " << source; #endif continue; } @@ -160,7 +161,8 @@ NodeID readBinaryOSRMGraphFromStream( intNodeID = ext2IntNodeMap.find(target); if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { #ifndef NDEBUG - WARN("unresolved target NodeID : " << target ); + SimpleLogger().Write(logWARNING) << + "unresolved target NodeID : " << target; #endif continue; } @@ -211,7 +213,7 @@ NodeID readBinaryOSRMGraphFromStream( typename std::vector::iterator newEnd = std::remove_if(edgeList.begin(), edgeList.end(), _ExcessRemover()); ext2IntNodeMap.clear(); std::vector(edgeList.begin(), newEnd).swap(edgeList); //remove excess candidates. - INFO("Graph loaded ok and has " << edgeList.size() << " edges"); + SimpleLogger().Write() << "Graph loaded ok and has " << edgeList.size() << " edges"; return n; } template @@ -221,14 +223,14 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; in >> n; - DEBUG("Importing n = " << n << " nodes "); + SimpleLogger().Write(logDEBUG) << "Importing n = " << n << " nodes "; for (NodeID i=0; i> id >> ycoord >> xcoord; int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); ext2IntNodeMap.insert(std::make_pair(id, i)); } in >> m; - DEBUG(" and " << m << " edges"); + SimpleLogger().Write(logDEBUG) << " and " << m << " edges"; edgeList.reserve(m); for (EdgeID i=0; i& edgeList, s } assert(length > 0); assert(weight > 0); - if(dir <0 || dir > 2) - WARN("direction bogus: " << dir); + if(dir <0 || dir > 2) { + SimpleLogger().Write(logWARNING) << "direction bogus: " << dir; + } assert(0<=dir && dir<=2); bool forward = true; @@ -349,9 +352,10 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s in >> d; in >> n; in >> m; -#ifndef DEBUG - std::cout << "expecting " << n << " nodes and " << m << " edges ..." << flush; -#endif + + SimpleLogger().Write(logDEBUG) << + "expecting " << n << " nodes and " << m << " edges ..."; + edgeList.reserve(m); for (EdgeID i=0; i edgeList; int main (int argc, char *argv[]) { try { + LogPolicy::GetInstance().Unmute(); if(argc < 3) { - std::cerr << - "usage: \n" << - argv[0] << " []" << std::endl; + SimpleLogger().Write(logWARNING) << + "usage: \n" << + argv[0] << " []"; return -1; } @@ -75,8 +77,8 @@ int main (int argc, char *argv[]) { number_of_threads = rawNumber; } omp_set_num_threads(number_of_threads); - - INFO("Using restrictions from file: " << argv[2]); + LogPolicy::GetInstance().Unmute(); + SimpleLogger().Write() << "Using restrictions from file: " << argv[2]; std::ifstream restrictionsInstream(argv[2], std::ios::binary); if(!restrictionsInstream.good()) { std::cerr << @@ -88,10 +90,9 @@ int main (int argc, char *argv[]) { unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID)); if( !uuid_loaded.TestPrepare(uuid_orig) ) { - WARN( - ".restrictions was prepared with different build.\n" - "Reprocess to get rid of this warning." - ); + SimpleLogger().Write(logWARNING) << + ".restrictions was prepared with different build.\n" + "Reprocess to get rid of this warning."; } restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); @@ -129,7 +130,10 @@ int main (int argc, char *argv[]) { luaAddScriptFolderToLoadPath( myLuaState, (argc > 3 ? argv[3] : "profile.lua") ); // Now call our function in a lua script - INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") ); + SimpleLogger().Write() << + "Parsing speedprofile from " << + (argc > 3 ? argv[3] : "profile.lua"); + if(0 != luaL_dofile(myLuaState, (argc > 3 ? argv[3] : "profile.lua") )) { std::cerr << lua_tostring(myLuaState,-1) << @@ -162,7 +166,14 @@ int main (int argc, char *argv[]) { std::vector edgeList; NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions); in.close(); - INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); + SimpleLogger().Write() << + inputRestrictions.size() << + " restrictions, " << + bollardNodes.size() << + " bollard nodes, " << + trafficLightNodes.size() << + " traffic lights"; + if(0 == edgeList.size()) { std::cerr << "The input data is broken. " @@ -175,7 +186,7 @@ int main (int argc, char *argv[]) { * Building an edge-expanded graph from node-based input an turn restrictions */ - INFO("Generating edge-expanded graph representation"); + SimpleLogger().Write() << "Generating edge-expanded graph representation"; EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); std::vector().swap(edgeList); edgeBasedGraphFactory->Run(edgeOut.c_str(), myLuaState); @@ -193,7 +204,7 @@ int main (int argc, char *argv[]) { * Writing info on original (node-based) nodes */ - INFO("writing node map ..."); + SimpleLogger().Write() << "writing node map ..."; std::ofstream mapOutFile(nodeOut.c_str(), std::ios::binary); mapOutFile.write((char *)&(internalToExternalNodeMapping[0]), internalToExternalNodeMapping.size()*sizeof(NodeInfo)); mapOutFile.close(); @@ -205,7 +216,7 @@ int main (int argc, char *argv[]) { * Building grid-like nearest-neighbor data structure */ - INFO("building r-tree ..."); + SimpleLogger().Write() << "building r-tree ..."; StaticRTree * rtree = new StaticRTree( nodeBasedEdgeList, @@ -216,17 +227,20 @@ int main (int argc, char *argv[]) { IteratorbasedCRC32 > crc32; unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); nodeBasedEdgeList.clear(); - INFO("CRC32 based checksum is " << crc32OfNodeBasedEdgeList); + SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList; /*** * Contracting the edge-expanded graph */ - INFO("initializing contractor"); + SimpleLogger().Write() << "initializing contractor"; Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); - INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec"); + SimpleLogger().Write() << + "Contraction took " << + (get_timestamp() - contractionStartedTimestamp) << + " sec"; DeallocatingVector< QueryEdge > contractedEdgeList; contractor->GetEdges( contractedEdgeList ); @@ -236,11 +250,15 @@ int main (int argc, char *argv[]) { * Sorting contracted edges in a way that the static query graph can read some in in-place. */ - INFO("Building Node Array"); + SimpleLogger().Write() << "Building Node Array"; std::sort(contractedEdgeList.begin(), contractedEdgeList.end()); unsigned numberOfNodes = 0; unsigned numberOfEdges = contractedEdgeList.size(); - INFO("Serializing compacted graph of " << numberOfEdges << " edges"); + SimpleLogger().Write() << + "Serializing compacted graph of " << + numberOfEdges << + " edges"; + std::ofstream hsgr_output_stream(graphOut.c_str(), std::ios::binary); hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) ); BOOST_FOREACH(const QueryEdge & edge, contractedEdgeList) { @@ -282,13 +300,15 @@ int main (int argc, char *argv[]) { currentEdge.target = contractedEdgeList[edge].target; currentEdge.data = contractedEdgeList[edge].data; if(currentEdge.data.distance <= 0) { - INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); - std::cerr << - "Failed at edges of node " << - node << - " of " << - numberOfNodes << - std::endl; + SimpleLogger().Write(logWARNING) << + "Edge: " << i << + ",source: " << contractedEdgeList[edge].source << + ", target: " << contractedEdgeList[edge].target << + ", dist: " << currentEdge.data.distance; + + SimpleLogger().Write(logWARNING) << + "Failed at edges of node " << node << + " of " << numberOfNodes; return -1; } //Serialize edges @@ -298,15 +318,22 @@ int main (int argc, char *argv[]) { } } double endTime = (get_timestamp() - startupTime); - INFO("Expansion : " << (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"); - INFO("Contraction: " << (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< usedEdgeCounter/endTime << " edges/sec"); + SimpleLogger().Write() << "Expansion : " << + (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and " << + (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"; + + SimpleLogger().Write() << "Contraction: " << + (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and " << + usedEdgeCounter/endTime << " edges/sec"; hsgr_output_stream.close(); //cleanedEdgeList.clear(); _nodes.clear(); - INFO("finished preprocessing"); + SimpleLogger().Write() << "finished preprocessing"; } catch ( const std::exception &e ) { - std::cerr << "Exception occured: " << e.what() << std::endl; + SimpleLogger().Write(logWARNING) << + "Exception occured: " << e.what() << std::endl; + return -1; } return 0; diff --git a/extractor.cpp b/extractor.cpp index 182545029..29296f919 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -28,6 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/MachineInfo.h" #include "Util/OpenMPWrapper.h" #include "Util/OSRMException.h" +#include "Util/SimpleLogger.h" #include "Util/StringUtil.h" #include "Util/UUID.h" #include "typedefs.h" @@ -43,14 +44,14 @@ UUID uuid; int main (int argc, char *argv[]) { try { + LogPolicy::GetInstance().Unmute(); double startup_time = get_timestamp(); if(argc < 2) { - std::cerr << + SimpleLogger().Write(logWARNING) << "usage: \n" << argv[0] << - " []" << - std::endl; + " []"; return -1; } @@ -60,16 +61,14 @@ int main (int argc, char *argv[]) { unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("extractor.ini")) { IniFile extractorConfig("extractor.ini"); - INFO("2"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); - INFO("3"); if( rawNumber != 0 && rawNumber <= number_of_threads) { number_of_threads = rawNumber; } } omp_set_num_threads(number_of_threads); - INFO("extracting data from input file " << argv[1]); + SimpleLogger().Write() << "extracting data from input file " << argv[1]; bool file_has_pbf_format(false); std::string output_file_name(argv[1]); std::string restrictionsFileName(argv[1]); @@ -103,7 +102,7 @@ int main (int argc, char *argv[]) { unsigned amountOfRAM = 1; unsigned installedRAM = GetPhysicalmemory(); if(installedRAM < 2048264) { - WARN("Machine has less than 2GB RAM."); + SimpleLogger().Write(logWARNING) << "Machine has less than 2GB RAM."; } StringMap stringMap; @@ -121,30 +120,29 @@ int main (int argc, char *argv[]) { if(!parser->ReadHeader()) { throw OSRMException("Parser not initialized!"); } - INFO("Parsing in progress.."); + SimpleLogger().Write() << "Parsing in progress.."; double parsing_start_time = get_timestamp(); parser->Parse(); - INFO("Parsing finished after " << + SimpleLogger().Write() << "Parsing finished after " << (get_timestamp() - parsing_start_time) << - " seconds" - ); + " seconds"; externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM); delete parser; delete extractCallBacks; - INFO("extraction finished after " << get_timestamp() - startup_time << "s"); + SimpleLogger().Write() << + "extraction finished after " << get_timestamp() - startup_time << + "s"; - std::cout << - "\nRun:\n" << - "./osrm-prepare " << + SimpleLogger().Write() << "\nRun:\n./osrm-prepare " << output_file_name << " " << restrictionsFileName << std::endl; } catch(std::exception & e) { - INFO("unhandled exception: " << e.what()); + SimpleLogger().Write(logWARNING) << "unhandled exception: " << e.what(); return -1; } return 0; diff --git a/routed.cpp b/routed.cpp index bd916266a..9f45149e9 100644 --- a/routed.cpp +++ b/routed.cpp @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/IniFile.h" #include "Util/InputFileUtil.h" #include "Util/OpenMPWrapper.h" +#include "Util/SimpleLogger.h" #include "Util/UUID.h" #ifdef __linux__ @@ -63,7 +64,7 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) int main (int argc, char * argv[]) { #ifdef __linux__ if(!mlockall(MCL_CURRENT | MCL_FUTURE)) - WARN("Process " << argv[0] << "could not be locked to RAM"); + SimpleLogger().Write(logWARNING) << "Process " << argv[0] << "could not be locked to RAM"; #endif #ifdef __linux__ @@ -122,7 +123,7 @@ int main (int argc, char * argv[]) { std::cout << "[server] stopping threads" << std::endl; if(!t.timed_join(boost::posix_time::seconds(2))) { -// INFO("Threads did not finish within 2 seconds. Hard abort!"); + SimpleLogger().Write(logDEBUG) << "Threads did not finish within 2 seconds. Hard abort!"; } std::cout << "[server] freeing objects" << std::endl; diff --git a/typedefs.h b/typedefs.h index bf0c731d0..b98783334 100644 --- a/typedefs.h +++ b/typedefs.h @@ -33,15 +33,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #endif #include - -#define INFO(x) do {std::cout << "[i " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); -#define WARN(x) do {std::cerr << "[? " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); - -#ifdef NDEBUG -#define DEBUG(x) -#else -#define DEBUG(x) do {std::cout << "[d " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); -#endif +#include #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -55,7 +47,6 @@ digitT round(digitT x) { } #endif - typedef unsigned int NodeID; typedef unsigned int EdgeID; typedef unsigned int EdgeWeight; From 44eed9282b7acabdaa8fc35eedd4cf3b38ebbd87 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:25:57 +0200 Subject: [PATCH 30/80] Adding new SimpleLogger class --- Util/SimpleLogger.h | 110 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Util/SimpleLogger.h diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h new file mode 100644 index 000000000..21d66fc5b --- /dev/null +++ b/Util/SimpleLogger.h @@ -0,0 +1,110 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + + +#ifndef SIMPLE_LOGGER_H_ +#define SIMPLE_LOGGER_H_ + +#include +#include +#include + +#include +#include + +enum LogLevel { logINFO, logWARNING, logDEBUG }; +static boost::mutex logger_mutex; + +class LogPolicy : boost::noncopyable { +public: + + void Unmute() { + m_is_mute = false; + } + + void Mute() { + m_is_mute = true; + } + + bool IsMute() const { + return m_is_mute; + } + + static LogPolicy & GetInstance() { + static LogPolicy runningInstance; + return runningInstance; + } + +private: + LogPolicy() : m_is_mute(true) { } + bool m_is_mute; +}; + +class SimpleLogger { +public: + std::ostringstream& Write(LogLevel l = logINFO) { + boost::mutex::scoped_lock lock(logger_mutex); + level = l; + os << "["; + switch(level) { + case logINFO: + os << "info"; + break; + case logWARNING: + os << "warn"; + break; + case logDEBUG: + os << "debug"; + break; + default: + BOOST_ASSERT_MSG(false, "should not happen"); + break; + } + os << "] "; + return os; + } + + virtual ~SimpleLogger() { + if(!LogPolicy::GetInstance().IsMute()) { + os << std::endl; + switch(level) { + case logINFO: + std::cout << os.str(); + break; + case logWARNING: + std::cerr << os.str(); + break; + case logDEBUG: + std::cout << os.str(); + break; + default: + BOOST_ASSERT_MSG(false, "should not happen"); + break; + } + } + } + +private: + LogLevel level; + std::ostringstream os; + bool m_is_mute; +}; + +#endif /* SIMPLE_LOGGER_H_ */ \ No newline at end of file From d7673dad7be1feb9ed1049f96e6513867d1ea041 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:39:51 +0200 Subject: [PATCH 31/80] fixing release build --- Extractor/PBFParser.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 6221c6f26..413217cc8 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -49,10 +49,12 @@ PBFParser::~PBFParser() { } google::protobuf::ShutdownProtobufLibrary(); +#ifndef NDEBUG SimpleLogger().Write(logDEBUG) << "parsed " << blockCount << " blocks from pbf with " << groupCount << " groups"; +#endif } inline bool PBFParser::ReadHeader() { From 7fe997d38c9c7098825b567972623bf6fce775f3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:53:49 +0200 Subject: [PATCH 32/80] Add missing newline on EOF --- Util/SimpleLogger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 21d66fc5b..7f7db01c4 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -107,4 +107,4 @@ private: bool m_is_mute; }; -#endif /* SIMPLE_LOGGER_H_ */ \ No newline at end of file +#endif /* SIMPLE_LOGGER_H_ */ From 5445b64376355ba2b3187f0624ed1c2f9097b7ae Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:58:40 +0200 Subject: [PATCH 33/80] Configure project for actually different build types --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24eb7681e..f0d828972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_script: - bundle install - mkdir build - cd build - - cmake .. + - cmake .. $OPTIONS script: make after_script: - cd .. @@ -21,8 +21,8 @@ branches: - master - develop env: - - OPTIONS="-DCMAKE_BUILD_TYPE=Release" - - OPTIONS="-DCMAKE_BUILD_TYPE=Debug" + - CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Release" + - CMAKEOPTIONS="-DCMAKE_BUILD_TYPE=Debug" notifications: irc: channels: From 503324162fbb8274eedd4033b91745491dbc22b5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 14:58:58 +0200 Subject: [PATCH 34/80] Configure project for actually different build types --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f0d828972..4894bdf4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_script: - bundle install - mkdir build - cd build - - cmake .. $OPTIONS + - cmake .. $CMAKEOPTIONS script: make after_script: - cd .. From 375dc63db3c04fb652f926863021b301f4208751 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 15:57:16 +0200 Subject: [PATCH 35/80] Make output conditional --- Library/OSRM.cpp | 2 +- Library/OSRM.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index f0937c988..1b714ef84 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -87,7 +87,7 @@ OSRM::~OSRM() { } void OSRM::RegisterPlugin(BasePlugin * plugin) { - std::cout << "[plugin] " << plugin->GetDescriptor() << std::endl; + SimpleLogger().Write() << "[plugin] " << plugin->GetDescriptor() << std::endl; pluginMap[plugin->GetDescriptor()] = plugin; } diff --git a/Library/OSRM.h b/Library/OSRM.h index a879a1223..7647f72c3 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -31,8 +31,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" #include "../Util/IniFile.h" -#include "../Util/OSRMException.h" #include "../Util/InputFileUtil.h" +#include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include "../Server/BasicDatastructures.h" #include @@ -54,4 +55,4 @@ private: PluginMap pluginMap; }; -#endif //OSRM_H \ No newline at end of file +#endif //OSRM_H From 088393ca1267f9c9c60fc05b4dede8c278b752f8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 16:19:25 +0200 Subject: [PATCH 36/80] Remove superflous output of endline --- Library/OSRM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 1b714ef84..f8146995c 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -87,7 +87,7 @@ OSRM::~OSRM() { } void OSRM::RegisterPlugin(BasePlugin * plugin) { - SimpleLogger().Write() << "[plugin] " << plugin->GetDescriptor() << std::endl; + SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); pluginMap[plugin->GetDescriptor()] = plugin; } From f57519b9094194c0568b5e8696ff52f9bc45067a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 16:20:05 +0200 Subject: [PATCH 37/80] adapt tool to output logs with new mechanism --- Tools/simpleclient.cpp | 65 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index 361bbce4b..d7cc5c08f 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -20,6 +20,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Library/OSRM.h" +#include "../Util/SimpleLogger.h" #include #include @@ -44,43 +45,49 @@ void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_ int main (int argc, char * argv[]) { - std::cout << "\n starting up engines, compile at " - << __DATE__ << ", " __TIME__ << std::endl; - IniFile serverConfig((argc > 1 ? argv[1] : "server.ini")); - OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); + LogPolicy::GetInstance().Unmute(); + try { + std::cout << "\n starting up engines, compile at " + << __DATE__ << ", " __TIME__ << std::endl; + IniFile serverConfig((argc > 1 ? argv[1] : "server.ini")); + OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); - RouteParameters route_parameters; - route_parameters.zoomLevel = 18; //no generalization - route_parameters.printInstructions = true; //turn by turn instructions - route_parameters.alternateRoute = true; //get an alternate route, too - route_parameters.geometry = true; //retrieve geometry of route - route_parameters.compression = true; //polyline encoding - route_parameters.checkSum = UINT_MAX; //see wiki - route_parameters.service = "viaroute"; //that's routing - route_parameters.outputFormat = "json"; - route_parameters.jsonpParameter = ""; //set for jsonp wrapping - route_parameters.language = ""; //unused atm - //route_parameters.hints.push_back(); // see wiki, saves I/O if done properly + RouteParameters route_parameters; + route_parameters.zoomLevel = 18; //no generalization + route_parameters.printInstructions = true; //turn by turn instructions + route_parameters.alternateRoute = true; //get an alternate route, too + route_parameters.geometry = true; //retrieve geometry of route + route_parameters.compression = true; //polyline encoding + route_parameters.checkSum = UINT_MAX; //see wiki + route_parameters.service = "viaroute"; //that's routing + route_parameters.outputFormat = "json"; + route_parameters.jsonpParameter = ""; //set for jsonp wrapping + route_parameters.language = ""; //unused atm + //route_parameters.hints.push_back(); // see wiki, saves I/O if done properly - _Coordinate start_coordinate(52.519930*1000000,13.438640*1000000); - _Coordinate target_coordinate(52.513191*1000000,13.415852*1000000); - route_parameters.coordinates.push_back(start_coordinate); - route_parameters.coordinates.push_back(target_coordinate); + _Coordinate start_coordinate(52.519930*COORDINATE_PRECISION,13.438640*COORDINATE_PRECISION); + _Coordinate target_coordinate(52.513191*COORDINATE_PRECISION,13.415852*COORDINATE_PRECISION); + route_parameters.coordinates.push_back(start_coordinate); + route_parameters.coordinates.push_back(target_coordinate); - http::Reply osrm_reply; + http::Reply osrm_reply; - routing_machine.RunQuery(route_parameters, osrm_reply); + routing_machine.RunQuery(route_parameters, osrm_reply); - std::cout << osrm_reply.content << std::endl; + std::cout << osrm_reply.content << std::endl; - //attention: super-inefficient hack below: + //attention: super-inefficient hack below: - std::stringstream ss; - ss << osrm_reply.content; + std::stringstream ss; + ss << osrm_reply.content; - boost::property_tree::ptree pt; - boost::property_tree::read_json(ss, pt); + boost::property_tree::ptree pt; + boost::property_tree::read_json(ss, pt); - print_tree(pt, 0); + print_tree(pt, 0); + } catch (std::exception & e) { + SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); + return -1; + } return 0; } From 0e2570b204af079da468986b0c81df3dd3fb7224 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 Aug 2013 16:23:28 +0200 Subject: [PATCH 38/80] enable logging for deamon --- routed.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/routed.cpp b/routed.cpp index 9f45149e9..9833ea3b4 100644 --- a/routed.cpp +++ b/routed.cpp @@ -62,6 +62,7 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) #endif int main (int argc, char * argv[]) { + LogPolicy::GetInstance().Unmute(); #ifdef __linux__ if(!mlockall(MCL_CURRENT | MCL_FUTURE)) SimpleLogger().Write(logWARNING) << "Process " << argv[0] << "could not be locked to RAM"; From df5455121c8305e3d12d3b520cf6c749c9044f17 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 12:49:49 +0200 Subject: [PATCH 39/80] Output uses new logging facility --- Algorithms/CRC32.cpp | 4 ++-- Algorithms/CRC32.h | 2 ++ Algorithms/IteratorBasedCRC32.h | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Algorithms/CRC32.cpp b/Algorithms/CRC32.cpp index d2f821cb4..cb72e85c6 100644 --- a/Algorithms/CRC32.cpp +++ b/Algorithms/CRC32.cpp @@ -62,10 +62,10 @@ CRC32::CRC32CFunctionPtr CRC32::detectBestCRC32C() { unsigned ecx = cpuid(1); bool hasSSE42 = ecx & (1 << SSE42_BIT); if (hasSSE42) { - std::cout << "using hardware base sse computation" << std::endl; + SimpleLogger().Write() << "using hardware base sse computation"; return &CRC32::SSEBasedCRC32; //crc32 hardware accelarated; } else { - std::cout << "using software base sse computation" << std::endl; + SimpleLogger().Write() << "using software base sse computation"; return &CRC32::SoftwareBasedCRC32; //crc32cSlicingBy8; } } diff --git a/Algorithms/CRC32.h b/Algorithms/CRC32.h index 6321030b7..fb7e50613 100644 --- a/Algorithms/CRC32.h +++ b/Algorithms/CRC32.h @@ -21,6 +21,8 @@ #ifndef CRC32_H_ #define CRC32_H_ +#include "../Util/SimpleLogger.h" + #include // for boost::crc_32_type #include diff --git a/Algorithms/IteratorBasedCRC32.h b/Algorithms/IteratorBasedCRC32.h index 5d4415cb5..82c6b8cb4 100644 --- a/Algorithms/IteratorBasedCRC32.h +++ b/Algorithms/IteratorBasedCRC32.h @@ -22,6 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef ITERATORBASEDCRC32_H_ #define ITERATORBASEDCRC32_H_ +#include "../Util/SimpleLogger.h" + #include // for boost::crc_32_type #include @@ -80,10 +82,10 @@ private: unsigned ecx = cpuid(1); bool hasSSE42 = ecx & (1 << SSE42_BIT); if (hasSSE42) { - std::cout << "using hardware base sse computation" << std::endl; + SimpleLogger().Write() << "using hardware base CRC32 computation"; return &IteratorbasedCRC32::SSEBasedCRC32; //crc32 hardware accelarated; } else { - std::cout << "using software base sse computation" << std::endl; + SimpleLogger().Write() << "using software based CRC32 computation"; return &IteratorbasedCRC32::SoftwareBasedCRC32; //crc32cSlicingBy8; } } From 1e1e254897b3e6e3486863fefa25c2c76d46a09f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 12:50:21 +0200 Subject: [PATCH 40/80] Pass values by const ref --- Util/IniFile.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Util/IniFile.h b/Util/IniFile.h index 1ed0ca578..26a9ed6c8 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -61,8 +61,8 @@ public: SetParameter(std::string(key), std::string(value)); } - void SetParameter(const std::string key, std::string value) { - parameters[key] = value; + void SetParameter(const std::string & key, const std::string & value) { + parameters.insert(std::make_pair(key, value)); } private: @@ -86,4 +86,4 @@ private: HashTable parameters; }; -#endif /* INI_FILE_H_ */ \ No newline at end of file +#endif /* INI_FILE_H_ */ From 4727bb5c9bd17a15741e35e650f9e38a8a15dc0b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 12:51:21 +0200 Subject: [PATCH 41/80] Fix coverity error 1061545 --- Util/SimpleLogger.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 7f7db01c4..62bc945b1 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -104,7 +104,6 @@ public: private: LogLevel level; std::ostringstream os; - bool m_is_mute; }; #endif /* SIMPLE_LOGGER_H_ */ From 60950c57e32fa9519788a0ad0043e13422ffb20d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 12:53:23 +0200 Subject: [PATCH 42/80] Fix coverity error 1061544 --- routed.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/routed.cpp b/routed.cpp index 9833ea3b4..f7b54d35f 100644 --- a/routed.cpp +++ b/routed.cpp @@ -62,10 +62,12 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) #endif int main (int argc, char * argv[]) { - LogPolicy::GetInstance().Unmute(); + try { + LogPolicy::GetInstance().Unmute(); #ifdef __linux__ - if(!mlockall(MCL_CURRENT | MCL_FUTURE)) - SimpleLogger().Write(logWARNING) << "Process " << argv[0] << "could not be locked to RAM"; + if(!mlockall(MCL_CURRENT | MCL_FUTURE)) { + SimpleLogger().Write(logWARNING) << "Process " << argv[0] << "could not be locked to RAM"; + } #endif #ifdef __linux__ @@ -79,11 +81,10 @@ int main (int argc, char * argv[]) { //exit(-1); //} - try { //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl; - std::cout << "starting up engines, compiled at " << - __DATE__ << ", " __TIME__ << std::endl; + SimpleLogger().Write(logWARNING) << + "starting up engines, compiled at " << __DATE__ << ", " __TIME__; #ifndef _WIN32 int sig = 0; From 8de4613a3ea400f5a070e6bf3511f5e02af924e4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 12:55:08 +0200 Subject: [PATCH 43/80] Fix coverity errors 1061543 751298 --- Util/SimpleLogger.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 62bc945b1..68582fd22 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -60,24 +60,26 @@ private: class SimpleLogger { public: std::ostringstream& Write(LogLevel l = logINFO) { - boost::mutex::scoped_lock lock(logger_mutex); - level = l; - os << "["; - switch(level) { - case logINFO: - os << "info"; - break; - case logWARNING: - os << "warn"; - break; - case logDEBUG: - os << "debug"; - break; - default: - BOOST_ASSERT_MSG(false, "should not happen"); - break; - } - os << "] "; + try { + boost::mutex::scoped_lock lock(logger_mutex); + level = l; + os << "["; + switch(level) { + case logINFO: + os << "info"; + break; + case logWARNING: + os << "warn"; + break; + case logDEBUG: + os << "debug"; + break; + default: + BOOST_ASSERT_MSG(false, "should not happen"); + break; + } + os << "] "; + } catch (...) { } return os; } From 149a42cc94728263b4a94b78909d1e4d329be891 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 13:24:05 +0200 Subject: [PATCH 44/80] Fixing coverity issue 1046672 and a potential memory leak --- Library/OSRM.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index f8146995c..629e43978 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -88,7 +88,10 @@ OSRM::~OSRM() { void OSRM::RegisterPlugin(BasePlugin * plugin) { SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); - pluginMap[plugin->GetDescriptor()] = plugin; + if( pluginMap.find(plugin->GetDescriptor()) != pluginMap.end() ) { + delete pluginMap[plugin->GetDescriptor()]; + } + pluginMap.insert(std::make_pair(plugin->GetDescriptor(), plugin)); } void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { From e86e8c37a844e1498f00eed4b1e7773a73a412d3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 13:49:30 +0200 Subject: [PATCH 45/80] const'ing parameters --- DataStructures/BinaryHeap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index 6b9bd10c4..b1e838b8f 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -147,13 +147,13 @@ public: return insertedNodes[index].weight; } - bool WasRemoved( NodeID node ) { + bool WasRemoved( const NodeID node ) { assert( WasInserted( node ) ); const Key index = nodeIndex[node]; return insertedNodes[index].key == 0; } - bool WasInserted( NodeID node ) { + bool WasInserted( const NodeID node ) { const Key index = nodeIndex[node]; if ( index >= static_cast (insertedNodes.size()) ) return false; From 0765ebf7355b0c4d70ca88f0dc78452dc84ede6c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 14:47:09 +0200 Subject: [PATCH 46/80] Implements #692 --- DataStructures/NodeInformationHelpDesk.h | 19 ++++++++++++++++--- Library/OSRM.cpp | 16 ++++++++++++++++ Server/DataStructures/QueryObjectsStorage.cpp | 19 +++++++++++++++++++ Util/IniFile.h | 6 +++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 37bead56f..d0721d03f 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -38,7 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt. typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; -class NodeInformationHelpDesk : boost::noncopyable{ +class NodeInformationHelpDesk : boost::noncopyable { public: NodeInformationHelpDesk( const std::string & ramIndexInput, @@ -47,8 +47,21 @@ public: const std::string & edges_filename, const unsigned number_of_nodes, const unsigned check_sum - ) : number_of_nodes(number_of_nodes), check_sum(check_sum) + ) : number_of_nodes(number_of_nodes), check_sum(check_sum) { + if ( "" == ramIndexInput ) { + throw OSRMException("no ram index file name in server ini"); + } + if ( "" == fileIndexInput ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( "" == nodes_filename ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( "" == edges_filename ) { + throw OSRMException("no edges file name in server ini"); + } + read_only_rtree = new StaticRTree( ramIndexInput, fileIndexInput @@ -136,7 +149,7 @@ private: throw OSRMException("edges file not found"); } - SimpleLogger().Write(logDEBUG) << "Loading node data"; + SimpleLogger().Write(logDEBUG) << "Loading node data" << nodes_file.length() << " ->" << nodes_file << "<-"; NodeInfo b; while(!nodes_input_stream.eof()) { nodes_input_stream.read((char *)&b, sizeof(NodeInfo)); diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 629e43978..3a60cb6b5 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -30,6 +30,22 @@ OSRM::OSRM(const char * server_ini_path) { boost::filesystem::path base_path = boost::filesystem::absolute(server_ini_path).parent_path(); + if ( !serverConfig.Holds("hsgrData")) { + throw OSRMException("no ram index file name in server ini"); + } + if ( !serverConfig.Holds("ramIndex") ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( !serverConfig.Holds("fileIndex") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("nodesData") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("edgesData") ) { + throw OSRMException("no edges file name in server ini"); + } + boost::filesystem::path hsgr_path = boost::filesystem::absolute( serverConfig.GetParameter("hsgrData"), base_path diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 9373a5f9e..258071e91 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -30,6 +30,25 @@ QueryObjectsStorage::QueryObjectsStorage( const std::string & namesPath, const std::string & timestampPath ) { + if("" == hsgrPath) { + throw OSRMException("no hsgr file given in ini file"); + } + if("" == ramIndexPath) { + throw OSRMException("no ram index file given in ini file"); + } + if("" == fileIndexPath) { + throw OSRMException("no mem index file given in ini file"); + } + if("" == nodesPath) { + throw OSRMException("no nodes file given in ini file"); + } + if("" == edgesPath) { + throw OSRMException("no edges file given in ini file"); + } + if("" == namesPath) { + throw OSRMException("no names file given in ini file"); + } + SimpleLogger().Write() << "loading graph data"; std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); if(!hsgrInStream) { diff --git a/Util/IniFile.h b/Util/IniFile.h index 26a9ed6c8..aa5c4b9c2 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -54,7 +54,11 @@ public: } std::string GetParameter(const std::string & key){ - return parameters.Find(key); + return parameters.Find(key); + } + + bool Holds(const std::string & key) const { + return parameters.Holds(key); } void SetParameter(const char* key, const char* value) { From a542292ce2bbf529f5ce62c93085666862f5acd8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 17:47:11 +0200 Subject: [PATCH 47/80] Check if files exist and contain data, fixes #693 --- DataStructures/NodeInformationHelpDesk.h | 31 ++++++++++----- DataStructures/StaticRTree.h | 39 +++++++++++++++---- Server/DataStructures/QueryObjectsStorage.cpp | 37 ++++++++++-------- Server/DataStructures/QueryObjectsStorage.h | 10 ++++- Util/GraphLoader.h | 21 ++++++++-- 5 files changed, 97 insertions(+), 41 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index d0721d03f..147c5985a 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -29,10 +29,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" #include +#include +#include #include #include -#include #include #include @@ -137,19 +138,29 @@ public: private: void LoadNodesAndEdges( - const std::string & nodes_file, - const std::string & edges_file + const std::string & nodes_filename, + const std::string & edges_filename ) { - std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); - if(!nodes_input_stream) { - throw OSRMException("nodes file not found"); + boost::filesystem::path nodes_file(nodes_filename); + if ( !boost::filesystem::exists( nodes_file ) ) { + throw OSRMException("nodes file does not exist"); } - std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); - if(!edges_input_stream) { - throw OSRMException("edges file not found"); + if ( 0 == boost::filesystem::file_size( nodes_file ) ) { + throw OSRMException("nodes file is empty"); } - SimpleLogger().Write(logDEBUG) << "Loading node data" << nodes_file.length() << " ->" << nodes_file << "<-"; + boost::filesystem::path edges_file(edges_filename); + if ( !boost::filesystem::exists( edges_file ) ) { + throw OSRMException("edges file does not exist"); + } + if ( 0 == boost::filesystem::file_size( edges_file ) ) { + throw OSRMException("edges file is empty"); + } + + boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary); + boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary); + + SimpleLogger().Write(logDEBUG) << "Loading node data"; NodeInfo b; while(!nodes_input_stream.eof()) { nodes_input_stream.read((char *)&b, sizeof(NodeInfo)); diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 02b372403..57c099b98 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "PhantomNodes.h" #include "DeallocatingVector.h" #include "HilbertValue.h" +#include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" #include "../typedefs.h" @@ -33,6 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include +#include #include #include #include @@ -44,7 +47,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include #include #include #include @@ -55,7 +57,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170; // Implements a static, i.e. packed, R-tree -static boost::thread_specific_ptr thread_local_rtree_stream; +static boost::thread_specific_ptr thread_local_rtree_stream; template class StaticRTree : boost::noncopyable { @@ -309,7 +311,7 @@ public: } //open leaf file - std::ofstream leaf_node_file(leaf_node_filename.c_str(), std::ios::binary); + boost::filesystem::ofstream leaf_node_file(leaf_node_filename, std::ios::binary); leaf_node_file.write((char*) &m_element_count, sizeof(uint64_t)); //sort the hilbert-value representatives @@ -390,7 +392,11 @@ public: } //open tree file - std::ofstream tree_node_file(tree_node_filename.c_str(), std::ios::binary); + boost::filesystem::ofstream tree_node_file( + tree_node_filename, + std::ios::binary + ); + uint32_t size_of_tree = m_search_tree.size(); BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty"); tree_node_file.write((char *)&size_of_tree, sizeof(uint32_t)); @@ -408,7 +414,16 @@ public: const std::string & leaf_filename ) : m_leaf_node_filename(leaf_filename) { //open tree node file and load into RAM. - std::ifstream tree_node_file(node_filename.c_str(), std::ios::binary); + boost::filesystem::path node_file(node_filename); + + if ( !boost::filesystem::exists( node_file ) ) { + throw OSRMException("ram index file does not exist"); + } + if ( 0 == boost::filesystem::file_size( node_file ) ) { + throw OSRMException("ram index file is empty"); + } + boost::filesystem::ifstream tree_node_file( node_file, std::ios::binary ); + uint32_t tree_size = 0; tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); //SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"; @@ -417,7 +432,15 @@ public: tree_node_file.close(); //open leaf node file and store thread specific pointer - std::ifstream leaf_node_file(leaf_filename.c_str(), std::ios::binary); + boost::filesystem::path leaf_file(leaf_filename); + if ( !boost::filesystem::exists( leaf_file ) ) { + throw OSRMException("mem index file does not exist"); + } + if ( 0 == boost::filesystem::file_size( leaf_file ) ) { + throw OSRMException("mem index file is empty"); + } + + boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary ); leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t)); leaf_node_file.close(); @@ -729,8 +752,8 @@ private: inline void LoadLeafFromDisk(const uint32_t leaf_id, LeafNode& result_node) { if(!thread_local_rtree_stream.get() || !thread_local_rtree_stream->is_open()) { thread_local_rtree_stream.reset( - new std::ifstream( - m_leaf_node_filename.c_str(), + new boost::filesystem::ifstream( + m_leaf_node_filename, std::ios::in | std::ios::binary ) ); diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 258071e91..393fd1bf7 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -50,20 +50,15 @@ QueryObjectsStorage::QueryObjectsStorage( } SimpleLogger().Write() << "loading graph data"; - std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); - if(!hsgrInStream) { - throw OSRMException("hsgr not found"); - } //Deserialize road network graph std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrEdge> edgeList; const int n = readHSGRFromStream( - hsgrInStream, + hsgrPath, nodeList, edgeList, &checkSum ); - hsgrInStream.close(); SimpleLogger().Write() << "Data checksum is " << checkSum; graph = new QueryGraph(nodeList, edgeList); @@ -100,23 +95,31 @@ QueryObjectsStorage::QueryObjectsStorage( //deserialize street name list SimpleLogger().Write() << "Loading names index"; - std::ifstream namesInStream(namesPath.c_str(), std::ios::binary); - if(!namesInStream) { - throw OSRMException("names file not found"); + boost::filesystem::path names_file(namesPath); + + if ( !boost::filesystem::exists( names_file ) ) { + throw OSRMException("names file does not exist"); } - unsigned size(0); - namesInStream.read((char *)&size, sizeof(unsigned)); + if ( 0 == boost::filesystem::file_size( names_file ) ) { + throw OSRMException("names file is empty"); + } + + boost::filesystem::ifstream name_stream(names_file, std::ios::binary); + unsigned size = 0; + name_stream.read((char *)&size, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != size, "name file empty"); char buf[1024]; - for(unsigned i = 0; i < size; ++i) { - unsigned sizeOfString = 0; - namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); - buf[sizeOfString] = '\0'; // instead of memset - namesInStream.read(buf, sizeOfString); + for( unsigned i = 0; i < size; ++i ) { + unsigned size_of_string = 0; + name_stream.read((char *)&size_of_string, sizeof(unsigned)); + buf[size_of_string] = '\0'; // instead of memset + name_stream.read(buf, size_of_string); names.push_back(buf); } std::vector(names).swap(names); - namesInStream.close(); + BOOST_ASSERT_MSG(0 != names.size(), "could not load any names"); + name_stream.close(); SimpleLogger().Write() << "All query data structures loaded"; } diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index 9d2429c0b..0f7ba2a6d 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -22,8 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef QUERYOBJECTSSTORAGE_H_ #define QUERYOBJECTSSTORAGE_H_ -#include -#include #include "../../Util/GraphLoader.h" #include "../../Util/OSRMException.h" #include "../../Util/SimpleLogger.h" @@ -31,6 +29,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" +#include +#include +#include + +#include +#include + + struct QueryObjectsStorage { typedef StaticGraph QueryGraph; typedef QueryGraph::InputEdge InputEdge; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index c3c9a5c44..dcf78386a 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -31,6 +31,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" #include +#include +#include #include #include @@ -398,40 +400,51 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s template unsigned readHSGRFromStream( - std::istream &hsgr_input_stream, + const std::string & hsgr_filename, std::vector & node_list, std::vector & edge_list, unsigned * check_sum ) { + boost::filesystem::path hsgr_file(hsgr_filename); + if ( !boost::filesystem::exists( hsgr_file ) ) { + throw OSRMException("hsgr file does not exist"); + } + if ( 0 == boost::filesystem::file_size( hsgr_file ) ) { + throw OSRMException("hsgr file is empty"); + } + + boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary); + UUID uuid_loaded, uuid_orig; hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { SimpleLogger().Write(logWARNING) << - ".hsgr was prepared with different build.\n" + ".hsgr was prepared with different build. " "Reprocess to get rid of this warning."; } unsigned number_of_nodes = 0; hsgr_input_stream.read((char*) check_sum, sizeof(unsigned)); hsgr_input_stream.read((char*) & number_of_nodes, sizeof(unsigned)); + BOOST_ASSERT_MSG( 0 != number_of_nodes, "number of nodes is zero"); node_list.resize(number_of_nodes + 1); hsgr_input_stream.read( (char*) &(node_list[0]), number_of_nodes*sizeof(NodeT) ); - unsigned number_of_edges = 0; hsgr_input_stream.read( (char*) &number_of_edges, sizeof(unsigned) ); + BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); edge_list.resize(number_of_edges); hsgr_input_stream.read( (char*) &(edge_list[0]), number_of_edges*sizeof(EdgeT) ); - + hsgr_input_stream.close(); return number_of_nodes; } From 0285bb6ea50aeb4f122a42187209abd453d7ec3a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 20:16:26 +0200 Subject: [PATCH 48/80] Implements https://github.com/DennisOSRM/Project-OSRM/commit/34735b8aad06098d09d3fb907137697799a281e4#commitcomment-3828247 --- Library/OSRM.cpp | 3 ++- Util/IniFile.h | 21 ++++++++++++++------- Util/OSRMException.h | 9 ++++++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 3a60cb6b5..1a0c8f5e9 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -22,7 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM::OSRM(const char * server_ini_path) { if( !testDataFile(server_ini_path) ){ - throw OSRMException("server.ini not found"); + std::string error_message = std::string(server_ini_path) + " not found"; + throw OSRMException(error_message.c_str()); } IniFile serverConfig(server_ini_path); diff --git a/Util/IniFile.h b/Util/IniFile.h index aa5c4b9c2..582cc273c 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -25,29 +25,36 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/HashTable.h" #include +#include +#include #include -#include #include #include class IniFile { public: - IniFile(const char * configFile) { - std::ifstream config( configFile ); - if(!config) { - std::string str = "[config] " + std::string(configFile) + " not found"; - throw OSRMException(str.c_str()); + IniFile(const char * config_filename) { + boost::filesystem::path config_file(config_filename); + if ( !boost::filesystem::exists( config_file ) ) { + std::string error = std::string(config_filename) + " not found"; + throw OSRMException(error); + } + if ( 0 == boost::filesystem::file_size( config_file ) ) { + std::string error = std::string(config_filename) + " is empty"; + throw OSRMException(error); } + boost::filesystem::ifstream config( config_file ); std::string line; if (config.is_open()) { while ( config.good() ) { getline (config,line); std::vector tokens; Tokenize(line, tokens); - if(2 == tokens.size() ) + if(2 == tokens.size() ) { parameters.insert(std::make_pair(tokens[0], tokens[1])); + } } config.close(); } diff --git a/Util/OSRMException.h b/Util/OSRMException.h index dcae24e18..804255a3c 100644 --- a/Util/OSRMException.h +++ b/Util/OSRMException.h @@ -22,15 +22,18 @@ or see http://www.gnu.org/licenses/agpl.txt. #define OSRM_EXCEPTION_H #include +#include class OSRMException: public std::exception { public: OSRMException(const char * message) : message(message) {} + OSRMException(const std::string & message) : message(message) {} + virtual ~OSRMException() throw() {} private: virtual const char* what() const throw() { - return message; + return message.c_str(); } - const char * message; + const std::string message; }; -#endif /* OSRM_EXCEPTION_H */ \ No newline at end of file +#endif /* OSRM_EXCEPTION_H */ From c3e6dc69bb292093d5acaf84ad9cca2c7a821e96 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 9 Aug 2013 21:33:30 +0200 Subject: [PATCH 49/80] implements https://github.com/DennisOSRM/Project-OSRM/commit/0765ebf7355b0c4d70ca88f0dc78452dc84ede6c#commitcomment-3828005 --- DataStructures/NodeInformationHelpDesk.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 147c5985a..581287cd5 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -50,16 +50,16 @@ public: const unsigned check_sum ) : number_of_nodes(number_of_nodes), check_sum(check_sum) { - if ( "" == ramIndexInput ) { + if ( ramIndexInput.empty() ) { throw OSRMException("no ram index file name in server ini"); } - if ( "" == fileIndexInput ) { + if ( fileIndexInput.empty() ) { throw OSRMException("no mem index file name in server ini"); } - if ( "" == nodes_filename ) { + if ( nodes_filename.empty() ) { throw OSRMException("no nodes file name in server ini"); } - if ( "" == edges_filename ) { + if ( edges_filename.empty() ) { throw OSRMException("no edges file name in server ini"); } From a75ae8bbef8acd76168a083ac413bc44028ae312 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 10 Aug 2013 14:43:49 +0200 Subject: [PATCH 50/80] enable output for tools --- Tools/componentAnalysis.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index b196ddca3..2273456c7 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -48,6 +48,7 @@ std::vector bollard_node_IDs_vector; std::vector traffic_light_node_IDs_vector; int main (int argument_count, char *argument_values[]) { + LogPolicy::GetInstance().Unmute(); if(argument_count < 3) { std::cerr << "usage:\n" << argument_values[0] << " " << std::endl; return -1; From 45754b27de1d84f18789a6a675c0bd5d614f5ccd Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 22:10:05 +0200 Subject: [PATCH 51/80] remove ignored const qualifiers --- Util/UUID.cpp.in | 12 ++++++------ Util/UUID.h | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index 8c2695525..9ba29dc15 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -55,39 +55,39 @@ const boost::uuids::uuid & UUID::GetUUID() const { return named_uuid; } -const bool UUID::IsMagicNumberOK() const { +bool UUID::IsMagicNumberOK() const { return 1297240911 == magic_number; } -const bool UUID::TestGraphUtil(const UUID & other) const { +bool UUID::TestGraphUtil(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("hsgr input file misses magic number. Check or reprocess the file"); } return std::equal(md5_graph, md5_graph+32, other.md5_graph); } -const bool UUID::TestPrepare(const UUID & other) const { +bool UUID::TestPrepare(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("extracted input file misses magic number. Check or reprocess the file"); } return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare); } -const bool UUID::TestRTree(const UUID & other) const { +bool UUID::TestRTree(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("r-tree input file misses magic number. Check or reprocess the file"); } return std::equal(md5_tree, md5_tree+32, other.md5_tree); } -const bool UUID::TestNodeInfo(const UUID & other) const { +bool UUID::TestNodeInfo(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("nodes file misses magic number. Check or reprocess the file"); } return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo); } -const bool UUID::TestQueryObjects(const UUID & other) const { +bool UUID::TestQueryObjects(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("missing magic number. Check or reprocess the file"); } diff --git a/Util/UUID.h b/Util/UUID.h index 6647b9764..d609d4592 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -41,12 +41,12 @@ public: UUID(); ~UUID(); const boost::uuids::uuid & GetUUID() const; - const bool IsMagicNumberOK() const; - const bool TestGraphUtil(const UUID & other) const; - const bool TestPrepare(const UUID & other) const; - const bool TestRTree(const UUID & other) const; - const bool TestNodeInfo(const UUID & other) const; - const bool TestQueryObjects(const UUID & other) const; + bool IsMagicNumberOK() const; + bool TestGraphUtil(const UUID & other) const; + bool TestPrepare(const UUID & other) const; + bool TestRTree(const UUID & other) const; + bool TestNodeInfo(const UUID & other) const; + bool TestQueryObjects(const UUID & other) const; private: const unsigned magic_number; char md5_prepare[33]; @@ -60,4 +60,4 @@ private: bool has_64_bits; }; -#endif /* UUID_H */ \ No newline at end of file +#endif /* UUID_H */ From 504817058bbbb1c900e8c6fe6784cb36a5443d9c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 22:35:13 +0200 Subject: [PATCH 52/80] remove checks for data that is not used here, log information through SimpleLogger --- Server/ServerFactory.h | 49 +++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index a41253105..bddb860e2 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -25,53 +25,38 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SERVERFACTORY_H_ #define SERVERFACTORY_H_ +#include #include "Server.h" #include "../Util/IniFile.h" -#include "../Util/InputFileUtil.h" #include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" -#include "../typedefs.h" - -#include - struct ServerFactory { - static Server * CreateServer(IniFile& serverConfig) { - - if(!testDataFile(serverConfig.GetParameter("nodesData"))) { - throw OSRMException("nodes file not found"); - } - - if(!testDataFile(serverConfig.GetParameter("hsgrData"))) { - throw OSRMException("hsgr file not found"); - } - - if(!testDataFile(serverConfig.GetParameter("namesData"))) { - throw OSRMException("names file not found"); - } - - if(!testDataFile(serverConfig.GetParameter("ramIndex"))) { - throw OSRMException("ram index file not found"); - } - - if(!testDataFile(serverConfig.GetParameter("fileIndex"))) { - throw OSRMException("file index file not found"); - } - + static Server * CreateServer( IniFile & serverConfig ) { int threads = omp_get_num_procs(); - if(serverConfig.GetParameter("IP") == "") { + if( serverConfig.GetParameter("IP").empty() ) { serverConfig.SetParameter("IP", "0.0.0.0"); } - if(serverConfig.GetParameter("Port") == "") { + if( serverConfig.GetParameter("Port").empty() ) { serverConfig.SetParameter("Port", "5000"); } - if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads) + if( + stringToInt(serverConfig.GetParameter("Threads")) >= 1 && + stringToInt(serverConfig.GetParameter("Threads")) <= threads + ) { threads = stringToInt( serverConfig.GetParameter("Threads") ); + } - std::cout << "[server] http 1.1 compression handled by zlib version " << zlibVersion() << std::endl; - Server * server = new Server(serverConfig.GetParameter("IP"), serverConfig.GetParameter("Port"), threads); + SimpleLogger().Write() << + "http 1.1 compression handled by zlib version " << zlibVersion(); + Server * server = new Server( + serverConfig.GetParameter("IP"), + serverConfig.GetParameter("Port"), + threads + ); return server; } From 83f0a2c0945de6f60633546584672d5ebdcb57e8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 22:49:33 +0200 Subject: [PATCH 53/80] Applying syntactic sugar --- Server/ServerFactory.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index bddb860e2..60502e257 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -16,33 +16,31 @@ You should have received a copy of the GNU Affero General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. - - Created on: 26.11.2010 - Author: dennis - */ #ifndef SERVERFACTORY_H_ #define SERVERFACTORY_H_ -#include #include "Server.h" - #include "../Util/IniFile.h" -#include "../Util/OpenMPWrapper.h" -#include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" -struct ServerFactory { +#include + +#include + +struct ServerFactory : boost::noncopyable { static Server * CreateServer( IniFile & serverConfig ) { int threads = omp_get_num_procs(); if( serverConfig.GetParameter("IP").empty() ) { serverConfig.SetParameter("IP", "0.0.0.0"); } + if( serverConfig.GetParameter("Port").empty() ) { serverConfig.SetParameter("Port", "5000"); } + if( stringToInt(serverConfig.GetParameter("Threads")) >= 1 && stringToInt(serverConfig.GetParameter("Threads")) <= threads @@ -52,6 +50,7 @@ struct ServerFactory { SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion(); + Server * server = new Server( serverConfig.GetParameter("IP"), serverConfig.GetParameter("Port"), From 679688705d8ab03a704cf31f47ddb389e9d49959 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 22:53:31 +0200 Subject: [PATCH 54/80] properly order includes --- Server/RequestParser.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/RequestParser.h b/Server/RequestParser.h index 7e33f9e09..54829de0a 100644 --- a/Server/RequestParser.h +++ b/Server/RequestParser.h @@ -21,9 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef REQUEST_PARSER_H #define REQUEST_PARSER_H +#include "BasicDatastructures.h" + #include #include -#include "BasicDatastructures.h" namespace http { From 7ee4692e8479befb9a3de7e7957694072a58fe43 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 23:01:15 +0200 Subject: [PATCH 55/80] properly order includes --- Extractor/ExtractorCallbacks.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Extractor/ExtractorCallbacks.h b/Extractor/ExtractorCallbacks.h index 0ba78c709..b175f76fa 100644 --- a/Extractor/ExtractorCallbacks.h +++ b/Extractor/ExtractorCallbacks.h @@ -21,8 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EXTRACTORCALLBACKS_H_ #define EXTRACTORCALLBACKS_H_ -#include -#include +#include "ExtractionContainers.h" +#include "ExtractionHelperFunctions.h" +#include "ExtractorStructs.h" + +#include "../DataStructures/Coordinate.h" #include @@ -30,11 +33,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include "ExtractionContainers.h" -#include "ExtractionHelperFunctions.h" -#include "ExtractorStructs.h" - -#include "../DataStructures/Coordinate.h" +#include +#include class ExtractorCallbacks{ private: From 5bc5e0e8e910df51632987d243cd3c0c64381c5c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 11 Aug 2013 23:25:22 +0200 Subject: [PATCH 56/80] logging into wrong channel --- routed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routed.cpp b/routed.cpp index f7b54d35f..b4b6b0c0e 100644 --- a/routed.cpp +++ b/routed.cpp @@ -83,7 +83,7 @@ int main (int argc, char * argv[]) { //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl; - SimpleLogger().Write(logWARNING) << + SimpleLogger().Write() << "starting up engines, compiled at " << __DATE__ << ", " __TIME__; #ifndef _WIN32 From 32c75786298062e8700705d0996e1acbb3f8b022 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 12 Aug 2013 13:19:07 +0200 Subject: [PATCH 57/80] fixes #695, maxspeed:forward incorrectly made any way routable --- profiles/car.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/profiles/car.lua b/profiles/car.lua index da6e6cedc..9ecbc81c2 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -197,7 +197,7 @@ function way_function (way) end -- Override speed settings if explicit forward/backward maxspeeds are given - if maxspeed_forward ~= nil and maxspeed_forward > 0 then + if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then if Way.bidirectional == way.direction then way.backward_speed = way.speed end @@ -211,7 +211,6 @@ function way_function (way) if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then way.ignore_in_grid = true end - way.type = 1 return 1 end From e50b5202b81bd44a22b17f9810b8c0d369cc0e57 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Mon, 12 Aug 2013 17:37:51 +0200 Subject: [PATCH 58/80] updated tests for car maxspeed forw/backw --- features/car/maxspeed.feature | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/features/car/maxspeed.feature b/features/car/maxspeed.feature index 3e09a0ad3..42bac96ce 100644 --- a/features/car/maxspeed.feature +++ b/features/car/maxspeed.feature @@ -52,3 +52,20 @@ Feature: Car - Max speed restrictions | 1 | 10 | | run | snail | | 1 | | 10 | snail | run | | 1 | 5 | 10 | walk | run | + + Scenario: Car - Maxspeed should not allow routing on unroutable ways + Then routability should be + | highway | railway | access | maxspeed | maxspeed:forward | maxspeed:backward | bothw | + | primary | | | | | | x | + | secondary | | no | | | | | + | secondary | | no | 100 | | | | + | secondary | | no | | 100 | | | + | secondary | | no | | | 100 | | + | (nil) | train | | | | | | + | (nil) | train | | 100 | | | | + | (nil) | train | | | 100 | | | + | (nil) | train | | | | 100 | | + | runway | | | | | | | + | runway | | | 100 | | | | + | runway | | | | 100 | | | + | runway | | | | | 100 | | \ No newline at end of file From aeba3aa2091124bba7a740d9cd23147043f95f2e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 12 Aug 2013 18:00:56 +0200 Subject: [PATCH 59/80] fixes #695 for bike profile --- features/bicycle/maxspeed.feature | 19 ++++++++++- profiles/bicycle.lua | 56 +++++++++++++++---------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/features/bicycle/maxspeed.feature b/features/bicycle/maxspeed.feature index 9924f5596..fa741685d 100644 --- a/features/bicycle/maxspeed.feature +++ b/features/bicycle/maxspeed.feature @@ -15,7 +15,7 @@ Feature: Bike - Max speed restrictions | highway | maxspeed | bothw | | residential | | 49s ~10% | | residential | 80 | 49s ~10% | - + @todo Scenario: Bicycle - Maxspeed formats Then routability should be @@ -68,3 +68,20 @@ Feature: Bike - Max speed restrictions | 1 | 10 | | run | snail | | 1 | | 10 | snail | run | | 1 | 5 | 10 | walk | run | + + Scenario: Bike - Maxspeed should not allow routing on unroutable ways + Then routability should be + | highway | railway | access | maxspeed | maxspeed:forward | maxspeed:backward | bothw | + | primary | | | | | | x | + | secondary | | no | | | | | + | secondary | | no | 100 | | | | + | secondary | | no | | 100 | | | + | secondary | | no | | | 100 | | + | (nil) | train | | | | | | + | (nil) | train | | 100 | | | | + | (nil) | train | | | 100 | | | + | (nil) | train | | | | 100 | | + | runway | | | | | | | + | runway | | | 100 | | | | + | runway | | | | 100 | | | + | runway | | | | | 100 | | diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 063ad50bc..5fd680239 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -14,7 +14,7 @@ default_speed = 15 walking_speed = 6 -bicycle_speeds = { +bicycle_speeds = { ["cycleway"] = default_speed, ["primary"] = default_speed, ["primary_link"] = default_speed, @@ -33,13 +33,13 @@ bicycle_speeds = { --["pedestrian"] = 12, } -pedestrian_speeds = { +pedestrian_speeds = { ["footway"] = walking_speed, ["pedestrian"] = walking_speed, ["steps"] = 2 } -railway_speeds = { +railway_speeds = { ["train"] = 10, ["railway"] = 10, ["subway"] = 10, @@ -48,24 +48,24 @@ railway_speeds = { ["tram"] = 10 } -platform_speeds = { +platform_speeds = { ["platform"] = walking_speed } -amenity_speeds = { +amenity_speeds = { ["parking"] = 10, ["parking_entrance"] = 10 } -man_made_speeds = { +man_made_speeds = { ["pier"] = walking_speed } -route_speeds = { +route_speeds = { ["ferry"] = 5 } -surface_speeds = { +surface_speeds = { ["cobblestone:flattened"] = 10, ["paving_stones"] = 10, ["compacted"] = 10, @@ -80,7 +80,7 @@ surface_speeds = { ["earth"] = 6, ["grass"] = 6, ["mud"] = 3, - ["sand"] = 3 + ["sand"] = 3 } take_minimum_of_speeds = true @@ -96,7 +96,7 @@ turn_bias = 1.4 -- End of globals function get_exceptions(vector) - for i,v in ipairs(restriction_exception_tags) do + for i,v in ipairs(restriction_exception_tags) do vector:Add(v) end end @@ -105,12 +105,12 @@ function node_function (node) local barrier = node.tags:Find ("barrier") local access = Access.find_access_tag(node, access_tags_hierachy) local traffic_signal = node.tags:Find("highway") - - -- flag node if it carries a traffic light + + -- flag node if it carries a traffic light if traffic_signal == "traffic_signals" then node.traffic_light = true end - + -- parse access and barrier tags if access and access ~= "" then if access_tag_blacklist[access] then @@ -125,7 +125,7 @@ function node_function (node) node.bollard = true end end - + return 1 end @@ -137,21 +137,21 @@ function way_function (way) local railway = way.tags:Find("railway") local amenity = way.tags:Find("amenity") local public_transport = way.tags:Find("public_transport") - if (not highway or highway == '') and - (not route or route == '') and - (not railway or railway=='') and + if (not highway or highway == '') and + (not route or route == '') and + (not railway or railway=='') and (not amenity or amenity=='') and (not man_made or man_made=='') and (not public_transport or public_transport=='') then return 0 end - + -- don't route on ways or railways that are still under construction if highway=='construction' or railway=='construction' then return 0 end - + -- access local access = Access.find_access_tag(way, access_tags_hierachy) if access_tag_blacklist[access] then @@ -178,7 +178,7 @@ function way_function (way) local foot = way.tags:Find("foot") local surface = way.tags:Find("surface") - -- name + -- name if "" ~= ref and "" ~= name then way.name = name .. ' / ' .. ref elseif "" ~= ref then @@ -214,7 +214,7 @@ function way_function (way) elseif railway and railway_speeds[railway] then -- railways if access and access_tag_whitelist[access] then - way.speed = railway_speeds[railway] + way.speed = railway_speeds[railway] way.direction = Way.bidirectional end elseif amenity and amenity_speeds[amenity] then @@ -242,7 +242,7 @@ function way_function (way) end end end - + -- direction way.direction = Way.bidirectional local impliedOneway = false @@ -250,7 +250,7 @@ function way_function (way) way.direction = Way.oneway impliedOneway = true end - + if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then way.direction = Way.oneway elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then @@ -284,7 +284,7 @@ function way_function (way) elseif oneway == "yes" or oneway == "1" or oneway == "true" then way.direction = Way.oneway end - + -- pushing bikes if bicycle_speeds[highway] or pedestrian_speeds[highway] then if foot ~= 'no' then @@ -303,7 +303,7 @@ function way_function (way) end end - + -- cycleways if cycleway and cycleway_tags[cycleway] then way.speed = bicycle_speeds["cycleway"] @@ -312,7 +312,7 @@ function way_function (way) elseif cycleway_right and cycleway_tags[cycleway_right] then way.speed = bicycle_speeds["cycleway"] end - + -- surfaces if surface then surface_speed = surface_speeds[surface] @@ -331,7 +331,7 @@ function way_function (way) end -- Override speed settings if explicit forward/backward maxspeeds are given - if maxspeed_forward ~= nil and maxspeed_forward > 0 then + if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then if Way.bidirectional == way.direction then way.backward_speed = way.speed end @@ -342,7 +342,7 @@ function way_function (way) end - + way.type = 1 return 1 end From 124e555ed0ccdc13769d6d7f73e8feed795b9fd7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 10:48:02 +0200 Subject: [PATCH 60/80] Disabling debug output in release build --- Util/SimpleLogger.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 68582fd22..8bbc6e4fe 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -72,7 +72,9 @@ public: os << "warn"; break; case logDEBUG: +#ifndef NDEBUG os << "debug"; +#endif break; default: BOOST_ASSERT_MSG(false, "should not happen"); @@ -85,16 +87,17 @@ public: virtual ~SimpleLogger() { if(!LogPolicy::GetInstance().IsMute()) { - os << std::endl; switch(level) { case logINFO: - std::cout << os.str(); + std::cout << os.str() << std::endl; break; case logWARNING: - std::cerr << os.str(); + std::cerr << os.str() << std::endl; break; case logDEBUG: - std::cout << os.str(); +#ifndef NDEBUG + std::cout << os.str() << std::endl; +#endif break; default: BOOST_ASSERT_MSG(false, "should not happen"); From c50b4c72d79019d4d56f6ee235897938972add60 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:09:20 +0200 Subject: [PATCH 61/80] Refactoring of Plugins --- Plugins/BasePlugin.h | 4 +--- Plugins/HelloWorldPlugin.h | 28 +++++++++++++++++++++------- Plugins/LocatePlugin.h | 8 +++----- Plugins/NearestPlugin.h | 12 +++++++----- Plugins/TimestampPlugin.h | 11 +++++------ Plugins/ViaRoutePlugin.h | 27 +++++++++------------------ 6 files changed, 46 insertions(+), 44 deletions(-) diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index 77b133efb..d8956d022 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -33,8 +33,7 @@ public: BasePlugin() { } //Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BasePlugin() { } - virtual std::string GetDescriptor() const = 0; - virtual std::string GetVersionString() const = 0 ; + virtual const std::string & GetDescriptor() const = 0; virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0; inline bool checkCoord(const _Coordinate & c) { @@ -48,7 +47,6 @@ public: } return true; } - }; #endif /* BASEPLUGIN_H_ */ diff --git a/Plugins/HelloWorldPlugin.h b/Plugins/HelloWorldPlugin.h index 8e755ea8a..546789b1e 100644 --- a/Plugins/HelloWorldPlugin.h +++ b/Plugins/HelloWorldPlugin.h @@ -1,8 +1,21 @@ /* - * LocatePlugin.h - * - * Created on: 01.01.2011 - * Author: dennis + open source routing machine + Copyright (C) Dennis Luxen, 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. */ #ifndef HELLOWORLDPLUGIN_H_ @@ -15,10 +28,9 @@ class HelloWorldPlugin : public BasePlugin { public: - HelloWorldPlugin() {} + HelloWorldPlugin() : descriptor_string("hello"){} virtual ~HelloWorldPlugin() { } - std::string GetDescriptor() const { return std::string("hello"); } - std::string GetVersionString() const { return std::string("0.1a"); } + const std::string & GetDescriptor() const { return descriptor_string; } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { reply.status = http::Reply::ok; @@ -45,6 +57,8 @@ public: reply.content.append(content.str()); reply.content.append(""); } +private: + std::string descriptor_string; }; #endif /* HELLOWORLDPLUGIN_H_ */ diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 9fff478dd..e6f59159e 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -27,18 +27,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" -#include - /* * This Plugin locates the nearest node in the road network for a given coordinate. */ class LocatePlugin : public BasePlugin { public: - LocatePlugin(QueryObjectsStorage * objects) { + LocatePlugin(QueryObjectsStorage * objects) : descriptor_string("locate") { nodeHelpDesk = objects->nodeHelpDesk; } - std::string GetDescriptor() const { return std::string("locate"); } - std::string GetVersionString() const { return std::string("0.3 (DL)"); } + const std::string & GetDescriptor() const { return descriptor_string; } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { //check number of parameters if(!routeParameters.coordinates.size()) { @@ -102,6 +99,7 @@ public: private: NodeInformationHelpDesk * nodeHelpDesk; + std::string descriptor_string; }; #endif /* LOCATEPLUGIN_H_ */ diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 9ea15d32b..a1ca3537e 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -28,21 +28,22 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" -#include - /* * This Plugin locates the nearest point on a street in the road network for a given coordinate. */ class NearestPlugin : public BasePlugin { public: - NearestPlugin(QueryObjectsStorage * objects) : names(objects->names) { + NearestPlugin(QueryObjectsStorage * objects ) + : + names(objects->names), + descriptor_string("nearest") + { nodeHelpDesk = objects->nodeHelpDesk; descriptorTable.insert(std::make_pair("" , 0)); //default descriptor descriptorTable.insert(std::make_pair("json", 1)); } - std::string GetDescriptor() const { return std::string("nearest"); } - std::string GetVersionString() const { return std::string("0.3 (DL)"); } + const std::string & GetDescriptor() const { return descriptor_string; } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { //check number of parameters if(!routeParameters.coordinates.size()) { @@ -112,6 +113,7 @@ private: NodeInformationHelpDesk * nodeHelpDesk; HashTable descriptorTable; std::vector & names; + std::string descriptor_string; }; #endif /* NearestPlugin_H_ */ diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 6a245e116..6142cb825 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -24,14 +24,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "RouteParameters.h" -#include - class TimestampPlugin : public BasePlugin { public: - TimestampPlugin(QueryObjectsStorage * o) : objects(o) { - } - std::string GetDescriptor() const { return std::string("timestamp"); } - std::string GetVersionString() const { return std::string("0.3 (DL)"); } + TimestampPlugin(QueryObjectsStorage * o) + : objects(o), descriptor_string("timestamp") + { } + const std::string & GetDescriptor() const { return descriptor_string; } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { std::string tmp; @@ -70,6 +68,7 @@ public: } private: QueryObjectsStorage * objects; + std::string descriptor_string; }; #endif /* TIMESTAMPPLUGIN_H_ */ diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index cbeae3fe8..46f17bb3b 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -38,8 +38,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include -#include #include #include @@ -49,17 +47,20 @@ private: std::vector & names; StaticGraph * graph; HashTable descriptorTable; - std::string pluginDescriptorString; SearchEngine * searchEnginePtr; public: - ViaRoutePlugin(QueryObjectsStorage * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) { + ViaRoutePlugin(QueryObjectsStorage * objects) + : + names(objects->names), + descriptor_string("viaroute") + { nodeHelpDesk = objects->nodeHelpDesk; graph = objects->graph; searchEnginePtr = new SearchEngine(graph, nodeHelpDesk, names); - descriptorTable.insert(std::make_pair("" , 0)); //default descriptor + descriptorTable.insert(std::make_pair("" , 0)); descriptorTable.insert(std::make_pair("json", 0)); descriptorTable.insert(std::make_pair("gpx" , 1)); } @@ -68,8 +69,8 @@ public: delete searchEnginePtr; } - std::string GetDescriptor() const { return pluginDescriptorString; } - std::string GetVersionString() const { return std::string("0.3 (DL)"); } + const std::string & GetDescriptor() const { return descriptor_string; } + void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { //check number of parameters if( 2 > routeParameters.coordinates.size() ) { @@ -209,17 +210,7 @@ public: return; } private: - inline bool checkCoord(const _Coordinate & c) { - if( - c.lat > 90*COORDINATE_PRECISION || - c.lat < -90*COORDINATE_PRECISION || - c.lon > 180*COORDINATE_PRECISION || - c.lon < -180*COORDINATE_PRECISION - ) { - return false; - } - return true; - } + std::string descriptor_string; }; From d7bd78d612d40af5bf392c7f2c085025a0a91f3d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:21:14 +0200 Subject: [PATCH 62/80] correct timing of durations --- createHierarchy.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 9d46d74e9..daa6138de 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -237,9 +237,10 @@ int main (int argc, char *argv[]) { Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); + const double contraction_duration = (get_timestamp() - contractionStartedTimestamp); SimpleLogger().Write() << "Contraction took " << - (get_timestamp() - contractionStartedTimestamp) << + contraction_duration << " sec"; DeallocatingVector< QueryEdge > contractedEdgeList; @@ -317,14 +318,15 @@ int main (int argc, char *argv[]) { ++usedEdgeCounter; } } - double endTime = (get_timestamp() - startupTime); + SimpleLogger().Write() << "Preprocessing : " << + (get_timestamp() - startupTime) << " seconds"; SimpleLogger().Write() << "Expansion : " << (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and " << (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"; SimpleLogger().Write() << "Contraction: " << - (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and " << - usedEdgeCounter/endTime << " edges/sec"; + (edgeBasedNodeNumber/contraction_duration) << " nodes/sec and " << + usedEdgeCounter/contraction_duration << " edges/sec"; hsgr_output_stream.close(); //cleanedEdgeList.clear(); @@ -333,7 +335,6 @@ int main (int argc, char *argv[]) { } catch ( const std::exception &e ) { SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl; - return -1; } return 0; From e26c41095f087e0be6397b3e67bfabdc3d8e89a2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:33:20 +0200 Subject: [PATCH 63/80] Some mild refactoring --- Contractor/EdgeBasedGraphFactory.cpp | 56 ++++++++++++++++++---------- Contractor/EdgeBasedGraphFactory.h | 7 ++-- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 7da2e4f67..7803e8e97 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -20,8 +20,7 @@ #include "EdgeBasedGraphFactory.h" -template<> -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { +EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { BOOST_FOREACH(const _Restriction & restriction, irs) { std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; @@ -49,7 +48,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector edges; _NodeBasedEdge edge; - for ( std::vector< NodeBasedEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) { + for ( std::vector< ImportEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) { if(!i->isForward()) { edge.source = i->target(); edge.target = i->source(); @@ -83,7 +82,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector().swap(inputEdges); + std::vector().swap(inputEdges); std::sort( edges.begin(), edges.end() ); _nodeBasedGraph = boost::make_shared<_NodeBasedDynamicGraph>( nodes, edges ); } @@ -107,10 +106,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & node } NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const { - std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); + const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); if (restrIter != _restrictionMap.end()) { - unsigned index = restrIter->second; + const unsigned index = restrIter->second; BOOST_FOREACH(const RestrictionSource & restrictionTarget, _restrictionBucketVector.at(index)) { if(restrictionTarget.second) { return restrictionTarget.first; @@ -122,11 +121,11 @@ NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const { //only add an edge if turn is not a U-turn except it is the end of dead-end street. - std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); + const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); if (restrIter != _restrictionMap.end()) { - unsigned index = restrIter->second; - BOOST_FOREACH(RestrictionTarget restrictionTarget, _restrictionBucketVector.at(index)) { + const unsigned index = restrIter->second; + BOOST_FOREACH(const RestrictionTarget & restrictionTarget, _restrictionBucketVector.at(index)) { if(w == restrictionTarget.first) return true; } @@ -276,8 +275,8 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State if(_trafficLights.find(v) != _trafficLights.end()) { distance += speedProfile.trafficSignalPenalty; } - unsigned penalty = 0; - TurnInstruction turnInstruction = AnalyzeTurn(u, v, w, penalty, myLuaState); + unsigned penalty = GetTurnPenalty(u, v, w, myLuaState); + TurnInstruction turnInstruction = AnalyzeTurn(u, v, w); if(turnInstruction == TurnInstructions.UTurn) distance += speedProfile.uTurnPenalty; // if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) { @@ -329,20 +328,39 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State SimpleLogger().Write() <<"Generated " << edgeBasedNodes.size() << " edge based nodes"; } -TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const { - const double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); +int EdgeBasedGraphFactory::GetTurnPenalty( + const NodeID u, + const NodeID v, + const NodeID w, + lua_State *myLuaState +) const { + const double angle = GetAngleBetweenTwoEdges( + inputNodeInfoList[u], + inputNodeInfoList[v], + inputNodeInfoList[w] + ); if( speedProfile.has_turn_penalty_function ) { - try { + try { //call lua profile to compute turn penalty - penalty = luabind::call_function( myLuaState, "turn_function", 180-angle ); + return luabind::call_function( + myLuaState, + "turn_function", + 180.-angle + ); } catch (const luabind::error &er) { - std::cerr << er.what() << std::endl; - //TODO handle lua errors + SimpleLogger().Write(logWARNING) << er.what(); } - } else { - penalty = 0; } + return 0; +} + +TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( + const NodeID u, + const NodeID v, + const NodeID w +) const { + const double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); if(u == w) { return TurnInstructions.UTurn; diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 2c5360c1c..43563b3b7 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -159,14 +159,15 @@ private: double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const; public: - template< class InputEdgeT > - explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector & nI, SpeedProfileProperties speedProfile); + explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector & nI, SpeedProfileProperties speedProfile); void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); - TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const; + TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; + int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; + unsigned GetNumberOfNodes() const; }; From 764ad815373ec8bf93b22a87595f805946892584 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:34:33 +0200 Subject: [PATCH 64/80] Some mild refactoring --- Contractor/EdgeBasedGraphFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 7803e8e97..fa5b4d722 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -97,7 +97,7 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector< EdgeBasedEdge void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & nodes) { #ifndef NDEBUG - BOOST_FOREACH(EdgeBasedNode & node, edgeBasedNodes){ + BOOST_FOREACH(const EdgeBasedNode & node, edgeBasedNodes){ assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX); assert(node.lat2 != INT_MAX); assert(node.lon2 != INT_MAX); } From dc6fda03a14a852a460fd60cacc07baba18eb7b8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:35:22 +0200 Subject: [PATCH 65/80] move const value to left-hand side of comparison --- DataStructures/DynamicGraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStructures/DynamicGraph.h b/DataStructures/DynamicGraph.h index 67db0650a..89baee882 100644 --- a/DataStructures/DynamicGraph.h +++ b/DataStructures/DynamicGraph.h @@ -194,7 +194,7 @@ class DynamicGraph { //searches for a specific edge EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const { for ( EdgeIterator i = BeginEdges( from ), iend = EndEdges( from ); i != iend; ++i ) { - if ( m_edges[i].target == to ) { + if ( to == m_edges[i].target ) { return i; } } From 5f4f631fc55c7e8f3a245888cf1a5cee7668601b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:35:54 +0200 Subject: [PATCH 66/80] Remove dead code --- DataStructures/QueryEdge.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/DataStructures/QueryEdge.h b/DataStructures/QueryEdge.h index 3a2aecb82..ef7c6b20b 100644 --- a/DataStructures/QueryEdge.h +++ b/DataStructures/QueryEdge.h @@ -29,7 +29,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include struct OriginalEdgeData{ - explicit OriginalEdgeData(NodeID v, unsigned n, TurnInstruction t) : viaNode(v), nameID(n), turnInstruction(t) {} + explicit OriginalEdgeData( + NodeID viaNode, + unsigned nameID, + TurnInstruction turnInstruction + ) : viaNode(viaNode), nameID(nameID), turnInstruction(turnInstruction) {} OriginalEdgeData() : viaNode(UINT_MAX), nameID(UINT_MAX), turnInstruction(UCHAR_MAX) {} NodeID viaNode; unsigned nameID; @@ -46,23 +50,12 @@ struct QueryEdge { bool forward:1; bool backward:1; } data; - bool operator<( const QueryEdge& right ) const { - if ( source != right.source ) - return source < right.source; - return target < right.target; - } - //sorts by source and other attributes - static bool CompareBySource( const QueryEdge& left, const QueryEdge& right ) { - if ( left.source != right.source ) - return left.source < right.source; - int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 ); - int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 ); - if ( l != r ) - return l < r; - if ( left.target != right.target ) - return left.target < right.target; - return left.data.distance < right.data.distance; + bool operator<( const QueryEdge& right ) const { + if ( source != right.source ) { + return source < right.source; + } + return target < right.target; } bool operator== ( const QueryEdge& right ) const { From dcd88260e9208241518b31e7de0e393e84823b62 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:36:23 +0200 Subject: [PATCH 67/80] Add a few braces here and there --- Util/GraphLoader.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index dcf78386a..a31a9f640 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -83,10 +83,12 @@ NodeID readBinaryOSRMGraphFromStream( in.read((char*)&node, sizeof(_Node)); int2ExtNodeMap->push_back(NodeInfo(node.lat, node.lon, node.id)); ext2IntNodeMap.insert(std::make_pair(node.id, i)); - if(node.bollard) + if(node.bollard) { bollardNodes.push_back(i); - if(node.trafficLight) + } + if(node.trafficLight) { trafficLightNodes.push_back(i); + } } //tighten vector sizes From beb9c1ba74306c168038ecf1860cd5609bfc3b94 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 13 Aug 2013 18:37:21 +0200 Subject: [PATCH 68/80] use proper check for empty string --- Server/DataStructures/QueryObjectsStorage.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 393fd1bf7..27a906312 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -30,22 +30,22 @@ QueryObjectsStorage::QueryObjectsStorage( const std::string & namesPath, const std::string & timestampPath ) { - if("" == hsgrPath) { + if( hsgrPath.empty() ) { throw OSRMException("no hsgr file given in ini file"); } - if("" == ramIndexPath) { + if( ramIndexPath.empty() ) { throw OSRMException("no ram index file given in ini file"); } - if("" == fileIndexPath) { + if( fileIndexPath.empty() ) { throw OSRMException("no mem index file given in ini file"); } - if("" == nodesPath) { + if( nodesPath.empty() ) { throw OSRMException("no nodes file given in ini file"); } - if("" == edgesPath) { + if( edgesPath.empty() ) { throw OSRMException("no edges file given in ini file"); } - if("" == namesPath) { + if( namesPath.empty() ) { throw OSRMException("no names file given in ini file"); } From 3167d3f451666a3254197e4246515184c6bce786 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 11:57:33 +0200 Subject: [PATCH 69/80] Export compile commands --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b17f1149a..7d047faa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.6) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project(OSRM) include(FindPackageHandleStandardArgs) From c8e0e5eca29f689ac011793591e0abe451d62cd7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 11:57:54 +0200 Subject: [PATCH 70/80] Export compile commands --- cmake/cmake_options_script.py | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cmake/cmake_options_script.py diff --git a/cmake/cmake_options_script.py b/cmake/cmake_options_script.py new file mode 100644 index 000000000..52e943e79 --- /dev/null +++ b/cmake/cmake_options_script.py @@ -0,0 +1,45 @@ +# Based on @berenm's pull request https://github.com/quarnster/SublimeClang/pull/135 +# Create the database with cmake with for example: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. +# or you could have set(CMAKE_EXPORT_COMPILE_COMMANDS ON) in your CMakeLists.txt +# Usage within SublimeClang: +# "sublimeclang_options_script": "python ${home}/code/cmake_options_script.py ${project_path:build}/compile_commands.json", + + +import re +import os +import os.path +import pickle +import sys +import json + +compilation_database_pattern = re.compile('(?<=\s)-[DIOUWfgs][^=\s]+(?:=\\"[^"]+\\"|=[^"]\S+)?') + +def load_db(filename): + compilation_database = {} + with open(filename) as compilation_database_file: + compilation_database_entries = json.load(compilation_database_file) + + total = len(compilation_database_entries) + entry = 0 + for compilation_entry in compilation_database_entries: + entry = entry + 1 + compilation_database[compilation_entry["file"]] = [ p.strip() for p in compilation_database_pattern.findall(compilation_entry["command"]) ] + return compilation_database + +scriptpath = os.path.dirname(os.path.abspath(sys.argv[1])) +cache_file = "%s/cached_options.txt" % (scriptpath) + +db = None +if os.access(cache_file, os.R_OK) == 0: + db = load_db(sys.argv[1]) + f = open(cache_file, "wb") + pickle.dump(db, f) + f.close() +else: + f = open(cache_file) + db = pickle.load(f) + f.close() + +if db and sys.argv[2] in db: + for option in db[sys.argv[2]]: + print option From 23f2c7e6f5f4c4cc162dd93c055a245247a9270b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 11:58:23 +0200 Subject: [PATCH 71/80] move windows specific defines behind define-fence --- typedefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typedefs.h b/typedefs.h index b98783334..2592f422b 100644 --- a/typedefs.h +++ b/typedefs.h @@ -35,12 +35,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +// Necessary workaround for Windows as VS doesn't implement C99 +#ifdef _MSC_VER #ifndef M_PI #define M_PI 3.14159265358979323846 #endif -// Necessary workaround for Windows as VS doesn't implement C99 -#ifdef _MSC_VER template digitT round(digitT x) { return std::floor(x + 0.5); From 216d7dcb861fd27b46bfe851a3f59565b4026533 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 11:59:01 +0200 Subject: [PATCH 72/80] Fixing typos --- Algorithms/IteratorBasedCRC32.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithms/IteratorBasedCRC32.h b/Algorithms/IteratorBasedCRC32.h index 82c6b8cb4..55a8f8084 100644 --- a/Algorithms/IteratorBasedCRC32.h +++ b/Algorithms/IteratorBasedCRC32.h @@ -82,7 +82,7 @@ private: unsigned ecx = cpuid(1); bool hasSSE42 = ecx & (1 << SSE42_BIT); if (hasSSE42) { - SimpleLogger().Write() << "using hardware base CRC32 computation"; + SimpleLogger().Write() << "using hardware based CRC32 computation"; return &IteratorbasedCRC32::SSEBasedCRC32; //crc32 hardware accelarated; } else { SimpleLogger().Write() << "using software based CRC32 computation"; @@ -95,7 +95,7 @@ public: crcFunction = detectBestCRC32C(); } - virtual ~IteratorbasedCRC32() {}; + virtual ~IteratorbasedCRC32() { } unsigned operator()( ContainerT_iterator iter, const ContainerT_iterator end) { unsigned crc = 0; From 916387748c651adbc2632da8f5eacb47310eb3d2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 11:59:46 +0200 Subject: [PATCH 73/80] Refactor _Restriction class --- Algorithms/StronglyConnectedComponents.h | 22 +++++++-- Contractor/EdgeBasedGraphFactory.cpp | 60 +++++++++++++++--------- Contractor/EdgeBasedGraphFactory.h | 32 ++++++++----- DataStructures/Restriction.h | 42 ++++++++++++----- Extractor/ExtractionContainers.cpp | 2 +- Tools/componentAnalysis.cpp | 23 +++++---- Util/GraphLoader.h | 2 +- createHierarchy.cpp | 16 +++++-- extractor.cpp | 2 +- 9 files changed, 132 insertions(+), 69 deletions(-) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index 2377258f8..f2376727e 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -118,9 +118,21 @@ private: DeallocatingVector edgeBasedNodes; public: - TarjanSCC(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { - BOOST_FOREACH(_Restriction & restriction, irs) { - std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); + TarjanSCC( + int nodes, + std::vector & inputEdges, + std::vector & bn, + std::vector & tl, + std::vector & irs, + std::vector & nI + ) : + inputNodeInfoList(nI), + numberOfTurnRestrictions(irs.size()) + { + BOOST_FOREACH(const TurnRestriction & restriction, irs) { + std::pair restrictionSource = std::make_pair( + restriction.fromNode, restriction.viaNode + ); unsigned index; RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource); if(restrIter == _restrictionMap.end()) { @@ -138,7 +150,9 @@ public: } } - _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); + _restrictionBucketVector.at(index).push_back( + std::make_pair(restriction.toNode, restriction.flags.isOnly) + ); } BOOST_FOREACH(NodeID id, bn) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index fa5b4d722..c6d138040 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -20,8 +20,18 @@ #include "EdgeBasedGraphFactory.h" -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { - BOOST_FOREACH(const _Restriction & restriction, irs) { +EdgeBasedGraphFactory::EdgeBasedGraphFactory( + int nodes, std::vector & inputEdges, + std::vector & bn, + std::vector & tl, + std::vector & input_restrictions_list, + std::vector & inputNodeInfoList, + SpeedProfileProperties speedProfile +) : speedProfile(speedProfile), + m_turn_restrictions_count(0), + inputNodeInfoList(inputNodeInfoList) +{ + BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource); @@ -36,10 +46,11 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector continue; else if(restriction.flags.isOnly){ //We are going to insert an is_only_*-restriction. There can be only one. + m_turn_restrictions_count -= _restrictionBucketVector.at(index).size(); _restrictionBucketVector.at(index).clear(); } } - + ++m_turn_restrictions_count; _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); } @@ -48,36 +59,36 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector DeallocatingVector< _NodeBasedEdge > edges; _NodeBasedEdge edge; - for ( std::vector< ImportEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) { - if(!i->isForward()) { - edge.source = i->target(); - edge.target = i->source(); - edge.data.backward = i->isForward(); - edge.data.forward = i->isBackward(); + BOOST_FOREACH(const ImportEdge & import_edge, inputEdges) { + if(!import_edge.isForward()) { + edge.source = import_edge.target(); + edge.target = import_edge.source(); + edge.data.backward = import_edge.isForward(); + edge.data.forward = import_edge.isBackward(); } else { - edge.source = i->source(); - edge.target = i->target(); - edge.data.forward = i->isForward(); - edge.data.backward = i->isBackward(); + edge.source = import_edge.source(); + edge.target = import_edge.target(); + edge.data.forward = import_edge.isForward(); + edge.data.backward = import_edge.isBackward(); } if(edge.source == edge.target) { continue; } - edge.data.distance = (std::max)((int)i->weight(), 1 ); + edge.data.distance = (std::max)((int)import_edge.weight(), 1 ); assert( edge.data.distance > 0 ); edge.data.shortcut = false; - edge.data.roundabout = i->isRoundabout(); - edge.data.ignoreInGrid = i->ignoreInGrid(); - edge.data.nameID = i->name(); - edge.data.type = i->type(); - edge.data.isAccessRestricted = i->isAccessRestricted(); + edge.data.roundabout = import_edge.isRoundabout(); + edge.data.ignoreInGrid = import_edge.ignoreInGrid(); + edge.data.nameID = import_edge.name(); + edge.data.type = import_edge.type(); + edge.data.isAccessRestricted = import_edge.isAccessRestricted(); edge.data.edgeBasedNodeID = edges.size(); - edge.data.contraFlow = i->isContraFlow(); + edge.data.contraFlow = import_edge.isContraFlow(); edges.push_back( edge ); if( edge.data.backward ) { std::swap( edge.source, edge.target ); - edge.data.forward = i->isBackward(); - edge.data.backward = i->isForward(); + edge.data.forward = import_edge.isBackward(); + edge.data.backward = import_edge.isForward(); edge.data.edgeBasedNodeID = edges.size(); edges.push_back( edge ); } @@ -105,7 +116,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & node nodes.swap(edgeBasedNodes); } -NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const { +NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( + const NodeID u, + const NodeID v +) const { const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); if (restrIter != _restrictionMap.end()) { diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 43563b3b7..c53d69464 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -105,6 +105,25 @@ public: bool has_turn_penalty_function; } speedProfile; + explicit EdgeBasedGraphFactory( + int nodes, + std::vector & inputEdges, + std::vector & _bollardNodes, + std::vector & trafficLights, + std::vector & inputRestrictions, + std::vector & nI, + SpeedProfileProperties speedProfile + ); + + void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); + void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); + void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); + void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); + TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; + int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; + + unsigned GetNumberOfNodes() const; + private: struct _NodeBasedEdgeData { int distance; @@ -129,6 +148,8 @@ private: TurnInstruction turnInstruction; }; + unsigned m_turn_restrictions_count; + typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge; std::vector inputNodeInfoList; @@ -158,17 +179,6 @@ private: template double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const; -public: - explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector & nI, SpeedProfileProperties speedProfile); - - void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); - void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); - void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); - void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); - TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; - int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; - - unsigned GetNumberOfNodes() const; }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h index fc40fb0ba..2693700e7 100644 --- a/DataStructures/Restriction.h +++ b/DataStructures/Restriction.h @@ -23,14 +23,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef RESTRICTION_H_ #define RESTRICTION_H_ +#include "../typedefs.h" #include -struct _Restriction { +struct TurnRestriction { NodeID viaNode; NodeID fromNode; NodeID toNode; struct Bits { //mostly unused - Bits() : + Bits() + : isOnly(false), unused1(false), unused2(false), @@ -38,9 +40,8 @@ struct _Restriction { unused4(false), unused5(false), unused6(false), - unused7(false) { - - } + unused7(false) + { } bool isOnly:1; bool unused1:1; @@ -52,14 +53,14 @@ struct _Restriction { bool unused7:1; } flags; - _Restriction(NodeID vn) : - viaNode(vn), + TurnRestriction(NodeID viaNode) : + viaNode(viaNode), fromNode(UINT_MAX), toNode(UINT_MAX) { } - _Restriction(const bool isOnly = false) : + TurnRestriction(const bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) { @@ -68,13 +69,32 @@ struct _Restriction { }; struct _RawRestrictionContainer { - _Restriction restriction; + TurnRestriction restriction; EdgeID fromWay; EdgeID toWay; unsigned viaNode; - _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;} - _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;} + _RawRestrictionContainer( + EdgeID fromWay, + EdgeID toWay, + NodeID vn, + unsigned vw + ) : + fromWay(fromWay), + toWay(toWay), + viaNode(vw) + { + restriction.viaNode = vn; + } + _RawRestrictionContainer( + bool isOnly = false + ) : + fromWay(UINT_MAX), + toWay(UINT_MAX), + viaNode(UINT_MAX) + { + restriction.flags.isOnly = isOnly; + } static _RawRestrictionContainer min_value() { return _RawRestrictionContainer(0, 0, 0, 0); diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 255d545e4..515c78b84 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -125,7 +125,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); for(restrictionsIT = restrictionsVector.begin(); restrictionsIT != restrictionsVector.end(); ++restrictionsIT) { if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { - restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(_Restriction)); + restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(TurnRestriction)); } } restrictionsOutstream.close(); diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index 2273456c7..12d0a1d64 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -43,19 +43,21 @@ typedef QueryEdge::EdgeData EdgeData; typedef DynamicGraph::InputEdge InputEdge; std::vector internal_to_external_node_map; -std::vector<_Restriction> restrictions_vector; +std::vector restrictions_vector; std::vector bollard_node_IDs_vector; std::vector traffic_light_node_IDs_vector; -int main (int argument_count, char *argument_values[]) { +int main (int argc, char * argv[]) { LogPolicy::GetInstance().Unmute(); - if(argument_count < 3) { - std::cerr << "usage:\n" << argument_values[0] << " " << std::endl; + if(argc < 3) { + SimpleLogger().Write(logWARNING) << + "usage:\n" << argv[0] << " "; return -1; } - SimpleLogger().Write() << "Using restrictions from file: " << argument_values[2]; - std::ifstream restriction_ifstream(argument_values[2], std::ios::binary); + SimpleLogger().Write() << + "Using restrictions from file: " << argv[2]; + std::ifstream restriction_ifstream(argv[2], std::ios::binary); if(!restriction_ifstream.good()) { throw OSRMException("Could not access files"); } @@ -68,15 +70,12 @@ int main (int argument_count, char *argument_values[]) { restriction_ifstream.read( (char *)&(restrictions_vector[0]), - usable_restriction_count*sizeof(_Restriction) + usable_restriction_count*sizeof(TurnRestriction) ); restriction_ifstream.close(); std::ifstream input_stream; - input_stream.open( - argument_values[1], - std::ifstream::in | std::ifstream::binary - ); + input_stream.open( argv[1], std::ifstream::in | std::ifstream::binary ); if (!input_stream.is_open()) { throw OSRMException("Cannot open osrm file"); @@ -115,7 +114,7 @@ int main (int argument_count, char *argument_values[]) { tarjan->Run(); - std::vector<_Restriction>().swap(restrictions_vector); + std::vector().swap(restrictions_vector); std::vector().swap(bollard_node_IDs_vector); std::vector().swap(traffic_light_node_IDs_vector); SimpleLogger().Write() << "finished component analysis"; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index a31a9f640..7a674da01 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -60,7 +60,7 @@ NodeID readBinaryOSRMGraphFromStream( std::vector &bollardNodes, std::vector &trafficLightNodes, std::vector * int2ExtNodeMap, - std::vector<_Restriction> & inputRestrictions + std::vector & inputRestrictions ) { const UUID uuid_orig; UUID uuid_loaded; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index daa6138de..a3c6ceb20 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -53,7 +53,7 @@ typedef StaticGraph::InputEdge StaticEdge; typedef IniFile ContractorConfiguration; std::vector internalToExternalNodeMapping; -std::vector<_Restriction> inputRestrictions; +std::vector inputRestrictions; std::vector bollardNodes; std::vector trafficLightNodes; std::vector edgeList; @@ -85,7 +85,7 @@ int main (int argc, char *argv[]) { "Could not access files" << std::endl; } - _Restriction restriction; + TurnRestriction restriction; UUID uuid_loaded, uuid_orig; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID)); @@ -95,9 +95,15 @@ int main (int argc, char *argv[]) { "Reprocess to get rid of this warning."; } - restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); + restrictionsInstream.read( + (char*)&usableRestrictionsCounter, + sizeof(unsigned) + ); inputRestrictions.resize(usableRestrictionsCounter); - restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction)); + restrictionsInstream.read( + (char *)&(inputRestrictions[0]), + usableRestrictionsCounter*sizeof(TurnRestriction) + ); restrictionsInstream.close(); std::ifstream in; @@ -190,7 +196,7 @@ int main (int argc, char *argv[]) { EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); std::vector().swap(edgeList); edgeBasedGraphFactory->Run(edgeOut.c_str(), myLuaState); - std::vector<_Restriction>().swap(inputRestrictions); + std::vector().swap(inputRestrictions); std::vector().swap(bollardNodes); std::vector().swap(trafficLightNodes); NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); diff --git a/extractor.cpp b/extractor.cpp index 29296f919..d39c00ab6 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -46,7 +46,6 @@ int main (int argc, char *argv[]) { try { LogPolicy::GetInstance().Unmute(); double startup_time = get_timestamp(); - if(argc < 2) { SimpleLogger().Write(logWARNING) << "usage: \n" << @@ -59,6 +58,7 @@ int main (int argc, char *argv[]) { ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); unsigned number_of_threads = omp_get_num_procs(); + if(testDataFile("extractor.ini")) { IniFile extractorConfig("extractor.ini"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); From 4748bca8a4d2a8fde3f483d1aa8e08344f93d1f9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 13:12:28 +0200 Subject: [PATCH 74/80] Refactoring _Coordinate class --- Algorithms/PolylineCompressor.h | 11 ++-- Contractor/EdgeBasedGraphFactory.cpp | 15 ++++-- Contractor/EdgeBasedGraphFactory.h | 5 +- DataStructures/Coordinate.h | 24 ++++----- DataStructures/HilbertValue.h | 3 +- DataStructures/NodeInformationHelpDesk.h | 12 ++--- DataStructures/PhantomNodes.h | 13 +++-- DataStructures/SearchEngine.cpp | 4 +- DataStructures/SearchEngine.h | 10 ++-- DataStructures/SegmentInformation.h | 6 +-- DataStructures/StaticRTree.h | 68 ++++++++++++------------ Descriptors/DescriptionFactory.cpp | 7 ++- Descriptors/DescriptionFactory.h | 4 +- Descriptors/GPXDescriptor.h | 2 +- Descriptors/JSONDescriptor.h | 2 +- Extractor/ExtractorStructs.h | 5 +- Plugins/BasePlugin.h | 2 +- Plugins/LocatePlugin.h | 2 +- Plugins/RawRouteData.h | 2 +- Plugins/RouteParameters.h | 4 +- Tools/simpleclient.cpp | 4 +- 21 files changed, 113 insertions(+), 92 deletions(-) diff --git a/Algorithms/PolylineCompressor.h b/Algorithms/PolylineCompressor.h index db90ef6ff..3e14c6639 100644 --- a/Algorithms/PolylineCompressor.h +++ b/Algorithms/PolylineCompressor.h @@ -56,11 +56,14 @@ private: } public: - inline void printEncodedString(const std::vector& polyline, std::string &output) const { + inline void printEncodedString( + const std::vector & polyline, + std::string & output + ) const { std::vector deltaNumbers; output += "\""; if(!polyline.empty()) { - _Coordinate lastCoordinate = polyline[0].location; + FixedPointCoordinate lastCoordinate = polyline[0].location; deltaNumbers.push_back( lastCoordinate.lat ); deltaNumbers.push_back( lastCoordinate.lon ); for(unsigned i = 1; i < polyline.size(); ++i) { @@ -76,7 +79,7 @@ public: } - inline void printEncodedString(const std::vector<_Coordinate>& polyline, std::string &output) const { + inline void printEncodedString(const std::vector& polyline, std::string &output) const { std::vector deltaNumbers(2*polyline.size()); output += "\""; if(!polyline.empty()) { @@ -91,7 +94,7 @@ public: output += "\""; } - inline void printUnencodedString(std::vector<_Coordinate> & polyline, std::string & output) const { + inline void printUnencodedString(std::vector & polyline, std::string & output) const { output += "["; std::string tmp; for(unsigned i = 0; i < polyline.size(); i++) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index c6d138040..9f6e64bee 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -22,8 +22,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( int nodes, std::vector & inputEdges, - std::vector & bn, - std::vector & tl, + std::vector & barrier_node_list, + std::vector & traffic_light_node_list, std::vector & input_restrictions_list, std::vector & inputNodeInfoList, SpeedProfileProperties speedProfile @@ -54,8 +54,15 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); } - _barrierNodes.insert(bn.begin(), bn.end()); - _trafficLights.insert(tl.begin(), tl.end()); + _barrierNodes.insert( + barrier_node_list.begin(), + barrier_node_list.end() + ); + + _trafficLights.insert( + traffic_light_node_list.begin(), + traffic_light_node_list.end() + ); DeallocatingVector< _NodeBasedEdge > edges; _NodeBasedEdge edge; diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index c53d69464..05b8462b3 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -75,8 +75,8 @@ public: return id == other.id; } - inline _Coordinate Centroid() const { - _Coordinate centroid; + inline FixedPointCoordinate Centroid() const { + FixedPointCoordinate centroid; //The coordinates of the midpoint are given by: //x = (x1 + x2) /2 and y = (y1 + y2) /2. centroid.lon = (std::min(lon1, lon2) + std::max(lon1, lon2))/2; @@ -87,6 +87,7 @@ public: inline bool isIgnored() const { return ignoreInGrid; } + NodeID id; int lat1; int lat2; diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h index 47008d65f..a701f80db 100644 --- a/DataStructures/Coordinate.h +++ b/DataStructures/Coordinate.h @@ -18,8 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -#ifndef COORDINATE_H_ -#define COORDINATE_H_ +#ifndef FIXED_POINT_COORDINATE_H_ +#define FIXED_POINT_COORDINATE_H_ #include "../Util/StringUtil.h" @@ -31,11 +31,11 @@ or see http://www.gnu.org/licenses/agpl.txt. static const double COORDINATE_PRECISION = 1000000.; -struct _Coordinate { +struct FixedPointCoordinate { int lat; int lon; - _Coordinate () : lat(INT_MIN), lon(INT_MIN) {} - explicit _Coordinate (int t, int n) : lat(t) , lon(n) {} + FixedPointCoordinate () : lat(INT_MIN), lon(INT_MIN) {} + explicit FixedPointCoordinate (int t, int n) : lat(t) , lon(n) {} void Reset() { lat = INT_MIN; @@ -55,12 +55,12 @@ struct _Coordinate { } return true; } - bool operator==(const _Coordinate & other) const { + bool operator==(const FixedPointCoordinate & other) const { return lat == other.lat && lon == other.lon; } }; -inline std::ostream & operator<<(std::ostream & out, const _Coordinate & c){ +inline std::ostream & operator<<(std::ostream & out, const FixedPointCoordinate & c){ out << "(" << c.lat << "," << c.lon << ")"; return out; } @@ -93,11 +93,11 @@ inline double ApproximateDistance( const int lat1, const int lon1, const int lat return distance; } -inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) { +inline double ApproximateDistance(const FixedPointCoordinate &c1, const FixedPointCoordinate &c2) { return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon ); } -inline double ApproximateEuclideanDistance(const _Coordinate &c1, const _Coordinate &c2) { +inline double ApproximateEuclideanDistance(const FixedPointCoordinate &c1, const FixedPointCoordinate &c2) { assert(c1.lat != INT_MIN); assert(c1.lon != INT_MIN); assert(c2.lat != INT_MIN); @@ -122,7 +122,7 @@ static inline void convertInternalLatLonToString(const int value, std::string & output = string; } -static inline void convertInternalCoordinateToString(const _Coordinate & coord, std::string & output) { +static inline void convertInternalCoordinateToString(const FixedPointCoordinate & coord, std::string & output) { std::string tmp; convertInternalLatLonToString(coord.lon, tmp); output = tmp; @@ -131,7 +131,7 @@ static inline void convertInternalCoordinateToString(const _Coordinate & coord, output += tmp; output += " "; } -static inline void convertInternalReversedCoordinateToString(const _Coordinate & coord, std::string & output) { +static inline void convertInternalReversedCoordinateToString(const FixedPointCoordinate & coord, std::string & output) { std::string tmp; convertInternalLatLonToString(coord.lat, tmp); output = tmp; @@ -141,4 +141,4 @@ static inline void convertInternalReversedCoordinateToString(const _Coordinate & output += " "; } -#endif /* COORDINATE_H_ */ +#endif /* FIXED_POINT_COORDINATE_H_ */ diff --git a/DataStructures/HilbertValue.h b/DataStructures/HilbertValue.h index 8b64a505b..f73396928 100644 --- a/DataStructures/HilbertValue.h +++ b/DataStructures/HilbertValue.h @@ -31,7 +31,8 @@ or see http://www.gnu.org/licenses/agpl.txt. class HilbertCode : boost::noncopyable { public: static uint64_t GetHilbertNumberForCoordinate( - const _Coordinate & current_coordinate) { + const FixedPointCoordinate & current_coordinate + ) { unsigned location[2]; location[0] = current_coordinate.lat+( 90*COORDINATE_PRECISION); location[1] = current_coordinate.lon+(180*COORDINATE_PRECISION); diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 581287cd5..7d638be3b 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -107,8 +107,8 @@ public: } inline bool FindNearestNodeCoordForLatLon( - const _Coordinate& input_coordinate, - _Coordinate& result, + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, const unsigned zoom_level = 18 ) const { PhantomNode resulting_phantom_node; @@ -121,7 +121,7 @@ public: } inline bool FindPhantomNodeForCoordinate( - const _Coordinate & input_coordinate, + const FixedPointCoordinate & input_coordinate, PhantomNode & resulting_phantom_node, const unsigned zoom_level ) const { @@ -164,9 +164,9 @@ private: NodeInfo b; while(!nodes_input_stream.eof()) { nodes_input_stream.read((char *)&b, sizeof(NodeInfo)); - coordinateVector.push_back(_Coordinate(b.lat, b.lon)); + coordinateVector.push_back(FixedPointCoordinate(b.lat, b.lon)); } - std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); + std::vector(coordinateVector).swap(coordinateVector); nodes_input_stream.close(); SimpleLogger().Write(logDEBUG) << "Loading edge data"; @@ -191,7 +191,7 @@ private: SimpleLogger().Write(logDEBUG) << "Opening NN indices"; } - std::vector<_Coordinate> coordinateVector; + std::vector coordinateVector; std::vector origEdgeData_viaNode; std::vector origEdgeData_nameID; std::vector origEdgeData_turnInstruction; diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 2827d7a91..d48d61797 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -24,13 +24,20 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Coordinate.h" struct PhantomNode { - PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX), ratio(0.) {} + PhantomNode() : + edgeBasedNode(UINT_MAX), + nodeBasedEdgeNameID(UINT_MAX), + weight1(INT_MAX), + weight2(INT_MAX), + ratio(0.) + { } + NodeID edgeBasedNode; unsigned nodeBasedEdgeNameID; int weight1; int weight2; double ratio; - _Coordinate location; + FixedPointCoordinate location; void Reset() { edgeBasedNode = UINT_MAX; nodeBasedEdgeNameID = UINT_MAX; @@ -88,7 +95,7 @@ inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn){ struct NodesOfEdge { NodeID edgeBasedNode; double ratio; - _Coordinate projectedPoint; + FixedPointCoordinate projectedPoint; }; #endif /* PHANTOMNODES_H_ */ diff --git a/DataStructures/SearchEngine.cpp b/DataStructures/SearchEngine.cpp index 2a538a7ac..f3e79aa63 100644 --- a/DataStructures/SearchEngine.cpp +++ b/DataStructures/SearchEngine.cpp @@ -33,14 +33,14 @@ SearchEngine::SearchEngine( void SearchEngine::GetCoordinatesForNodeID( NodeID id, - _Coordinate& result + FixedPointCoordinate& result ) const { result.lat = _queryData.nodeHelpDesk->getLatitudeOfNode(id); result.lon = _queryData.nodeHelpDesk->getLongitudeOfNode(id); } void SearchEngine::FindPhantomNodeForCoordinate( - const _Coordinate & location, + const FixedPointCoordinate & location, PhantomNode & result, const unsigned zoomLevel ) const { diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 64d273bb0..14cbd975e 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -45,17 +45,17 @@ public: AlternativeRouting alternativePaths; SearchEngine( - QueryGraph * g, - NodeInformationHelpDesk * nh, + QueryGraph * g, + NodeInformationHelpDesk * nh, std::vector & n ); ~SearchEngine(); - void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const; + void GetCoordinatesForNodeID(NodeID id, FixedPointCoordinate& result) const; void FindPhantomNodeForCoordinate( - const _Coordinate & location, - PhantomNode & result, + const FixedPointCoordinate & location, + PhantomNode & result, unsigned zoomLevel ) const; diff --git a/DataStructures/SegmentInformation.h b/DataStructures/SegmentInformation.h index 8f65eda72..20e5e05d8 100644 --- a/DataStructures/SegmentInformation.h +++ b/DataStructures/SegmentInformation.h @@ -27,16 +27,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #include struct SegmentInformation { - _Coordinate location; + FixedPointCoordinate location; NodeID nameID; double length; unsigned duration; double bearing; TurnInstruction turnInstruction; bool necessary; - SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) : + SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) : location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {} - SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) : + SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) : location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {} }; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 57c099b98..603e7b3d4 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -100,8 +100,8 @@ private: max_lat = std::max(max_lat, other.max_lat); } - inline _Coordinate Centroid() const { - _Coordinate centroid; + inline FixedPointCoordinate Centroid() const { + FixedPointCoordinate centroid; //The coordinates of the midpoints are given by: //x = (x1 + x2) /2 and y = (y1 + y2) /2. centroid.lon = (min_lon + max_lon)/2; @@ -110,10 +110,10 @@ private: } inline bool Intersects(const RectangleInt2D & other) const { - _Coordinate upper_left (other.max_lat, other.min_lon); - _Coordinate upper_right(other.max_lat, other.max_lon); - _Coordinate lower_right(other.min_lat, other.max_lon); - _Coordinate lower_left (other.min_lat, other.min_lon); + FixedPointCoordinate upper_left (other.max_lat, other.min_lon); + FixedPointCoordinate upper_right(other.max_lat, other.max_lon); + FixedPointCoordinate lower_right(other.min_lat, other.max_lon); + FixedPointCoordinate lower_left (other.min_lat, other.min_lon); return ( Contains(upper_left) @@ -123,7 +123,7 @@ private: ); } - inline double GetMinDist(const _Coordinate & location) const { + inline double GetMinDist(const FixedPointCoordinate & location) const { bool is_contained = Contains(location); if (is_contained) { return 0.0; @@ -169,13 +169,13 @@ private: return min_dist; } - inline double GetMinMaxDist(const _Coordinate & location) const { + inline double GetMinMaxDist(const FixedPointCoordinate & location) const { double min_max_dist = DBL_MAX; //Get minmax distance to each of the four sides - _Coordinate upper_left (max_lat, min_lon); - _Coordinate upper_right(max_lat, max_lon); - _Coordinate lower_right(min_lat, max_lon); - _Coordinate lower_left (min_lat, min_lon); + FixedPointCoordinate upper_left (max_lat, min_lon); + FixedPointCoordinate upper_right(max_lat, max_lon); + FixedPointCoordinate lower_right(min_lat, max_lon); + FixedPointCoordinate lower_left (min_lat, min_lon); min_max_dist = std::min( min_max_dist, @@ -211,7 +211,7 @@ private: return min_max_dist; } - inline bool Contains(const _Coordinate & location) const { + inline bool Contains(const FixedPointCoordinate & location) const { bool lats_contained = (location.lat > min_lat) && (location.lat < max_lat); bool lons_contained = @@ -303,7 +303,7 @@ public: input_wrapper_vector[element_counter].m_array_index = element_counter; //Get Hilbert-Value for centroid in mercartor projection DataT & current_element = input_data_vector[element_counter]; - _Coordinate current_centroid = current_element.Centroid(); + FixedPointCoordinate current_centroid = current_element.Centroid(); current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION); uint64_t current_hilbert_value = HilbertCode::GetHilbertNumberForCoordinate(current_centroid); @@ -449,7 +449,7 @@ public: } /* inline void FindKNearestPhantomNodesForCoordinate( - const _Coordinate & location, + const FixedPointCoordinate & location, const unsigned zoom_level, const unsigned candidate_count, std::vector > & result_vector @@ -465,7 +465,7 @@ public: double min_max_dist = DBL_MAX; bool found_a_nearest_edge = false; - _Coordinate nearest, current_start_coordinate, current_end_coordinate; + FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate; //initialize queue with root element std::priority_queue traversal_queue; @@ -493,8 +493,8 @@ public: double current_ratio = 0.; double current_perpendicular_distance = ComputePerpendicularDistance( input_coordinate, - _Coordinate(current_edge.lat1, current_edge.lon1), - _Coordinate(current_edge.lat2, current_edge.lon2), + FixedPointCoordinate(current_edge.lat1, current_edge.lon1), + FixedPointCoordinate(current_edge.lat2, current_edge.lon2), nearest, ¤t_ratio ); @@ -523,11 +523,11 @@ public: 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) && CoordinatesAreEquivalent( current_start_coordinate, - _Coordinate( + FixedPointCoordinate( current_edge.lat1, current_edge.lon1 ), - _Coordinate( + FixedPointCoordinate( current_edge.lat2, current_edge.lon2 ), @@ -563,14 +563,14 @@ public: const double distance_to_edge = ApproximateDistance ( - _Coordinate(nearest_edge.lat1, nearest_edge.lon1), + FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1), result_phantom_node.location ); const double length_of_edge = ApproximateDistance( - _Coordinate(nearest_edge.lat1, nearest_edge.lon1), - _Coordinate(nearest_edge.lat2, nearest_edge.lon2) + FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1), + FixedPointCoordinate(nearest_edge.lat2, nearest_edge.lon2) ); const double ratio = (found_a_nearest_edge ? @@ -596,7 +596,7 @@ public: */ bool FindPhantomNodeForCoordinate( - const _Coordinate & input_coordinate, + const FixedPointCoordinate & input_coordinate, PhantomNode & result_phantom_node, const unsigned zoom_level ) { @@ -611,7 +611,7 @@ public: double min_max_dist = DBL_MAX; bool found_a_nearest_edge = false; - _Coordinate nearest, current_start_coordinate, current_end_coordinate; + FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate; //initialize queue with root element std::priority_queue traversal_queue; @@ -650,8 +650,8 @@ public: double current_ratio = 0.; double current_perpendicular_distance = ComputePerpendicularDistance( input_coordinate, - _Coordinate(current_edge.lat1, current_edge.lon1), - _Coordinate(current_edge.lat2, current_edge.lon2), + FixedPointCoordinate(current_edge.lat1, current_edge.lon1), + FixedPointCoordinate(current_edge.lat2, current_edge.lon2), nearest, ¤t_ratio ); @@ -680,11 +680,11 @@ public: 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) && CoordinatesAreEquivalent( current_start_coordinate, - _Coordinate( + FixedPointCoordinate( current_edge.lat1, current_edge.lon1 ), - _Coordinate( + FixedPointCoordinate( current_edge.lat2, current_edge.lon2 ), @@ -768,10 +768,10 @@ private: } inline double ComputePerpendicularDistance( - const _Coordinate& inputPoint, - const _Coordinate& source, - const _Coordinate& target, - _Coordinate& nearest, double *r) const { + const FixedPointCoordinate& inputPoint, + const FixedPointCoordinate& source, + const FixedPointCoordinate& target, + FixedPointCoordinate& nearest, double *r) const { const double x = static_cast(inputPoint.lat); const double y = static_cast(inputPoint.lon); const double a = static_cast(source.lat); @@ -815,7 +815,7 @@ private: return (p-x)*(p-x) + (q-y)*(q-y); } - inline bool CoordinatesAreEquivalent(const _Coordinate & a, const _Coordinate & b, const _Coordinate & c, const _Coordinate & d) const { + inline bool CoordinatesAreEquivalent(const FixedPointCoordinate & a, const FixedPointCoordinate & b, const FixedPointCoordinate & c, const FixedPointCoordinate & d) const { return (a == b && c == d) || (a == c && b == d) || (a == d && b == c); } diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 692dc31cb..1acf83a66 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -32,7 +32,10 @@ inline double DescriptionFactory::RadianToDegree(const double radian) const { return radian * (180/M_PI); } -double DescriptionFactory::GetBearing(const _Coordinate& A, const _Coordinate& B) const { +double DescriptionFactory::GetBearing( + const FixedPointCoordinate & A, + const FixedPointCoordinate & B +) const { double deltaLong = DegreeToRadian(B.lon/COORDINATE_PRECISION - A.lon/COORDINATE_PRECISION); double lat1 = DegreeToRadian(A.lat/COORDINATE_PRECISION); @@ -59,7 +62,7 @@ void DescriptionFactory::SetEndSegment(const PhantomNode & _targetPhantom) { pathDescription.push_back(SegmentInformation(_targetPhantom.location, _targetPhantom.nodeBasedEdgeNameID, 0, _targetPhantom.weight1, 0, true) ); } -void DescriptionFactory::AppendSegment(const _Coordinate & coordinate, const _PathData & data ) { +void DescriptionFactory::AppendSegment(const FixedPointCoordinate & coordinate, const _PathData & data ) { if(1 == pathDescription.size() && pathDescription.back().location == coordinate) { pathDescription.back().nameID = data.nameID; } else { diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 36071e492..68182a881 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -63,10 +63,10 @@ public: std::vector pathDescription; DescriptionFactory(); virtual ~DescriptionFactory(); - double GetBearing(const _Coordinate& C, const _Coordinate& B) const; + double GetBearing(const FixedPointCoordinate& C, const FixedPointCoordinate& B) const; void AppendEncodedPolylineString(std::string &output); void AppendUnencodedPolylineString(std::string &output); - void AppendSegment(const _Coordinate & coordinate, const _PathData & data); + void AppendSegment(const FixedPointCoordinate & coordinate, const _PathData & data); void BuildRouteSummary(const double distance, const unsigned time); void SetStartSegment(const PhantomNode & startPhantom); void SetEndSegment(const PhantomNode & startPhantom); diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index f4a8190c5..9c3caa77b 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -28,7 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class GPXDescriptor : public BaseDescriptor{ private: _DescriptorConfig config; - _Coordinate current; + FixedPointCoordinate current; std::string tmp; public: diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index da7afcbb8..a45d478ed 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -39,7 +39,7 @@ private: _DescriptorConfig config; DescriptionFactory descriptionFactory; DescriptionFactory alternateDescriptionFactory; - _Coordinate current; + FixedPointCoordinate current; unsigned numberOfEnteredRestrictedAreas; struct RoundAbout{ RoundAbout() : diff --git a/Extractor/ExtractorStructs.h b/Extractor/ExtractorStructs.h index 108acf97d..778778ed0 100644 --- a/Extractor/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -21,7 +21,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EXTRACTORSTRUCTS_H_ #define EXTRACTORSTRUCTS_H_ - #include "../DataStructures/Coordinate.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportNode.h" @@ -110,8 +109,8 @@ struct InternalExtractorEdge { bool isAccessRestricted; bool isContraFlow; - _Coordinate startCoord; - _Coordinate targetCoord; + FixedPointCoordinate startCoord; + FixedPointCoordinate targetCoord; static InternalExtractorEdge min_value() { return InternalExtractorEdge(0,0); diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index d8956d022..4985719b5 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -36,7 +36,7 @@ public: virtual const std::string & GetDescriptor() const = 0; virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0; - inline bool checkCoord(const _Coordinate & c) { + inline bool checkCoord(const FixedPointCoordinate & c) { if( c.lat > 90*COORDINATE_PRECISION || c.lat < -90*COORDINATE_PRECISION || diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index e6f59159e..8a1c9af91 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -48,7 +48,7 @@ public: } //query to helpdesk - _Coordinate result; + FixedPointCoordinate result; std::string tmp; //json diff --git a/Plugins/RawRouteData.h b/Plugins/RawRouteData.h index f0c105486..e43e22c62 100644 --- a/Plugins/RawRouteData.h +++ b/Plugins/RawRouteData.h @@ -35,7 +35,7 @@ struct RawRouteData { std::vector< _PathData > computedShortestPath; std::vector< _PathData > computedAlternativePath; std::vector< PhantomNodes > segmentEndCoordinates; - std::vector< _Coordinate > rawViaNodeCoordinates; + std::vector< FixedPointCoordinate > rawViaNodeCoordinates; unsigned checkSum; int lengthOfShortestPath; int lengthOfAlternativePath; diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index e4455f839..ecef68f24 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -52,7 +52,7 @@ struct RouteParameters { std::string jsonpParameter; std::string language; std::vector hints; - std::vector<_Coordinate> coordinates; + std::vector coordinates; typedef HashTable::const_iterator OptionsIterator; void setZoomLevel(const short i) { @@ -109,7 +109,7 @@ struct RouteParameters { void addCoordinate(const boost::fusion::vector < double, double > & arg_) { int lat = COORDINATE_PRECISION*boost::fusion::at_c < 0 > (arg_); int lon = COORDINATE_PRECISION*boost::fusion::at_c < 1 > (arg_); - coordinates.push_back(_Coordinate(lat, lon)); + coordinates.push_back(FixedPointCoordinate(lat, lon)); } }; diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index d7cc5c08f..a4588a5db 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -65,8 +65,8 @@ int main (int argc, char * argv[]) { route_parameters.language = ""; //unused atm //route_parameters.hints.push_back(); // see wiki, saves I/O if done properly - _Coordinate start_coordinate(52.519930*COORDINATE_PRECISION,13.438640*COORDINATE_PRECISION); - _Coordinate target_coordinate(52.513191*COORDINATE_PRECISION,13.415852*COORDINATE_PRECISION); + FixedPointCoordinate start_coordinate(52.519930*COORDINATE_PRECISION,13.438640*COORDINATE_PRECISION); + FixedPointCoordinate target_coordinate(52.513191*COORDINATE_PRECISION,13.415852*COORDINATE_PRECISION); route_parameters.coordinates.push_back(start_coordinate); route_parameters.coordinates.push_back(target_coordinate); From 06c8656b9ed4d82313855bc62838fe9ece1a4eb1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 13:41:23 +0200 Subject: [PATCH 75/80] Moving DataStructures out of Plugin directory --- {Plugins => DataStructures}/RawRouteData.h | 4 ++++ Plugins/BasePlugin.h | 2 +- Plugins/HelloWorldPlugin.h | 1 - Plugins/LocatePlugin.h | 1 - Plugins/NearestPlugin.h | 1 - Plugins/TimestampPlugin.h | 1 - Plugins/ViaRoutePlugin.h | 1 - RoutingAlgorithms/BasicRoutingInterface.h | 2 +- {Plugins => Server/DataStructures}/RouteParameters.h | 4 ++-- 9 files changed, 8 insertions(+), 9 deletions(-) rename {Plugins => DataStructures}/RawRouteData.h (93%) rename {Plugins => Server/DataStructures}/RouteParameters.h (97%) diff --git a/Plugins/RawRouteData.h b/DataStructures/RawRouteData.h similarity index 93% rename from Plugins/RawRouteData.h rename to DataStructures/RawRouteData.h index e43e22c62..7607e3300 100644 --- a/Plugins/RawRouteData.h +++ b/DataStructures/RawRouteData.h @@ -21,8 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef RAWROUTEDATA_H_ #define RAWROUTEDATA_H_ +#include "../DataStructures/Coordinate.h" +#include "../DataStructures/PhantomNodes.h" #include "../typedefs.h" +#include + struct _PathData { _PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), nameID(na), durationOfSegment(dur), turnInstruction(tu) { } NodeID node; diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index 4985719b5..f359942af 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -21,9 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASEPLUGIN_H_ #define BASEPLUGIN_H_ -#include "RouteParameters.h" #include "../DataStructures/Coordinate.h" #include "../Server/BasicDatastructures.h" +#include "../Server/DataStructures/RouteParameters.h" #include #include diff --git a/Plugins/HelloWorldPlugin.h b/Plugins/HelloWorldPlugin.h index 546789b1e..7c2987ecf 100644 --- a/Plugins/HelloWorldPlugin.h +++ b/Plugins/HelloWorldPlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define HELLOWORLDPLUGIN_H_ #include "BasePlugin.h" -#include "RouteParameters.h" #include diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 8a1c9af91..c1c69c009 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define LOCATEPLUGIN_H_ #include "BasePlugin.h" -#include "RouteParameters.h" #include "../DataStructures/NodeInformationHelpDesk.h" #include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index a1ca3537e..89bbc86e5 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define NearestPlugin_H_ #include "BasePlugin.h" -#include "RouteParameters.h" #include "../DataStructures/NodeInformationHelpDesk.h" #include "../Server/DataStructures/QueryObjectsStorage.h" diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 6142cb825..ba0510c3e 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define TIMESTAMPPLUGIN_H_ #include "BasePlugin.h" -#include "RouteParameters.h" class TimestampPlugin : public BasePlugin { public: diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 46f17bb3b..847a32a9f 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define VIAROUTEPLUGIN_H_ #include "BasePlugin.h" -#include "RouteParameters.h" #include "../Algorithms/ObjectToBase64.h" #include "../DataStructures/HashTable.h" diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 67615a89d..cb956b504 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASICROUTINGINTERFACE_H_ #define BASICROUTINGINTERFACE_H_ -#include "../Plugins/RawRouteData.h" +#include "../DataStructures/RawRouteData.h" #include "../Util/ContainerUtils.h" #include "../Util/SimpleLogger.h" diff --git a/Plugins/RouteParameters.h b/Server/DataStructures/RouteParameters.h similarity index 97% rename from Plugins/RouteParameters.h rename to Server/DataStructures/RouteParameters.h index ecef68f24..f46a20a10 100644 --- a/Plugins/RouteParameters.h +++ b/Server/DataStructures/RouteParameters.h @@ -21,8 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef ROUTE_PARAMETERS_H #define ROUTE_PARAMETERS_H -#include "../DataStructures/Coordinate.h" -#include "../DataStructures/HashTable.h" +#include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/HashTable.h" #include #include From c2f9467f61795a6ba21b1d63381b890bc5e0cf61 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 13:54:59 +0200 Subject: [PATCH 76/80] Moving DataStructures out of Plugin directory --- Descriptors/BaseDescriptor.h | 3 ++- Library/OSRM.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 64d776cb3..0d1359a10 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -23,8 +23,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/HashTable.h" #include "../DataStructures/PhantomNodes.h" +#include "../DataStructures/RawRouteData.h" #include "../DataStructures/SearchEngine.h" -#include "../Plugins/RawRouteData.h" +#include "../Server/BasicDatastructures.h" #include "../Util/StringUtil.h" #include "../typedefs.h" diff --git a/Library/OSRM.h b/Library/OSRM.h index 7647f72c3..bb3caa7d9 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -29,7 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/NearestPlugin.h" #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" -#include "../Plugins/RouteParameters.h" +#include "../Server/DataStructures/RouteParameters.h" #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" #include "../Util/OSRMException.h" From 311c50df9f1d60dd7c68eba501961f21a4e5ddb5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 13:57:57 +0200 Subject: [PATCH 77/80] Moving DataStructures out of Plugin directory --- Server/RequestHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 0105703b3..56ce787ad 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -23,8 +23,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "APIGrammar.h" #include "BasicDatastructures.h" +#include "DataStructures/RouteParameters.h" #include "../Library/OSRM.h" -#include "../Plugins/RouteParameters.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include "../typedefs.h" From b01e30acfd1e3f636c524986fae4066bbdc19385 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 14:09:42 +0200 Subject: [PATCH 78/80] Moving DataStructures out of Plugin directory --- Server/RequestHandler.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 56ce787ad..af2217f7b 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -47,25 +47,35 @@ public: try { std::string request(req.uri); - { //This block logs the current request to std out. should be moved to a logging component - time_t ltime; - struct tm *Tm; + time_t ltime; + struct tm *Tm; - ltime=time(NULL); - Tm=localtime(<ime); + ltime=time(NULL); + Tm=localtime(<ime); - SimpleLogger().Write() << (Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << (Tm->tm_mon+1 < 10 ? "0" : "" ) << (Tm->tm_mon+1) << "-" << 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " << - req.endpoint.to_string() << " " << req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri; - } + SimpleLogger().Write() << + (Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << + (Tm->tm_mon+1 < 10 ? "0" : "" ) << (Tm->tm_mon+1) << "-" << + 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << + Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << + Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << + Tm->tm_sec << " " << req.endpoint.to_string() << " " << + req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << + req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri; RouteParameters routeParameters; APIGrammarParser apiParser(&routeParameters); std::string::iterator it = request.begin(); - bool result = boost::spirit::qi::parse(it, request.end(), apiParser); - if (!result || (it != request.end()) ) { + const bool result = boost::spirit::qi::parse( + it, + request.end(), + apiParser + ); + + if ( !result || (it != request.end()) ) { rep = http::Reply::stockReply(http::Reply::badRequest); - int position = std::distance(request.begin(), it); + const int position = std::distance(request.begin(), it); std::string tmp_position_string; intToString(position, tmp_position_string); rep.content += "Input seems to be malformed close to position "; @@ -73,7 +83,7 @@ public: rep.content += request; rep.content += tmp_position_string; rep.content += "
"; - unsigned end = std::distance(request.begin(), it); + const unsigned end = std::distance(request.begin(), it); for(unsigned i = 0; i < end; ++i) { rep.content += " "; } From 0a0bed7ae0b27f8ce2c634aba46553325384db44 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 14 Aug 2013 18:43:01 +0200 Subject: [PATCH 79/80] Refactoring graph factory --- Contractor/EdgeBasedGraphFactory.cpp | 513 ++++++++++++++++----------- Contractor/EdgeBasedGraphFactory.h | 108 +++--- DataStructures/Coordinate.h | 21 +- DataStructures/QueryEdge.h | 2 - 4 files changed, 396 insertions(+), 248 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 9f6e64bee..cd87a4e69 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -21,52 +21,56 @@ #include "EdgeBasedGraphFactory.h" EdgeBasedGraphFactory::EdgeBasedGraphFactory( - int nodes, std::vector & inputEdges, + int number_of_nodes, + std::vector & input_edge_list, std::vector & barrier_node_list, std::vector & traffic_light_node_list, std::vector & input_restrictions_list, - std::vector & inputNodeInfoList, - SpeedProfileProperties speedProfile -) : speedProfile(speedProfile), + std::vector & m_node_info_list, + SpeedProfileProperties speed_profile +) : speed_profile(speed_profile), m_turn_restrictions_count(0), - inputNodeInfoList(inputNodeInfoList) + m_node_info_list(m_node_info_list) { BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { - std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); + std::pair restriction_source = + std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; - RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource); - if(restrIter == _restrictionMap.end()) { - index = _restrictionBucketVector.size(); - _restrictionBucketVector.resize(index+1); - _restrictionMap[restrictionSource] = index; + RestrictionMap::iterator restriction_iter = m_restriction_map.find(restriction_source); + if(restriction_iter == m_restriction_map.end()) { + index = m_restriction_bucket_list.size(); + m_restriction_bucket_list.resize(index+1); + m_restriction_map[restriction_source] = index; } else { - index = restrIter->second; + index = restriction_iter->second; //Map already contains an is_only_*-restriction - if(_restrictionBucketVector.at(index).begin()->second) + if(m_restriction_bucket_list.at(index).begin()->second) { continue; - else if(restriction.flags.isOnly){ + } else if(restriction.flags.isOnly) { //We are going to insert an is_only_*-restriction. There can be only one. - m_turn_restrictions_count -= _restrictionBucketVector.at(index).size(); - _restrictionBucketVector.at(index).clear(); + m_turn_restrictions_count -= m_restriction_bucket_list.at(index).size(); + m_restriction_bucket_list.at(index).clear(); } } ++m_turn_restrictions_count; - _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); + m_restriction_bucket_list.at(index).push_back( + std::make_pair( restriction.toNode, restriction.flags.isOnly) + ); } - _barrierNodes.insert( + m_barrier_nodes.insert( barrier_node_list.begin(), barrier_node_list.end() ); - _trafficLights.insert( + m_traffic_lights.insert( traffic_light_node_list.begin(), traffic_light_node_list.end() ); - DeallocatingVector< _NodeBasedEdge > edges; - _NodeBasedEdge edge; - BOOST_FOREACH(const ImportEdge & import_edge, inputEdges) { + DeallocatingVector< NodeBasedEdge > edges_list; + NodeBasedEdge edge; + BOOST_FOREACH(const ImportEdge & import_edge, input_edge_list) { if(!import_edge.isForward()) { edge.source = import_edge.target(); edge.target = import_edge.source(); @@ -89,139 +93,189 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( edge.data.nameID = import_edge.name(); edge.data.type = import_edge.type(); edge.data.isAccessRestricted = import_edge.isAccessRestricted(); - edge.data.edgeBasedNodeID = edges.size(); + edge.data.edgeBasedNodeID = edges_list.size(); edge.data.contraFlow = import_edge.isContraFlow(); - edges.push_back( edge ); + edges_list.push_back( edge ); if( edge.data.backward ) { std::swap( edge.source, edge.target ); edge.data.forward = import_edge.isBackward(); edge.data.backward = import_edge.isForward(); - edge.data.edgeBasedNodeID = edges.size(); - edges.push_back( edge ); + edge.data.edgeBasedNodeID = edges_list.size(); + edges_list.push_back( edge ); } } - std::vector().swap(inputEdges); - std::sort( edges.begin(), edges.end() ); - _nodeBasedGraph = boost::make_shared<_NodeBasedDynamicGraph>( nodes, edges ); + std::vector().swap(input_edge_list); + std::sort( edges_list.begin(), edges_list.end() ); + m_node_based_graph = boost::make_shared( + number_of_nodes, edges_list + ); } -void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector< EdgeBasedEdge >& outputEdgeList ) { +void EdgeBasedGraphFactory::GetEdgeBasedEdges( + DeallocatingVector< EdgeBasedEdge >& output_edge_list +) { BOOST_ASSERT_MSG( - 0 == outputEdgeList.size(), + 0 == output_edge_list.size(), "Vector is not empty" ); - edgeBasedEdges.swap(outputEdgeList); + m_edge_based_edge_list.swap(output_edge_list); } void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & nodes) { #ifndef NDEBUG - BOOST_FOREACH(const EdgeBasedNode & node, edgeBasedNodes){ + BOOST_FOREACH(const EdgeBasedNode & node, m_edge_based_node_list){ assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX); assert(node.lat2 != INT_MAX); assert(node.lon2 != INT_MAX); } #endif - nodes.swap(edgeBasedNodes); + nodes.swap(m_edge_based_node_list); } NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( const NodeID u, const NodeID v ) const { - const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); - RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); - if (restrIter != _restrictionMap.end()) { - const unsigned index = restrIter->second; - BOOST_FOREACH(const RestrictionSource & restrictionTarget, _restrictionBucketVector.at(index)) { - if(restrictionTarget.second) { - return restrictionTarget.first; + const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v); + RestrictionMap::const_iterator restriction_iter = m_restriction_map.find(restriction_source); + if (restriction_iter != m_restriction_map.end()) { + const unsigned index = restriction_iter->second; + BOOST_FOREACH( + const RestrictionSource & restriction_target, + m_restriction_bucket_list.at(index) + ) { + if(restriction_target.second) { + return restriction_target.first; } } } return UINT_MAX; } -bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const { +bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( + const NodeID u, + const NodeID v, + const NodeID w +) const { //only add an edge if turn is not a U-turn except it is the end of dead-end street. - const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); - RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); - if (restrIter != _restrictionMap.end()) { - const unsigned index = restrIter->second; - BOOST_FOREACH(const RestrictionTarget & restrictionTarget, _restrictionBucketVector.at(index)) { - if(w == restrictionTarget.first) + const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v); + RestrictionMap::const_iterator restriction_iter = m_restriction_map.find(restriction_source); + if (restriction_iter != m_restriction_map.end()) { + const unsigned index = restriction_iter->second; + BOOST_FOREACH( + const RestrictionTarget & restriction_target, + m_restriction_bucket_list.at(index) + ) { + if(w == restriction_target.first) { return true; + } } } return false; } void EdgeBasedGraphFactory::InsertEdgeBasedNode( - _NodeBasedDynamicGraph::EdgeIterator e1, - _NodeBasedDynamicGraph::NodeIterator u, - _NodeBasedDynamicGraph::NodeIterator v, + EdgeIterator e1, + NodeIterator u, + NodeIterator v, bool belongsToTinyComponent) { - _NodeBasedDynamicGraph::EdgeData & data = _nodeBasedGraph->GetEdgeData(e1); + EdgeData & data = m_node_based_graph->GetEdgeData(e1); EdgeBasedNode currentNode; currentNode.nameID = data.nameID; - currentNode.lat1 = inputNodeInfoList[u].lat; - currentNode.lon1 = inputNodeInfoList[u].lon; - currentNode.lat2 = inputNodeInfoList[v].lat; - currentNode.lon2 = inputNodeInfoList[v].lon; + currentNode.lat1 = m_node_info_list[u].lat; + currentNode.lon1 = m_node_info_list[u].lon; + currentNode.lat2 = m_node_info_list[v].lat; + currentNode.lon2 = m_node_info_list[v].lon; currentNode.belongsToTinyComponent = belongsToTinyComponent; currentNode.id = data.edgeBasedNodeID; currentNode.ignoreInGrid = data.ignoreInGrid; currentNode.weight = data.distance; - edgeBasedNodes.push_back(currentNode); + m_edge_based_node_list.push_back(currentNode); } -void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State *myLuaState) { - Percent p(_nodeBasedGraph->GetNumberOfNodes()); - int numberOfSkippedTurns(0); - int nodeBasedEdgeCounter(0); - unsigned numberOfOriginalEdges(0); - std::ofstream originalEdgeDataOutFile(originalEdgeDataFilename, std::ios::binary); - originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned)); +void EdgeBasedGraphFactory::Run( + const char * original_edge_data_filename, + lua_State *lua_state +) { + SimpleLogger().Write() << "Identifying components of the road network"; + Percent p(m_node_based_graph->GetNumberOfNodes()); + unsigned skipped_turns_counter = 0; + unsigned node_based_edge_counter = 0; + unsigned original_edges_counter = 0; - SimpleLogger().Write() << "Identifying small components"; + std::ofstream edge_data_file( + original_edge_data_filename, + std::ios::binary + ); + + //writes a dummy value that is updated later + edge_data_file.write( + (char*)&original_edges_counter, + sizeof(unsigned) + ); + + unsigned current_component = 0, current_component_size = 0; //Run a BFS on the undirected graph and identify small components - std::queue > bfsQueue; - std::vector componentsIndex(_nodeBasedGraph->GetNumberOfNodes(), UINT_MAX); - std::vector vectorOfComponentSizes; - unsigned currentComponent = 0, sizeOfCurrentComponent = 0; + std::queue > bfs_queue; + std::vector component_index_list( + m_node_based_graph->GetNumberOfNodes(), + UINT_MAX + ); + + std::vector component_size_list; //put unexplorered node with parent pointer into queue - for(NodeID node = 0, endNodes = _nodeBasedGraph->GetNumberOfNodes(); node < endNodes; ++node) { - if(UINT_MAX == componentsIndex[node]) { - bfsQueue.push(std::make_pair(node, node)); + for( + NodeID node = 0, + last_node = m_node_based_graph->GetNumberOfNodes(); + node < last_node; + ++node + ) { + if(UINT_MAX == component_index_list[node]) { + bfs_queue.push(std::make_pair(node, node)); //mark node as read - componentsIndex[node] = currentComponent; + component_index_list[node] = current_component; p.printIncrement(); - while(!bfsQueue.empty()) { + while(!bfs_queue.empty()) { //fetch element from BFS queue - std::pair currentQueueItem = bfsQueue.front(); - bfsQueue.pop(); - // SimpleLogger().Write() << "sizeof queue: " << bfsQueue.size() << ", sizeOfCurrentComponents: " << sizeOfCurrentComponent << ", settled nodes: " << settledNodes++ << ", max: " << endNodes; - const NodeID v = currentQueueItem.first; //current node - const NodeID u = currentQueueItem.second; //parent + std::pair current_queue_item = bfs_queue.front(); + bfs_queue.pop(); + // SimpleLogger().Write() << "sizeof queue: " << bfs_queue.size() << + // ", current_component_sizes: " << current_component_size << + //", settled nodes: " << settledNodes++ << ", max: " << endNodes; + const NodeID v = current_queue_item.first; //current node + const NodeID u = current_queue_item.second; //parent //increment size counter of current component - ++sizeOfCurrentComponent; - const bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end()); - if(!isBollardNode) { - const NodeID onlyToNode = CheckForEmanatingIsOnlyTurn(u, v); + ++current_component_size; + const bool is_barrier_node = (m_barrier_nodes.find(v) != m_barrier_nodes.end()); + if(!is_barrier_node) { + const NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v); //relaxieren edge outgoing edge like below where edge-expanded graph - for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { - _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2); + for( + EdgeIterator e2 = m_node_based_graph->BeginEdges(v); + e2 < m_node_based_graph->EndEdges(v); + ++e2 + ) { + NodeIterator w = m_node_based_graph->GetTarget(e2); - if(onlyToNode != UINT_MAX && w != onlyToNode) { //We are at an only_-restriction but not at the right turn. + if( + to_node_of_only_restriction != UINT_MAX && + w != to_node_of_only_restriction + ) { + //We are at an only_-restriction but not at the right turn. continue; } - if( u != w ) { //only add an edge if turn is not a U-turn except it is the end of dead-end street. - if (!CheckIfTurnIsRestricted(u, v, w) ) { //only add an edge if turn is not prohibited - //insert next (node, parent) only if w has not yet been explored - if(UINT_MAX == componentsIndex[w]) { + if( u != w ) { + //only add an edge if turn is not a U-turn except + //when it is at the end of a dead-end street. + if (!CheckIfTurnIsRestricted(u, v, w) ) { + //only add an edge if turn is not prohibited + if(UINT_MAX == component_index_list[w]) { + //insert next (node, parent) only if w has + //not yet been explored //mark node as read - componentsIndex[w] = currentComponent; - bfsQueue.push(std::make_pair(w,v)); + component_index_list[w] = current_component; + bfs_queue.push(std::make_pair(w,v)); p.printIncrement(); } } @@ -230,142 +284,206 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State } } //push size into vector - vectorOfComponentSizes.push_back(sizeOfCurrentComponent); + component_size_list.push_back(current_component_size); //reset counters; - sizeOfCurrentComponent = 0; - ++currentComponent; + current_component_size = 0; + ++current_component; } } - SimpleLogger().Write() << "identified: " << vectorOfComponentSizes.size() << " many components"; + SimpleLogger().Write() << + "identified: " << component_size_list.size() << " many components"; - p.reinit(_nodeBasedGraph->GetNumberOfNodes()); + p.reinit(m_node_based_graph->GetNumberOfNodes()); //loop over all edges and generate new set of nodes. - for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { - for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { - _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); + for( + NodeIterator u = 0, + number_of_nodes = m_node_based_graph->GetNumberOfNodes(); + u < number_of_nodes; + ++u + ) { + for( + EdgeIterator e1 = m_node_based_graph->BeginEdges(u), + last_edge = m_node_based_graph->EndEdges(u); + e1 < last_edge; + ++e1 + ) { + NodeIterator v = m_node_based_graph->GetTarget(e1); - if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX) { - assert(e1 != UINT_MAX); - assert(u != UINT_MAX); - assert(v != UINT_MAX); - //edges that end on bollard nodes may actually be in two distinct components - InsertEdgeBasedNode(e1, u, v, (std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 1000) ); + if(m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX) { + BOOST_ASSERT_MSG(e1 != UINT_MAX, "edge id invalid"); + BOOST_ASSERT_MSG(u != UINT_MAX, "souce node invalid"); + BOOST_ASSERT_MSG(v != UINT_MAX, "target node invalid"); + //Note: edges that end on barrier nodes or on a turn restriction + //may actually be in two distinct components. We choose the smallest + const unsigned size_of_component = std::min( + component_size_list[component_index_list[u]], + component_size_list[component_index_list[v]] + ); + + InsertEdgeBasedNode( e1, u, v, size_of_component < 1000 ); } } } - std::vector().swap(vectorOfComponentSizes); - std::vector().swap(componentsIndex); - + std::vector().swap(component_size_list); + BOOST_ASSERT_MSG( + 0 == component_size_list.capacity(), + "component size vector not deallocated" + ); + std::vector().swap(component_index_list); + BOOST_ASSERT_MSG( + 0 == component_index_list.capacity(), + "component index vector not deallocated" + ); std::vector original_edge_data_vector; original_edge_data_vector.reserve(10000); //Loop over all turns and generate new set of edges. - //Three nested loop look super-linear, but we are dealing with a linear number of turns only. - for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { - for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { - ++nodeBasedEdgeCounter; - _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); - bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end()); - //EdgeWeight heightPenalty = ComputeHeightPenalty(u, v); - NodeID onlyToNode = CheckForEmanatingIsOnlyTurn(u, v); - for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { - const _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2); - - if(onlyToNode != UINT_MAX && w != onlyToNode) { //We are at an only_-restriction but not at the right turn. - ++numberOfSkippedTurns; + //Three nested loop look super-linear, but we are dealing with a (kind of) + //linear number of turns only. + for( + NodeIterator u = 0, + last_node = m_node_based_graph->GetNumberOfNodes(); + u < last_node; + ++u + ) { + for( + EdgeIterator e1 = m_node_based_graph->BeginEdges(u), + last_edge_u = m_node_based_graph->EndEdges(u); + e1 < last_edge_u; + ++e1 + ) { + ++node_based_edge_counter; + NodeIterator v = m_node_based_graph->GetTarget(e1); + bool is_barrier_node = (m_barrier_nodes.find(v) != m_barrier_nodes.end()); + NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v); + for( + EdgeIterator e2 = m_node_based_graph->BeginEdges(v), + last_edge_v = m_node_based_graph->EndEdges(v); + e2 < last_edge_v; + ++e2 + ) { + const NodeIterator w = m_node_based_graph->GetTarget(e2); + if( + to_node_of_only_restriction != UINT_MAX && + w != to_node_of_only_restriction + ) { + //We are at an only_-restriction but not at the right turn. + ++skipped_turns_counter; continue; } - if(u == w && 1 != _nodeBasedGraph->GetOutDegree(v) ) { + if(u == w && 1 != m_node_based_graph->GetOutDegree(v) ) { continue; } - if( !isBollardNode ) { //only add an edge if turn is not a U-turn except it is the end of dead-end street. - if (!CheckIfTurnIsRestricted(u, v, w) || (onlyToNode != UINT_MAX && w == onlyToNode)) { //only add an edge if turn is not prohibited - const _NodeBasedDynamicGraph::EdgeData edgeData1 = _nodeBasedGraph->GetEdgeData(e1); - const _NodeBasedDynamicGraph::EdgeData edgeData2 = _nodeBasedGraph->GetEdgeData(e2); - assert(edgeData1.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges()); - assert(edgeData2.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges()); + if( !is_barrier_node ) { + //only add an edge if turn is not a U-turn except when it is + //at the end of a dead-end street + if ( + !CheckIfTurnIsRestricted(u, v, w) || + (to_node_of_only_restriction != UINT_MAX && w == to_node_of_only_restriction) + ) { //only add an edge if turn is not prohibited + const EdgeData edge_data1 = m_node_based_graph->GetEdgeData(e1); + const EdgeData edge_data2 = m_node_based_graph->GetEdgeData(e2); + assert(edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges()); + assert(edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges()); - if(!edgeData1.forward || !edgeData2.forward) { + if(!edge_data1.forward || !edge_data2.forward) { continue; } - unsigned distance = edgeData1.distance; - if(_trafficLights.find(v) != _trafficLights.end()) { - distance += speedProfile.trafficSignalPenalty; + unsigned distance = edge_data1.distance; + if(m_traffic_lights.find(v) != m_traffic_lights.end()) { + distance += speed_profile.trafficSignalPenalty; } - unsigned penalty = GetTurnPenalty(u, v, w, myLuaState); + const unsigned penalty = + GetTurnPenalty(u, v, w, lua_state); TurnInstruction turnInstruction = AnalyzeTurn(u, v, w); - if(turnInstruction == TurnInstructions.UTurn) - distance += speedProfile.uTurnPenalty; -// if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) { -// distance += TurnInstructions.AccessRestrictionPenalty; -// turnInstruction |= TurnInstructions.AccessRestrictionFlag; -// } + if(turnInstruction == TurnInstructions.UTurn){ + distance += speed_profile.uTurnPenalty; + } distance += penalty; - //distance += heightPenalty; //distance += ComputeTurnPenalty(u, v, w); - assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID); - OriginalEdgeData oed(v,edgeData2.nameID, turnInstruction); - original_edge_data_vector.push_back(oed); - ++numberOfOriginalEdges; + assert(edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID); + original_edge_data_vector.push_back( + OriginalEdgeData( + v, + edge_data2.nameID, + turnInstruction + ) + ); + ++original_edges_counter; if(original_edge_data_vector.size() > 100000) { - originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData)); + edge_data_file.write( + (char*)&(original_edge_data_vector[0]), + original_edge_data_vector.size()*sizeof(OriginalEdgeData) + ); original_edge_data_vector.clear(); } - EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, edgeBasedEdges.size(), distance, true, false ); - edgeBasedEdges.push_back(newEdge); + m_edge_based_edge_list.push_back( + EdgeBasedEdge( + edge_data1.edgeBasedNodeID, + edge_data2.edgeBasedNodeID, + m_edge_based_edge_list.size(), + distance, + true, + false + ) + ); } else { - ++numberOfSkippedTurns; + ++skipped_turns_counter; } } } } p.printIncrement(); } - originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData)); - originalEdgeDataOutFile.seekp(std::ios::beg); - originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned)); - originalEdgeDataOutFile.close(); + edge_data_file.write( + (char*)&(original_edge_data_vector[0]), + original_edge_data_vector.size()*sizeof(OriginalEdgeData) + ); + edge_data_file.seekp(std::ios::beg); + edge_data_file.write( + (char*)&original_edges_counter, + sizeof(unsigned) + ); + edge_data_file.close(); -// SimpleLogger().Write() <<"Sorting edge-based Nodes"; -// std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end(); -// SimpleLogger().Write() <<"Removing duplicate nodes (if any)"; -// edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() ); -// SimpleLogger().Write() <<"Applying vector self-swap trick to free up memory"; -// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity(); -// std::vector(edgeBasedNodes).swap(edgeBasedNodes); -// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity(); - SimpleLogger().Write() <<"Node-based graph contains " << nodeBasedEdgeCounter << " edges"; - SimpleLogger().Write() <<"Edge-based graph contains " << edgeBasedEdges.size() << " edges"; -// SimpleLogger().Write() << "Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << 2*((double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter; - SimpleLogger().Write() <<"Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions."; - SimpleLogger().Write() <<"Generated " << edgeBasedNodes.size() << " edge based nodes"; + SimpleLogger().Write() << + "Generated " << m_edge_based_node_list.size() << " edge based nodes"; + SimpleLogger().Write() << + "Node-based graph contains " << node_based_edge_counter << " edges"; + SimpleLogger().Write() << + "Edge-expanded graph ..."; + SimpleLogger().Write() << + " contains " << m_edge_based_edge_list.size() << " edges"; + SimpleLogger().Write() << + " skips " << skipped_turns_counter << " turns, " + "defined by " << m_turn_restrictions_count << " restrictions"; } int EdgeBasedGraphFactory::GetTurnPenalty( const NodeID u, const NodeID v, const NodeID w, - lua_State *myLuaState + lua_State *lua_state ) const { - const double angle = GetAngleBetweenTwoEdges( - inputNodeInfoList[u], - inputNodeInfoList[v], - inputNodeInfoList[w] + const double angle = GetAngleBetweenThreeFixedPointCoordinates ( + m_node_info_list[u], + m_node_info_list[v], + m_node_info_list[w] ); - if( speedProfile.has_turn_penalty_function ) { + if( speed_profile.has_turn_penalty_function ) { try { //call lua profile to compute turn penalty return luabind::call_function( - myLuaState, + lua_state, "turn_function", 180.-angle ); @@ -381,17 +499,15 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( const NodeID v, const NodeID w ) const { - const double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); - if(u == w) { return TurnInstructions.UTurn; } - _NodeBasedDynamicGraph::EdgeIterator edge1 = _nodeBasedGraph->FindEdge(u, v); - _NodeBasedDynamicGraph::EdgeIterator edge2 = _nodeBasedGraph->FindEdge(v, w); + EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v); + EdgeIterator edge2 = m_node_based_graph->FindEdge(v, w); - _NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1); - _NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2); + EdgeData & data1 = m_node_based_graph->GetEdgeData(edge1); + EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2); if(!data1.contraFlow && data2.contraFlow) { return TurnInstructions.EnterAgainstAllowedDirection; @@ -403,7 +519,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( //roundabouts need to be handled explicitely if(data1.roundabout && data2.roundabout) { //Is a turn possible? If yes, we stay on the roundabout! - if( 1 == (_nodeBasedGraph->EndEdges(v) - _nodeBasedGraph->BeginEdges(v)) ) { + if( 1 == m_node_based_graph->GetOutDegree(v) ) { //No turn possible. return TurnInstructions.NoTurn; } @@ -421,31 +537,28 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( } } - //If street names stay the same and if we are certain that it is not a roundabout, we skip it. - if( (data1.nameID == data2.nameID) && (0 != data1.nameID)) { - return TurnInstructions.NoTurn; - } - if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) ) { - return TurnInstructions.NoTurn; + //If street names stay the same and if we are certain that it is not a + //a segment of a roundabout, we skip it. + if( data1.nameID == data2.nameID ) { + //TODO: Here we should also do a small graph exploration to check for + // more complex situations + if( 0 != data1.nameID ) { + return TurnInstructions.NoTurn; + } else if (m_node_based_graph->GetOutDegree(v) <= 2) { + return TurnInstructions.NoTurn; + } } + const double angle = GetAngleBetweenThreeFixedPointCoordinates ( + m_node_info_list[u], + m_node_info_list[v], + m_node_info_list[w] + ); + return TurnInstructions.GetTurnDirectionOfInstruction(angle); } unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { - return _nodeBasedGraph->GetNumberOfEdges(); + return m_node_based_graph->GetNumberOfEdges(); } -/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ -template -double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const { - const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION; - const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); - const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION; - const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); - - double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI; - while(angle < 0) - angle += 360; - return angle; -} diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 05b8462b3..5f4df157b 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -18,9 +18,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ -/* - * This class constructs the edge base representation of a graph from a given node based edge list - */ +// This class constructs the edge-expanded routing graph #ifndef EDGEBASEDGRAPHFACTORY_H_ #define EDGEBASEDGRAPHFACTORY_H_ @@ -31,15 +29,12 @@ #include "../Extractor/ExtractorStructs.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportEdge.h" -#include "../DataStructures/MercatorUtil.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/Percent.h" #include "../DataStructures/TurnInstructions.h" #include "../Util/LuaUtil.h" #include "../Util/SimpleLogger.h" -#include - #include #include #include @@ -47,9 +42,8 @@ #include #include -#include - #include +#include #include #include @@ -67,6 +61,7 @@ public: weight(UINT_MAX >> 1), ignoreInGrid(false) { } + bool operator<(const EdgeBasedNode & other) const { return other.id < id; } @@ -100,33 +95,47 @@ public: }; struct SpeedProfileProperties{ - SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0), has_turn_penalty_function(false) {} + SpeedProfileProperties() : + trafficSignalPenalty(0), + uTurnPenalty(0), + has_turn_penalty_function(false) + { } + int trafficSignalPenalty; int uTurnPenalty; bool has_turn_penalty_function; - } speedProfile; + } speed_profile; explicit EdgeBasedGraphFactory( - int nodes, - std::vector & inputEdges, - std::vector & _bollardNodes, - std::vector & trafficLights, - std::vector & inputRestrictions, - std::vector & nI, - SpeedProfileProperties speedProfile + int number_of_nodes, + std::vector & input_edge_list, + std::vector & barrier_node_list, + std::vector & traffic_light_node_list, + std::vector & input_restrictions_list, + std::vector & m_node_info_list, + SpeedProfileProperties speed_profile ); void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); - void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); - TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; - int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; + void GetOriginalEdgeData( std::vector & originalEdgeData); + TurnInstruction AnalyzeTurn( + const NodeID u, + const NodeID v, + const NodeID w + ) const; + int GetTurnPenalty( + const NodeID u, + const NodeID v, + const NodeID w, + lua_State *myLuaState + ) const; unsigned GetNumberOfNodes() const; private: - struct _NodeBasedEdgeData { + struct NodeBasedEdgeData { int distance; unsigned edgeBasedNodeID; unsigned nameID; @@ -151,35 +160,44 @@ private: unsigned m_turn_restrictions_count; - typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; - typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge; - std::vector inputNodeInfoList; - unsigned numberOfTurnRestrictions; - - boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; - boost::unordered_set _barrierNodes; - boost::unordered_set _trafficLights; - - typedef std::pair RestrictionSource; - typedef std::pair RestrictionTarget; - typedef std::vector EmanatingRestrictionsVector; + typedef DynamicGraph NodeBasedDynamicGraph; + typedef NodeBasedDynamicGraph::InputEdge NodeBasedEdge; + typedef NodeBasedDynamicGraph::NodeIterator NodeIterator; + typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator; + typedef NodeBasedDynamicGraph::EdgeData EdgeData; + typedef std::pair RestrictionSource; + typedef std::pair RestrictionTarget; + typedef std::vector EmanatingRestrictionsVector; typedef boost::unordered_map RestrictionMap; - std::vector _restrictionBucketVector; - RestrictionMap _restrictionMap; - DeallocatingVector edgeBasedEdges; - std::vector edgeBasedNodes; + std::vector m_node_info_list; + std::vector m_restriction_bucket_list; + std::vector m_edge_based_node_list; + DeallocatingVector m_edge_based_edge_list; + + boost::shared_ptr m_node_based_graph; + boost::unordered_set m_barrier_nodes; + boost::unordered_set m_traffic_lights; + + RestrictionMap m_restriction_map; + + + NodeID CheckForEmanatingIsOnlyTurn( + const NodeID u, + const NodeID v + ) const; + + bool CheckIfTurnIsRestricted( + const NodeID u, + const NodeID v, + const NodeID w + ) const; - NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const; - bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const; void InsertEdgeBasedNode( - _NodeBasedDynamicGraph::EdgeIterator e1, - _NodeBasedDynamicGraph::NodeIterator u, - _NodeBasedDynamicGraph::NodeIterator v, + NodeBasedDynamicGraph::EdgeIterator e1, + NodeBasedDynamicGraph::NodeIterator u, + NodeBasedDynamicGraph::NodeIterator v, bool belongsToTinyComponent); - template - double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const; - }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h index a701f80db..bf0d3eaad 100644 --- a/DataStructures/Coordinate.h +++ b/DataStructures/Coordinate.h @@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef FIXED_POINT_COORDINATE_H_ #define FIXED_POINT_COORDINATE_H_ +#include "../DataStructures/MercatorUtil.h" #include "../Util/StringUtil.h" #include @@ -35,7 +36,7 @@ struct FixedPointCoordinate { int lat; int lon; FixedPointCoordinate () : lat(INT_MIN), lon(INT_MIN) {} - explicit FixedPointCoordinate (int t, int n) : lat(t) , lon(n) {} + explicit FixedPointCoordinate (int lat, int lon) : lat(lat) , lon(lon) {} void Reset() { lat = INT_MIN; @@ -141,4 +142,22 @@ static inline void convertInternalReversedCoordinateToString(const FixedPointCoo output += " "; } + +/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ +template +static inline double GetAngleBetweenThreeFixedPointCoordinates ( + const CoordinateT & A, + const CoordinateT & C, + const CoordinateT & B +) { + const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION; + const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); + const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION; + const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION); + + double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI; + while(angle < 0) + angle += 360; + return angle; +} #endif /* FIXED_POINT_COORDINATE_H_ */ diff --git a/DataStructures/QueryEdge.h b/DataStructures/QueryEdge.h index ef7c6b20b..1a7c39223 100644 --- a/DataStructures/QueryEdge.h +++ b/DataStructures/QueryEdge.h @@ -18,8 +18,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ - - #ifndef QUERYEDGE_H_ #define QUERYEDGE_H_ From b7980b83dfe67a41d7f69737e58ca5cfcf217f8f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 15 Aug 2013 15:51:07 +0200 Subject: [PATCH 80/80] removing dead comments --- Contractor/EdgeBasedGraphFactory.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index cd87a4e69..8d71db190 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -405,8 +405,6 @@ void EdgeBasedGraphFactory::Run( } distance += penalty; - //distance += heightPenalty; - //distance += ComputeTurnPenalty(u, v, w); assert(edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID); original_edge_data_vector.push_back( OriginalEdgeData( @@ -561,4 +559,3 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { return m_node_based_graph->GetNumberOfEdges(); } -