From dd971d6b7d55858fef07b2bec1c943667629dd12 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 5 Jun 2013 11:38:45 +0200 Subject: [PATCH 01/61] Fixing test for new Rtree --- features/testbot/snap.feature | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/features/testbot/snap.feature b/features/testbot/snap.feature index ebed9f829..bb3156dbd 100644 --- a/features/testbot/snap.feature +++ b/features/testbot/snap.feature @@ -98,7 +98,7 @@ Feature: Snap start/end point to the nearest way | b | x | xb | | c | x | xc | - Scenario: Find edges within 1km, but not 10km + Scenario: Find edges within 1km, and the same from 10km Given a grid size of 1000 meters Given the node map | p | | | | | | | | | | | i | | | | | | | | | | | j | @@ -144,11 +144,11 @@ Feature: Snap start/end point to the nearest way | x | 6 | xf | | x | 7 | xg | | x | 8 | xh | - | x | i | | - | x | j | | - | x | k | | - | x | l | | - | x | m | | - | x | n | | - | x | o | | - | x | p | | \ No newline at end of file + | x | i | xa | + | x | j | xb | + | x | k | xc | + | x | l | xd | + | x | m | xe | + | x | n | xf | + | x | o | xg | + | x | p | xh | \ No newline at end of file From 4430cbc3cbca656e21aa617b53a65f9d524feeaa Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 19:47:16 -0400 Subject: [PATCH 02/61] First implementation of moving the algorithmic core into a library --- Algorithms/Bresenham.h | 3 ++- Algorithms/DouglasPeucker.h | 5 +++-- Algorithms/ObjectToBase64.h | 4 ++-- Algorithms/PolylineCompressor.h | 5 ++--- Server/ServerConfiguration.h | 28 ---------------------------- server.ini | 14 +++++++------- typedefs.h | 1 - 7 files changed, 16 insertions(+), 44 deletions(-) delete mode 100644 Server/ServerConfiguration.h diff --git a/Algorithms/Bresenham.h b/Algorithms/Bresenham.h index a4f7e6147..60eed7228 100644 --- a/Algorithms/Bresenham.h +++ b/Algorithms/Bresenham.h @@ -23,9 +23,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include + typedef std::pair BresenhamPixel; -inline void Bresenham (int x0, int y0, int x1, int y1, std::vector &resultList) { +inline void Bresenham (int x0, int y0, const int x1, int const y1, std::vector &resultList) { int dx = std::abs(x1-x0); int dy = std::abs(y1-y0); int sx = (x0 < x1 ? 1 : -1); diff --git a/Algorithms/DouglasPeucker.h b/Algorithms/DouglasPeucker.h index 47b0ce96c..5de5fbd7e 100644 --- a/Algorithms/DouglasPeucker.h +++ b/Algorithms/DouglasPeucker.h @@ -21,12 +21,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef DOUGLASPEUCKER_H_ #define DOUGLASPEUCKER_H_ +#include "../DataStructures/Coordinate.h" + #include #include #include #include - -#include "../DataStructures/Coordinate.h" +#include /*This class object computes the bitvector of indicating generalized input points * according to the (Ramer-)Douglas-Peucker algorithm. diff --git a/Algorithms/ObjectToBase64.h b/Algorithms/ObjectToBase64.h index 8d69c0a8a..928095189 100644 --- a/Algorithms/ObjectToBase64.h +++ b/Algorithms/ObjectToBase64.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef OBJECTTOBASE64_H_ #define OBJECTTOBASE64_H_ +#include "../Util/StringUtil.h" + #include #include #include @@ -29,8 +31,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include "../Util/StringUtil.h" - typedef boost::archive::iterators::base64_from_binary< boost::archive::iterators::transform_width diff --git a/Algorithms/PolylineCompressor.h b/Algorithms/PolylineCompressor.h index 7bb143bd4..db90ef6ff 100644 --- a/Algorithms/PolylineCompressor.h +++ b/Algorithms/PolylineCompressor.h @@ -21,12 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef POLYLINECOMPRESSOR_H_ #define POLYLINECOMPRESSOR_H_ -#include - -//#include "../DataStructures/ExtractorStructs.h" #include "../DataStructures/SegmentInformation.h" #include "../Util/StringUtil.h" +#include + class PolylineCompressor { private: inline void encodeVectorSignedNumber(std::vector & numbers, std::string & output) const { diff --git a/Server/ServerConfiguration.h b/Server/ServerConfiguration.h deleted file mode 100644 index 0393a7fe5..000000000 --- a/Server/ServerConfiguration.h +++ /dev/null @@ -1,28 +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 SERVERCONFIGURATION_H_ -#define SERVERCONFIGURATION_H_ - -#include "../Util/BaseConfiguration.h" - -typedef BaseConfiguration ServerConfiguration; - -#endif /* SERVERCONFIGURATION_H_ */ diff --git a/server.ini b/server.ini index 3fe844afa..e8138257e 100644 --- a/server.ini +++ b/server.ini @@ -2,10 +2,10 @@ Threads = 8 IP = 0.0.0.0 Port = 5000 -hsgrData=/opt/osm/berlin.osrm.hsgr -nodesData=/opt/osm/berlin.osrm.nodes -edgesData=/opt/osm/berlin.osrm.edges -ramIndex=/opt/osm/berlin.osrm.ramIndex -fileIndex=/opt/osm/berlin.osrm.fileIndex -namesData=/opt/osm/berlin.osrm.names -timestamp=/opt/osm/berlin.osrm.timestamp +hsgrData=/Users/dennisluxen/Downloads/berlin-latest.osrm.hsgr +nodesData=/Users/dennisluxen/Downloads/berlin-latest.osrm.nodes +edgesData=/Users/dennisluxen/Downloads/berlin-latest.osrm.edges +ramIndex=/Users/dennisluxen/Downloads/berlin-latest.osrm.ramIndex +fileIndex=/Users/dennisluxen/Downloads/berlin-latest.osrm.fileIndex +namesData=/Users/dennisluxen/Downloads/berlin-latest.osrm.names +timestamp=/Users/dennisluxen/Downloads/berlin-latest.osrm.timestamp diff --git a/typedefs.h b/typedefs.h index a962598e9..180e47ca0 100644 --- a/typedefs.h +++ b/typedefs.h @@ -21,7 +21,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef TYPEDEFS_H_ #define TYPEDEFS_H_ -#include #include #include From bfef8f39b7bfefcfba728a5dd10623c4c95453dc Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 19:47:47 -0400 Subject: [PATCH 03/61] First implementation of moving the algorithmic core into a library --- Util/BaseConfiguration.h | 16 ++++++---- Util/InputFileUtil.h | 4 +-- Util/LinuxStackTrace.h | 1 - Util/MachineInfo.h | 22 +++++++------- Util/OpenMPWrapper.h | 10 +++---- Util/StringUtil.h | 7 +++-- routed.cpp | 63 +++++++++++++--------------------------- 7 files changed, 53 insertions(+), 70 deletions(-) diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h index 69bc61f89..a998c6189 100644 --- a/Util/BaseConfiguration.h +++ b/Util/BaseConfiguration.h @@ -21,12 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASECONFIGURATION_H_ #define BASECONFIGURATION_H_ -#include -#include +#include "../DataStructures/HashTable.h" + #include #include - -#include "../DataStructures/HashTable.h" +#include +#include class BaseConfiguration { public: @@ -73,7 +73,11 @@ public: } private: - void Tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = "=") { + 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); @@ -86,6 +90,7 @@ private: 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) @@ -93,6 +98,7 @@ private: 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) diff --git a/Util/InputFileUtil.h b/Util/InputFileUtil.h index 685d92f3f..b130d2136 100644 --- a/Util/InputFileUtil.h +++ b/Util/InputFileUtil.h @@ -21,10 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INPUTFILEUTIL_H_ #define INPUTFILEUTIL_H_ -#include - #include "../typedefs.h" +#include + // Check if file exists and if it can be opened for reading with ifstream an object inline bool testDataFile(const std::string & filename){ boost::filesystem::path fileToTest(filename); diff --git a/Util/LinuxStackTrace.h b/Util/LinuxStackTrace.h index a3a23a7c5..593c07d41 100644 --- a/Util/LinuxStackTrace.h +++ b/Util/LinuxStackTrace.h @@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include - #ifdef __linux__ #include #include diff --git a/Util/MachineInfo.h b/Util/MachineInfo.h index 7c0f31c3b..bdb085aa5 100644 --- a/Util/MachineInfo.h +++ b/Util/MachineInfo.h @@ -1,17 +1,17 @@ /* 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 @@ -23,11 +23,11 @@ #if defined(__APPLE__) || defined(__FreeBSD__) extern "C" { -#include -#include -} + #include + #include +} #elif defined _WIN32 -#include + #include #endif enum Endianness { @@ -55,28 +55,28 @@ inline unsigned swapEndian(unsigned x) { inline unsigned GetPhysicalmemory(void){ #if defined(SUN5) || defined(__linux__) return (sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE)); - + #elif defined(__APPLE__) int mib[2] = {CTL_HW, HW_MEMSIZE}; long long memsize; size_t len = sizeof(memsize); sysctl(mib, 2, &memsize, &len, NULL, 0); return memsize/1024; - + #elif defined(__FreeBSD__) int mib[2] = {CTL_HW, HW_PHYSMEM}; long long memsize; size_t len = sizeof(memsize); sysctl(mib, 2, &memsize, &len, NULL, 0); return memsize/1024; - + #elif defined(_WIN32) MEMORYSTATUSEX status; status.dwLength = sizeof(status); GlobalMemoryStatusEx(&status); return status.ullTotalPhys/1024; #else - std::cout << "[Warning] Compiling on unknown architecture." << std::endl + std::cout << "[Warning] Compiling on unknown architecture." << std::endl << "Please file a ticket at http://project-osrm.org" << std::endl; return 2048*1024; /* 128 Mb default memory */ diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h index 232dcbd62..520ac252c 100644 --- a/Util/OpenMPWrapper.h +++ b/Util/OpenMPWrapper.h @@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #define _OPENMPREPLACEMENTY_H #ifdef _OPENMP -#include + #include #else -inline const int omp_get_num_procs() { return 1; } -inline const int omp_get_max_threads() { return 1; } -inline const int omp_get_thread_num() { return 0; } -inline const void omp_set_num_threads(int i) {} + inline const int omp_get_num_procs() { return 1; } + inline const int omp_get_max_threads() { return 1; } + inline const int omp_get_thread_num() { return 0; } + inline const void omp_set_num_threads(int i) {} #endif #endif diff --git a/Util/StringUtil.h b/Util/StringUtil.h index b09ac166a..951a21c4a 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -21,6 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STRINGUTIL_H_ #define STRINGUTIL_H_ + +#include "../DataStructures/Coordinate.h" +#include "../typedefs.h" + #include #include @@ -29,9 +33,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "../DataStructures/Coordinate.h" -#include "../typedefs.h" - // precision: position after decimal point // length: maximum number of digits including comma and decimals template< int length, int precision > diff --git a/routed.cpp b/routed.cpp index e097bd70d..596f610d7 100644 --- a/routed.cpp +++ b/routed.cpp @@ -17,34 +17,28 @@ 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. */ + + +#include "Library/OSRM.h" + +#include "Server/ServerFactory.h" + +#include "Util/BaseConfiguration.h" +#include "Util/InputFileUtil.h" +#include "Util/OpenMPWrapper.h" + #ifdef __linux__ +#include "Util/LinuxStackTrace.h" #include #endif -#include + #include #include #include #include -#include "Server/DataStructures/QueryObjectsStorage.h" -#include "Server/ServerConfiguration.h" -#include "Server/ServerFactory.h" - -#include "Plugins/HelloWorldPlugin.h" -#include "Plugins/LocatePlugin.h" -#include "Plugins/NearestPlugin.h" -#include "Plugins/TimestampPlugin.h" -#include "Plugins/ViaRoutePlugin.h" - -#include "Util/InputFileUtil.h" -#include "Util/OpenMPWrapper.h" - -#ifndef _WIN32 -#include "Util/LinuxStackTrace.h" -#endif - -typedef http::RequestHandler RequestHandler; +#include #ifdef _WIN32 boost::function0 console_ctrl_function; @@ -70,7 +64,7 @@ int main (int argc, char * argv[]) { if(!mlockall(MCL_CURRENT | MCL_FUTURE)) WARN("Process " << argv[0] << "could not be locked to RAM"); #endif -#ifndef _WIN32 +#ifdef __linux__ installCrashHandler(argv[0]); #endif @@ -83,7 +77,8 @@ int main (int argc, char * argv[]) { //} try { - std::cout << std::endl << "[server] starting up engines, saved at " << __TIMESTAMP__ << std::endl; + std::cout << "\n starting up engines, compile at " << + __DATE__ << ", " __TIME__ << std::endl; #ifndef _WIN32 int sig = 0; @@ -93,28 +88,11 @@ int main (int argc, char * argv[]) { pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - ServerConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); + Server * s = ServerFactory::CreateServer(serverConfig); - RequestHandler & h = s->GetRequestHandlerPtr(); - - QueryObjectsStorage * objects = new QueryObjectsStorage(serverConfig.GetParameter("hsgrData"), - serverConfig.GetParameter("ramIndex"), - serverConfig.GetParameter("fileIndex"), - serverConfig.GetParameter("nodesData"), - serverConfig.GetParameter("edgesData"), - serverConfig.GetParameter("namesData"), - serverConfig.GetParameter("timestamp") - ); - - h.RegisterPlugin(new HelloWorldPlugin()); - - h.RegisterPlugin(new LocatePlugin(objects)); - - h.RegisterPlugin(new NearestPlugin(objects)); - - h.RegisterPlugin(new TimestampPlugin(objects)); - - h.RegisterPlugin(new ViaRoutePlugin(objects)); + s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine); boost::thread t(boost::bind(&Server::Run, s)); @@ -146,7 +124,6 @@ int main (int argc, char * argv[]) { std::cout << "[server] freeing objects" << std::endl; delete s; - delete objects; std::cout << "[server] shutdown completed" << std::endl; } catch (std::exception& e) { std::cerr << "[fatal error] exception: " << e.what() << std::endl; From 2c397bfa0be2eabdbe5d4487f6646e8207d2fea4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 19:48:02 -0400 Subject: [PATCH 04/61] First implementation of moving the algorithmic core into a library --- Extractor/BaseParser.h | 16 +++---- Extractor/ExtractionHelperFunctions.h | 7 +-- Extractor/ExtractorCallbacks.cpp | 1 - Extractor/ExtractorCallbacks.h | 1 + Extractor/ExtractorStructs.h | 17 ++++---- Extractor/PBFParser.h | 5 +-- Extractor/ScriptingEnvironment.h | 12 ++--- Extractor/XMLParser.cpp | 7 ++- Plugins/BasePlugin.h | 7 ++- Plugins/HelloWorldPlugin.h | 6 +-- Plugins/NearestPlugin.h | 7 ++- Plugins/RouteParameters.h | 20 ++++++--- Plugins/TimestampPlugin.h | 8 +++- Plugins/ViaRoutePlugin.h | 23 +++++----- Server/BasicDatastructures.h | 14 +++--- Server/Connection.h | 10 ++--- Server/RequestHandler.h | 63 ++++++++++----------------- Server/Server.h | 48 ++++++++++++++------ Server/ServerFactory.h | 10 ++--- 19 files changed, 143 insertions(+), 139 deletions(-) diff --git a/Extractor/BaseParser.h b/Extractor/BaseParser.h index 6a19efa07..690f8a247 100644 --- a/Extractor/BaseParser.h +++ b/Extractor/BaseParser.h @@ -21,17 +21,17 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASEPARSER_H_ #define BASEPARSER_H_ +#include "ExtractorCallbacks.h" +#include "ScriptingEnvironment.h" + extern "C" { -#include -#include -#include + #include + #include + #include } #include -#include "ExtractorCallbacks.h" -#include "ScriptingEnvironment.h" - class BaseParser : boost::noncopyable { public: BaseParser(ExtractorCallbacks* ec, ScriptingEnvironment& se); @@ -43,11 +43,11 @@ public: virtual void ParseWayInLua(ExtractionWay& n, lua_State* luaStateForThread); virtual void report_errors(lua_State *L, const int status) const; -protected: +protected: virtual void ReadUseRestrictionsSetting(); virtual void ReadRestrictionExceptions(); virtual bool ShouldIgnoreRestriction(const std::string& except_tag_string) const; - + ExtractorCallbacks* extractor_callbacks; ScriptingEnvironment& scriptingEnvironment; lua_State* luaState; diff --git a/Extractor/ExtractionHelperFunctions.h b/Extractor/ExtractionHelperFunctions.h index 6771939a9..0c654d141 100644 --- a/Extractor/ExtractionHelperFunctions.h +++ b/Extractor/ExtractionHelperFunctions.h @@ -18,19 +18,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ - - #ifndef EXTRACTIONHELPERFUNCTIONS_H_ #define EXTRACTIONHELPERFUNCTIONS_H_ +#include "../Util/StringUtil.h" + #include #include #include #include - -#include "../Util/StringUtil.h" - namespace qi = boost::spirit::qi; //TODO: Move into LUA diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index c8b5fc1aa..cd690abde 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -40,7 +40,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ExtractorCallbacks.h" -#include "ExtractionHelperFunctions.h" ExtractorCallbacks::ExtractorCallbacks() {externalMemory = NULL; stringMap = NULL; } ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers * ext, StringMap * strMap) { diff --git a/Extractor/ExtractorCallbacks.h b/Extractor/ExtractorCallbacks.h index 4293d1330..3e9fcddf5 100644 --- a/Extractor/ExtractorCallbacks.h +++ b/Extractor/ExtractorCallbacks.h @@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include "ExtractionContainers.h" +#include "ExtractionHelperFunctions.h" #include "ExtractorStructs.h" class ExtractorCallbacks{ diff --git a/Extractor/ExtractorStructs.h b/Extractor/ExtractorStructs.h index fe21da957..b481469f6 100644 --- a/Extractor/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -21,13 +21,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef EXTRACTORSTRUCTS_H_ #define EXTRACTORSTRUCTS_H_ -#include -#include - -#include -#include -#include -#include #include "../DataStructures/Coordinate.h" #include "../DataStructures/HashTable.h" @@ -37,6 +30,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/TimingUtil.h" #include "../typedefs.h" +#include +#include +#include +#include + +#include +#include + typedef boost::unordered_map StringMap; typedef boost::unordered_map > StringToIntPairMap; @@ -44,7 +45,7 @@ struct ExtractionWay { ExtractionWay() { Clear(); } - + inline void Clear(){ id = UINT_MAX; nameID = UINT_MAX; diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index f3748b67b..a1606bb6f 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -21,13 +21,14 @@ #ifndef PBFPARSER_H_ #define PBFPARSER_H_ +#include "BaseParser.h" + #include "../DataStructures/HashTable.h" #include "../DataStructures/ConcurrentQueue.h" #include "../Util/MachineInfo.h" #include "../Util/OpenMPWrapper.h" #include "../typedefs.h" -#include "BaseParser.h" #include #include #include @@ -37,8 +38,6 @@ #include - - class PBFParser : public BaseParser { enum EntityType { diff --git a/Extractor/ScriptingEnvironment.h b/Extractor/ScriptingEnvironment.h index 015ff2529..efb128100 100644 --- a/Extractor/ScriptingEnvironment.h +++ b/Extractor/ScriptingEnvironment.h @@ -21,20 +21,14 @@ #ifndef SCRIPTINGENVIRONMENT_H_ #define SCRIPTINGENVIRONMENT_H_ -extern "C" { -#include -#include -#include -} -#include - #include "ExtractionHelperFunctions.h" #include "ExtractorStructs.h" - -#include "../typedefs.h" #include "../DataStructures/ImportNode.h" #include "../Util/LuaUtil.h" #include "../Util/OpenMPWrapper.h" +#include "../typedefs.h" + +#include class ScriptingEnvironment { public: diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index fa810a702..d9ab60411 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -18,14 +18,13 @@ or see http://www.gnu.org/licenses/agpl.txt. */ -#include - #include "XMLParser.h" #include "ExtractorStructs.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/InputReaderFactory.h" +#include XMLParser::XMLParser(const char * filename, ExtractorCallbacks* ec, ScriptingEnvironment& se) : BaseParser(ec, se) { WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf"); @@ -43,12 +42,12 @@ bool XMLParser::Parse() { if ( type != 1 ) { continue; } - + xmlChar* currentName = xmlTextReaderName( inputReader ); if ( currentName == NULL ) { continue; } - + if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) { ImportNode n = _ReadXMLNode(); ParseNodeInLua( n, luaState ); diff --git a/Plugins/BasePlugin.h b/Plugins/BasePlugin.h index 266d5d83a..954edbf8b 100644 --- a/Plugins/BasePlugin.h +++ b/Plugins/BasePlugin.h @@ -21,13 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASEPLUGIN_H_ #define BASEPLUGIN_H_ -#include -#include -#include - #include "RouteParameters.h" #include "../Server/BasicDatastructures.h" +#include +#include + class BasePlugin { public: BasePlugin() { } diff --git a/Plugins/HelloWorldPlugin.h b/Plugins/HelloWorldPlugin.h index ae0ff64b1..6315dad8c 100644 --- a/Plugins/HelloWorldPlugin.h +++ b/Plugins/HelloWorldPlugin.h @@ -8,15 +8,15 @@ #ifndef HELLOWORLDPLUGIN_H_ #define HELLOWORLDPLUGIN_H_ -#include - #include "BasePlugin.h" #include "RouteParameters.h" +#include + class HelloWorldPlugin : public BasePlugin { public: HelloWorldPlugin() {} - virtual ~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ } + virtual ~HelloWorldPlugin() { } std::string GetDescriptor() const { return std::string("hello"); } std::string GetVersionString() const { return std::string("0.1a"); } diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index c10230f6c..0b60225ef 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -21,16 +21,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef NearestPlugin_H_ #define NearestPlugin_H_ -#include - #include "BasePlugin.h" #include "RouteParameters.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" - #include "../DataStructures/NodeInformationHelpDesk.h" +#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. */ diff --git a/Plugins/RouteParameters.h b/Plugins/RouteParameters.h index a718f9630..88fd1c260 100644 --- a/Plugins/RouteParameters.h +++ b/Plugins/RouteParameters.h @@ -21,15 +21,25 @@ 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 +#include +#include + #include #include -#include - -#include "../DataStructures/Coordinate.h" - struct RouteParameters { - RouteParameters() : zoomLevel(18), printInstructions(false), alternateRoute(true), geometry(true), compression(true), deprecatedAPI(false), checkSum(-1) {} + RouteParameters() : + zoomLevel(18), + printInstructions(false), + alternateRoute(true), + geometry(true), + compression(true), + deprecatedAPI(false), + checkSum(-1) {} short zoomLevel; bool printInstructions; bool alternateRoute; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 33c606e44..0475a04fd 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -21,18 +21,22 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef TIMESTAMPPLUGIN_H_ #define TIMESTAMPPLUGIN_H_ -#include - #include "BasePlugin.h" #include "RouteParameters.h" +#include + class TimestampPlugin : public BasePlugin { public: TimestampPlugin(QueryObjectsStorage * o) : objects(o) { } + ~TimestampPlugin() { + std::cout << "shutdown time stamp" << std::endl; + } std::string GetDescriptor() const { return std::string("timestamp"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { + std::cout << "handling request" << std::endl; std::string tmp; //json diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 8249d991b..9934c4791 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -21,29 +21,26 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef VIAROUTEPLUGIN_H_ #define VIAROUTEPLUGIN_H_ -#include -#include -#include -#include -#include - #include "BasePlugin.h" #include "RouteParameters.h" #include "../Algorithms/ObjectToBase64.h" - -#include "../Descriptors/BaseDescriptor.h" -#include "../Descriptors/GPXDescriptor.h" -#include "../Descriptors/JSONDescriptor.h" - #include "../DataStructures/HashTable.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/StaticGraph.h" #include "../DataStructures/SearchEngine.h" - +#include "../Descriptors/BaseDescriptor.h" +#include "../Descriptors/GPXDescriptor.h" +#include "../Descriptors/JSONDescriptor.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" +#include + +#include +#include +#include +#include class ViaRoutePlugin : public BasePlugin { private: diff --git a/Server/BasicDatastructures.h b/Server/BasicDatastructures.h index 366abaece..633675684 100644 --- a/Server/BasicDatastructures.h +++ b/Server/BasicDatastructures.h @@ -20,12 +20,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASIC_DATASTRUCTURES_H #define BASIC_DATASTRUCTURES_H -#include -#include -#include #include "../Util/StringUtil.h" +#include +#include + +#include +#include +#include + namespace http { const std::string okString = "HTTP/1.0 200 OK\r\n"; @@ -77,7 +81,7 @@ struct Reply { BOOST_FOREACH ( Header& h, headers) { if("Content-Length" == h.name) { std::string sizeString; - intToString(size,h.value ); + intToString(size,h.value); } } } @@ -139,7 +143,7 @@ Reply Reply::stockReply(Reply::status_type status) { Reply rep; rep.status = status; rep.content = ToString(status); - rep.headers.resize(3); + rep.headers.resize(3); rep.headers[0].name = "Access-Control-Allow-Origin"; rep.headers[0].value = "*"; rep.headers[1].name = "Content-Length"; diff --git a/Server/Connection.h b/Server/Connection.h index 5dd4b7913..ffd6be3dc 100644 --- a/Server/Connection.h +++ b/Server/Connection.h @@ -21,7 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef CONNECTION_H #define CONNECTION_H -#include +#include "BasicDatastructures.h" +#include "RequestHandler.h" +#include "RequestParser.h" #include #include @@ -30,11 +32,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include "BasicDatastructures.h" -#include "RequestHandler.h" -#include "RequestParser.h" +#include -#include "zlib.h" +#include namespace http { diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 9dd0e2849..0f91601ab 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -21,35 +21,27 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef REQUEST_HANDLER_H #define REQUEST_HANDLER_H -#include -#include // std::tolower -#include -#include -#include - #include "APIGrammar.h" #include "BasicDatastructures.h" -#include "../DataStructures/HashTable.h" -#include "../Plugins/BasePlugin.h" +#include "../Library/OSRM.h" #include "../Plugins/RouteParameters.h" #include "../Util/StringUtil.h" #include "../typedefs.h" -namespace http { +#include +#include + +#include +#include +#include +#include class RequestHandler : private boost::noncopyable { public: - explicit RequestHandler() : _pluginCount(0) { } + typedef APIGrammar APIGrammarParser; + explicit RequestHandler() { } - ~RequestHandler() { - - for(unsigned i = 0; i < _pluginVector.size(); i++) { - BasePlugin * tempPointer = _pluginVector[i]; - delete tempPointer; - } - } - - void handle_request(const Request& req, Reply& rep){ + void handle_request(const http::Request& req, http::Reply& rep){ //parse command try { std::string request(req.uri); @@ -66,10 +58,10 @@ public: } RouteParameters routeParameters; - APIGrammar apiParser(&routeParameters); + APIGrammarParser apiParser(&routeParameters); std::string::iterator it = request.begin(); - bool result = boost::spirit::qi::parse(it, request.end(), apiParser); // returns true if successful + 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); @@ -80,38 +72,29 @@ public: rep.content += request; rep.content += tmp_position_string; rep.content += "
"; - for(unsigned i = 0, end = std::distance(request.begin(), it); i < end; ++i) + unsigned end = std::distance(request.begin(), it); + for(unsigned i = 0; i < end; ++i) { rep.content += " "; + } rep.content += "^
"; } else { - //Finished parsing, lets call the right plugin to handle the request - if(pluginMap.Holds(routeParameters.service)) { - rep.status = Reply::ok; - _pluginVector[pluginMap.Find(routeParameters.service)]->HandleRequest(routeParameters, rep ); - } else { - rep = Reply::stockReply(Reply::badRequest); - } + //parsing done, lets call the right plugin to handle the request + routing_machine->RunQuery(routeParameters, rep); return; } } catch(std::exception& e) { - rep = Reply::stockReply(Reply::internalServerError); - std::cerr << "[server error] code: " << e.what() << ", uri: " << req.uri << std::endl; + rep = http::Reply::stockReply(http::Reply::internalServerError); + WARN("[server error] code: " << e.what() << ", uri: " << req.uri); return; } }; - void RegisterPlugin(BasePlugin * plugin) { - std::cout << "[handler] registering plugin " << plugin->GetDescriptor() << std::endl; - pluginMap.Add(plugin->GetDescriptor(), _pluginCount); - _pluginVector.push_back(plugin); - ++_pluginCount; + void RegisterRoutingMachine(OSRM * osrm) { + routing_machine = osrm; } private: - HashTable pluginMap; - std::vector _pluginVector; - unsigned _pluginCount; + OSRM * routing_machine; }; -} // namespace http #endif // REQUEST_HANDLER_H diff --git a/Server/Server.h b/Server/Server.h index db525f5a2..f3638cb38 100644 --- a/Server/Server.h +++ b/Server/Server.h @@ -21,21 +21,29 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SERVER_H #define SERVER_H -#include +#include "Connection.h" +#include "RequestHandler.h" + #include #include #include #include #include -#include "Connection.h" -#include "RequestHandler.h" - -namespace http { +#include class Server: private boost::noncopyable { public: - explicit Server(const std::string& address, const std::string& port, unsigned thread_pool_size) : threadPoolSize(thread_pool_size), acceptor(ioService), newConnection(new Connection(ioService, requestHandler)), requestHandler(){ + explicit Server( + const std::string& address, + const std::string& port, + unsigned thread_pool_size + ) : + threadPoolSize(thread_pool_size), + acceptor(ioService), + newConnection(new http::Connection(ioService, requestHandler)), + requestHandler() + { boost::asio::ip::tcp::resolver resolver(ioService); boost::asio::ip::tcp::resolver::query query(address, port); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); @@ -44,7 +52,14 @@ public: acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen(); - acceptor.async_accept(newConnection->socket(), boost::bind(&Server::handleAccept, this, boost::asio::placeholders::error)); + acceptor.async_accept( + newConnection->socket(), + boost::bind( + &Server::handleAccept, + this, + boost::asio::placeholders::error + ) + ); } void Run() { @@ -66,23 +81,28 @@ public: } private: - typedef boost::shared_ptr ConnectionPtr; - void handleAccept(const boost::system::error_code& e) { if (!e) { newConnection->start(); - newConnection.reset(new Connection(ioService, requestHandler)); - acceptor.async_accept(newConnection->socket(), boost::bind(&Server::handleAccept, this, boost::asio::placeholders::error)); + newConnection.reset( + new http::Connection(ioService, requestHandler) + ); + acceptor.async_accept( + newConnection->socket(), + boost::bind( + &Server::handleAccept, + this, + boost::asio::placeholders::error + ) + ); } } unsigned threadPoolSize; boost::asio::io_service ioService; boost::asio::ip::tcp::acceptor acceptor; - ConnectionPtr newConnection; + boost::shared_ptr newConnection; RequestHandler requestHandler; }; -} // namespace http - #endif // SERVER_H diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index 966dc920f..160e5ac10 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -25,21 +25,19 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SERVERFACTORY_H_ #define SERVERFACTORY_H_ -#include - #include "Server.h" -#include "ServerConfiguration.h" +#include "../Util/BaseConfiguration.h" #include "../Util/InputFileUtil.h" #include "../Util/OpenMPWrapper.h" #include "../Util/StringUtil.h" #include "../typedefs.h" -typedef http::Server Server; +#include struct ServerFactory { - static Server * CreateServer(ServerConfiguration& serverConfig) { + static Server * CreateServer(BaseConfiguration& serverConfig) { if(!testDataFile(serverConfig.GetParameter("nodesData"))) { ERR("nodes file not found"); @@ -76,7 +74,7 @@ struct ServerFactory { } static Server * CreateServer(const char * iniFile) { - ServerConfiguration serverConfig(iniFile); + BaseConfiguration serverConfig(iniFile); return CreateServer(serverConfig); } }; From 63d8abe32fa003abca8940ac85e4f9617c125a3f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 19:48:22 -0400 Subject: [PATCH 05/61] First implementation of moving the algorithmic core into a library --- CMakeLists.txt | 26 ++++++++++++++-------- Contractor/TemporaryStorage.cpp | 2 -- Contractor/TemporaryStorage.h | 1 + DataStructures/BinaryHeap.h | 12 +++++----- DataStructures/NodeCoords.h | 5 +++-- DataStructures/SegmentInformation.h | 5 +++-- DataStructures/StaticGraph.h | 7 +++--- DataStructures/XORFastHashStorage.h | 4 ++-- Descriptors/BaseDescriptor.h | 18 +++++++-------- Descriptors/DescriptionFactory.h | 6 ++--- Descriptors/GPXDescriptor.h | 3 ++- Descriptors/JSONDescriptor.h | 10 ++++----- RoutingAlgorithms/AlternativePathRouting.h | 7 +++--- RoutingAlgorithms/ShortestPathRouting.h | 12 +++++----- 14 files changed, 64 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3de4c4f13..d24f7a894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,21 +12,27 @@ file(GLOB PrepareGlob Contractor/*.cpp) set(PrepareSources createHierarchy.cpp ${PrepareGlob}) add_executable(osrm-prepare ${PrepareSources}) -file(GLOB RoutedGlob Server/DataStructures/*.cpp Descriptors/*.cpp DataStructures/SearchEngine*.cpp) -set(RoutedSources routed.cpp ${RoutedGlob}) -add_executable(osrm-routed ${RoutedSources}) +add_executable(osrm-routed routed.cpp) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) +file(GLOB DescriptorGlob Descriptors/*.cpp) +file(GLOB LibOSRMGlob Library/*.cpp) +file(GLOB SearchEngineSource DataStructures/SearchEngine*.cpp) +file(GLOB ServerStructureGlob Server/DataStructures/*.cpp) + +set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${SearchEngineSource} ${ServerStructureGlob}) +add_library(OSRM SHARED ${OSRMSources}) + # Check the release mode if(NOT CMAKE_BUILD_TYPE MATCHES Debug) set(CMAKE_BUILD_TYPE Release) -endif(NOT CMAKE_BUILD_TYPE MATCHES Debug) +endif(NOT CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Debug) message(STATUS "Configuring OSRM in debug mode") -endif(CMAKE_BUILD_TYPE MATCHES Debug) +endif(CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Release) message(STATUS "Configuring OSRM in release mode") -endif(CMAKE_BUILD_TYPE MATCHES Release) +endif(CMAKE_BUILD_TYPE MATCHES Release) #Configuring compilers if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -35,7 +41,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") message(STATUS "OpenMP parallelization not available using clang++") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "-Wall -fopenmp -pedantic") + set(CMAKE_CXX_FLAGS "-Wall -fopenmp -pedantic") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # using Intel C++ set(CMAKE_CXX_FLAGS "-static-intel -wd10237 -Wall -openmp -ipo") @@ -55,9 +61,11 @@ if (NOT Boost_FOUND) message(FATAL_ERROR "Fatal error: Boost (version >= 1.44.0) required.\n") endif (NOT Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) + +target_link_libraries( OSRM ${Boost_LIBRARIES}) target_link_libraries( osrm-extract ${Boost_LIBRARIES} ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) -target_link_libraries( osrm-routed ${Boost_LIBRARIES} ) +target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM) find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) @@ -70,7 +78,7 @@ target_link_libraries (osrm-routed ${ZLIB_LIBRARY}) find_package( Threads REQUIRED ) target_link_libraries (osrm-extract ${Threads_LIBRARY}) -find_package( Lua51 REQUIRED ) +find_package( Lua51 REQUIRED ) include_directories(${LUA_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUA_LIBRARY} ) target_link_libraries( osrm-prepare ${LUA_LIBRARY} ) diff --git a/Contractor/TemporaryStorage.cpp b/Contractor/TemporaryStorage.cpp index 7c894b05c..dbd86e3e5 100644 --- a/Contractor/TemporaryStorage.cpp +++ b/Contractor/TemporaryStorage.cpp @@ -18,8 +18,6 @@ or see http://www.gnu.org/licenses/agpl.txt. */ -#include - #include "TemporaryStorage.h" TemporaryStorage::TemporaryStorage() { diff --git a/Contractor/TemporaryStorage.h b/Contractor/TemporaryStorage.h index e1899817b..84004c71c 100644 --- a/Contractor/TemporaryStorage.h +++ b/Contractor/TemporaryStorage.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index f8b34704f..5bbcb3b3f 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -23,13 +23,15 @@ or see http://www.gnu.org/licenses/agpl.txt. //Not compatible with non contiguous node ids -#include -#include -#include -#include -#include #include +#include + +#include +#include +#include +#include + template< typename NodeID, typename Key > class ArrayStorage { public: diff --git a/DataStructures/NodeCoords.h b/DataStructures/NodeCoords.h index 4893a9de6..80fda42b8 100644 --- a/DataStructures/NodeCoords.h +++ b/DataStructures/NodeCoords.h @@ -21,12 +21,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef _NODE_COORDS_H #define _NODE_COORDS_H +#include "../typedefs.h" + #include #include #include -#include -#include "../typedefs.h" +#include template struct NodeCoords { diff --git a/DataStructures/SegmentInformation.h b/DataStructures/SegmentInformation.h index cbe4b81cc..8f65eda72 100644 --- a/DataStructures/SegmentInformation.h +++ b/DataStructures/SegmentInformation.h @@ -21,9 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SEGMENTINFORMATION_H_ #define SEGMENTINFORMATION_H_ -#include - #include "TurnInstructions.h" +#include "../typedefs.h" + +#include struct SegmentInformation { _Coordinate location; diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index eb41683a5..7504cbaa9 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -21,11 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STATICGRAPH_H_INCLUDED #define STATICGRAPH_H_INCLUDED -#include -#include - #include "../typedefs.h" -#include "ImportEdge.h" + +#include +#include template< typename EdgeDataT> class StaticGraph { diff --git a/DataStructures/XORFastHashStorage.h b/DataStructures/XORFastHashStorage.h index 91820e118..1998f2832 100644 --- a/DataStructures/XORFastHashStorage.h +++ b/DataStructures/XORFastHashStorage.h @@ -21,12 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef XORFASTHASHSTORAGE_H_ #define XORFASTHASHSTORAGE_H_ +#include "XORFastHash.h" + #include #include #include -#include "XORFastHash.h" - template< typename NodeID, typename Key > class XORFastHashStorage { public: diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 2ead8bdae..64d776cb3 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -21,19 +21,19 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASE_DESCRIPTOR_H_ #define BASE_DESCRIPTOR_H_ -#include -#include -#include -#include -#include - -#include "../typedefs.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/PhantomNodes.h" #include "../DataStructures/SearchEngine.h" -#include "../Util/StringUtil.h" - #include "../Plugins/RawRouteData.h" +#include "../Util/StringUtil.h" +#include "../typedefs.h" + +#include +#include +#include + +#include +#include struct _DescriptorConfig { _DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(true), z(18) {} diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 911aae7de..e54752d16 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -21,15 +21,15 @@ #ifndef DESCRIPTIONFACTORY_H_ #define DESCRIPTIONFACTORY_H_ -#include - -#include "../typedefs.h" #include "../Algorithms/DouglasPeucker.h" #include "../Algorithms/PolylineCompressor.h" #include "../DataStructures/Coordinate.h" #include "../DataStructures/SearchEngine.h" #include "../DataStructures/SegmentInformation.h" #include "../DataStructures/TurnInstructions.h" +#include "../typedefs.h" + +#include /* This class is fed with all way segments in consecutive order * and produces the description plus the encoded polyline */ diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index 1d3389ade..f4a8190c5 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -21,9 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef GPX_DESCRIPTOR_H_ #define GPX_DESCRIPTOR_H_ -#include #include "BaseDescriptor.h" +#include + class GPXDescriptor : public BaseDescriptor{ private: _DescriptorConfig config; diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 1db2c688f..7ef4c8dfd 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -21,11 +21,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef JSON_DESCRIPTOR_H_ #define JSON_DESCRIPTOR_H_ -#include - -#include -#include - #include "BaseDescriptor.h" #include "DescriptionFactory.h" #include "../Algorithms/ObjectToBase64.h" @@ -34,6 +29,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/Azimuth.h" #include "../Util/StringUtil.h" +#include +#include + +#include + class JSONDescriptor : public BaseDescriptor{ private: _DescriptorConfig config; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 4cd256b98..8c3e53ef3 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -21,11 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef ALTERNATIVEROUTES_H_ #define ALTERNATIVEROUTES_H_ -#include -#include -#include - #include "BasicRoutingInterface.h" +#include +#include +#include const double VIAPATH_ALPHA = 0.15; const double VIAPATH_EPSILON = 0.10; //alternative at most 15% longer diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 472e7ddbe..dc69ed31f 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -73,23 +73,23 @@ public: //insert new starting nodes into forward heap, adjusted by previous distances. if(searchFrom1stStartNode) { forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); - INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); + // INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); - INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); + // INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); } if(phantomNodePair.startPhantom.isBidirected() && searchFrom2ndStartNode) { forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); - INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); + // INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); - INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); + // INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); } //insert new backward nodes into backward heap, unadjusted. reverse_heap1.Insert(phantomNodePair.targetPhantom.edgeBasedNode, phantomNodePair.targetPhantom.weight1, phantomNodePair.targetPhantom.edgeBasedNode); - INFO("rv1: " << phantomNodePair.targetPhantom.edgeBasedNode << ", w;" << phantomNodePair.targetPhantom.weight1 ); + // INFO("rv1: " << phantomNodePair.targetPhantom.edgeBasedNode << ", w;" << phantomNodePair.targetPhantom.weight1 ); if(phantomNodePair.targetPhantom.isBidirected() ) { reverse_heap2.Insert(phantomNodePair.targetPhantom.edgeBasedNode+1, phantomNodePair.targetPhantom.weight2, phantomNodePair.targetPhantom.edgeBasedNode+1); - INFO("rv2: " << phantomNodePair.targetPhantom.edgeBasedNode+1 << ", w;" << phantomNodePair.targetPhantom.weight2 ); + // INFO("rv2: " << phantomNodePair.targetPhantom.edgeBasedNode+1 << ", w;" << phantomNodePair.targetPhantom.weight2 ); } const int forward_offset = phantomNodePair.startPhantom.weight1 + (phantomNodePair.startPhantom.isBidirected() ? phantomNodePair.startPhantom.weight2 : 0); const int reverse_offset = phantomNodePair.targetPhantom.weight1 + (phantomNodePair.targetPhantom.isBidirected() ? phantomNodePair.targetPhantom.weight2 : 0); From 74729a372b163a592d49a3d2e49cdef2a08c8c22 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 20:05:03 -0400 Subject: [PATCH 06/61] some refactoring --- Extractor/ExtractionContainers.cpp | 6 ++-- Extractor/ExtractionContainers.h | 2 +- createHierarchy.cpp | 8 ++--- extractor.cpp | 53 ++++++++++++++++-------------- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 2cb2baf22..14e8352b5 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -20,7 +20,7 @@ #include "ExtractionContainers.h" -void ExtractionContainers::PrepareData(const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM) { +void ExtractionContainers::PrepareData(const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM) { try { unsigned usedNodeCounter = 0; unsigned usedEdgeCounter = 0; @@ -130,7 +130,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const restrictionsOutstream.close(); std::ofstream fout; - fout.open(outputFileName.c_str(), std::ios::binary); + fout.open(output_file_name.c_str(), std::ios::binary); fout.write((char*)&usedNodeCounter, sizeof(unsigned)); time = get_timestamp(); std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush; @@ -271,7 +271,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const std::cout << "ok" << std::endl; time = get_timestamp(); std::cout << "[extractor] writing street name index ... " << std::flush; - std::string nameOutFileName = (outputFileName + ".names"); + std::string nameOutFileName = (output_file_name + ".names"); std::ofstream nameOutFile(nameOutFileName.c_str(), std::ios::binary); unsigned sizeOfNameIndex = nameVector.size(); nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned)); diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index f5dfa789d..f3815c12f 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -55,7 +55,7 @@ public: wayStartEndVector.clear(); } - void PrepareData( const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM); + void PrepareData( const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM); STXXLNodeIDVector usedNodeIDs; STXXLNodeVector allNodes; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 5e6343d1d..3f76fcd19 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -63,14 +63,14 @@ int main (int argc, char *argv[]) { } double startupTime = get_timestamp(); - unsigned numberOfThreads = omp_get_num_procs(); + unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("contractor.ini")) { ContractorConfiguration contractorConfig("contractor.ini"); unsigned rawNumber = stringToInt(contractorConfig.GetParameter("Threads")); - if(rawNumber != 0 && rawNumber <= numberOfThreads) - numberOfThreads = rawNumber; + if(rawNumber != 0 && rawNumber <= number_of_threads) + number_of_threads = rawNumber; } - omp_set_num_threads(numberOfThreads); + omp_set_num_threads(number_of_threads); INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], std::ios::binary); diff --git a/extractor.cpp b/extractor.cpp index 3beeef510..800fd8be5 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -31,17 +31,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "typedefs.h" #include + #include #include - #include -typedef BaseConfiguration ExtractorConfiguration; - ExtractorCallbacks * extractCallBacks; int main (int argc, char *argv[]) { - double earliestTime = get_timestamp(); + double startup_time = get_timestamp(); if(argc < 2) { ERR("usage: \n" << argv[0] << " []"); @@ -50,36 +48,37 @@ int main (int argc, char *argv[]) { /*** Setup Scripting Environment ***/ ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); - unsigned numberOfThreads = omp_get_num_procs(); + unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("extractor.ini")) { - ExtractorConfiguration extractorConfig("extractor.ini"); + BaseConfiguration extractorConfig("extractor.ini"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); - if( rawNumber != 0 && rawNumber <= numberOfThreads) - numberOfThreads = rawNumber; + if( rawNumber != 0 && rawNumber <= number_of_threads) { + number_of_threads = rawNumber; + } } - omp_set_num_threads(numberOfThreads); + omp_set_num_threads(number_of_threads); INFO("extracting data from input file " << argv[1]); - bool isPBF(false); - std::string outputFileName(argv[1]); + bool file_has_pbf_format(false); + std::string output_file_name(argv[1]); std::string restrictionsFileName(argv[1]); - std::string::size_type pos = outputFileName.find(".osm.bz2"); + std::string::size_type pos = output_file_name.find(".osm.bz2"); if(pos==std::string::npos) { - pos = outputFileName.find(".osm.pbf"); + pos = output_file_name.find(".osm.pbf"); if(pos!=std::string::npos) { - isPBF = true; + file_has_pbf_format = true; } } if(pos!=std::string::npos) { - outputFileName.replace(pos, 8, ".osrm"); + output_file_name.replace(pos, 8, ".osrm"); restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); } else { - pos=outputFileName.find(".osm"); + pos=output_file_name.find(".osm"); if(pos!=std::string::npos) { - outputFileName.replace(pos, 5, ".osrm"); + output_file_name.replace(pos, 5, ".osrm"); restrictionsFileName.replace(pos, 5, ".osrm.restrictions"); } else { - outputFileName.append(".osrm"); + output_file_name.append(".osrm"); restrictionsFileName.append(".osrm.restrictions"); } } @@ -96,7 +95,7 @@ int main (int argc, char *argv[]) { stringMap[""] = 0; extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap); BaseParser* parser; - if(isPBF) { + if(file_has_pbf_format) { parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment); } else { parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment); @@ -106,18 +105,22 @@ int main (int argc, char *argv[]) { ERR("Parser not initialized!"); } INFO("Parsing in progress.."); - double time = get_timestamp(); + double parsing_start_time = get_timestamp(); parser->Parse(); - INFO("Parsing finished after " << get_timestamp() - time << " seconds"); + INFO("Parsing finished after " << + (get_timestamp() - parsing_start_time) << + " seconds" + ); - externalMemory.PrepareData(outputFileName, restrictionsFileName, amountOfRAM); + externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM); - stringMap.clear(); delete parser; delete extractCallBacks; - INFO("finished after " << get_timestamp() - earliestTime << "s"); + + INFO("extraction finished after " << get_timestamp() - startup_time << "s"); std::cout << "\nRun:\n" - "./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl; + << "./osrm-prepare " << output_file_name << " " << restrictionsFileName + << std::endl; return 0; } From aecbcdd3904157fd50d91d716f093ded255e4bd7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 20:05:42 -0400 Subject: [PATCH 07/61] move OSRM core into library --- Library/OSRM.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ Library/OSRM.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 Library/OSRM.cpp create mode 100644 Library/OSRM.h diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp new file mode 100644 index 000000000..d6ef0763d --- /dev/null +++ b/Library/OSRM.cpp @@ -0,0 +1,61 @@ +/* + 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. + */ + +#include "OSRM.h" + +OSRM::OSRM(const char * server_ini_path) { + BaseConfiguration serverConfig(server_ini_path); + QueryObjectsStorage * objects = new QueryObjectsStorage( + serverConfig.GetParameter("hsgrData"), + serverConfig.GetParameter("ramIndex"), + serverConfig.GetParameter("fileIndex"), + serverConfig.GetParameter("nodesData"), + serverConfig.GetParameter("edgesData"), + serverConfig.GetParameter("namesData"), + serverConfig.GetParameter("timestamp") + ); + + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin(objects)); + RegisterPlugin(new NearestPlugin(objects)); + RegisterPlugin(new TimestampPlugin(objects)); + RegisterPlugin(new ViaRoutePlugin(objects)); +} + +OSRM::~OSRM() { + BOOST_FOREACH(PluginMap::value_type plugin_pointer, pluginMap) { + delete plugin_pointer.second; + } +} + +void OSRM::RegisterPlugin(BasePlugin * plugin) { + std::cout << "[plugin] " << plugin->GetDescriptor() << std::endl; + pluginMap[plugin->GetDescriptor()] = plugin; +} + +void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { + PluginMap::const_iterator iter = pluginMap.find(route_parameters.service); + if(pluginMap.end() != iter) { + reply.status = http::Reply::ok; + iter->second->HandleRequest(route_parameters, reply ); + } else { + reply = http::Reply::stockReply(http::Reply::badRequest); + } +} diff --git a/Library/OSRM.h b/Library/OSRM.h new file mode 100644 index 000000000..adace328e --- /dev/null +++ b/Library/OSRM.h @@ -0,0 +1,55 @@ +/* + 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_H +#define OSRM_H + +#include "OSRM.h" + +#include "../Plugins/BasePlugin.h" +#include "../Plugins/HelloWorldPlugin.h" +#include "../Plugins/LocatePlugin.h" +#include "../Plugins/NearestPlugin.h" +#include "../Plugins/TimestampPlugin.h" +#include "../Plugins/ViaRoutePlugin.h" +#include "../Plugins/RouteParameters.h" +#include "../Util/BaseConfiguration.h" +#include "../Server/BasicDataStructures.h" + + +#include +#include +#include + +#include + +class OSRM : boost::noncopyable { + typedef boost::unordered_map PluginMap; + +public: + OSRM(const char * server_ini_path); + ~OSRM(); + void RunQuery(RouteParameters & route_parameters, http::Reply & reply); +private: + void RegisterPlugin(BasePlugin * plugin); + PluginMap pluginMap; +}; + +#endif //OSRM_H \ No newline at end of file From cfa8b1f0dd6f781cd12932658d30dac3104bf1d2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 09:45:28 -0400 Subject: [PATCH 08/61] Moving coordinate auxiliary functions into the appropriate place --- DataStructures/Coordinate.h | 30 +++++++++++++++++++++++++++++- Descriptors/DescriptionFactory.cpp | 2 +- Util/StringUtil.h | 28 ---------------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h index bc6328991..11ae3069e 100644 --- a/DataStructures/Coordinate.h +++ b/DataStructures/Coordinate.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef COORDINATE_H_ #define COORDINATE_H_ +#include "../Util/StringUtil.h" + #include #include #include @@ -87,7 +89,7 @@ inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon ); } -inline double ApproximateDistanceByEuclid(const _Coordinate &c1, const _Coordinate &c2) { +inline double ApproximateEuclideanDistance(const _Coordinate &c1, const _Coordinate &c2) { assert(c1.lat != INT_MIN); assert(c1.lon != INT_MIN); assert(c2.lat != INT_MIN); @@ -105,4 +107,30 @@ inline double ApproximateDistanceByEuclid(const _Coordinate &c1, const _Coordina return d; } +static inline void convertInternalLatLonToString(const int value, std::string & output) { + char buffer[100]; + buffer[10] = 0; // Nullterminierung + char* string = printInt< 10, 5 >( buffer, value ); + output = string; +} + +static inline void convertInternalCoordinateToString(const _Coordinate & coord, std::string & output) { + std::string tmp; + convertInternalLatLonToString(coord.lon, tmp); + output = tmp; + output += ","; + convertInternalLatLonToString(coord.lat, tmp); + output += tmp; + output += " "; +} +static inline void convertInternalReversedCoordinateToString(const _Coordinate & coord, std::string & output) { + std::string tmp; + convertInternalLatLonToString(coord.lat, tmp); + output = tmp; + output += ","; + convertInternalLatLonToString(coord.lon, tmp); + output += tmp; + output += " "; +} + #endif /* COORDINATE_H_ */ diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index b1f2f8538..63e8883eb 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -91,7 +91,7 @@ void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLev /** starts at index 1 */ pathDescription[0].length = 0; for(unsigned i = 1; i < pathDescription.size(); ++i) { - pathDescription[i].length = ApproximateDistanceByEuclid(pathDescription[i-1].location, pathDescription[i].location); + pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); } double lengthOfSegment = 0; diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 951a21c4a..3c1b590f1 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -21,8 +21,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STRINGUTIL_H_ #define STRINGUTIL_H_ - -#include "../DataStructures/Coordinate.h" #include "../typedefs.h" #include @@ -95,32 +93,6 @@ static inline void doubleToStringWithTwoDigitsBehindComma(const double value, st output = buffer ; } -static inline void convertInternalLatLonToString(const int value, std::string & output) { - char buffer[100]; - buffer[10] = 0; // Nullterminierung - char* string = printInt< 10, 5 >( buffer, value ); - output = string; -} - -static inline void convertInternalCoordinateToString(const _Coordinate & coord, std::string & output) { - std::string tmp; - convertInternalLatLonToString(coord.lon, tmp); - output = tmp; - output += ","; - convertInternalLatLonToString(coord.lat, tmp); - output += tmp; - output += " "; -} -static inline void convertInternalReversedCoordinateToString(const _Coordinate & coord, std::string & output) { - std::string tmp; - convertInternalLatLonToString(coord.lat, tmp); - output = tmp; - output += ","; - convertInternalLatLonToString(coord.lon, tmp); - output += tmp; - output += " "; -} - inline void replaceAll(std::string &s, const std::string &sub, const std::string &other) { boost::replace_all(s, sub, other); } From 1f5f8a76fb9b7001f0e12c0c5debf38551fab380 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 09:54:58 -0400 Subject: [PATCH 09/61] Removing files that are not used anymore --- DataStructures/GridEdge.h | 82 ----- DataStructures/NNGrid.h | 602 ------------------------------------- Plugins/PluginMapFactory.h | 34 --- 3 files changed, 718 deletions(-) delete mode 100644 DataStructures/GridEdge.h delete mode 100644 DataStructures/NNGrid.h delete mode 100644 Plugins/PluginMapFactory.h diff --git a/DataStructures/GridEdge.h b/DataStructures/GridEdge.h deleted file mode 100644 index 7b2dd7825..000000000 --- a/DataStructures/GridEdge.h +++ /dev/null @@ -1,82 +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 GRIDEDGE_H_ -#define GRIDEDGE_H_ - -#include "Coordinate.h" - -struct _GridEdge { - _GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc, bool bttc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc), belongsToTinyComponent(bttc) {} - _GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX), belongsToTinyComponent(false) {} - NodeID edgeBasedNode; - NodeID nameID; - int weight; - _Coordinate startCoord; - _Coordinate targetCoord; - bool belongsToTinyComponent; - - bool operator< ( const _GridEdge& right) const { - return edgeBasedNode < right.edgeBasedNode; - } - bool operator== ( const _GridEdge& right) const { - return edgeBasedNode == right.edgeBasedNode; - } -}; - -struct GridEntry { - GridEntry() : fileIndex(UINT_MAX), ramIndex(UINT_MAX){} - GridEntry(_GridEdge e, unsigned f, unsigned r) : edge(e), fileIndex(f), ramIndex(r) {} - _GridEdge edge; - unsigned fileIndex; - unsigned ramIndex; - bool operator< ( const GridEntry& right ) const { - return (edge.edgeBasedNode < right.edge.edgeBasedNode); - } - bool operator==( const GridEntry& right ) const { - return right.edge.edgeBasedNode == edge.edgeBasedNode; - } -}; - -struct CompareGridEdgeDataByFileIndex { - bool operator () (const GridEntry & a, const GridEntry & b) const { - return a.fileIndex < b.fileIndex; - } -}; - -struct CompareGridEdgeDataByRamIndex { - typedef GridEntry value_type; - - bool operator () (const GridEntry & a, const GridEntry & b) const { - return a.ramIndex < b.ramIndex; - } - value_type max_value() { - GridEntry e; - e.ramIndex = (1024*1024) - 1; - return e; - } - value_type min_value() { - GridEntry e; - e.ramIndex = 0; - return e; - } -}; - -#endif /* GRIDEDGE_H_ */ diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h deleted file mode 100644 index 22cb4e2d4..000000000 --- a/DataStructures/NNGrid.h +++ /dev/null @@ -1,602 +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 NNGRID_H_ -#define NNGRID_H_ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifndef ROUTED -#include -#endif - -#ifdef _WIN32 -#include -#endif - -#include -#include -#include - -#include "DeallocatingVector.h" -#include "GridEdge.h" -#include "Percent.h" -#include "PhantomNodes.h" -#include "MercatorUtil.h" -#include "StaticGraph.h" -#include "TimingUtil.h" -#include "../Algorithms/Bresenham.h" - -namespace NNGrid{ - -static boost::thread_specific_ptr localStream; - -template -class NNGrid { -public: - NNGrid() /*: cellCache(500), fileCache(500)*/ { - ramIndexTable.resize((1024*1024), std::numeric_limits::max()); - } - - NNGrid(const char* rif, const char* _i) { - if(WriteAccess) { - ERR("Not available in Write mode"); - } - iif = std::string(_i); - ramIndexTable.resize((1024*1024), std::numeric_limits::max()); - ramInFile.open(rif, std::ios::in | std::ios::binary); - if(!ramInFile) { ERR(rif << " not found"); } - - } - - ~NNGrid() { - if(ramInFile.is_open()) ramInFile.close(); - -#ifndef ROUTED - if (WriteAccess) { - entries.clear(); - } -#endif - if(localStream.get() && localStream->is_open()) { - localStream->close(); - } - } - - void OpenIndexFiles() { - assert(ramInFile.is_open()); - ramInFile.read(static_cast(static_cast(&ramIndexTable[0]) ), sizeof(uint64_t)*1024*1024); - ramInFile.close(); - } - -#ifndef ROUTED - template - inline void ConstructGrid(DeallocatingVector & edgeList, const char * ramIndexOut, const char * fileIndexOut) { - //TODO: Implement this using STXXL-Streams - Percent p(edgeList.size()); - BOOST_FOREACH(EdgeT & edge, edgeList) { - p.printIncrement(); - if(edge.ignoreInGrid) - continue; - int slat = 100000*lat2y(edge.lat1/100000.); - int slon = edge.lon1; - int tlat = 100000*lat2y(edge.lat2/100000.); - int tlon = edge.lon2; - AddEdge( _GridEdge( edge.id, edge.nameID, edge.weight, _Coordinate(slat, slon), _Coordinate(tlat, tlon), edge.belongsToTinyComponent ) ); - } - if( 0 == entries.size() ) { - ERR("No viable edges for nearest neighbor index. Aborting"); - } - double timestamp = get_timestamp(); - //create index file on disk, old one is over written - indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc); - //sort entries - stxxl::sort(entries.begin(), entries.end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024); - INFO("finished sorting after " << (get_timestamp() - timestamp) << "s"); - std::vector entriesInFileWithRAMSameIndex; - unsigned indexInRamTable = entries.begin()->ramIndex; - uint64_t lastPositionInIndexFile = 0; - std::cout << "writing data ..." << std::flush; - p.reinit(entries.size()); - boost::unordered_map< unsigned, unsigned > cellMap(1024); - BOOST_FOREACH(GridEntry & gridEntry, entries) { - p.printIncrement(); - if(gridEntry.ramIndex != indexInRamTable) { - cellMap.clear(); - BuildCellIndexToFileIndexMap(indexInRamTable, cellMap); - - unsigned numberOfBytesInCell = FillCell(entriesInFileWithRAMSameIndex, lastPositionInIndexFile, cellMap); - ramIndexTable[indexInRamTable] = lastPositionInIndexFile; - lastPositionInIndexFile += numberOfBytesInCell; - entriesInFileWithRAMSameIndex.clear(); - indexInRamTable = gridEntry.ramIndex; - } - entriesInFileWithRAMSameIndex.push_back(gridEntry); - } - cellMap.clear(); - BuildCellIndexToFileIndexMap(indexInRamTable, cellMap); - /*unsigned numberOfBytesInCell = */FillCell(entriesInFileWithRAMSameIndex, lastPositionInIndexFile, cellMap); - ramIndexTable[indexInRamTable] = lastPositionInIndexFile; - entriesInFileWithRAMSameIndex.clear(); - std::vector().swap(entriesInFileWithRAMSameIndex); - assert(entriesInFileWithRAMSameIndex.size() == 0); - //close index file - indexOutFile.close(); - - //Serialize RAM Index - std::ofstream ramFile(ramIndexOut, std::ios::out | std::ios::binary | std::ios::trunc); - //write 4 MB of index Table in RAM - ramFile.write((char *)&ramIndexTable[0], sizeof(uint64_t)*1024*1024 ); - //close ram index file - ramFile.close(); - } -#endif - inline bool CoordinatesAreEquivalent(const _Coordinate & a, const _Coordinate & b, const _Coordinate & c, const _Coordinate & d) const { - return (a == b && c == d) || (a == c && b == d) || (a == d && b == c); - } - - bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) { - bool ignoreTinyComponents = (zoomLevel <= 14); -// INFO("Coordinate: " << location << ", zoomLevel: " << zoomLevel << ", ignoring tinyComponentents: " << (ignoreTinyComponents ? "yes" : "no")); -// double time1 = get_timestamp(); - bool foundNode = false; - const _Coordinate startCoord(100000*(lat2y(static_cast(location.lat)/100000.)), location.lon); - /** search for point on edge close to source */ - const unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon); - std::vector<_GridEdge> candidates; - const int lowerBoundForLoop = (fileIndex < 32768 ? 0 : -32768); - for(int j = lowerBoundForLoop; (j < (32768+1)) && (fileIndex != UINT_MAX); j+=32768) { - for(int i = -1; i < 2; ++i){ -// unsigned oldSize = candidates.size(); - GetContentsOfFileBucketEnumerated(fileIndex+i+j, candidates); -// INFO("Getting fileIndex=" << fileIndex+i+j << " with " << candidates.size() - oldSize << " candidates"); - } - } -// INFO("looked up " << candidates.size()); - _GridEdge smallestEdge; - _Coordinate tmp, edgeStartCoord, edgeEndCoord; - double dist = std::numeric_limits::max(); - double r, tmpDist; - - BOOST_FOREACH(const _GridEdge & candidate, candidates) { - if(candidate.belongsToTinyComponent && ignoreTinyComponents) - continue; - r = 0.; - tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); -// INFO("dist " << startCoord << "->[" << candidate.startCoord << "-" << candidate.targetCoord << "]=" << tmpDist ); -// INFO("Looking at edge " << candidate.edgeBasedNode << " at distance " << tmpDist); - if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) { -// INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist << ", tinyCC: " << (candidate.belongsToTinyComponent ? "yes" : "no")); - dist = tmpDist; - resultNode.edgeBasedNode = candidate.edgeBasedNode; - resultNode.nodeBasedEdgeNameID = candidate.nameID; - resultNode.weight1 = candidate.weight; - resultNode.weight2 = INT_MAX; - resultNode.location.lat = tmp.lat; - resultNode.location.lon = tmp.lon; - edgeStartCoord = candidate.startCoord; - edgeEndCoord = candidate.targetCoord; - foundNode = true; - smallestEdge = candidate; - //} else if(tmpDist < dist) { - //INFO("a) ignored " << candidate.edgeBasedNode << " at distance " << std::fabs(dist - tmpDist)); - } else if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs(static_cast(candidate.edgeBasedNode)-static_cast(resultNode.edgeBasedNode) ) && CoordinatesAreEquivalent(edgeStartCoord, candidate.startCoord, edgeEndCoord, candidate.targetCoord)) { - resultNode.edgeBasedNode = std::min(candidate.edgeBasedNode, resultNode.edgeBasedNode); - resultNode.weight2 = candidate.weight; - //INFO("b) " << candidate.edgeBasedNode << ", dist: " << tmpDist); - } - } - - // INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint); - // INFO("length of old edge: " << ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord)); - // INFO("Length of new edge: " << ApproximateDistance(smallestEdge.startCoord, newEndpoint)); - // assert(!resultNode.isBidirected() || (resultNode.weight1 == resultNode.weight2)); - // if(resultNode.weight1 != resultNode.weight2) { - // INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2); - // INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected() ? "yes" : "no")); - // } - -// INFO("startCoord: " << smallestEdge.startCoord << "; targetCoord: " << smallestEdge.targetCoord << "; newEndpoint: " << resultNode.location); - const double ratio = (foundNode ? std::min(1., ApproximateDistance(smallestEdge.startCoord, resultNode.location)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord)) : 0); - resultNode.location.lat = round(100000.*(y2lat(static_cast(resultNode.location.lat)/100000.))); -// INFO("Length of vector: " << ApproximateDistance(smallestEdge.startCoord, resultNode.location)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord)); - //Hack to fix rounding errors and wandering via nodes. - if(std::abs(location.lon - resultNode.location.lon) == 1) - resultNode.location.lon = location.lon; - if(std::abs(location.lat - resultNode.location.lat) == 1) - resultNode.location.lat = location.lat; - - resultNode.weight1 *= ratio; - if(INT_MAX != resultNode.weight2) { - resultNode.weight2 *= (1.-ratio); - } - resultNode.ratio = ratio; -// INFO("start: " << edgeStartCoord << ", end: " << edgeEndCoord); -// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no")); -// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio); - // INFO("distance to input coordinate: " << ApproximateDistance(location, resultNode.location) << "\n--"); -// double time2 = get_timestamp(); -// INFO("NN-Lookup in " << 1000*(time2-time1) << "ms"); - return foundNode; - } - - bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes & routingStarts, unsigned zoomLevel) { - routingStarts.Reset(); - return (FindPhantomNodeForCoordinate( start, routingStarts.startPhantom, zoomLevel) && - FindPhantomNodeForCoordinate( target, routingStarts.targetPhantom, zoomLevel) ); - } - - bool FindNearestCoordinateOnEdgeInNodeBasedGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate, unsigned zoomLevel = 18) { - PhantomNode resultNode; - bool foundNode = FindPhantomNodeForCoordinate(inputCoordinate, resultNode, zoomLevel); - outputCoordinate = resultNode.location; - return foundNode; - } - - void FindNearestPointOnEdge(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) { - _Coordinate startCoord(100000*(lat2y(static_cast(inputCoordinate.lat)/100000.)), inputCoordinate.lon); - unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon); - - std::vector<_GridEdge> candidates; - boost::unordered_map< unsigned, unsigned > cellMap; - for(int j = -32768; j < (32768+1); j+=32768) { - for(int i = -1; i < 2; ++i) { - GetContentsOfFileBucket(fileIndex+i+j, candidates, cellMap); - } - } - _Coordinate tmp; - double dist = (std::numeric_limits::max)(); - BOOST_FOREACH(const _GridEdge & candidate, candidates) { - double r = 0.; - double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); - if(tmpDist < dist) { - dist = tmpDist; - outputCoordinate.lat = round(100000*(y2lat(static_cast(tmp.lat)/100000.))); - outputCoordinate.lon = tmp.lon; - } - } - } - - -private: - inline unsigned GetCellIndexFromRAMAndFileIndex(const unsigned ramIndex, const unsigned fileIndex) const { - unsigned lineBase = ramIndex/1024; - lineBase = lineBase*32*32768; - unsigned columnBase = ramIndex%1024; - columnBase=columnBase*32; - for (int i = 0;i < 32;++i) { - for (int j = 0;j < 32;++j) { - const unsigned localFileIndex = lineBase + i * 32768 + columnBase + j; - if(localFileIndex == fileIndex) { - unsigned cellIndex = i * 32 + j; - return cellIndex; - } - } - } - return UINT_MAX; - } - - inline void BuildCellIndexToFileIndexMap(const unsigned ramIndex, boost::unordered_map& cellMap){ - unsigned lineBase = ramIndex/1024; - lineBase = lineBase*32*32768; - unsigned columnBase = ramIndex%1024; - columnBase=columnBase*32; - std::vector >insertionVector(1024); - for (int i = 0;i < 32;++i) { - for (int j = 0;j < 32;++j) { - unsigned fileIndex = lineBase + i * 32768 + columnBase + j; - unsigned cellIndex = i * 32 + j; - insertionVector[i * 32 + j] = std::make_pair(fileIndex, cellIndex); - } - } - cellMap.insert(insertionVector.begin(), insertionVector.end()); - } - - inline bool DoubleEpsilonCompare(const double d1, const double d2) const { - return (std::fabs(d1 - d2) < FLT_EPSILON); - } - -#ifndef ROUTED - inline unsigned FillCell(std::vector& entriesWithSameRAMIndex, const uint64_t fileOffset, boost::unordered_map< unsigned, unsigned > & cellMap ) { - std::vector tmpBuffer(32*32*4096,0); - uint64_t indexIntoTmpBuffer = 0; - unsigned numberOfWrittenBytes = 0; - assert(indexOutFile.is_open()); - - std::vector cellIndex(32*32,std::numeric_limits::max()); - - for(unsigned i = 0; i < entriesWithSameRAMIndex.size() -1; ++i) { - assert(entriesWithSameRAMIndex[i].ramIndex== entriesWithSameRAMIndex[i+1].ramIndex); - } - - //sort & unique - std::sort(entriesWithSameRAMIndex.begin(), entriesWithSameRAMIndex.end(), CompareGridEdgeDataByFileIndex()); -// entriesWithSameRAMIndex.erase(std::unique(entriesWithSameRAMIndex.begin(), entriesWithSameRAMIndex.end()), entriesWithSameRAMIndex.end()); - - //traverse each file bucket and write its contents to disk - std::vector entriesWithSameFileIndex; - unsigned fileIndex = entriesWithSameRAMIndex.begin()->fileIndex; - - BOOST_FOREACH(GridEntry & gridEntry, entriesWithSameRAMIndex) { - assert(cellMap.find(gridEntry.fileIndex) != cellMap.end() ); //asserting that file index belongs to cell index - if(gridEntry.fileIndex != fileIndex) { - // start in cellIndex vermerken - int localFileIndex = entriesWithSameFileIndex.begin()->fileIndex; - int localCellIndex = cellMap.find(localFileIndex)->second; - assert(cellMap.find(entriesWithSameFileIndex.begin()->fileIndex) != cellMap.end()); - - cellIndex[localCellIndex] = indexIntoTmpBuffer + fileOffset; - indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer); - fileIndex = gridEntry.fileIndex; - } - entriesWithSameFileIndex.push_back(gridEntry); - } - assert(cellMap.find(entriesWithSameFileIndex.begin()->fileIndex) != cellMap.end()); - int localFileIndex = entriesWithSameFileIndex.begin()->fileIndex; - int localCellIndex = cellMap.find(localFileIndex)->second; - - cellIndex[localCellIndex] = indexIntoTmpBuffer + fileOffset; - indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer); - - assert(entriesWithSameFileIndex.size() == 0); - indexOutFile.write(static_cast(static_cast(&cellIndex[0])),32*32*sizeof(uint64_t)); - numberOfWrittenBytes += 32*32*sizeof(uint64_t); - - //write contents of tmpbuffer to disk - indexOutFile.write(&tmpBuffer[0], indexIntoTmpBuffer*sizeof(char)); - numberOfWrittenBytes += indexIntoTmpBuffer*sizeof(char); - - return numberOfWrittenBytes; - } - - inline unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector &vectorWithSameFileIndex, std::vector & tmpBuffer, const uint64_t index) const { - sort( vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end() ); - vectorWithSameFileIndex.erase(unique(vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end()), vectorWithSameFileIndex.end()); - const unsigned lengthOfBucket = vectorWithSameFileIndex.size(); - tmpBuffer.resize(tmpBuffer.size()+(sizeof(_GridEdge)*lengthOfBucket) + sizeof(unsigned) ); - unsigned counter = 0; - - for(unsigned i = 0; i < vectorWithSameFileIndex.size()-1; ++i) { - assert( vectorWithSameFileIndex[i].fileIndex == vectorWithSameFileIndex[i+1].fileIndex ); - assert( vectorWithSameFileIndex[i].ramIndex == vectorWithSameFileIndex[i+1].ramIndex ); - } - - //write length of bucket - memcpy((char*)&(tmpBuffer[index+counter]), (char*)&lengthOfBucket, sizeof(lengthOfBucket)); - counter += sizeof(lengthOfBucket); - - BOOST_FOREACH(const GridEntry & entry, vectorWithSameFileIndex) { - char * data = (char*)&(entry.edge); - memcpy(static_cast(static_cast(&(tmpBuffer[index+counter]) )), data, sizeof(entry.edge)); - counter += sizeof(entry.edge); - } - //Freeing data - vectorWithSameFileIndex.clear(); - return counter; - } -#endif - - inline void GetContentsOfFileBucketEnumerated(const unsigned fileIndex, std::vector<_GridEdge>& result) const { - unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex); - uint64_t startIndexInFile = ramIndexTable[ramIndex]; - if(startIndexInFile == std::numeric_limits::max()) { - return; - } - unsigned enumeratedIndex = GetCellIndexFromRAMAndFileIndex(ramIndex, fileIndex); - - if(!localStream.get() || !localStream->is_open()) { - localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary)); - } - if(!localStream->good()) { - localStream->clear(std::ios::goodbit); - DEBUG("Resetting stale filestream"); - } - - //only read the single necessary cell index - localStream->seekg(startIndexInFile+(enumeratedIndex*sizeof(uint64_t))); - uint64_t fetchedIndex = 0; - localStream->read(static_cast( static_cast(&fetchedIndex)), sizeof(uint64_t)); - - if(fetchedIndex == std::numeric_limits::max()) { - return; - } - const uint64_t position = fetchedIndex + 32*32*sizeof(uint64_t) ; - - unsigned lengthOfBucket; - unsigned currentSizeOfResult = result.size(); - localStream->seekg(position); - localStream->read(static_cast( static_cast(&(lengthOfBucket))), sizeof(unsigned)); - result.resize(currentSizeOfResult+lengthOfBucket); - localStream->read(static_cast( static_cast(&result[currentSizeOfResult])), lengthOfBucket*sizeof(_GridEdge)); - } - - inline void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_GridEdge>& result, boost::unordered_map< unsigned, unsigned> & cellMap) { - unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex); - uint64_t startIndexInFile = ramIndexTable[ramIndex]; - if(startIndexInFile == std::numeric_limits::max()) { - return; - } - - uint64_t cellIndex[32*32]; - - cellMap.clear(); - BuildCellIndexToFileIndexMap(ramIndex, cellMap); - if(!localStream.get() || !localStream->is_open()) { - localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary)); - } - if(!localStream->good()) { - localStream->clear(std::ios::goodbit); - DEBUG("Resetting stale filestream"); - } - - localStream->seekg(startIndexInFile); - localStream->read(static_cast(static_cast( cellIndex)), 32*32*sizeof(uint64_t)); - assert(cellMap.find(fileIndex) != cellMap.end()); - if(cellIndex[cellMap[fileIndex]] == std::numeric_limits::max()) { - return; - } - const uint64_t position = cellIndex[cellMap[fileIndex]] + 32*32*sizeof(uint64_t) ; - - unsigned lengthOfBucket; - unsigned currentSizeOfResult = result.size(); - localStream->seekg(position); - localStream->read(static_cast(static_cast(&(lengthOfBucket))), sizeof(unsigned)); - result.resize(currentSizeOfResult+lengthOfBucket); - localStream->read(static_cast(static_cast(&result[currentSizeOfResult])), lengthOfBucket*sizeof(_GridEdge)); - } - -#ifndef ROUTED - inline void AddEdge(const _GridEdge & edge) { - std::vector indexList; - GetListOfIndexesForEdgeAndGridSize(edge.startCoord, edge.targetCoord, indexList); - for(unsigned i = 0; i < indexList.size(); ++i) { - entries.push_back(GridEntry(edge, indexList[i].first, indexList[i].second)); - } - } -#endif - - inline double ComputeDistance(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target, _Coordinate& nearest, double *r) { -// INFO("comparing point " << inputPoint << " to edge [" << source << "-" << target << "]"); - const double x = static_cast(inputPoint.lat); - const double y = static_cast(inputPoint.lon); - const double a = static_cast(source.lat); - const double b = static_cast(source.lon); - const double c = static_cast(target.lat); - const double d = static_cast(target.lon); - double p,q,mX,nY; -// INFO("x=" << x << ", y=" << y << ", a=" << a << ", b=" << b << ", c=" << c << ", d=" << d); - if(fabs(a-c) > FLT_EPSILON){ - const double m = (d-b)/(c-a); // slope - // Projection of (x,y) on line joining (a,b) and (c,d) - p = ((x + (m*y)) + (m*m*a - m*b))/(1. + m*m); - q = b + m*(p - a); - } - else{ - p = c; - q = y; - } - nY = (d*p - c*q)/(a*d - b*c); - mX = (p - nY*a)/c;// These values are actually n/m+n and m/m+n , we neednot calculate the values of m an n as we are just interested in the ratio -// INFO("p=" << p << ", q=" << q << ", nY=" << nY << ", mX=" << mX); - if(std::isnan(mX)) { - *r = (target == inputPoint) ? 1. : 0.; - } else { - *r = mX; - } -// INFO("r=" << *r); - if(*r<=0.){ - nearest.lat = source.lat; - nearest.lon = source.lon; -// INFO("a returning distance " << ((b - y)*(b - y) + (a - x)*(a - x))) - return ((b - y)*(b - y) + (a - x)*(a - x)); - } - else if(*r >= 1.){ - nearest.lat = target.lat; - nearest.lon = target.lon; -// INFO("b returning distance " << ((d - y)*(d - y) + (c - x)*(c - x))) - - return ((d - y)*(d - y) + (c - x)*(c - x)); - } - // point lies in between - nearest.lat = p; - nearest.lon = q; -// INFO("c returning distance " << (p-x)*(p-x) + (q-y)*(q-y)) - - return (p-x)*(p-x) + (q-y)*(q-y); - } - - inline void GetListOfIndexesForEdgeAndGridSize(const _Coordinate& start, const _Coordinate& target, std::vector &indexList) const { - double lat1 = start.lat/100000.; - double lon1 = start.lon/100000.; - - double x1 = ( lon1 + 180.0 ) / 360.0; - double y1 = ( lat1 + 180.0 ) / 360.0; - - double lat2 = target.lat/100000.; - double lon2 = target.lon/100000.; - - double x2 = ( lon2 + 180.0 ) / 360.0; - double y2 = ( lat2 + 180.0 ) / 360.0; - - Bresenham(x1*32768, y1*32768, x2*32768, y2*32768, indexList); - BOOST_FOREACH(BresenhamPixel & pixel, indexList) { - int fileIndex = (pixel.second-1)*32768 + pixel.first; - int ramIndex = GetRAMIndexFromFileIndex(fileIndex); - pixel.first = fileIndex; - pixel.second = ramIndex; - } - } - - inline unsigned GetFileIndexForLatLon(const int lt, const int ln) const { - double lat = lt/100000.; - double lon = ln/100000.; - - double x = ( lon + 180.0 ) / 360.0; - double y = ( lat + 180.0 ) / 360.0; - - if( x>1.0 || x < 0.) - return UINT_MAX; - if( y>1.0 || y < 0.) - return UINT_MAX; - - unsigned line = (32768 * (32768-1))*y; - line = line - (line % 32768); - assert(line % 32768 == 0); - unsigned column = 32768.*x; - unsigned fileIndex = line+column; - return fileIndex; - } - - inline unsigned GetRAMIndexFromFileIndex(const int fileIndex) const { - unsigned fileLine = fileIndex / 32768; - fileLine = fileLine / 32; - fileLine = fileLine * 1024; - unsigned fileColumn = (fileIndex % 32768); - fileColumn = fileColumn / 32; - unsigned ramIndex = fileLine + fileColumn; - assert(ramIndex < 1024*1024); - return ramIndex; - } - - const static uint64_t END_OF_BUCKET_DELIMITER = boost::integer_traits::const_max; - - std::ifstream ramInFile; -#ifndef ROUTED - std::ofstream indexOutFile; - stxxl::vector entries; -#endif - std::vector ramIndexTable; //8 MB for first level index in RAM - std::string iif; - // LRUCache > cellCache; - // LRUCache > fileCache; -}; -} - -typedef NNGrid::NNGrid ReadOnlyGrid; -typedef NNGrid::NNGrid WritableGrid; - -#endif /* NNGRID_H_ */ diff --git a/Plugins/PluginMapFactory.h b/Plugins/PluginMapFactory.h deleted file mode 100644 index 9027b184b..000000000 --- a/Plugins/PluginMapFactory.h +++ /dev/null @@ -1,34 +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 PLUGINMAPFACTORY_H_ -#define PLUGINMAPFACTORY_H_ - -//#include "../DataStructures/HashTable.h" -//#include "../Plugins/BasePlugin.h" -// -//struct PluginMapFactory { -// static HashTable * CreatePluginMap() { -// HashTable * map = new HashTable(); -// -// } -//}; - -#endif /* PLUGINMAPFACTORY_H_ */ From 1bcacfab74408f4211ad69b365272dd1c2d81660 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 10:57:40 -0400 Subject: [PATCH 10/61] minor code massage --- DataStructures/StaticRTree.h | 199 +++++++++-------------------------- 1 file changed, 48 insertions(+), 151 deletions(-) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index b85516f04..503cd675e 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -215,8 +215,14 @@ private: return lats_contained && lons_contained; } - inline friend std::ostream & operator<< ( std::ostream & out, const RectangleInt2D & rect ) { - out << rect.min_lat/100000. << "," << rect.min_lon/100000. << " " << rect.max_lat/100000. << "," << rect.max_lon/100000.; + inline friend std::ostream & operator<< ( + std::ostream & out, + const RectangleInt2D & rect + ) { + out << rect.min_lat/100000. << "," + << rect.min_lon/100000. << " " + << rect.max_lat/100000. << "," + << rect.max_lon/100000.; return out; } }; @@ -224,8 +230,11 @@ private: typedef RectangleInt2D RectangleT; struct WrappedInputElement { - explicit WrappedInputElement(const uint32_t _array_index, const uint64_t _hilbert_value) : - m_array_index(_array_index), m_hilbert_value(_hilbert_value) {} + explicit WrappedInputElement( + const uint32_t _array_index, + const uint64_t _hilbert_value + ) : m_array_index(_array_index), m_hilbert_value(_hilbert_value) {} + WrappedInputElement() : m_array_index(UINT_MAX), m_hilbert_value(0) {} uint32_t m_array_index; @@ -251,11 +260,13 @@ private: }; struct QueryCandidate { - explicit QueryCandidate(const uint32_t n_id, const double dist) : node_id(n_id), min_dist(dist)/*, minmax_dist(DBL_MAX)*/ {} - QueryCandidate() : node_id(UINT_MAX), min_dist(DBL_MAX)/*, minmax_dist(DBL_MAX)*/ {} + explicit QueryCandidate( + const uint32_t n_id, + const double dist + ) : node_id(n_id), min_dist(dist) {} + QueryCandidate() : node_id(UINT_MAX), min_dist(DBL_MAX) {} uint32_t node_id; double min_dist; - // double minmax_dist; inline bool operator<(const QueryCandidate & other) const { return min_dist < other.min_dist; } @@ -266,24 +277,23 @@ private: std::string m_leaf_node_filename; public: - //Construct a pack R-Tree from the input-list with Kamel-Faloutsos algorithm [1] - explicit StaticRTree(std::vector & input_data_vector, const char * tree_node_filename, const char * leaf_node_filename) : - m_leaf_node_filename(leaf_node_filename) { - m_element_count = input_data_vector.size(); - //remove elements that are flagged to be ignored -// boost::remove_erase_if(input_data_vector, boost::bind(&DataT::isIgnored, _1 )); + //Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1] + explicit StaticRTree( + std::vector & input_data_vector, + const char * tree_node_filename, + const char * leaf_node_filename + ) : + m_element_count(input_data_vector.size()), + m_leaf_node_filename(leaf_node_filename) + { INFO("constructing r-tree of " << m_element_count << " elements"); -// INFO("sizeof(LeafNode)=" << sizeof(LeafNode)); -// INFO("sizeof(TreeNode)=" << sizeof(TreeNode)); -// INFO("sizeof(WrappedInputElement)=" << sizeof(WrappedInputElement)); double time1 = get_timestamp(); - std::vector input_wrapper_vector(input_data_vector.size()); + std::vector input_wrapper_vector(m_element_count); //generate auxiliary vector of hilbert-values #pragma omp parallel for schedule(guided) for(uint64_t element_counter = 0; element_counter < m_element_count; ++element_counter) { - //INFO("ID: " << input_data_vector[element_counter].id); 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]; @@ -294,15 +304,12 @@ public: input_wrapper_vector[element_counter].m_hilbert_value = current_hilbert_value; } - //INFO("finished wrapper setup"); - //open leaf file std::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 std::sort(input_wrapper_vector.begin(), input_wrapper_vector.end()); - // INFO("finished sorting"); std::vector tree_nodes_in_level; //pack M elements into leaf node and write to leaf file @@ -313,19 +320,12 @@ public: TreeNode current_node; for(uint32_t current_element_index = 0; RTREE_LEAF_NODE_SIZE > current_element_index; ++current_element_index) { if(m_element_count > (processed_objects_count + current_element_index)) { - // INFO("Checking element " << (processed_objects_count + current_element_index)); uint32_t index_of_next_object = input_wrapper_vector[processed_objects_count + current_element_index].m_array_index; current_leaf.objects[current_element_index] = input_data_vector[index_of_next_object]; ++current_leaf.object_count; } } - if(0 == processed_objects_count) { - for(uint32_t i = 0; i < current_leaf.object_count; ++i) { - //INFO("[" << i << "] id: " << current_leaf.objects[i].id << ", weight: " << current_leaf.objects[i].weight << ", " << current_leaf.objects[i].lat1/100000. << "," << current_leaf.objects[i].lon1/100000. << ";" << current_leaf.objects[i].lat2/100000. << "," << current_leaf.objects[i].lon2/100000.); - } - } - //generate tree node that resemble the objects in leaf and store it for next level current_node.minimum_bounding_rectangle.InitializeMBRectangle(current_leaf.objects, current_leaf.object_count); current_node.child_is_on_disk = true; @@ -337,20 +337,21 @@ public: processed_objects_count += current_leaf.object_count; } - // INFO("wrote " << processed_objects_count << " leaf objects"); - //close leaf file leaf_node_file.close(); uint32_t processing_level = 0; while(1 < tree_nodes_in_level.size()) { - // INFO("processing " << (uint32_t)tree_nodes_in_level.size() << " tree nodes in level " << processing_level); std::vector tree_nodes_in_next_level; uint32_t processed_tree_nodes_in_level = 0; while(processed_tree_nodes_in_level < tree_nodes_in_level.size()) { TreeNode parent_node; //pack RTREE_BRANCHING_FACTOR elements into tree_nodes each - for(uint32_t current_child_node_index = 0; RTREE_BRANCHING_FACTOR > current_child_node_index; ++current_child_node_index) { + for( + uint32_t current_child_node_index = 0; + RTREE_BRANCHING_FACTOR > current_child_node_index; + ++current_child_node_index + ) { if(processed_tree_nodes_in_level < tree_nodes_in_level.size()) { TreeNode & current_child_node = tree_nodes_in_level[processed_tree_nodes_in_level]; //add tree node to parent entry @@ -364,15 +365,12 @@ public: } } tree_nodes_in_next_level.push_back(parent_node); - // INFO("processed: " << processed_tree_nodes_in_level << ", generating " << (uint32_t)tree_nodes_in_next_level.size() << " parents"); } tree_nodes_in_level.swap(tree_nodes_in_next_level); ++processing_level; } BOOST_ASSERT_MSG(1 == tree_nodes_in_level.size(), "tree broken, more than one root node"); - //last remaining entry is the root node; - // INFO("root node has " << (uint32_t)tree_nodes_in_level[0].child_count << " children"); - //store root node + //last remaining entry is the root node, store it m_search_tree.push_back(tree_nodes_in_level[0]); //reverse and renumber tree to have root at index 0 @@ -396,27 +394,7 @@ public: //close tree node file. tree_node_file.close(); double time2 = get_timestamp(); -// INFO("written " << processed_objects_count << " leafs in " << sizeof(LeafNode)*(1+(unsigned)std::ceil(processed_objects_count/RTREE_LEAF_NODE_SIZE) )+sizeof(uint64_t) << " bytes"); -// INFO("written search tree of " << size_of_tree << " tree nodes in " << sizeof(TreeNode)*size_of_tree+sizeof(uint32_t) << " bytes"); INFO("finished r-tree construction in " << (time2-time1) << " seconds"); - - //todo: test queries -/* INFO("first MBR:" << m_search_tree[0].minimum_bounding_rectangle); - - DataT result; - time1 = get_timestamp(); - bool found_nearest = NearestNeighbor(_Coordinate(50.191085,8.466479), result); - time2 = get_timestamp(); - INFO("found nearest element to (50.191085,8.466479): " << (found_nearest ? "yes" : "no") << " in " << (time2-time1) << "s at (" << result.lat1/100000. << "," << result.lon1/100000. << " " << result.lat2/100000. << "," << result.lon2/100000. << ")"); - time1 = get_timestamp(); - found_nearest = NearestNeighbor(_Coordinate(50.23979, 8.51882), result); - time2 = get_timestamp(); - INFO("found nearest element to (50.23979, 8.51882): " << (found_nearest ? "yes" : "no") << " in " << (time2-time1) << "s at (" << result.lat1/100000. << "," << result.lon1/100000. << " " << result.lat2/100000. << "," << result.lon2/100000. << ")"); - time1 = get_timestamp(); - found_nearest = NearestNeighbor(_Coordinate(49.0316,2.6937), result); - time2 = get_timestamp(); - INFO("found nearest element to (49.0316,2.6937): " << (found_nearest ? "yes" : "no") << " in " << (time2-time1) << "s at (" << result.lat1/100000. << "," << result.lon1/100000. << " " << result.lat2/100000. << "," << result.lon2/100000. << ")"); -*/ } //Read-only operation for queries @@ -557,11 +535,20 @@ public: } } + const double distance_to_edge = + ApproximateDistance ( + _Coordinate(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) + ); + const double ratio = (found_a_nearest_edge ? - std::min(1., ApproximateDistance(_Coordinate(nearest_edge.lat1, nearest_edge.lon1), - result_phantom_node.location)/ApproximateDistance(_Coordinate(nearest_edge.lat1, nearest_edge.lon1), _Coordinate(nearest_edge.lat2, nearest_edge.lon2)) - ) : 0 - ); + std::min(1., distance_to_edge/ length_of_edge ) : 0 ); result_phantom_node.weight1 *= ratio; if(INT_MAX != result_phantom_node.weight2) { result_phantom_node.weight2 *= (1.-ratio); @@ -576,8 +563,7 @@ public: result_phantom_node.location.lat = input_coordinate.lat; } - INFO("mindist: " << min_dist << ", io's: " << io_count << ", nodes: " << explored_tree_nodes_count << ", loc: " << result_phantom_node.location << ", ratio: " << ratio << ", id: " << result_phantom_node.edgeBasedNode); - INFO("bidirected: " << (result_phantom_node.isBidirected() ? "yes" : "no") ); + INFO("mindist: " << min_distphantom_node.isBidirected() ? "yes" : "no") ); return found_a_nearest_edge; } @@ -644,10 +630,6 @@ public: ¤t_ratio ); - //INFO("[" << current_edge.id << "] (" << current_edge.lat1/100000. << "," << current_edge.lon1/100000. << ")==(" << current_edge.lat2/100000. << "," << current_edge.lon2/100000. << ") at distance " << current_perpendicular_distance << " min dist: " << min_dist - // << ", ratio " << current_ratio - // ); - if( current_perpendicular_distance < min_dist && !DoubleEpsilonCompare( @@ -737,94 +719,9 @@ public: result_phantom_node.location.lat = input_coordinate.lat; } -// INFO("start: (" << nearest_edge.lat1 << "," << nearest_edge.lon1 << "), end: (" << nearest_edge.lat2 << "," << nearest_edge.lon2 << ")" ); -// INFO("mindist: " << min_dist << ", io's: " << io_count << ", nodes: " << explored_tree_nodes_count << ", loc: " << result_phantom_node.location << ", ratio: " << ratio << ", id: " << result_phantom_node.edgeBasedNode); -// INFO("weight1: " << result_phantom_node.weight1 << ", weight2: " << result_phantom_node.weight2); -// INFO("bidirected: " << (result_phantom_node.isBidirected() ? "yes" : "no") ); -// INFO("NameID: " << result_phantom_node.nodeBasedEdgeNameID); return found_a_nearest_edge; } -/* - //Nearest-Neighbor query with the Roussopoulos et al. algorithm [2] - inline bool NearestNeighbor(const _Coordinate & input_coordinate, DataT & result_element) { - uint32_t io_count = 0; - uint32_t explored_tree_nodes_count = 0; - INFO("searching for coordinate " << input_coordinate); - double min_dist = DBL_MAX; - double min_max_dist = DBL_MAX; - bool found_return_value = false; - - //initialize queue with root element - std::priority_queue traversal_queue; - traversal_queue.push(QueryCandidate(0, m_search_tree[0].minimum_bounding_rectangle.GetMinDist(input_coordinate))); - BOOST_ASSERT_MSG(FLT_EPSILON > (0. - traversal_queue.top().min_dist), "Root element in NN Search has min dist != 0."); - - while(!traversal_queue.empty()) { - const QueryCandidate current_query_node = traversal_queue.top(); traversal_queue.pop(); - - ++explored_tree_nodes_count; - - // INFO("popped node " << current_query_node.node_id << " at distance " << current_query_node.min_dist); - bool prune_downward = (current_query_node.min_dist >= min_max_dist); - bool prune_upward = (current_query_node.min_dist >= min_dist); - // INFO(" up prune: " << (prune_upward ? "y" : "n" )); - // INFO(" down prune: " << (prune_downward ? "y" : "n" )); - if( prune_downward || prune_upward ) { //downward pruning - // INFO(" pruned node " << current_query_node.node_id << " because " << current_query_node.min_dist << "<" << min_max_dist); - } else { - TreeNode & current_tree_node = m_search_tree[current_query_node.node_id]; - if (current_tree_node.child_is_on_disk) { - // INFO(" Fetching child from disk for id: " << current_query_node.node_id); - LeafNode current_leaf_node; - LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node); - ++io_count; - double ratio = 0.; - _Coordinate nearest; - for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) { - DataT & current_object = current_leaf_node.objects[i]; - double current_perpendicular_distance = ComputePerpendicularDistance( - input_coordinate, - _Coordinate(current_object.lat1, current_object.lon1), - _Coordinate(current_object.lat2, current_object.lon2), - nearest, - &ratio - ); - - if(current_perpendicular_distance < min_dist && !DoubleEpsilonCompare(current_perpendicular_distance, min_dist)) { //found a new minimum - min_dist = current_perpendicular_distance; - result_element = current_object; - found_return_value = true; - } - } - } else { - //traverse children, prune if global mindist is smaller than local one - // INFO(" Checking " << current_tree_node.child_count << " children of node " << current_query_node.node_id); - for (uint32_t i = 0; i < current_tree_node.child_count; ++i) { - const int32_t child_id = current_tree_node.children[i]; - TreeNode & child_tree_node = m_search_tree[child_id]; - RectangleT & child_rectangle = child_tree_node.minimum_bounding_rectangle; - const double current_min_dist = child_rectangle.GetMinDist(input_coordinate); - const double current_min_max_dist = child_rectangle.GetMinMaxDist(input_coordinate); - if( current_min_max_dist < min_max_dist ) { - min_max_dist = current_min_max_dist; - } - if (current_min_dist > min_max_dist) { - continue; - } - if (current_min_dist > min_dist) { //upward pruning - continue; - } - // INFO(" pushing node " << child_id << " at distance " << current_min_dist); - traversal_queue.push(QueryCandidate(child_id, current_min_dist)); - } - } - } - } - INFO("mindist: " << min_dist << ", io's: " << io_count << ", touched nodes: " << explored_tree_nodes_count); - return found_return_value; - } - */ private: inline void LoadLeafFromDisk(const uint32_t leaf_id, LeafNode& result_node) { if(!thread_local_rtree_stream.get() || !thread_local_rtree_stream->is_open()) { From 5c84c12f40ab5c6906ff4a26a264628e005a4132 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 11:44:32 -0400 Subject: [PATCH 11/61] Fixing errors from static analysis --- Contractor/Contractor.h | 2 +- Contractor/EdgeBasedGraphFactory.h | 11 ++ Descriptors/JSONDescriptor.h | 7 +- extractor.cpp | 156 +++++++++++++++-------------- 4 files changed, 98 insertions(+), 78 deletions(-) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 35d2aa29e..18bee5de6 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -474,7 +474,7 @@ public: newEdge.data.id = data.id; } BOOST_ASSERT_MSG( - newEdge.data.id <= INT_MAX, //2^31 + newEdge.data.id != INT_MAX, //2^31 "edge id invalid" ); newEdge.data.forward = data.forward; diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index c51e4d2ea..7949af6ff 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -56,6 +56,17 @@ class EdgeBasedGraphFactory : boost::noncopyable { public: struct EdgeBasedNode { + EdgeBasedNode() : + id(INT_MAX), + lat1(INT_MAX), + lat2(INT_MAX), + lon1(INT_MAX), + lon2(INT_MAX >> 1), + belongsToTinyComponent(false), + nameID(UINT_MAX), + weight(UINT_MAX >> 1), + ignoreInGrid(false) + { } bool operator<(const EdgeBasedNode & other) const { return other.id < id; } diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 7ef4c8dfd..da7afcbb8 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -41,7 +41,12 @@ private: DescriptionFactory alternateDescriptionFactory; _Coordinate current; unsigned numberOfEnteredRestrictedAreas; - struct { + struct RoundAbout{ + RoundAbout() : + startIndex(INT_MAX), + nameID(INT_MAX), + leaveAtExit(INT_MAX) + {} int startIndex; int nameID; int leaveAtExit; diff --git a/extractor.cpp b/extractor.cpp index 800fd8be5..de801ff51 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -39,88 +39,92 @@ or see http://www.gnu.org/licenses/agpl.txt. ExtractorCallbacks * extractCallBacks; int main (int argc, char *argv[]) { - double startup_time = get_timestamp(); + try { + double startup_time = get_timestamp(); - if(argc < 2) { - ERR("usage: \n" << argv[0] << " []"); - } - - /*** Setup Scripting Environment ***/ - ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); - - unsigned number_of_threads = omp_get_num_procs(); - if(testDataFile("extractor.ini")) { - BaseConfiguration extractorConfig("extractor.ini"); - unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); - if( rawNumber != 0 && rawNumber <= number_of_threads) { - number_of_threads = rawNumber; + if(argc < 2) { + ERR("usage: \n" << argv[0] << " []"); } - } - omp_set_num_threads(number_of_threads); - INFO("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]); - std::string::size_type pos = output_file_name.find(".osm.bz2"); - if(pos==std::string::npos) { - pos = output_file_name.find(".osm.pbf"); - if(pos!=std::string::npos) { - file_has_pbf_format = true; + /*** Setup Scripting Environment ***/ + ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); + + unsigned number_of_threads = omp_get_num_procs(); + if(testDataFile("extractor.ini")) { + BaseConfiguration extractorConfig("extractor.ini"); + unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); + 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]); + bool file_has_pbf_format(false); + std::string output_file_name(argv[1]); + std::string restrictionsFileName(argv[1]); + std::string::size_type pos = output_file_name.find(".osm.bz2"); + if(pos==std::string::npos) { + pos = output_file_name.find(".osm.pbf"); + if(pos!=std::string::npos) { + file_has_pbf_format = true; + } } - } - if(pos!=std::string::npos) { - output_file_name.replace(pos, 8, ".osrm"); - restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); - } else { - pos=output_file_name.find(".osm"); if(pos!=std::string::npos) { - output_file_name.replace(pos, 5, ".osrm"); - restrictionsFileName.replace(pos, 5, ".osrm.restrictions"); + output_file_name.replace(pos, 8, ".osrm"); + restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); } else { - output_file_name.append(".osrm"); - restrictionsFileName.append(".osrm.restrictions"); + pos=output_file_name.find(".osm"); + if(pos!=std::string::npos) { + output_file_name.replace(pos, 5, ".osrm"); + restrictionsFileName.replace(pos, 5, ".osrm.restrictions"); + } else { + output_file_name.append(".osrm"); + restrictionsFileName.append(".osrm.restrictions"); + } } + + unsigned amountOfRAM = 1; + unsigned installedRAM = GetPhysicalmemory(); + if(installedRAM < 2048264) { + WARN("Machine has less than 2GB RAM."); + } + + StringMap stringMap; + ExtractionContainers externalMemory; + + stringMap[""] = 0; + extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap); + BaseParser* parser; + if(file_has_pbf_format) { + parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment); + } else { + parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment); + } + + if(!parser->ReadHeader()) { + ERR("Parser not initialized!"); + } + INFO("Parsing in progress.."); + double parsing_start_time = get_timestamp(); + parser->Parse(); + INFO("Parsing finished after " << + (get_timestamp() - parsing_start_time) << + " seconds" + ); + + externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM); + + delete parser; + delete extractCallBacks; + + INFO("extraction finished after " << get_timestamp() - startup_time << "s"); + + std::cout << "\nRun:\n" + << "./osrm-prepare " << output_file_name << " " << restrictionsFileName + << std::endl; + return 0; + } catch(std::exception & e) { + WARN("unhandled exception: " << e.what()); } - - unsigned amountOfRAM = 1; - unsigned installedRAM = GetPhysicalmemory(); - if(installedRAM < 2048264) { - WARN("Machine has less than 2GB RAM."); - } - - StringMap stringMap; - ExtractionContainers externalMemory; - - stringMap[""] = 0; - extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap); - BaseParser* parser; - if(file_has_pbf_format) { - parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment); - } else { - parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment); - } - - if(!parser->ReadHeader()) { - ERR("Parser not initialized!"); - } - INFO("Parsing in progress.."); - double parsing_start_time = get_timestamp(); - parser->Parse(); - INFO("Parsing finished after " << - (get_timestamp() - parsing_start_time) << - " seconds" - ); - - externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM); - - delete parser; - delete extractCallBacks; - - INFO("extraction finished after " << get_timestamp() - startup_time << "s"); - - std::cout << "\nRun:\n" - << "./osrm-prepare " << output_file_name << " " << restrictionsFileName - << std::endl; - return 0; } From c940c2722e313878c8957b26d282f92e327258b2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 11:44:55 -0400 Subject: [PATCH 12/61] Fixing errors from static analysis --- DataStructures/BinaryHeap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index 5bbcb3b3f..6b9bd10c4 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -186,8 +186,8 @@ public: void DecreaseKey( NodeID node, Weight weight ) { assert( UINT_MAX != node ); - const Key index = nodeIndex[node]; - Key key = insertedNodes[index].key; + const Key & index = nodeIndex[node]; + Key & key = insertedNodes[index].key; assert ( key >= 0 ); insertedNodes[index].weight = weight; From a0e9f59e041191ae9454f88f9c88cbfec3706f48 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 13:21:33 -0400 Subject: [PATCH 13/61] Adding a simple example on how to call the lib --- CMakeLists.txt | 3 ++ DataStructures/Coordinate.h | 3 +- Plugins/TimestampPlugin.h | 4 -- simpleclient.cpp | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 simpleclient.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d24f7a894..857ea0725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,9 @@ target_link_libraries( osrm-extract ${Boost_LIBRARIES} ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM) +add_executable ( osrm-cli simpleclient.cpp) +target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM) + find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) target_link_libraries (osrm-extract ${BZIP2_LIBRARIES}) diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h index 11ae3069e..68219d5a1 100644 --- a/DataStructures/Coordinate.h +++ b/DataStructures/Coordinate.h @@ -33,7 +33,8 @@ struct _Coordinate { int lat; int lon; _Coordinate () : lat(INT_MIN), lon(INT_MIN) {} - _Coordinate (int t, int n) : lat(t) , lon(n) {} + explicit _Coordinate (int t, int n) : lat(t) , lon(n) {} + void Reset() { lat = INT_MIN; lon = INT_MIN; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 0475a04fd..6a245e116 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -30,13 +30,9 @@ class TimestampPlugin : public BasePlugin { public: TimestampPlugin(QueryObjectsStorage * o) : objects(o) { } - ~TimestampPlugin() { - std::cout << "shutdown time stamp" << std::endl; - } std::string GetDescriptor() const { return std::string("timestamp"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { - std::cout << "handling request" << std::endl; std::string tmp; //json diff --git a/simpleclient.cpp b/simpleclient.cpp new file mode 100644 index 000000000..17eedffa7 --- /dev/null +++ b/simpleclient.cpp @@ -0,0 +1,89 @@ +/* + 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. + */ + + +#include "Library/OSRM.h" +#include "Plugins/RouteParameters.h" +#include "Server/BasicDatastructures.h" + +#include +#include + + +#include +#include +#include +#include + +//Dude, real recursions on the OS stack? You must be brave... +void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_depth) +{ + boost::property_tree::ptree::const_iterator end = pt.end(); + for (boost::property_tree::ptree::const_iterator it = pt.begin(); it != end; ++it) { + for(unsigned i = 0; i < recursion_depth; ++i) { + std::cout << " " << std::flush; + } + std::cout << it->first << ": " << it->second.get_value() << std::endl; + print_tree(it->second, recursion_depth+1); + } +} + + +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")); + 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 + + _Coordinate start_coordinate(52.519930*100000,13.438640*100000); + _Coordinate target_coordinate(52.513191*100000,13.415852*100000); + route_parameters.coordinates.push_back(start_coordinate); + route_parameters.coordinates.push_back(target_coordinate); + + http::Reply osrm_reply; + + routing_machine.RunQuery(route_parameters, osrm_reply); + + std::cout << osrm_reply.content << std::endl; + + //attention: super-inefficient hack below: + + std::stringstream ss; + ss << osrm_reply.content; + + boost::property_tree::ptree pt; + boost::property_tree::read_json(ss, pt); + + print_tree(pt, 0); + return 0; +} From 4194ce309562c1ccbeb4639dd22cbed52d9d25c5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 16:08:33 -0400 Subject: [PATCH 14/61] Moving cli client to tools directory --- Algorithms/StronglyConnectedComponents.h | 129 ++++++++++++++--------- CMakeLists.txt | 5 +- Tools/componentAnalysis.cpp | 119 ++++++++++++--------- 3 files changed, 150 insertions(+), 103 deletions(-) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index a83110034..4ef81e90f 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -16,25 +16,15 @@ 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. + +Strongly connected components using Tarjan's Algorithm + */ - - #ifndef STRONGLYCONNECTEDCOMPONENTS_H_ #define STRONGLYCONNECTEDCOMPONENTS_H_ -#include - -#include -#include - -#include -#include -#include - -#include -#include - +#include "../DataStructures/Coordinate.h" #include "../DataStructures/DeallocatingVector.h" #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/ImportEdge.h" @@ -43,11 +33,34 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/Restriction.h" #include "../DataStructures/TurnInstructions.h" -// Strongly connected components using Tarjan's Algorithm +#include +#include +#include +#include +#include + +#ifdef __APPLE__ + #include + #include +#else + #include + #include +#endif +#include +#include +#include class TarjanSCC { private: - struct _NodeBasedEdgeData { + + struct TarjanNode { + TarjanNode() : index(UINT_MAX), lowlink(UINT_MAX), onStack(false) {} + unsigned index; + unsigned lowlink; + bool onStack; + }; + + struct TarjanEdgeData { int distance; unsigned edgeBasedNodeID; unsigned nameID:31; @@ -58,25 +71,31 @@ private: bool backward:1; bool roundabout:1; bool ignoreInGrid:1; + bool reversedEdge:1; }; - typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; - typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge; - std::vector inputNodeInfoList; - unsigned numberOfTurnRestrictions; - boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; - boost::unordered_map _barrierNodes; - boost::unordered_map _trafficLights; + struct TarjanStackFrame { + explicit TarjanStackFrame(NodeID _v, NodeID p) : v(_v), parent(p) {} + NodeID v; + NodeID parent; + }; + typedef DynamicGraph TarjanDynamicGraph; + typedef TarjanDynamicGraph::InputEdge TarjanEdge; typedef std::pair RestrictionSource; typedef std::pair RestrictionTarget; typedef std::vector EmanatingRestrictionsVector; typedef boost::unordered_map RestrictionMap; + + std::vector inputNodeInfoList; + unsigned numberOfTurnRestrictions; + boost::shared_ptr _nodeBasedGraph; + boost::unordered_map _barrierNodes; + boost::unordered_map _trafficLights; + std::vector _restrictionBucketVector; RestrictionMap _restrictionMap; - -public: struct EdgeBasedNode { bool operator<(const EdgeBasedNode & other) const { return other.id < id; @@ -95,21 +114,7 @@ public: bool ignoreInGrid:1; }; -private: DeallocatingVector edgeBasedNodes; - - struct TarjanNode { - TarjanNode() : index(UINT_MAX), lowlink(UINT_MAX), onStack(false) {} - unsigned index; - unsigned lowlink; - bool onStack; - }; - - struct TarjanStackFrame { - explicit TarjanStackFrame(NodeID _v, NodeID p) : v(_v), parent(p) {} - NodeID v; - NodeID parent; - }; 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) { @@ -141,10 +146,10 @@ public: _trafficLights[id] = true; } - DeallocatingVector< _NodeBasedEdge > edges; + DeallocatingVector< TarjanEdge > edges; for ( std::vector< NodeBasedEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) { - _NodeBasedEdge edge; + TarjanEdge edge; if(!i->isForward()) { edge.source = i->target(); edge.target = i->source(); @@ -168,21 +173,28 @@ public: edge.data.type = i->type(); edge.data.isAccessRestricted = i->isAccessRestricted(); edge.data.edgeBasedNodeID = edges.size(); + edge.data.reversedEdge = false; 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.edgeBasedNodeID = edges.size(); + edge.data.reversedEdge = true; edges.push_back( edge ); } } std::vector().swap(inputEdges); std::sort( edges.begin(), edges.end() ); - _nodeBasedGraph = boost::make_shared<_NodeBasedDynamicGraph>( nodes, edges ); + _nodeBasedGraph = boost::make_shared( nodes, edges ); } void Run() { + //remove files from previous run if exist + DeleteFileIfExists("component.dbf"); + DeleteFileIfExists("component.shx"); + DeleteFileIfExists("component.shp"); + Percent p(_nodeBasedGraph->GetNumberOfNodes()); const char *pszDriverName = "ESRI Shapefile"; @@ -247,8 +259,8 @@ public: // INFO("pushing " << v << " onto tarjan stack, idx[" << v << "]=" << tarjanNodes[v].index << ", lowlink["<< v << "]=" << tarjanNodes[v].lowlink); //Traverse outgoing edges - for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { - _NodeBasedDynamicGraph::NodeIterator vprime = _nodeBasedGraph->GetTarget(e2); + for(TarjanDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { + TarjanDynamicGraph::NodeIterator vprime = _nodeBasedGraph->GetTarget(e2); // INFO("traversing edge (" << v << "," << vprime << ")"); if(UINT_MAX == tarjanNodes[vprime].index) { @@ -306,16 +318,28 @@ public: ++singleCounter; } INFO("identified " << singleCounter << " SCCs of size 1"); - + uint64_t total_network_distance = 0; p.reinit(_nodeBasedGraph->GetNumberOfNodes()); - 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(TarjanDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { + p.printIncrement(); + for(TarjanDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { + if(_nodeBasedGraph->GetEdgeData(e1).reversedEdge) { + continue; + } + TarjanDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); + + total_network_distance += 100*ApproximateDistance( + inputNodeInfoList[u].lat, + inputNodeInfoList[u].lon, + inputNodeInfoList[v].lat, + inputNodeInfoList[v].lon + ); 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 if(std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 10) { @@ -323,7 +347,6 @@ public: OGRLineString lineString; lineString.addPoint(inputNodeInfoList[u].lon/100000., inputNodeInfoList[u].lat/100000.); lineString.addPoint(inputNodeInfoList[v].lon/100000., inputNodeInfoList[v].lat/100000.); - OGRFeature *poFeature; poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() ); poFeature->SetGeometry( &lineString ); @@ -339,7 +362,7 @@ public: OGRDataSource::DestroyDataSource( poDS ); std::vector().swap(vectorOfComponentSizes); std::vector().swap(componentsIndex); - + INFO("total network distance: " << total_network_distance/100/1000. << " km"); } private: unsigned CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const { @@ -368,6 +391,12 @@ private: } return false; } + + void DeleteFileIfExists(const std::string file_name) const { + if (boost::filesystem::exists(file_name) ) { + boost::filesystem::remove(file_name); + } + } }; #endif /* STRONGLYCONNECTEDCOMPONENTS_H_ */ diff --git a/CMakeLists.txt b/CMakeLists.txt index 857ea0725..f3a68301e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,9 +67,6 @@ target_link_libraries( osrm-extract ${Boost_LIBRARIES} ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM) -add_executable ( osrm-cli simpleclient.cpp) -target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM) - find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) target_link_libraries (osrm-extract ${BZIP2_LIBRARIES}) @@ -119,4 +116,6 @@ if(WITH_TOOLS) target_link_libraries( osrm-components ${GDAL_LIBRARIES} ) target_link_libraries( osrm-components ${Boost_LIBRARIES} ) endif(GDAL_FOUND) + add_executable ( osrm-cli Tools/simpleclient.cpp) + target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM) endif(WITH_TOOLS) diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index 64790aa87..664c58954 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -18,23 +18,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -#define VERBOSE(x) x -#define VERBOSE2(x) - -#ifdef NDEBUG -#undef VERBOSE -#undef VERBOSE2 -#endif - -#include - -#include -#include -#include -#include -#include -#include - #include "../typedefs.h" #include "../Algorithms/StronglyConnectedComponents.h" #include "../DataStructures/BinaryHeap.h" @@ -46,57 +29,93 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/InputFileUtil.h" #include "../Util/GraphLoader.h" -using namespace std; +#include +#include +#include +#include +#include +#include +#include -typedef QueryEdge::EdgeData EdgeData; +typedef QueryEdge::EdgeData EdgeData; typedef DynamicGraph::InputEdge InputEdge; -typedef BaseConfiguration ContractorConfiguration; +typedef BaseConfiguration ContractorConfiguration; -std::vector internalToExternalNodeMapping; -std::vector<_Restriction> inputRestrictions; -std::vector bollardNodes; -std::vector trafficLightNodes; +std::vector internal_to_external_node_map; +std::vector<_Restriction> restrictions_vector; +std::vector bollard_node_IDs_vector; +std::vector traffic_light_node_IDs_vector; -int main (int argc, char *argv[]) { - if(argc < 3) { - ERR("usage: " << std::endl << argv[0] << " "); +int main (int argument_count, char *argument_values[]) { + if(argument_count < 3) { + ERR("usage:\n" << argument_values[0] << " "); } - std::string SRTM_ROOT; - INFO("Using restrictions from file: " << argv[2]); - std::ifstream restrictionsInstream(argv[2], ios::binary); - if(!restrictionsInstream.good()) { + 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"); } - _Restriction restriction; - unsigned usableRestrictionsCounter(0); - restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); - inputRestrictions.resize(usableRestrictionsCounter); - restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction)); - restrictionsInstream.close(); + uint32_t usable_restriction_count = 0; + restriction_ifstream.read( + (char*)&usable_restriction_count, + sizeof(uint32_t) + ); + restrictions_vector.resize(usable_restriction_count); - std::ifstream in; - in.open (argv[1], std::ifstream::in | std::ifstream::binary); - if (!in.is_open()) { - ERR("Cannot open " << argv[1]); + restriction_ifstream.read( + (char *)&(restrictions_vector[0]), + usable_restriction_count*sizeof(_Restriction) + ); + restriction_ifstream.close(); + + std::ifstream input_stream; + input_stream.open( + argument_values[1], + std::ifstream::in | std::ifstream::binary + ); + + if (!input_stream.is_open()) { + ERR("Cannot open " << argument_values[1]); } - 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"); + std::vector edge_list; + NodeID node_based_node_count = readBinaryOSRMGraphFromStream( + input_stream, + edge_list, + bollard_node_IDs_vector, + traffic_light_node_IDs_vector, + &internal_to_external_node_map, + restrictions_vector + ); + input_stream.close(); + + INFO( + restrictions_vector.size() << " restrictions, " << + bollard_node_IDs_vector.size() << " bollard nodes, " << + 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"); - TarjanSCC * tarjan = new TarjanSCC (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping); - std::vector().swap(edgeList); + TarjanSCC * tarjan = new TarjanSCC ( + node_based_node_count, + edge_list, + bollard_node_IDs_vector, + traffic_light_node_IDs_vector, + restrictions_vector, + internal_to_external_node_map + ); + std::vector().swap(edge_list); + tarjan->Run(); - std::vector<_Restriction>().swap(inputRestrictions); - std::vector().swap(bollardNodes); - std::vector().swap(trafficLightNodes); + + 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"); return 0; } From c209245b0e02c0edf161ed231b92aeb326d46ad5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 16:09:01 -0400 Subject: [PATCH 15/61] Moving cli client to tools directory --- Tools/simpleclient.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Tools/simpleclient.cpp diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp new file mode 100644 index 000000000..32dc07a76 --- /dev/null +++ b/Tools/simpleclient.cpp @@ -0,0 +1,86 @@ +/* + 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. + */ + + +#include "../Library/OSRM.h" + +#include +#include + +#include +#include +#include +#include + +//Dude, real recursions on the OS stack? You must be brave... +void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_depth) +{ + boost::property_tree::ptree::const_iterator end = pt.end(); + for (boost::property_tree::ptree::const_iterator it = pt.begin(); it != end; ++it) { + for(unsigned i = 0; i < recursion_depth; ++i) { + std::cout << " " << std::flush; + } + std::cout << it->first << ": " << it->second.get_value() << std::endl; + print_tree(it->second, recursion_depth+1); + } +} + + +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")); + 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 + + _Coordinate start_coordinate(52.519930*100000,13.438640*100000); + _Coordinate target_coordinate(52.513191*100000,13.415852*100000); + route_parameters.coordinates.push_back(start_coordinate); + route_parameters.coordinates.push_back(target_coordinate); + + http::Reply osrm_reply; + + routing_machine.RunQuery(route_parameters, osrm_reply); + + std::cout << osrm_reply.content << std::endl; + + //attention: super-inefficient hack below: + + std::stringstream ss; + ss << osrm_reply.content; + + boost::property_tree::ptree pt; + boost::property_tree::read_json(ss, pt); + + print_tree(pt, 0); + return 0; +} From 29e363e7fbbdabc88ed956fa12b399eca0b21ea4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 16:09:21 -0400 Subject: [PATCH 16/61] some refactoring --- DataStructures/NodeInformationHelpDesk.h | 11 ++++++--- Server/DataStructures/QueryObjectsStorage.cpp | 24 +++++++++++-------- Server/DataStructures/QueryObjectsStorage.h | 14 ++++++++--- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index f13c9ad34..12d465096 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -23,7 +23,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "NodeCoords.h" #include "PhantomNodes.h" -#include "QueryEdge.h" #include "StaticRTree.h" #include "../Contractor/EdgeBasedGraphFactory.h" #include "../typedefs.h" @@ -82,7 +81,10 @@ public: OriginalEdgeData deserialized_originalEdgeData; for(unsigned i = 0; i < numberOfOrigEdges; ++i) { - edgesInStream.read((char*)&(deserialized_originalEdgeData), sizeof(OriginalEdgeData)); + edgesInStream.read( + (char*)&(deserialized_originalEdgeData), + sizeof(OriginalEdgeData) + ); origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode; origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID; origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction; @@ -124,7 +126,10 @@ public: const unsigned zoom_level = 18 ) const { PhantomNode resulting_phantom_node; - bool foundNode = FindPhantomNodeForCoordinate(input_coordinate, resulting_phantom_node, zoom_level); + bool foundNode = FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, zoom_level + ); result = resulting_phantom_node.location; return foundNode; } diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index df15f532c..16de52eb8 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -23,13 +23,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../Util/GraphLoader.h" QueryObjectsStorage::QueryObjectsStorage( - std::string hsgrPath, - std::string ramIndexPath, - std::string fileIndexPath, - std::string nodesPath, - std::string edgesPath, - std::string namesPath, - std::string timestampPath + const std::string & hsgrPath, + const std::string & ramIndexPath, + const std::string & fileIndexPath, + const std::string & nodesPath, + const std::string & edgesPath, + const std::string & namesPath, + const std::string & timestampPath ) { INFO("loading graph data"); std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); @@ -43,6 +43,7 @@ QueryObjectsStorage::QueryObjectsStorage( edgeList, &checkSum ); + hsgrInStream.close(); INFO("Data checksum is " << checkSum); graph = new QueryGraph(nodeList, edgeList); @@ -68,7 +69,12 @@ QueryObjectsStorage::QueryObjectsStorage( if(!nodesInStream) { ERR(nodesPath << " not found"); } std::ifstream edgesInStream(edgesPath.c_str(), std::ios::binary); if(!edgesInStream) { ERR(edgesPath << " not found"); } - nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum); + nodeHelpDesk = new NodeInformationHelpDesk( + ramIndexPath.c_str(), + fileIndexPath.c_str(), + n, + checkSum + ); nodeHelpDesk->initNNGrid(nodesInStream, edgesInStream); //deserialize street name list @@ -77,7 +83,6 @@ QueryObjectsStorage::QueryObjectsStorage( if(!namesInStream) { ERR(namesPath << " not found"); } unsigned size(0); namesInStream.read((char *)&size, sizeof(unsigned)); - // names = new std::vector(); char buf[1024]; for(unsigned i = 0; i < size; ++i) { @@ -88,7 +93,6 @@ QueryObjectsStorage::QueryObjectsStorage( names.push_back(buf); } std::vector(names).swap(names); - hsgrInStream.close(); namesInStream.close(); INFO("All query data structures loaded"); } diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index be8bba073..cd1b63b63 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -30,8 +30,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/StaticGraph.h" struct QueryObjectsStorage { - typedef StaticGraph QueryGraph; - typedef QueryGraph::InputEdge InputEdge; + typedef StaticGraph QueryGraph; + typedef QueryGraph::InputEdge InputEdge; NodeInformationHelpDesk * nodeHelpDesk; std::vector names; @@ -39,7 +39,15 @@ struct QueryObjectsStorage { std::string timestamp; unsigned checkSum; - QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string edgesPath, std::string namesPath, std::string timestampPath); + QueryObjectsStorage( + const std::string & hsgrPath, + const std::string & ramIndexPath, + const std::string & fileIndexPath, + const std::string & nodesPath, + const std::string & edgesPath, + const std::string & namesPath, + const std::string & timestampPath + ); ~QueryObjectsStorage(); }; From e3b619fd54ebc9df08b09c2719379946de5dc780 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 16:09:40 -0400 Subject: [PATCH 17/61] Moved File --- simpleclient.cpp | 89 ------------------------------------------------ 1 file changed, 89 deletions(-) delete mode 100644 simpleclient.cpp diff --git a/simpleclient.cpp b/simpleclient.cpp deleted file mode 100644 index 17eedffa7..000000000 --- a/simpleclient.cpp +++ /dev/null @@ -1,89 +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. - */ - - -#include "Library/OSRM.h" -#include "Plugins/RouteParameters.h" -#include "Server/BasicDatastructures.h" - -#include -#include - - -#include -#include -#include -#include - -//Dude, real recursions on the OS stack? You must be brave... -void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_depth) -{ - boost::property_tree::ptree::const_iterator end = pt.end(); - for (boost::property_tree::ptree::const_iterator it = pt.begin(); it != end; ++it) { - for(unsigned i = 0; i < recursion_depth; ++i) { - std::cout << " " << std::flush; - } - std::cout << it->first << ": " << it->second.get_value() << std::endl; - print_tree(it->second, recursion_depth+1); - } -} - - -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")); - 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 - - _Coordinate start_coordinate(52.519930*100000,13.438640*100000); - _Coordinate target_coordinate(52.513191*100000,13.415852*100000); - route_parameters.coordinates.push_back(start_coordinate); - route_parameters.coordinates.push_back(target_coordinate); - - http::Reply osrm_reply; - - routing_machine.RunQuery(route_parameters, osrm_reply); - - std::cout << osrm_reply.content << std::endl; - - //attention: super-inefficient hack below: - - std::stringstream ss; - ss << osrm_reply.content; - - boost::property_tree::ptree pt; - boost::property_tree::read_json(ss, pt); - - print_tree(pt, 0); - return 0; -} From fff1460dfbfb254cd621fffa04bb47c8a24ace28 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Jun 2013 16:11:13 -0400 Subject: [PATCH 18/61] ignore osrm-cli tool --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2e6107ad3..d6b86fad5 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,7 @@ stxxl.errlog /osrm-extract /osrm-routed /osrm-prepare +/osrm-cli /nohup.out # Sandbox folder # From 99aef2a178cd2d38679b653ed99b4c00bb3cda66 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Jun 2013 10:14:31 -0400 Subject: [PATCH 19/61] fixing coding style on OpenMP wrapper --- Util/OpenMPWrapper.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h index 520ac252c..c5426b06c 100644 --- a/Util/OpenMPWrapper.h +++ b/Util/OpenMPWrapper.h @@ -19,16 +19,17 @@ or see http://www.gnu.org/licenses/agpl.txt. */ -#ifndef _OPENMPREPLACEMENTY_H -#define _OPENMPREPLACEMENTY_H +#ifndef _OPENMWRAPPER_H +#define _OPENMWRAPPER_H #ifdef _OPENMP - #include + // extern "C" { + #include + // } #else - inline const int omp_get_num_procs() { return 1; } - inline const int omp_get_max_threads() { return 1; } - inline const int omp_get_thread_num() { return 0; } - inline const void omp_set_num_threads(int i) {} -#endif - -#endif + inline int omp_get_num_procs () { return 1; } + inline int omp_get_max_threads () { return 1; } + inline int omp_get_thread_num () { return 0; } + inline void omp_set_num_threads (int i) {} +#endif /* _OPENMP */ +#endif /* _OPENMWRAPPER_H */ From 8cb5e68b1af0afaad449a2265908e018887fdcd8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Jun 2013 10:22:47 -0400 Subject: [PATCH 20/61] fixing coding style on OpenMP wrapper --- Util/OpenMPWrapper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h index c5426b06c..7d0cab806 100644 --- a/Util/OpenMPWrapper.h +++ b/Util/OpenMPWrapper.h @@ -23,9 +23,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #define _OPENMWRAPPER_H #ifdef _OPENMP - // extern "C" { + extern "C" { #include - // } + } #else inline int omp_get_num_procs () { return 1; } inline int omp_get_max_threads () { return 1; } From de947d8b17db4d5d030a09f781733314f8b73ab2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Jun 2013 10:23:58 -0400 Subject: [PATCH 21/61] Add forgotten include --- DataStructures/Percent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStructures/Percent.h b/DataStructures/Percent.h index dafbe55dc..b5b909970 100644 --- a/DataStructures/Percent.h +++ b/DataStructures/Percent.h @@ -21,9 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef PERCENT_H #define PERCENT_H +#include "../Util/OpenMPWrapper.h" #include - class Percent { public: From dbf15c2db2e2b5d0aeac23703f66b0f891de11c2 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Sun, 30 Jun 2013 10:41:29 +0200 Subject: [PATCH 22/61] add test case for overruled implied oneways On a motorway `oneway=no` should overrule the implied oneway rule. --- features/car/oneway.feature | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/features/car/oneway.feature b/features/car/oneway.feature index b18108539..136a005d2 100644 --- a/features/car/oneway.feature +++ b/features/car/oneway.feature @@ -15,7 +15,7 @@ Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tag | highway | oneway | forw | backw | | primary | -1 | | x | - Scenario: Car - Implied onewatys + Scenario: Car - Implied oneways Then routability should be | highway | junction | forw | backw | | motorway | | x | | @@ -25,6 +25,12 @@ Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tag | motorway_link | roundabout | x | | | primary | roundabout | x | | + Scenario: Car - Overrule implied oneway + Then routability should be + | highway | oneway | forw | backw | + | motorway | no | x | x | + | motorway_link | no | x | x | + Scenario: Car - Around the Block Given the node map | a | b | @@ -70,4 +76,4 @@ Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tag When I route I should get | from | to | route | - | a | c | ab,bc | \ No newline at end of file + | a | c | ab,bc | From 3119e4b82b1edb12deb8c0232c8b7bd1f2338fc8 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 11:41:14 +0200 Subject: [PATCH 23/61] Use LuaJIT if available --- CMakeLists.txt | 15 ++++++-- cmake/FindLuaJIT.cmake | 86 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 cmake/FindLuaJIT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3de4c4f13..e9ea03922 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,10 +70,17 @@ target_link_libraries (osrm-routed ${ZLIB_LIBRARY}) find_package( Threads REQUIRED ) target_link_libraries (osrm-extract ${Threads_LIBRARY}) -find_package( Lua51 REQUIRED ) -include_directories(${LUA_INCLUDE_DIR}) -target_link_libraries( osrm-extract ${LUA_LIBRARY} ) -target_link_libraries( osrm-prepare ${LUA_LIBRARY} ) +find_package( LuaJIT ) +IF(LUAJIT_LIBRARIES) + include_directories(${LUAJIT_INCLUDE_DIR}) + target_link_libraries( osrm-extract ${LUAJIT_LIBRARIES} ) + target_link_libraries( osrm-prepare ${LUAJIT_LIBRARIES} ) +ELSE(LUAJIT_LIBRARIES) + find_package( Lua51 REQUIRED ) + include_directories(${LUA_INCLUDE_DIR}) + target_link_libraries( osrm-extract ${LUA_LIBRARY} ) + target_link_libraries( osrm-prepare ${LUA_LIBRARY} ) +ENDIF(LUAJIT_LIBRARIES) find_package( LibXml2 REQUIRED ) include_directories(${LIBXML2_INCLUDE_DIR}) diff --git a/cmake/FindLuaJIT.cmake b/cmake/FindLuaJIT.cmake new file mode 100644 index 000000000..864d83b74 --- /dev/null +++ b/cmake/FindLuaJIT.cmake @@ -0,0 +1,86 @@ +# Locate Lua library +# This module defines +# LUAJIT_FOUND, if false, do not try to link to Lua +# LUAJIT_LIBRARIES +# LUAJIT_INCLUDE_DIR, where to find lua.h +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) +# +# ################ +# 2010 - modified for cronkite to find luajit instead of lua, as it was before. +# + +IF( NOT LUAJIT_FIND_QUIETLY ) + MESSAGE(STATUS "Looking for LuaJIT...") +ENDIF() + +FIND_PATH(LUAJIT_INCLUDE_DIR lua.h + HINTS + $ENV{LUAJIT_DIR} + PATH_SUFFIXES include/luajit-2.0 include/luajit2.0 include/luajit include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_LIBRARY(LUAJIT_LIBRARY + NAMES luajit-51 luajit-5.1 luajit + HINTS + $ENV{LUAJIT_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUAJIT_MATH_LIBRARY m) + SET( LUAJIT_LIBRARIES "${LUAJIT_LIBRARY};${LUAJIT_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUAJIT_LIBRARIES "${LUAJIT_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +#ENDIF(LUAJIT_LIBRARY) + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUAJIT_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJIT DEFAULT_MSG LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR) + +IF( NOT LUAJIT_FIND_QUIETLY ) + IF( LUAJIT_FOUND ) + MESSAGE(STATUS "Found LuaJIT: ${LUAJIT_LIBRARY}" ) + ENDIF() +ENDIF() +MARK_AS_ADVANCED(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARIES LUAJIT_LIBRARY LUAJIT_MATH_LIBRARY) From b234760e923598cce1988f38968c48bb544b2740 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 13:32:31 +0200 Subject: [PATCH 24/61] Check if platform supports 64 bits --- CMakeLists.txt | 9 +++++++++ cmake/size.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 cmake/size.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e9ea03922..0f40e00cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,15 @@ cmake_minimum_required(VERSION 2.6) project(OSRM) include(FindPackageHandleStandardArgs) + +TRY_RUN(SHARED_LIBRARY_PATH_TYPE SHARED_LIBRARY_PATH_INFO_COMPILED ${PROJECT_BINARY_DIR}/CMakeTmp ${PROJECT_SOURCE_DIR}/cmake/size.cpp OUTPUT_VARIABLE IS_64_SYSTEM) +if(IS_64_SYSTEM) + message(STATUS "System supports 64 bits.") +else(IS_64_SYSTEM) + MESSAGE(WARNING "Compiling on a 32 bit system is unsupported!") +endif(IS_64_SYSTEM) + + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(BOOST_COMPONENTS filesystem regex system thread) diff --git a/cmake/size.cpp b/cmake/size.cpp new file mode 100644 index 000000000..2ac045227 --- /dev/null +++ b/cmake/size.cpp @@ -0,0 +1,9 @@ +#include + +int main( int argc, char* argv[] ) { + size_t size = sizeof(void*); + if ( 4 == size ) { + return 0; + } + return 1; +} \ No newline at end of file From 7ebe6de02263600ffec038e43cc1a2908d16cc62 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 13:46:55 +0200 Subject: [PATCH 25/61] Proper check for luajit --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f40e00cc..466226103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,16 +80,16 @@ find_package( Threads REQUIRED ) target_link_libraries (osrm-extract ${Threads_LIBRARY}) find_package( LuaJIT ) -IF(LUAJIT_LIBRARIES) +IF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES ) include_directories(${LUAJIT_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUAJIT_LIBRARIES} ) target_link_libraries( osrm-prepare ${LUAJIT_LIBRARIES} ) -ELSE(LUAJIT_LIBRARIES) - find_package( Lua51 REQUIRED ) +ELSE( LUAJIT_INCLUDE_DIR ) + find_package( Lua51 REQUIRED AND LUAJIT_LIBRARIES ) include_directories(${LUA_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUA_LIBRARY} ) target_link_libraries( osrm-prepare ${LUA_LIBRARY} ) -ENDIF(LUAJIT_LIBRARIES) +ENDIF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES ) find_package( LibXml2 REQUIRED ) include_directories(${LIBXML2_INCLUDE_DIR}) From e1e79206f92b35b99a34ad0ade3ac140f74cb923 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 16:01:59 +0200 Subject: [PATCH 26/61] fixing include typo --- Library/OSRM.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index adace328e..31088e3f2 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" #include "../Util/BaseConfiguration.h" -#include "../Server/BasicDataStructures.h" +#include "../Server/BasicDatastructures.h" #include From 7ab44728656516ece8477489f7232d72a5a29034 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 16:54:51 +0200 Subject: [PATCH 27/61] Fix non-critical memory leak --- Library/OSRM.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index d6ef0763d..cbcd12d3c 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -43,6 +43,7 @@ OSRM::~OSRM() { BOOST_FOREACH(PluginMap::value_type plugin_pointer, pluginMap) { delete plugin_pointer.second; } + delete objects; } void OSRM::RegisterPlugin(BasePlugin * plugin) { From 932b2b9acfa75afe3f95e23ef7dbb5e8f54bc59f Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 3 Jul 2013 16:56:52 +0200 Subject: [PATCH 28/61] Move pointer to member variables --- Library/OSRM.cpp | 2 +- Library/OSRM.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index cbcd12d3c..57603953d 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -22,7 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM::OSRM(const char * server_ini_path) { BaseConfiguration serverConfig(server_ini_path); - QueryObjectsStorage * objects = new QueryObjectsStorage( + objects = new QueryObjectsStorage( serverConfig.GetParameter("hsgrData"), serverConfig.GetParameter("ramIndex"), serverConfig.GetParameter("fileIndex"), diff --git a/Library/OSRM.h b/Library/OSRM.h index 31088e3f2..ec5f5d98f 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -42,7 +42,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class OSRM : boost::noncopyable { typedef boost::unordered_map PluginMap; - + QueryObjectsStorage * objects; public: OSRM(const char * server_ini_path); ~OSRM(); From 34735b8aad06098d09d3fb907137697799a281e4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 5 Jul 2013 22:36:51 +0200 Subject: [PATCH 29/61] throw an exception when server.ini is missing --- Library/OSRM.cpp | 4 ++++ Library/OSRM.h | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 57603953d..4a472c626 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -21,6 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRM.h" OSRM::OSRM(const char * server_ini_path) { + if( !testDataFile(server_ini_path) ){ + throw OSRMException("server.ini not found"); + } + BaseConfiguration serverConfig(server_ini_path); objects = new QueryObjectsStorage( serverConfig.GetParameter("hsgrData"), diff --git a/Library/OSRM.h b/Library/OSRM.h index ec5f5d98f..9a4c601d5 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -31,15 +31,26 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/RouteParameters.h" #include "../Util/BaseConfiguration.h" +#include "../Util/InputFileUtil.h" #include "../Server/BasicDatastructures.h" - #include #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; From bf621478024e4a9b7eca3e0405914c4af1bcb2f9 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 8 Jul 2013 10:27:41 +0200 Subject: [PATCH 30/61] Fixing unneeded explicit conversion --- DataStructures/Restriction.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h index 3627c6ade..2d396aa4d 100644 --- a/DataStructures/Restriction.h +++ b/DataStructures/Restriction.h @@ -31,14 +31,14 @@ struct _Restriction { NodeID toNode; struct Bits { //mostly unused Bits() : isOnly(false), unused1(false), unused2(false), unused3(false), unused4(false), unused5(false), unused6(false), unused7(false) {} - char isOnly:1; - char unused1:1; - char unused2:1; - char unused3:1; - char unused4:1; - char unused5:1; - char unused6:1; - char unused7:1; + bool isOnly:1; + bool unused1:1; + bool unused2:1; + bool unused3:1; + bool unused4:1; + bool unused5:1; + bool unused6:1; + bool unused7:1; } flags; _Restriction(NodeID vn) : viaNode(vn), fromNode(UINT_MAX), toNode(UINT_MAX) { } From 9d29e5d87a0efbef479aedef3652eb2a9fe06892 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 8 Jul 2013 14:51:21 +0200 Subject: [PATCH 31/61] Base64 needs 3-byte padded inputs --- Algorithms/ObjectToBase64.h | 57 ++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/Algorithms/ObjectToBase64.h b/Algorithms/ObjectToBase64.h index 928095189..067ac8c56 100644 --- a/Algorithms/ObjectToBase64.h +++ b/Algorithms/ObjectToBase64.h @@ -30,38 +30,63 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include typedef boost::archive::iterators::base64_from_binary< - boost::archive::iterators::transform_width -> base64_t; + boost::archive::iterators::transform_width + > base64_t; typedef boost::archive::iterators::transform_width< - boost::archive::iterators::binary_from_base64, 8, 6 + boost::archive::iterators::binary_from_base64< + std::string::const_iterator>, 8, 6 > binary_t; -template -static void EncodeObjectToBase64(const ToEncodeT & object, std::string& encoded) { - encoded.clear(); - char * pointerToOriginalObject = (char *)&object; - encoded = std::string(base64_t(pointerToOriginalObject), base64_t(pointerToOriginalObject+sizeof(ToEncodeT))); - //replace "+" with "-" and "/" with "_" +template +static void EncodeObjectToBase64(const ObjectT & object, std::string& encoded) { + const char * char_ptr_to_object = (const char *)&object; + std::vector data(sizeof(object)); + std::copy( + char_ptr_to_object, + char_ptr_to_object + sizeof(ObjectT), + data.begin() + ); + + unsigned char number_of_padded_chars = 0; // is in {0,1,2}; + while(data.size() % 3 != 0) { + ++number_of_padded_chars; + data.push_back(0x00); + } + + BOOST_ASSERT_MSG( + 0 == data.size() % 3, + "base64 input data size is not a multiple of 3!" + ); + encoded.resize(sizeof(ObjectT)); + encoded.assign( + base64_t( &data[0] ), + base64_t( &data[0] + (data.size() - number_of_padded_chars) ) + ); replaceAll(encoded, "+", "-"); replaceAll(encoded, "/", "_"); } -template -static void DecodeObjectFromBase64(ToEncodeT & object, const std::string& _encoded) { +template +static void DecodeObjectFromBase64(const std::string& input, ObjectT & object) { try { - std::string encoded(_encoded); + std::string encoded(input); //replace "-" with "+" and "_" with "/" replaceAll(encoded, "-", "+"); replaceAll(encoded, "_", "/"); - char * pointerToDecodedObject = (char *)&object; - std::string dec(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1)); - std::copy ( dec.begin(), dec.end(), pointerToDecodedObject ); - } catch(...) {} + + std::copy ( + binary_t( encoded.begin() ), + binary_t( encoded.begin() + encoded.length() - 1), + (char *)&object + ); + + } catch(...) { } } #endif /* OBJECTTOBASE64_H_ */ From d8c97da0878c4de6267a498b4c9007d4f732bbfa Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 8 Jul 2013 14:51:55 +0200 Subject: [PATCH 32/61] Remove dead code and reformat --- DataStructures/Restriction.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h index 2d396aa4d..fc40fb0ba 100644 --- a/DataStructures/Restriction.h +++ b/DataStructures/Restriction.h @@ -30,7 +30,18 @@ struct _Restriction { NodeID fromNode; NodeID toNode; struct Bits { //mostly unused - Bits() : isOnly(false), unused1(false), unused2(false), unused3(false), unused4(false), unused5(false), unused6(false), unused7(false) {} + Bits() : + isOnly(false), + unused1(false), + unused2(false), + unused3(false), + unused4(false), + unused5(false), + unused6(false), + unused7(false) { + + } + bool isOnly:1; bool unused1:1; bool unused2:1; @@ -41,14 +52,21 @@ struct _Restriction { bool unused7:1; } flags; - _Restriction(NodeID vn) : viaNode(vn), fromNode(UINT_MAX), toNode(UINT_MAX) { } - _Restriction(bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) { + _Restriction(NodeID vn) : + viaNode(vn), + fromNode(UINT_MAX), + toNode(UINT_MAX) { + + } + + _Restriction(const bool isOnly = false) : + viaNode(UINT_MAX), + fromNode(UINT_MAX), + toNode(UINT_MAX) { flags.isOnly = isOnly; } }; -inline bool CmpRestrictionByFrom ( _Restriction a, _Restriction b) { return (a.fromNode < b.fromNode); } - struct _RawRestrictionContainer { _Restriction restriction; EdgeID fromWay; @@ -66,7 +84,7 @@ struct _RawRestrictionContainer { } }; -struct CmpRestrictionContainerByFrom: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { +struct CmpRestrictionContainerByFrom : public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { typedef _RawRestrictionContainer value_type; bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { return a.fromWay < b.fromWay; @@ -92,6 +110,4 @@ struct CmpRestrictionContainerByTo: public std::binary_function<_RawRestrictionC } }; - - #endif /* RESTRICTION_H_ */ From df1f8284884b66c782714260f5916610f2f4f22a Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 8 Jul 2013 14:52:43 +0200 Subject: [PATCH 33/61] Pass references instead of value types --- Library/OSRM.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 57603953d..065b170d4 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -40,7 +40,7 @@ OSRM::OSRM(const char * server_ini_path) { } OSRM::~OSRM() { - BOOST_FOREACH(PluginMap::value_type plugin_pointer, pluginMap) { + BOOST_FOREACH(PluginMap::value_type & plugin_pointer, pluginMap) { delete plugin_pointer.second; } delete objects; @@ -52,7 +52,7 @@ void OSRM::RegisterPlugin(BasePlugin * plugin) { } void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { - PluginMap::const_iterator iter = pluginMap.find(route_parameters.service); + const PluginMap::const_iterator & iter = pluginMap.find(route_parameters.service); if(pluginMap.end() != iter) { reply.status = http::Reply::ok; iter->second->HandleRequest(route_parameters, reply ); From 92ae8f37bac69aff4fc5d69ee5a495090b068e7b Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 8 Jul 2013 14:59:51 +0200 Subject: [PATCH 34/61] Reorder parameters --- Algorithms/ObjectToBase64.h | 1 + Plugins/ViaRoutePlugin.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Algorithms/ObjectToBase64.h b/Algorithms/ObjectToBase64.h index 067ac8c56..9c0d5377d 100644 --- a/Algorithms/ObjectToBase64.h +++ b/Algorithms/ObjectToBase64.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/StringUtil.h" +#include #include #include #include diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 9934c4791..1bd924ece 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -91,7 +91,7 @@ public: 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); - DecodeObjectFromBase64(phantomNodeVector[i], routeParameters.hints[i]); + DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]); if(phantomNodeVector[i].isValid(nodeHelpDesk->getNumberOfNodes())) { // INFO("Decoded hint " << i << " successfully"); continue; From 9ab86ae2bf03cc143df274d188df3edea89a1864 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 9 Jul 2013 14:08:24 +0200 Subject: [PATCH 35/61] Fixes issue #663 --- features/car/barrier.feature | 4 ++-- profiles/car.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/car/barrier.feature b/features/car/barrier.feature index 9d37d354a..3d2596b79 100644 --- a/features/car/barrier.feature +++ b/features/car/barrier.feature @@ -4,7 +4,7 @@ Feature: Car - Barriers Background: Given the profile "car" - Scenario: Car - Barriers + Scenario: Car - Barriers Then routability should be | node/barrier | bothw | | | x | @@ -14,7 +14,7 @@ Feature: Car - Barriers | border_control | x | | toll_booth | x | | sally_port | x | - | entrance | | + | entrance | x | | wall | | | fence | | | some_tag | | diff --git a/profiles/car.lua b/profiles/car.lua index ff7c37971..79c63c12f 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -1,7 +1,7 @@ -- Begin of globals require("lib/access") -barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true} +barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true, ["entrance"] = true} access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true } access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true } access_tag_restricted = { ["destination"] = true, ["delivery"] = true } From f5124de32783600d66333d1863d8ae697967268d Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Tue, 9 Jul 2013 14:25:32 +0200 Subject: [PATCH 36/61] Partially fixes #646. Values were incorrectly casted to int32_t and not uint32_t --- Extractor/XMLParser.cpp | 12 ++++----- Extractor/XMLParser.h | 14 ++++++----- Util/StringUtil.h | 54 +++++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index d9ab60411..90590e5e9 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -129,13 +129,13 @@ _RawRestrictionContainer XMLParser::_ReadXMLRestriction() { xmlChar * type = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "type" ); if(xmlStrEqual(role, (const xmlChar *) "to") && xmlStrEqual(type, (const xmlChar *) "way")) { - restriction.toWay = atoi((const char*) ref); + restriction.toWay = stringToUint((const char*) ref); } if(xmlStrEqual(role, (const xmlChar *) "from") && xmlStrEqual(type, (const xmlChar *) "way")) { - restriction.fromWay = atoi((const char*) ref); + restriction.fromWay = stringToUint((const char*) ref); } if(xmlStrEqual(role, (const xmlChar *) "via") && xmlStrEqual(type, (const xmlChar *) "node")) { - restriction.restriction.viaNode = atoi((const char*) ref); + restriction.restriction.viaNode = stringToUint((const char*) ref); } if(NULL != type) { @@ -176,7 +176,7 @@ ExtractionWay XMLParser::_ReadXMLWay() { if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) { xmlChar* id = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); - way.id = atoi((char*)id); + way.id = stringToUint((char*)id); xmlFree(id); xmlFree( childName ); break; @@ -202,7 +202,7 @@ ExtractionWay XMLParser::_ReadXMLWay() { } else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) { xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" ); if ( ref != NULL ) { - way.path.push_back( atoi(( const char* ) ref ) ); + way.path.push_back( stringToUint(( const char* ) ref ) ); xmlFree( ref ); } } @@ -227,7 +227,7 @@ ImportNode XMLParser::_ReadXMLNode() { } attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" ); if ( attribute != NULL ) { - node.id = atoi(( const char* ) attribute ); + node.id = stringToUint(( const char* ) attribute ); xmlFree( attribute ); } diff --git a/Extractor/XMLParser.h b/Extractor/XMLParser.h index a2af2fb86..d17230dfe 100644 --- a/Extractor/XMLParser.h +++ b/Extractor/XMLParser.h @@ -1,17 +1,17 @@ /* 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 @@ -21,17 +21,19 @@ #ifndef XMLPARSER_H_ #define XMLPARSER_H_ +#include "BaseParser.h" +#include "../Util/StringUtil.h" +#include "../typedefs.h" + #include -#include "../typedefs.h" -#include "BaseParser.h" class XMLParser : public BaseParser { public: XMLParser(const char* filename, ExtractorCallbacks* ec, ScriptingEnvironment& se); bool ReadHeader(); bool Parse(); - + private: _RawRestrictionContainer _ReadXMLRestriction(); ExtractionWay _ReadXMLWay(); diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 3c1b590f1..6945575f4 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -62,23 +62,63 @@ static inline char* printInt( char* buffer, int value ) { } static inline void intToString(const int value, std::string & output) { - // The largest 32-bit integer is 4294967295, that is 10 chars - // On the safe side, add 1 for sign, and 1 for trailing zero output.clear(); std::back_insert_iterator sink(output); boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value); } +static inline void int64ToString(const int64_t value, std::string & output) { + output.clear(); + std::back_insert_iterator sink(output); + boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value); +} + static inline int stringToInt(const std::string& input) { - std::string::const_iterator realBeginOfNumber = input.begin(); + std::string::const_iterator first_digit = input.begin(); //Delete any trailing white-spaces - while(realBeginOfNumber != input.end() && std::isspace(*realBeginOfNumber)) - ++realBeginOfNumber; - int value = 0; // 2 - boost::spirit::qi::parse(realBeginOfNumber, input.end(), boost::spirit::int_, value); // 3 + while(first_digit != input.end() && std::isspace(*first_digit)) { + ++first_digit; + } + int value = 0; + boost::spirit::qi::parse( + first_digit, + input.end(), + boost::spirit::int_, value + ); return value; } +static inline unsigned stringToUint(const std::string& input) { + std::string::const_iterator first_digit = input.begin(); + //Delete any trailing white-spaces + while(first_digit != input.end() && std::isspace(*first_digit)) { + ++first_digit; + } + int value = 0; + boost::spirit::qi::parse( + first_digit, + input.end(), + boost::spirit::uint_, value + ); + return value; +} + +static inline uint64_t stringToInt64(const std::string& input) { + std::string::const_iterator first_digit = input.begin(); + //Delete any trailing white-spaces + while(first_digit != input.end() && std::isspace(*first_digit)) { + ++first_digit; + } + uint64_t value = 0; + boost::spirit::qi::parse( + first_digit, + input.end(), + boost::spirit::long_long, value + ); + return value; +} + + static inline void doubleToString(const double value, std::string & output){ output.clear(); std::back_insert_iterator sink(output); From f579b6f971b3719dba340035aed6ce73efa5de97 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 13:20:48 +0200 Subject: [PATCH 37/61] Fixes #670 --- extractor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extractor.cpp b/extractor.cpp index de801ff51..a324f5970 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -70,6 +70,12 @@ int main (int argc, char *argv[]) { file_has_pbf_format = true; } } + if(pos==std::string::npos) { + pos = output_file_name.find(".pbf"); + if(pos!=std::string::npos) { + file_has_pbf_format = true; + } + } if(pos!=std::string::npos) { output_file_name.replace(pos, 8, ".osrm"); restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); From 4dffeedd1c59bd0ec2d1cd3b7831cac3b8a7df96 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 14:47:13 +0200 Subject: [PATCH 38/61] (partially) adding new fingerprint objects --- Util/UUID.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ Util/UUID.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Util/UUID.cpp create mode 100644 Util/UUID.h diff --git a/Util/UUID.cpp b/Util/UUID.cpp new file mode 100644 index 000000000..64a316708 --- /dev/null +++ b/Util/UUID.cpp @@ -0,0 +1,40 @@ +/* + 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. + */ + +#include "UUID.h" + +UUID::UUID() { + boost::uuids::name_generator gen(named_uuid); + named_uuid = gen(std::string(__DATE__).append(__TIME__)); +} + +UUID::~UUID() { + +} + +const boost::uuids::uuid & UUID::GetUUID() const { + return named_uuid; +} + +/*static UUID & UUID::GetInstance() { + static UUID instance; + return instance; +}*/ + diff --git a/Util/UUID.h b/Util/UUID.h new file mode 100644 index 000000000..c580ab514 --- /dev/null +++ b/Util/UUID.h @@ -0,0 +1,47 @@ +/* + 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 UUID_H +#define UUID_H + +#include +#include // uuid class +#include // generators +#include // streaming operators etc. + +#include +#include + +//implements a singleton, i.e. there is one and only one conviguration object +class UUID : boost::noncopyable { +public: + static UUID & GetInstance() { + static UUID instance; + return instance; + } + ~UUID(); + const boost::uuids::uuid & GetUUID() const; +private: + UUID(); + // initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8} + boost::uuids::uuid named_uuid; +}; + +#endif /* UUID_H */ \ No newline at end of file From 15308931e9f51cd908ffdc91d2fc858b687a54fc Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 14:47:22 +0200 Subject: [PATCH 39/61] (partially) adding new fingerprint objects --- CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fec7a90b0..91e7a6774 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8) project(OSRM) include(FindPackageHandleStandardArgs) @@ -9,13 +9,14 @@ else(IS_64_SYSTEM) MESSAGE(WARNING "Compiling on a 32 bit system is unsupported!") endif(IS_64_SYSTEM) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(BOOST_COMPONENTS filesystem regex system thread) +add_library(uuid OBJECT Util/UUID.cpp) + file(GLOB ExtractorGlob Extractor/*.cpp) set(ExtractorSources extractor.cpp ${ExtractorGlob}) -add_executable(osrm-extract ${ExtractorSources}) +add_executable(osrm-extract ${ExtractorSources} $) file(GLOB PrepareGlob Contractor/*.cpp) set(PrepareSources createHierarchy.cpp ${PrepareGlob}) @@ -71,10 +72,10 @@ if (NOT Boost_FOUND) endif (NOT Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) -target_link_libraries( OSRM ${Boost_LIBRARIES}) +target_link_libraries( OSRM ${Boost_LIBRARIES} ) target_link_libraries( osrm-extract ${Boost_LIBRARIES} ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) -target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM) +target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM ) find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) From 129a846393766d589fe54694fc4e9de566a6e0ce Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 15:27:38 +0200 Subject: [PATCH 40/61] add bit size to config object --- .gitignore | 1 + CMakeLists.txt | 7 +++++-- Util/UUID.cpp | 2 ++ Util/UUID.h | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a3aefbf70..6516e9005 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ Thumbs.db # build related files # ####################### /build/ +/Util/UUID.config.h # Eclipse related files # ######################### diff --git a/CMakeLists.txt b/CMakeLists.txt index 91e7a6774..a4d7fd34d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,12 @@ include(FindPackageHandleStandardArgs) TRY_RUN(SHARED_LIBRARY_PATH_TYPE SHARED_LIBRARY_PATH_INFO_COMPILED ${PROJECT_BINARY_DIR}/CMakeTmp ${PROJECT_SOURCE_DIR}/cmake/size.cpp OUTPUT_VARIABLE IS_64_SYSTEM) if(IS_64_SYSTEM) message(STATUS "System supports 64 bits.") + set( HAS64BITS 1 ) else(IS_64_SYSTEM) MESSAGE(WARNING "Compiling on a 32 bit system is unsupported!") + set( HAS64BITS 0 ) endif(IS_64_SYSTEM) +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/Util/UUID.config.h.in ${CMAKE_SOURCE_DIR}/Util/UUID.config.h ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(BOOST_COMPONENTS filesystem regex system thread) @@ -20,9 +23,9 @@ add_executable(osrm-extract ${ExtractorSources} $) file(GLOB PrepareGlob Contractor/*.cpp) set(PrepareSources createHierarchy.cpp ${PrepareGlob}) -add_executable(osrm-prepare ${PrepareSources}) +add_executable(osrm-prepare ${PrepareSources} $) -add_executable(osrm-routed routed.cpp) +add_executable(osrm-routed routed.cpp $) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) file(GLOB DescriptorGlob Descriptors/*.cpp) diff --git a/Util/UUID.cpp b/Util/UUID.cpp index 64a316708..322cc02b5 100644 --- a/Util/UUID.cpp +++ b/Util/UUID.cpp @@ -23,6 +23,8 @@ or see http://www.gnu.org/licenses/agpl.txt. UUID::UUID() { boost::uuids::name_generator gen(named_uuid); named_uuid = gen(std::string(__DATE__).append(__TIME__)); + + has_64_bits = HAS64BITS; } UUID::~UUID() { diff --git a/Util/UUID.h b/Util/UUID.h index c580ab514..29689f4a1 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef UUID_H #define UUID_H +#include "UUID.config.h" + #include #include // uuid class #include // generators @@ -42,6 +44,7 @@ private: UUID(); // initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8} boost::uuids::uuid named_uuid; + bool has_64_bits; }; #endif /* UUID_H */ \ No newline at end of file From d2e68068bf050eeecbb9e13775317929df7685c1 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 16:23:57 +0200 Subject: [PATCH 41/61] fixes #659 --- profiles/car.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/profiles/car.lua b/profiles/car.lua index 79c63c12f..da6e6cedc 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -32,13 +32,13 @@ speed_profile = { ["default"] = 50 } -take_minimum_of_speeds = false -obey_oneway = true -obey_bollards = true -use_restrictions = true -ignore_areas = true -- future feature -traffic_signal_penalty = 2 -u_turn_penalty = 20 +take_minimum_of_speeds = false +obey_oneway = true +obey_bollards = true +use_restrictions = true +ignore_areas = true -- future feature +traffic_signal_penalty = 2 +u_turn_penalty = 20 -- End of globals @@ -182,11 +182,17 @@ function way_function (way) -- Set direction according to tags on way way.direction = Way.bidirectional - if obey_oneway then + if obey_oneway then if oneway == "-1" then way.direction = Way.opposite - elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then - way.direction = Way.oneway + elseif oneway == "yes" or + oneway == "1" or + oneway == "true" or + junction == "roundabout" or + (highway == "motorway_link" and oneway ~="no") or + (highway == "motorway" and oneway ~= "no") + then + way.direction = Way.oneway end end From b782c8560c237dc512e6e4d03a04bc3b3a891543 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 16:27:09 +0200 Subject: [PATCH 42/61] add forgotten include file --- Util/UUID.config.h.in | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Util/UUID.config.h.in diff --git a/Util/UUID.config.h.in b/Util/UUID.config.h.in new file mode 100644 index 000000000..7e018c4ef --- /dev/null +++ b/Util/UUID.config.h.in @@ -0,0 +1,6 @@ +#ifndef UUID_CONFIG_H_ +#define UUID_CONFIG_H_ + +#cmakedefine01 HAS64BITS + +#endif /* UUID_CONFIG_H_ */ \ No newline at end of file From 1ca213cec650aefbf6c6cd18fe3d71a2fd7826be Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 16:27:50 +0200 Subject: [PATCH 43/61] Remove duplicate license header --- Extractor/ExtractorCallbacks.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index cd690abde..db8e8f8f9 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -12,26 +12,6 @@ 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. - */ - -/* - 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 From a4f6ec516bb83e1e9af8dba51b3bf234f2a0b274 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 17 Jul 2013 16:29:11 +0200 Subject: [PATCH 44/61] Remove unnecessary file --- cmake/GetGitRevisionDescription.cmake | 123 -------------------------- 1 file changed, 123 deletions(-) delete mode 100644 cmake/GetGitRevisionDescription.cmake diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake deleted file mode 100644 index 1bf023008..000000000 --- a/cmake/GetGitRevisionDescription.cmake +++ /dev/null @@ -1,123 +0,0 @@ -# - Returns a version string from Git -# -# These functions force a re-configure on each git commit so that you can -# trust the values of the variables in your build system. -# -# get_git_head_revision( [ ...]) -# -# Returns the refspec and sha hash of the current head revision -# -# git_describe( [ ...]) -# -# Returns the results of git describe on the source tree, and adjusting -# the output so that it tests false if an error occurs. -# -# git_get_exact_tag( [ ...]) -# -# Returns the results of git describe --exact-match on the source tree, -# and adjusting the output so that it tests false if there was no exact -# matching tag. -# -# Requires CMake 2.6 or newer (uses the 'function' command) -# -# Original Author: -# 2009-2010 Ryan Pavlik -# http://academic.cleardefinition.com -# Iowa State University HCI Graduate Program/VRAC -# -# Copyright Iowa State University 2009-2010. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -if(__get_git_revision_description) - return() -endif() -set(__get_git_revision_description YES) - -# We must run the following at "include" time, not at function call time, -# to find the path to this module rather than the path to a calling list file -get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) - -function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories - set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") - get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) - if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) - # We have reached the root directory, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - endwhile() - set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") - if(NOT EXISTS "${GIT_DATA}") - file(MAKE_DIRECTORY "${GIT_DATA}") - endif() - - if(NOT EXISTS "${GIT_DIR}/HEAD") - return() - endif() - set(HEAD_FILE "${GIT_DATA}/HEAD") - configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) - - configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" - "${GIT_DATA}/grabRef.cmake" - @ONLY) - include("${GIT_DATA}/grabRef.cmake") - - set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) - set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) -endfunction() - -function(git_describe _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - get_git_head_revision(refspec hash) - if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) - return() - endif() - if(NOT hash) - set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) - return() - endif() - - # TODO sanitize - #if((${ARGN}" MATCHES "&&") OR - # (ARGN MATCHES "||") OR - # (ARGN MATCHES "\\;")) - # message("Please report the following error to the project!") - # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") - #endif() - - #message(STATUS "Arguments to execute_process: ${ARGN}") - - execute_process(COMMAND - "${GIT_EXECUTABLE}" - describe - ${hash} - ${ARGN} - WORKING_DIRECTORY - "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE - res - OUTPUT_VARIABLE - out - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT res EQUAL 0) - set(out "${out}-${res}-NOTFOUND") - endif() - - set(${_var} "${out}" PARENT_SCOPE) -endfunction() - -function(git_get_exact_tag _var) - git_describe(out --exact-match ${ARGN}) - set(${_var} "${out}" PARENT_SCOPE) -endfunction() From c3dab15eb6cb599c5e90883813f52d5e7ceba5ec Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Thu, 18 Jul 2013 14:11:45 +0200 Subject: [PATCH 45/61] Several lookup fixes and fingerprinting of files with input IO, thx @alex85k --- CMakeLists.txt | 19 ++++++++++++++----- Util/UUID.config.h.in | 5 +++++ cmake/FindLuabind.cmake | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d7fd34d..32896c0f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.6) project(OSRM) include(FindPackageHandleStandardArgs) @@ -10,22 +10,29 @@ else(IS_64_SYSTEM) MESSAGE(WARNING "Compiling on a 32 bit system is unsupported!") set( HAS64BITS 0 ) endif(IS_64_SYSTEM) + +file(MD5 ${CMAKE_SOURCE_DIR}/createHierarchy.cpp MD5PREPARE) +file(MD5 ${CMAKE_SOURCE_DIR}/DataStructures/StaticRTree.h MD5RTREE) +file(MD5 ${CMAKE_SOURCE_DIR}/DataStructures/NodeInformationHelpDesk.h MD5NODEINFO) +file(MD5 ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h MD5GRAPH) +file(MD5 ${CMAKE_SOURCE_DIR}/Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) + CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/Util/UUID.config.h.in ${CMAKE_SOURCE_DIR}/Util/UUID.config.h ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(BOOST_COMPONENTS filesystem regex system thread) -add_library(uuid OBJECT Util/UUID.cpp) +#add_library(uuid OBJECT Util/UUID.cpp) file(GLOB ExtractorGlob Extractor/*.cpp) set(ExtractorSources extractor.cpp ${ExtractorGlob}) -add_executable(osrm-extract ${ExtractorSources} $) +add_executable(osrm-extract ${ExtractorSources} ) file(GLOB PrepareGlob Contractor/*.cpp) set(PrepareSources createHierarchy.cpp ${PrepareGlob}) -add_executable(osrm-prepare ${PrepareSources} $) +add_executable(osrm-prepare ${PrepareSources} ) -add_executable(osrm-routed routed.cpp $) +add_executable(osrm-routed routed.cpp ) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) file(GLOB DescriptorGlob Descriptors/*.cpp) @@ -85,6 +92,7 @@ include_directories(${BZIP_INCLUDE_DIRS}) target_link_libraries (osrm-extract ${BZIP2_LIBRARIES}) find_package( ZLIB REQUIRED ) +include_directories(${ZLIB_INCLUDE_DIRS}) target_link_libraries (osrm-extract ${ZLIB_LIBRARY}) target_link_libraries (osrm-routed ${ZLIB_LIBRARY}) @@ -119,6 +127,7 @@ target_link_libraries (osrm-prepare ${PROTOBUF_LIBRARY}) find_package( STXXL REQUIRED ) include_directories(${STXXL_INCLUDE_DIR}) +target_link_libraries (OSRM ${STXXL_LIBRARY}) target_link_libraries (osrm-extract ${STXXL_LIBRARY}) target_link_libraries (osrm-prepare ${STXXL_LIBRARY}) diff --git a/Util/UUID.config.h.in b/Util/UUID.config.h.in index 7e018c4ef..ac87491fc 100644 --- a/Util/UUID.config.h.in +++ b/Util/UUID.config.h.in @@ -2,5 +2,10 @@ #define UUID_CONFIG_H_ #cmakedefine01 HAS64BITS +#cmakedefine MD5PREPARE "${MD5PREPARE}" +#cmakedefine MD5RTREE "${MD5RTREE}" +#cmakedefine MD5NODEINFO "${MD5NODEINFO}" +#cmakedefine MD5GRAPH "${MD5GRAPH}" +#cmakedefine MD5OBJECTS "${MD5OBJECTS}" #endif /* UUID_CONFIG_H_ */ \ No newline at end of file diff --git a/cmake/FindLuabind.cmake b/cmake/FindLuabind.cmake index 39b325059..4b99b3c0e 100644 --- a/cmake/FindLuabind.cmake +++ b/cmake/FindLuabind.cmake @@ -27,7 +27,7 @@ FIND_PATH(LUABIND_INCLUDE_DIR luabind.hpp ) FIND_LIBRARY(LUABIND_LIBRARY - NAMES luabind + NAMES luabind luabind09 HINTS $ENV{LUABIND_DIR} PATH_SUFFIXES lib64 lib @@ -72,4 +72,4 @@ IF( NOT LUABIND_FIND_QUIETLY ) ENDIF() ENDIF() -MARK_AS_ADVANCED(LUABIND_INCLUDE_DIR LUABIND_LIBRARIES LUABIND_LIBRARY LUABIND_LIBRARY_DBG) +MARK_AS_ADVANCED(LUABIND_INCLUDE_DIR LUABIND_LIBRARIES LUABIND_LIBRARY LUABIND_LIBRARY_DBG) From 03f1430ddcc7313b02099e0e02e7b28cd03945a0 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 14:37:40 +0200 Subject: [PATCH 46/61] Trigger rebuild of fingerprint everytime --- Util/UUID.config.h.in | 11 ----------- Util/UUID.cpp | 42 ------------------------------------------ 2 files changed, 53 deletions(-) delete mode 100644 Util/UUID.config.h.in delete mode 100644 Util/UUID.cpp diff --git a/Util/UUID.config.h.in b/Util/UUID.config.h.in deleted file mode 100644 index ac87491fc..000000000 --- a/Util/UUID.config.h.in +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef UUID_CONFIG_H_ -#define UUID_CONFIG_H_ - -#cmakedefine01 HAS64BITS -#cmakedefine MD5PREPARE "${MD5PREPARE}" -#cmakedefine MD5RTREE "${MD5RTREE}" -#cmakedefine MD5NODEINFO "${MD5NODEINFO}" -#cmakedefine MD5GRAPH "${MD5GRAPH}" -#cmakedefine MD5OBJECTS "${MD5OBJECTS}" - -#endif /* UUID_CONFIG_H_ */ \ No newline at end of file diff --git a/Util/UUID.cpp b/Util/UUID.cpp deleted file mode 100644 index 322cc02b5..000000000 --- a/Util/UUID.cpp +++ /dev/null @@ -1,42 +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. - */ - -#include "UUID.h" - -UUID::UUID() { - boost::uuids::name_generator gen(named_uuid); - named_uuid = gen(std::string(__DATE__).append(__TIME__)); - - has_64_bits = HAS64BITS; -} - -UUID::~UUID() { - -} - -const boost::uuids::uuid & UUID::GetUUID() const { - return named_uuid; -} - -/*static UUID & UUID::GetInstance() { - static UUID instance; - return instance; -}*/ - From f5f7269f7004a9314827e84f24d51e1accdb7ec3 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 14:38:12 +0200 Subject: [PATCH 47/61] Trigger rebuild of fingerprint everytime --- .gitignore | 2 +- CMakeLists.txt | 27 ++++++++++++++++----------- Util/UUID.h | 12 ++++++++++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 6516e9005..dbee9e07a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ Thumbs.db # build related files # ####################### /build/ -/Util/UUID.config.h +/Util/UUID.cpp # Eclipse related files # ######################### diff --git a/CMakeLists.txt b/CMakeLists.txt index 32896c0f6..4c70ad560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,18 +11,21 @@ else(IS_64_SYSTEM) set( HAS64BITS 0 ) endif(IS_64_SYSTEM) -file(MD5 ${CMAKE_SOURCE_DIR}/createHierarchy.cpp MD5PREPARE) -file(MD5 ${CMAKE_SOURCE_DIR}/DataStructures/StaticRTree.h MD5RTREE) -file(MD5 ${CMAKE_SOURCE_DIR}/DataStructures/NodeInformationHelpDesk.h MD5NODEINFO) -file(MD5 ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h MD5GRAPH) -file(MD5 ${CMAKE_SOURCE_DIR}/Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) - -CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/Util/UUID.config.h.in ${CMAKE_SOURCE_DIR}/Util/UUID.config.h ) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -set(BOOST_COMPONENTS filesystem regex system thread) -#add_library(uuid OBJECT Util/UUID.cpp) +add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.config.h + COMMAND ${CMAKE_COMMAND} -P + ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake + DEPENDS + ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake + ${CMAKE_SOURCE_DIR}/Util/UUID.config.h.in + COMMENT "Configuring UUID.config.h" + VERBATIM) + +add_custom_target(UUIDConfigure ALL + DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.config.h ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h) + +set(BOOST_COMPONENTS filesystem regex system thread) file(GLOB ExtractorGlob Extractor/*.cpp) set(ExtractorSources extractor.cpp ${ExtractorGlob}) @@ -42,6 +45,8 @@ file(GLOB ServerStructureGlob Server/DataStructures/*.cpp) set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${SearchEngineSource} ${ServerStructureGlob}) add_library(OSRM SHARED ${OSRMSources}) +add_library(UUID STATIC Util/UUID.cpp) +add_dependencies( UUID UUIDConfigure ) # Check the release mode if(NOT CMAKE_BUILD_TYPE MATCHES Debug) @@ -83,7 +88,7 @@ endif (NOT Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries( OSRM ${Boost_LIBRARIES} ) -target_link_libraries( osrm-extract ${Boost_LIBRARIES} ) +target_link_libraries( osrm-extract ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM ) diff --git a/Util/UUID.h b/Util/UUID.h index 29689f4a1..5dfce34cf 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -21,13 +21,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef UUID_H #define UUID_H -#include "UUID.config.h" - #include #include // uuid class #include // generators #include // streaming operators etc. +#include + +#include #include #include @@ -42,6 +43,13 @@ public: const boost::uuids::uuid & GetUUID() const; private: UUID(); + const unsigned magic_number; + char md5_prepare[33]; + char md5_tree[33]; + char md5_nodeinfo[33]; + char md5_graph[33]; + char md5_objects[33]; + // initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8} boost::uuids::uuid named_uuid; bool has_64_bits; From 61c2ea9225ad19008305591436c0fe4984d08d65 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 14:53:47 +0200 Subject: [PATCH 48/61] Trigger rebuild of fingerprint everytime --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c70ad560..fec9dafbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,17 +13,17 @@ endif(IS_64_SYSTEM) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.config.h +add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.h COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake DEPENDS ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake - ${CMAKE_SOURCE_DIR}/Util/UUID.config.h.in - COMMENT "Configuring UUID.config.h" + ${CMAKE_SOURCE_DIR}/Util/UUID.h + COMMENT "Configuring UUID.cpp" VERBATIM) add_custom_target(UUIDConfigure ALL - DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.config.h ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h) + DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.h ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h) set(BOOST_COMPONENTS filesystem regex system thread) From 4961b819f3712468d9a1387aebd6d8aac5963718 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 15:00:41 +0200 Subject: [PATCH 49/61] Trigger rebuild of fingerprint everytime --- CMakeLists.txt | 2 +- Util/UUID.cpp.in | 56 +++++++++++++++++++++++++++++++++++++++++ cmake/UUID-Config.cmake | 12 +++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Util/UUID.cpp.in create mode 100644 cmake/UUID-Config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index fec9dafbb..757e2167e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.h ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake DEPENDS ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake - ${CMAKE_SOURCE_DIR}/Util/UUID.h + ${CMAKE_SOURCE_DIR}/Util/UUID.cpp COMMENT "Configuring UUID.cpp" VERBATIM) diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in new file mode 100644 index 000000000..621c59cfc --- /dev/null +++ b/Util/UUID.cpp.in @@ -0,0 +1,56 @@ +/* + 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. + */ + +#include "UUID.h" + +#cmakedefine01 HAS64BITS +#cmakedefine MD5PREPARE "${MD5PREPARE}" +#cmakedefine MD5RTREE "${MD5RTREE}" +#cmakedefine MD5NODEINFO "${MD5NODEINFO}" +#cmakedefine MD5GRAPH "${MD5GRAPH}" +#cmakedefine MD5OBJECTS "${MD5OBJECTS}" + +UUID::UUID() : magic_number(1297240911) { + boost::uuids::name_generator gen(named_uuid); + std::string temp_string(__DATE__); + temp_string += __TIME__; + + std::copy(MD5PREPARE, MD5PREPARE+strlen(MD5PREPARE), md5_prepare); + temp_string += md5_prepare; + std::copy(MD5RTREE, MD5RTREE+32, md5_tree); + temp_string += md5_tree; + std::copy(MD5NODEINFO, MD5NODEINFO+32, md5_nodeinfo); + temp_string += md5_nodeinfo; + std::copy(MD5GRAPH, MD5GRAPH+32, md5_graph); + temp_string += md5_graph; + std::copy(MD5OBJECTS, MD5OBJECTS+32, md5_objects); + temp_string += md5_objects; + + named_uuid = gen(temp_string); + has_64_bits = HAS64BITS; +} + +UUID::~UUID() { + +} + +const boost::uuids::uuid & UUID::GetUUID() const { + return named_uuid; +} diff --git a/cmake/UUID-Config.cmake b/cmake/UUID-Config.cmake new file mode 100644 index 000000000..3da918765 --- /dev/null +++ b/cmake/UUID-Config.cmake @@ -0,0 +1,12 @@ +set(oldfile ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp) +if (EXISTS ${oldfile}) + file(REMOVE_RECURSE ${oldfile}) +endif() + +file(MD5 ${CMAKE_SOURCE_DIR}/../createHierarchy.cpp MD5PREPARE) +file(MD5 ${CMAKE_SOURCE_DIR}/../DataStructures/StaticRTree.h MD5RTREE) +file(MD5 ${CMAKE_SOURCE_DIR}/../DataStructures/NodeInformationHelpDesk.h MD5NODEINFO) +file(MD5 ${CMAKE_SOURCE_DIR}/../Util/GraphLoader.h MD5GRAPH) +file(MD5 ${CMAKE_SOURCE_DIR}/../Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) + +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp.in ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp ) From 9a024210910ddcc139f9825da7588548ebb08868 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 15:02:45 +0200 Subject: [PATCH 50/61] Some mild refactoring --- Util/GraphLoader.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 5dc50f888..6b664a696 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -202,7 +202,7 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s ExternalNodeMap ext2IntNodeMap; in >> n; DEBUG("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)); @@ -219,9 +219,9 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s int length; in >> source >> target >> length >> dir >> speedType; - if(dir == 3) + if(dir == 3) { dir = 0; - + } switch(speedType) { case 1: weight = 130; @@ -271,8 +271,9 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s } weight = length*weight/3.6; - if(speedType == 13) + if(speedType == 13) { weight = length; + } assert(length > 0); assert(weight > 0); if(dir <0 || dir > 2) @@ -281,8 +282,12 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s bool forward = true; bool backward = true; - if (dir == 1) backward = false; - if (dir == 2) forward = false; + if (dir == 1) { + backward = false; + } + if (dir == 2) { + forward = false; + } if(length == 0) { ERR("loaded null length edge"); } From 90303d5952e186d4569a1023c87dc7fffa116fb7 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 16:36:57 +0200 Subject: [PATCH 51/61] further addition to cmake script --- CMakeLists.txt | 7 +++---- cmake/UUID-Config.cmake | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 757e2167e..a835d0016 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,17 +13,16 @@ endif(IS_64_SYSTEM) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.h +add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake DEPENDS ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake - ${CMAKE_SOURCE_DIR}/Util/UUID.cpp + ${CMAKE_SOURCE_DIR}/Util/UUID.cpp.in COMMENT "Configuring UUID.cpp" VERBATIM) -add_custom_target(UUIDConfigure ALL - DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.h ${CMAKE_SOURCE_DIR}/Util/GraphLoader.h) +add_custom_target(UUIDConfigure ALL DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp ) set(BOOST_COMPONENTS filesystem regex system thread) diff --git a/cmake/UUID-Config.cmake b/cmake/UUID-Config.cmake index 3da918765..d373dc89f 100644 --- a/cmake/UUID-Config.cmake +++ b/cmake/UUID-Config.cmake @@ -9,4 +9,4 @@ file(MD5 ${CMAKE_SOURCE_DIR}/../DataStructures/NodeInformationHelpDesk.h MD5NODE file(MD5 ${CMAKE_SOURCE_DIR}/../Util/GraphLoader.h MD5GRAPH) file(MD5 ${CMAKE_SOURCE_DIR}/../Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) -CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp.in ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp ) +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp.in ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp @ONLY) From 3515ddcfe6d0ccd7f7db00a37d8882ff1ebf74e5 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 16:58:13 +0200 Subject: [PATCH 52/61] Automatic rebuild --- CMakeLists.txt | 6 +++--- cmake/UUID-Config.cmake | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a835d0016..97bab9d56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,16 +13,16 @@ endif(IS_64_SYSTEM) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp +add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/UUID.cpp UUID.cpp.alwaysbuild COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake DEPENDS - ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake ${CMAKE_SOURCE_DIR}/Util/UUID.cpp.in + ${CMAKE_SOURCE_DIR}/cmake/UUID-Config.cmake COMMENT "Configuring UUID.cpp" VERBATIM) -add_custom_target(UUIDConfigure ALL DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp ) +add_custom_target(UUIDConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/UUID.cpp ) set(BOOST_COMPONENTS filesystem regex system thread) diff --git a/cmake/UUID-Config.cmake b/cmake/UUID-Config.cmake index d373dc89f..3da918765 100644 --- a/cmake/UUID-Config.cmake +++ b/cmake/UUID-Config.cmake @@ -9,4 +9,4 @@ file(MD5 ${CMAKE_SOURCE_DIR}/../DataStructures/NodeInformationHelpDesk.h MD5NODE file(MD5 ${CMAKE_SOURCE_DIR}/../Util/GraphLoader.h MD5GRAPH) file(MD5 ${CMAKE_SOURCE_DIR}/../Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) -CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp.in ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp @ONLY) +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp.in ${CMAKE_SOURCE_DIR}/../Util/UUID.cpp ) From 31fbfa3a70e6173ee1c42a01bfee96e6d2a3fea0 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 18:05:15 +0200 Subject: [PATCH 53/61] Link against UUID --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97bab9d56..ce6826292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,8 +88,8 @@ include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries( OSRM ${Boost_LIBRARIES} ) target_link_libraries( osrm-extract ${Boost_LIBRARIES} UUID ) -target_link_libraries( osrm-prepare ${Boost_LIBRARIES} ) -target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM ) +target_link_libraries( osrm-prepare ${Boost_LIBRARIES} UUID ) +target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM UUID ) find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) From c5db4dc15f298fe511f45acf1c11d065bcafc8c4 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 19 Jul 2013 18:05:54 +0200 Subject: [PATCH 54/61] Check for correct magic number --- Util/GraphLoader.h | 16 ++++++++++++++++ Util/UUID.cpp.in | 8 ++++++++ Util/UUID.h | 8 +++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 6b664a696..6fdcd3228 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/ImportEdge.h" #include "../DataStructures/NodeCoords.h" #include "../DataStructures/Restriction.h" +#include "../Util/UUID.h" #include "../typedefs.h" #include @@ -50,6 +51,21 @@ struct _ExcessRemover { template NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector& edgeList, std::vector &bollardNodes, std::vector &trafficLightNodes, std::vector * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) { + const UUID uuid_orig; + UUID uuid_loaded; + in.read((char *) &uuid_loaded, sizeof(UUID)); + if(!uuid_loaded.IsMagicNumberOK()) { + ERR("hsgr input file misses magic number. Check or reprocess the file"); + } + + if( uuid_loaded.TestHSGR(uuid_orig) ) { + WARN( + ".hsgr was prepared with different build.\n" + "Reprocess to get rid of this warning." + ) + } + + NodeID n, source, target; EdgeID m; short dir;// direction (0 = open, 1 = forward, 2+ = open) diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index 621c59cfc..c5b522af7 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -54,3 +54,11 @@ UUID::~UUID() { const boost::uuids::uuid & UUID::GetUUID() const { return named_uuid; } + +const bool UUID::IsMagicNumberOK() const { + return 1297240911 == magic_number; +} + +const bool UUID::TestHSGR(const UUID & other) const { + return std::equal(md5_graph, md5_graph+32, other.md5_graph); +} \ No newline at end of file diff --git a/Util/UUID.h b/Util/UUID.h index 5dfce34cf..354540e07 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -35,14 +35,12 @@ or see http://www.gnu.org/licenses/agpl.txt. //implements a singleton, i.e. there is one and only one conviguration object class UUID : boost::noncopyable { public: - static UUID & GetInstance() { - static UUID instance; - return instance; - } + UUID(); ~UUID(); const boost::uuids::uuid & GetUUID() const; + const bool IsMagicNumberOK() const; + const bool TestHSGR(const UUID & other) const; private: - UUID(); const unsigned magic_number; char md5_prepare[33]; char md5_tree[33]; From 0367399c89e633201feb51908c222ee79e0787a6 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 22 Jul 2013 16:32:19 +0200 Subject: [PATCH 55/61] Partial refactoring --- DataStructures/NodeInformationHelpDesk.h | 95 +++++++++++++----------- DataStructures/StaticRTree.h | 26 +++---- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 12d465096..48bad7879 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -30,9 +30,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include - #include +#include +#include #include typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; @@ -40,10 +40,14 @@ typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; class NodeInformationHelpDesk : boost::noncopyable{ public: NodeInformationHelpDesk( - const char* ramIndexInput, - const char* fileIndexInput, + const std::string & ramIndexInput, + const std::string & fileIndexInput, + const std::string & nodes_filename, + const std::string & edges_filename, const unsigned number_of_nodes, - const unsigned crc) : number_of_nodes(number_of_nodes), checkSum(crc) { + const unsigned check_sum + ) : number_of_nodes(number_of_nodes), check_sum(check_sum) + { read_only_rtree = new StaticRTree( ramIndexInput, fileIndexInput @@ -52,6 +56,8 @@ public: 0 == coordinateVector.size(), "Coordinate vector not empty" ); + + LoadNodesAndEdges(nodes_filename, edges_filename); } //Todo: Shared memory mechanism @@ -59,41 +65,6 @@ public: delete read_only_rtree; } - void initNNGrid( - std::ifstream& nodesInstream, - std::ifstream& edgesInStream - ) { - DEBUG("Loading node data"); - NodeInfo b; - while(!nodesInstream.eof()) { - nodesInstream.read((char *)&b, sizeof(NodeInfo)); - coordinateVector.push_back(_Coordinate(b.lat, b.lon)); - } - std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); - nodesInstream.close(); - - DEBUG("Loading edge data"); - unsigned numberOfOrigEdges(0); - edgesInStream.read((char*)&numberOfOrigEdges, sizeof(unsigned)); - origEdgeData_viaNode.resize(numberOfOrigEdges); - origEdgeData_nameID.resize(numberOfOrigEdges); - origEdgeData_turnInstruction.resize(numberOfOrigEdges); - - OriginalEdgeData deserialized_originalEdgeData; - for(unsigned i = 0; i < numberOfOrigEdges; ++i) { - edgesInStream.read( - (char*)&(deserialized_originalEdgeData), - sizeof(OriginalEdgeData) - ); - origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode; - origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID; - origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction; - } - edgesInStream.close(); - DEBUG("Loaded " << numberOfOrigEdges << " orig edges"); - DEBUG("Opening NN indices"); - } - inline int getLatitudeOfNode(const unsigned id) const { const NodeID node = origEdgeData_viaNode.at(id); return coordinateVector.at(node).lat; @@ -147,10 +118,50 @@ public: } inline unsigned GetCheckSum() const { - return checkSum; + return check_sum; } private: + void LoadNodesAndEdges( + 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"); } + + DEBUG("Loading node data"); + NodeInfo b; + while(!nodes_input_stream.eof()) { + nodes_input_stream.read((char *)&b, sizeof(NodeInfo)); + coordinateVector.push_back(_Coordinate(b.lat, b.lon)); + } + std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); + nodes_input_stream.close(); + + DEBUG("Loading edge data"); + unsigned numberOfOrigEdges(0); + edges_input_stream.read((char*)&numberOfOrigEdges, sizeof(unsigned)); + origEdgeData_viaNode.resize(numberOfOrigEdges); + origEdgeData_nameID.resize(numberOfOrigEdges); + origEdgeData_turnInstruction.resize(numberOfOrigEdges); + + OriginalEdgeData deserialized_originalEdgeData; + for(unsigned i = 0; i < numberOfOrigEdges; ++i) { + edges_input_stream.read( + (char*)&(deserialized_originalEdgeData), + sizeof(OriginalEdgeData) + ); + origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode; + origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID; + origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction; + } + edges_input_stream.close(); + DEBUG("Loaded " << numberOfOrigEdges << " orig edges"); + DEBUG("Opening NN indices"); + } + std::vector<_Coordinate> coordinateVector; std::vector origEdgeData_viaNode; std::vector origEdgeData_nameID; @@ -158,7 +169,7 @@ private: StaticRTree * read_only_rtree; const unsigned number_of_nodes; - const unsigned checkSum; + const unsigned check_sum; }; #endif /*NODEINFORMATIONHELPDESK_H_*/ diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 503cd675e..3e598f3e4 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -45,6 +45,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include #include //tuning parameters @@ -275,17 +276,16 @@ private: std::vector m_search_tree; uint64_t m_element_count; - std::string m_leaf_node_filename; + const std::string m_leaf_node_filename; public: //Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1] explicit StaticRTree( std::vector & input_data_vector, - const char * tree_node_filename, - const char * leaf_node_filename - ) : - m_element_count(input_data_vector.size()), + const std::string tree_node_filename, + const std::string leaf_node_filename + ) + : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) - { INFO("constructing r-tree of " << m_element_count << " elements"); double time1 = get_timestamp(); @@ -305,7 +305,7 @@ public: } //open leaf file - std::ofstream leaf_node_file(leaf_node_filename, std::ios::binary); + std::ofstream leaf_node_file(leaf_node_filename.c_str(), std::ios::binary); leaf_node_file.write((char*) &m_element_count, sizeof(uint64_t)); //sort the hilbert-value representatives @@ -386,7 +386,7 @@ public: } //open tree file - std::ofstream tree_node_file(tree_node_filename, std::ios::binary); + std::ofstream tree_node_file(tree_node_filename.c_str(), 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)); @@ -399,13 +399,11 @@ public: //Read-only operation for queries explicit StaticRTree( - const char * node_filename, - const char * leaf_filename + const std::string & node_filename, + const std::string & leaf_filename ) : m_leaf_node_filename(leaf_filename) { - //INFO("Loading nodes: " << node_filename); - //INFO("opening leafs: " << leaf_filename); //open tree node file and load into RAM. - std::ifstream tree_node_file(node_filename, std::ios::binary); + 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"); @@ -414,7 +412,7 @@ public: tree_node_file.close(); //open leaf node file and store thread specific pointer - std::ifstream leaf_node_file(leaf_filename, std::ios::binary); + std::ifstream leaf_node_file(leaf_filename.c_str(), std::ios::binary); leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t)); leaf_node_file.close(); From 4a39a4af1c1f647651dbfb4d74493f556385bf5e Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 22 Jul 2013 16:34:06 +0200 Subject: [PATCH 56/61] Check for valid data files. Implements #224 --- Extractor/ExtractionContainers.cpp | 4 +- Extractor/ExtractionContainers.h | 3 +- Server/DataStructures/QueryObjectsStorage.cpp | 17 +++-- Util/GraphLoader.h | 67 +++++++++++++------ Util/UUID.cpp.in | 35 +++++++++- Util/UUID.h | 8 ++- createHierarchy.cpp | 25 ++++--- extractor.cpp | 2 + routed.cpp | 5 +- 9 files changed, 123 insertions(+), 43 deletions(-) diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 14e8352b5..292e994cf 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -121,6 +121,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con //serialize restrictions std::ofstream restrictionsOutstream; restrictionsOutstream.open(restrictionsFileName.c_str(), std::ios::binary); + restrictionsOutstream.write((char*)&uuid, sizeof(UUID)); 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) { @@ -131,6 +132,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con std::ofstream fout; fout.open(output_file_name.c_str(), std::ios::binary); + fout.write((char*)&uuid, sizeof(UUID)); fout.write((char*)&usedNodeCounter, sizeof(unsigned)); time = get_timestamp(); std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush; @@ -158,7 +160,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con std::cout << "[extractor] setting number of nodes ... " << std::flush; std::ios::pos_type positionInFile = fout.tellp(); - fout.seekp(std::ios::beg); + fout.seekp(std::ios::beg+sizeof(UUID)); fout.write((char*)&usedNodeCounter, sizeof(unsigned)); fout.seekp(positionInFile); diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index f3815c12f..78c1b2a62 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -23,6 +23,7 @@ #include "ExtractorStructs.h" #include "../DataStructures/TimingUtil.h" +#include "../Util/UUID.h" #include #include @@ -63,7 +64,7 @@ public: STXXLStringVector nameVector; STXXLRestrictionsVector restrictionsVector; STXXLWayIDStartEndVector wayStartEndVector; - + const UUID uuid; }; #endif /* EXTRACTIONCONTAINERS_H_ */ diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index 16de52eb8..69142434c 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -58,24 +58,23 @@ QueryObjectsStorage::QueryObjectsStorage( getline(timestampInStream, timestamp); timestampInStream.close(); } - if(!timestamp.length()) + if(!timestamp.length()) { timestamp = "n/a"; - if(25 < timestamp.length()) + } + if(25 < timestamp.length()) { timestamp.resize(25); + } INFO("Loading auxiliary information"); //Init nearest neighbor data structure - std::ifstream nodesInStream(nodesPath.c_str(), std::ios::binary); - if(!nodesInStream) { ERR(nodesPath << " not found"); } - std::ifstream edgesInStream(edgesPath.c_str(), std::ios::binary); - if(!edgesInStream) { ERR(edgesPath << " not found"); } nodeHelpDesk = new NodeInformationHelpDesk( - ramIndexPath.c_str(), - fileIndexPath.c_str(), + ramIndexPath, + fileIndexPath, + nodesPath, + edgesPath, n, checkSum ); - nodeHelpDesk->initNNGrid(nodesInStream, edgesInStream); //deserialize street name list INFO("Loading names index"); diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 6fdcd3228..cd3e0cf7d 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -50,28 +50,31 @@ struct _ExcessRemover { }; template -NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector& edgeList, std::vector &bollardNodes, std::vector &trafficLightNodes, std::vector * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) { +NodeID readBinaryOSRMGraphFromStream( + std::istream &in, + std::vector& edgeList, + std::vector &bollardNodes, + std::vector &trafficLightNodes, + std::vector * int2ExtNodeMap, + std::vector<_Restriction> & inputRestrictions +) { const UUID uuid_orig; UUID uuid_loaded; in.read((char *) &uuid_loaded, sizeof(UUID)); - if(!uuid_loaded.IsMagicNumberOK()) { - ERR("hsgr input file misses magic number. Check or reprocess the file"); - } - if( uuid_loaded.TestHSGR(uuid_orig) ) { + if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { WARN( - ".hsgr was prepared with different build.\n" + ".osrm was prepared with different build.\n" "Reprocess to get rid of this warning." ) } - NodeID n, source, target; EdgeID m; short dir;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; in.read((char*)&n, sizeof(NodeID)); - DEBUG("Importing n = " << n << " nodes "); + INFO("Importing n = " << n << " nodes "); _Node node; for (NodeID i=0; i& edgeL std::vector(trafficLightNodes).swap(trafficLightNodes); in.read((char*)&m, sizeof(unsigned)); - DEBUG(" and " << m << " edges "); + INFO(" and " << m << " edges "); for(unsigned i = 0; i < inputRestrictions.size(); ++i) { ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); if( intNodeID == ext2IntNodeMap.end()) { @@ -380,19 +383,43 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s } template -unsigned readHSGRFromStream(std::istream &in, std::vector& nodeList, std::vector & edgeList, unsigned * checkSum) { - unsigned numberOfNodes = 0; - in.read((char*) checkSum, sizeof(unsigned)); - in.read((char*) & numberOfNodes, sizeof(unsigned)); - nodeList.resize(numberOfNodes + 1); - in.read((char*) &(nodeList[0]), numberOfNodes*sizeof(NodeT)); +unsigned readHSGRFromStream( + std::istream &hsgr_input_stream, + std::vector & node_list, + std::vector & edge_list, + unsigned * check_sum +) { + UUID uuid_loaded, uuid_orig; + hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); + if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { + WARN( + ".hsgr was prepared with different build.\n" + "Reprocess to get rid of this warning." + ) + } - unsigned numberOfEdges = 0; - in.read((char*) &numberOfEdges, sizeof(unsigned)); - edgeList.resize(numberOfEdges); - in.read((char*) &(edgeList[0]), numberOfEdges*sizeof(EdgeT)); + unsigned number_of_nodes = 0; + hsgr_input_stream.read((char*) check_sum, sizeof(unsigned)); + hsgr_input_stream.read((char*) & number_of_nodes, sizeof(unsigned)); + node_list.resize(number_of_nodes + 1); + hsgr_input_stream.read( + (char*) &(node_list[0]), + number_of_nodes*sizeof(NodeT) + ); - return numberOfNodes; + unsigned number_of_edges = 0; + hsgr_input_stream.read( + (char*) &number_of_edges, + sizeof(unsigned) + ); + + edge_list.resize(number_of_edges); + hsgr_input_stream.read( + (char*) &(edge_list[0]), + number_of_edges*sizeof(EdgeT) + ); + + return number_of_nodes; } #endif // GRAPHLOADER_H diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index c5b522af7..36726c4ae 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -59,6 +59,37 @@ const bool UUID::IsMagicNumberOK() const { return 1297240911 == magic_number; } -const bool UUID::TestHSGR(const UUID & other) const { +const bool UUID::TestGraphUtil(const UUID & other) const { + if(!other.IsMagicNumberOK()) { + ERR("hsgr input file misses magic number. Check or reprocess the file"); + } return std::equal(md5_graph, md5_graph+32, other.md5_graph); -} \ No newline at end of file +} + +const bool UUID::TestPrepare(const UUID & other) const { + if(!other.IsMagicNumberOK()) { + ERR("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"); + } + 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"); + } + 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"); + } + return std::equal(md5_objects, md5_objects+32, other.md5_objects); +} diff --git a/Util/UUID.h b/Util/UUID.h index 354540e07..188ab26a1 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef UUID_H #define UUID_H +#include "../typedefs.h" + #include #include // uuid class #include // generators @@ -39,7 +41,11 @@ public: ~UUID(); const boost::uuids::uuid & GetUUID() const; const bool IsMagicNumberOK() const; - const bool TestHSGR(const UUID & other) 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; private: const unsigned magic_number; char md5_prepare[33]; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 3f76fcd19..85cfea942 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -78,7 +78,16 @@ int main (int argc, char *argv[]) { ERR("Could not access files"); } _Restriction restriction; + UUID uuid_loaded, uuid_orig; 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." + ) + } + restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); inputRestrictions.resize(usableRestrictionsCounter); restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction)); @@ -211,8 +220,8 @@ int main (int argc, char *argv[]) { unsigned numberOfNodes = 0; unsigned numberOfEdges = contractedEdgeList.size(); INFO("Serializing compacted graph of " << numberOfEdges << " edges"); - std::ofstream edgeOutFile(graphOut.c_str(), std::ios::binary); - + 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) { if(edge.source > numberOfNodes) { numberOfNodes = edge.source; @@ -237,11 +246,11 @@ int main (int argc, char *argv[]) { } ++numberOfNodes; //Serialize numberOfNodes, nodes - edgeOutFile.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); - edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned)); - edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes)); + hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); + hsgr_output_stream.write((char*) &numberOfNodes, sizeof(unsigned)); + hsgr_output_stream.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes)); //Serialize number of Edges - edgeOutFile.write((char*) &position, sizeof(unsigned)); + hsgr_output_stream.write((char*) &position, sizeof(unsigned)); --numberOfNodes; edge = 0; int usedEdgeCounter = 0; @@ -256,7 +265,7 @@ int main (int argc, char *argv[]) { ERR("Failed at edges of node " << node << " of " << numberOfNodes); } //Serialize edges - edgeOutFile.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); + hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); ++edge; ++usedEdgeCounter; } @@ -265,7 +274,7 @@ int main (int argc, char *argv[]) { INFO("Expansion : " << (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"); INFO("Contraction: " << (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< usedEdgeCounter/endTime << " edges/sec"); - edgeOutFile.close(); + hsgr_output_stream.close(); //cleanedEdgeList.clear(); _nodes.clear(); INFO("finished preprocessing"); diff --git a/extractor.cpp b/extractor.cpp index a324f5970..5e580d8e7 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/StringUtil.h" +#include "Util/UUID.h" #include "typedefs.h" #include @@ -37,6 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include ExtractorCallbacks * extractCallBacks; +UUID uuid; int main (int argc, char *argv[]) { try { diff --git a/routed.cpp b/routed.cpp index 596f610d7..1f4e43550 100644 --- a/routed.cpp +++ b/routed.cpp @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/BaseConfiguration.h" #include "Util/InputFileUtil.h" #include "Util/OpenMPWrapper.h" +#include "Util/UUID.h" #ifdef __linux__ #include "Util/LinuxStackTrace.h" @@ -77,7 +78,9 @@ int main (int argc, char * argv[]) { //} try { - std::cout << "\n starting up engines, compile at " << + //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl; + + std::cout << "starting up engines, compiled at " << __DATE__ << ", " __TIME__ << std::endl; #ifndef _WIN32 From f70174d1d15f5781c894b1076f87541cf5495811 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 22 Jul 2013 17:54:04 +0200 Subject: [PATCH 57/61] Link internal tools against UUID --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce6826292..ca7cdda21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,9 +146,10 @@ if(WITH_TOOLS) if(GDAL_FOUND) add_executable(osrm-components Tools/componentAnalysis.cpp) include_directories(${GDAL_INCLUDE_DIR}) - target_link_libraries( osrm-components ${GDAL_LIBRARIES} ) - target_link_libraries( osrm-components ${Boost_LIBRARIES} ) + target_link_libraries( + osrm-components ${GDAL_LIBRARIES} ${Boost_LIBRARIES} UUID + ) endif(GDAL_FOUND) - add_executable ( osrm-cli Tools/simpleclient.cpp) - target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM) + add_executable ( osrm-cli Tools/simpleclient.cpp ) + target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM UUID ) endif(WITH_TOOLS) From bcdd9374c7359e5b7dab8d499e1cc464df4052c8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 23 Jul 2013 10:18:42 +0200 Subject: [PATCH 58/61] Compile fixes on OS X --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca7cdda21..a21ee2d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ if (NOT Boost_FOUND) endif (NOT Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) -target_link_libraries( OSRM ${Boost_LIBRARIES} ) +target_link_libraries( OSRM ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-extract ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM UUID ) From 811d6deb41a3443eeec878b023091eda5aae0123 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 23 Jul 2013 11:38:15 +0200 Subject: [PATCH 59/61] Don't link against LuaJIT on OS X --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a21ee2d1f..68173132b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,7 @@ find_package( Threads REQUIRED ) target_link_libraries (osrm-extract ${Threads_LIBRARY}) find_package( LuaJIT ) -IF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES ) +IF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES AND NOT APPLE) include_directories(${LUAJIT_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUAJIT_LIBRARIES} ) target_link_libraries( osrm-prepare ${LUAJIT_LIBRARIES} ) From bf0b43aa24b57a2cc31fa6c7372645db8361d57c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 23 Jul 2013 11:49:23 +0200 Subject: [PATCH 60/61] Platform specific linker flags --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68173132b..b17f1149a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,11 @@ if (NOT Boost_FOUND) endif (NOT Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) -target_link_libraries( OSRM ${Boost_LIBRARIES} UUID ) +IF( APPLE ) + target_link_libraries( OSRM ${Boost_LIBRARIES} UUID ) +ELSE( APPLE ) + target_link_libraries( OSRM ${Boost_LIBRARIES} ) +ENDIF( APPLE ) target_link_libraries( osrm-extract ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-prepare ${Boost_LIBRARIES} UUID ) target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM UUID ) @@ -104,7 +108,7 @@ find_package( Threads REQUIRED ) target_link_libraries (osrm-extract ${Threads_LIBRARY}) find_package( LuaJIT ) -IF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES AND NOT APPLE) +IF( NOT APPLE AND LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES) include_directories(${LUAJIT_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUAJIT_LIBRARIES} ) target_link_libraries( osrm-prepare ${LUAJIT_LIBRARIES} ) @@ -113,7 +117,7 @@ ELSE( LUAJIT_INCLUDE_DIR ) include_directories(${LUA_INCLUDE_DIR}) target_link_libraries( osrm-extract ${LUA_LIBRARY} ) target_link_libraries( osrm-prepare ${LUA_LIBRARY} ) -ENDIF( LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES ) +ENDIF( NOT APPLE AND LUAJIT_INCLUDE_DIR AND LUAJIT_LIBRARIES ) find_package( LibXml2 REQUIRED ) include_directories(${LIBXML2_INCLUDE_DIR}) From f2b81ba86c583656d370c5c0f05b1b15bb04a37c Mon Sep 17 00:00:00 2001 From: Sven Luzar Date: Tue, 30 Jul 2013 21:37:57 +0200 Subject: [PATCH 61/61] pull request moved to develop branch: roundabout handling from car profile moved to bike profile --- profiles/bicycle.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 98d03c83d..063ad50bc 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -189,7 +189,12 @@ function way_function (way) way.name = "{highway:"..highway.."}" -- if no name exists, use way type -- this encoding scheme is excepted to be a temporary solution end - + + -- roundabout handling + if "roundabout" == junction then + way.roundabout = true; + end + -- speed if route_speeds[route] then -- ferries (doesn't cover routes tagged using relations)