From da277d981681425169d51d67ff3c1d5856bc5d3c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 14:23:06 +0200 Subject: [PATCH 001/127] Adding shared memory data types --- DataStructures/SharedMemoryFactory.h | 165 +++++++++++++++++++++ DataStructures/SharedMemoryVectorWrapper.h | 96 ++++++++++++ Server/DataStructures/SharedDataType.h | 26 ++++ 3 files changed, 287 insertions(+) create mode 100644 DataStructures/SharedMemoryFactory.h create mode 100644 DataStructures/SharedMemoryVectorWrapper.h create mode 100644 Server/DataStructures/SharedDataType.h diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h new file mode 100644 index 000000000..9c908a187 --- /dev/null +++ b/DataStructures/SharedMemoryFactory.h @@ -0,0 +1,165 @@ +/* + 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 SHARED_MEMORY_FACTORY_H +#define SHARED_MEMORY_FACTORY_H + +#include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" + +#include +#include +#include +#include + +#include +#include + +struct OSRMLockFile { + boost::filesystem::path operator()() { + boost::filesystem::path temp_dir = + boost::filesystem::temp_directory_path(); + SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; + boost::filesystem::path lock_file = temp_dir / "osrm.lock"; + SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; + return lock_file; + } +}; + +class SharedMemory : boost::noncopyable { + + //Remove shared memory on destruction + class shm_remove : boost::noncopyable { + private: + int m_shmid; + bool m_initialized; + public: + void SetID(int shmid) { + m_shmid = shmid; + m_initialized = true; + } + + shm_remove() : m_shmid(INT_MIN), m_initialized(false) {} + + ~shm_remove(){ + if(m_initialized) { + SimpleLogger().Write(logDEBUG) << + "automatic memory deallocation"; + boost::interprocess::xsi_shared_memory::remove(m_shmid); + } + } + + }; + +public: + void * Ptr() const { + return region.get_address(); + } + + template + SharedMemory( + const boost::filesystem::path & lock_file, + const IdentifierT id, + const unsigned size = 0 + ) : key( + lock_file.string().c_str(), + id + ) { + if( 0 == size ){ //read_only + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::open_only, + key + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_only + ); + } else { //writeable pointer + //remove previously allocated mem + RemoveSharedMemory(key); + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::create_only, + key, + size + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_write + ); + + remover.SetID( shm.get_shmid() ); + SimpleLogger().Write(logDEBUG) << + "writeable memory allocated " << size << " bytes"; + } + } + +private: + static void RemoveSharedMemory( + const boost::interprocess::xsi_key &key + ) { + try{ + SimpleLogger().Write(logDEBUG) << "deallocating prev memory"; + boost::interprocess::xsi_shared_memory xsi( + boost::interprocess::open_only, + key + ); + boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid()); + } catch(boost::interprocess::interprocess_exception &e){ + if(e.get_error_code() != boost::interprocess::not_found_error) { + throw; + } + } + } + + boost::interprocess::xsi_key key; + boost::interprocess::xsi_shared_memory shm; + boost::interprocess::mapped_region region; + shm_remove remover; +}; + +template +class SharedMemoryFactory_tmpl : boost::noncopyable { +public: + template + static SharedMemory * Get( + const IdentifierT & id, + const unsigned size = 0 + ) { + try { + LockFileT lock_file; + if(0 == size && !boost::filesystem::exists(lock_file()) ) { + throw OSRMException("lock file does not exist, exiting"); + } + return new SharedMemory(lock_file(), id, size); + } catch(const boost::interprocess::interprocess_exception &e){ + SimpleLogger().Write(logWARNING) << + "caught exception: " << e.what() << + ", code " << e.get_error_code(); + throw OSRMException(e.what()); + } + }; + +private: + SharedMemoryFactory_tmpl() {} +}; + +typedef SharedMemoryFactory_tmpl<> SharedMemoryFactory; + +#endif /* SHARED_MEMORY_POINTER_FACTORY_H */ diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h new file mode 100644 index 000000000..0773466d9 --- /dev/null +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -0,0 +1,96 @@ +/* + 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 SHARED_MEMORY_VECTOR_WRAPPER_H +#define SHARED_MEMORY_VECTOR_WRAPPER_H + +#include +#include +#include + +#include +#include + +template +class ShMemIterator : public std::iterator { + boost::shared_ptr p; +public: + ShMemIterator(boost::shared_ptr & x) :p(x) {} + ShMemIterator(const ShMemIterator & mit) : p(mit.p) {} + ShMemIterator& operator++() { + ++p; + return *this; + } + ShMemIterator operator++(int) { + ShMemIterator tmp(*this); + operator++(); + return tmp; + } + bool operator==(const ShMemIterator& rhs) { + return p==rhs.p; + } + bool operator!=(const ShMemIterator& rhs) { + return p!=rhs.p; + } + DataT& operator*() { + return *p; + } +}; + +template +class SharedMemoryWrapper { +private: + boost::shared_ptr m_ptr; + std::size_t m_size; + + SharedMemoryWrapper() {}; +public: + SharedMemoryWrapper(const DataT * ptr, std::size_t size) : + m_ptr(ptr), + m_size(size) + { } + + ShMemIterator begin() const { + return ShMemIterator(m_ptr); + } + + ShMemIterator end() const { + return ShMemIterator(m_ptr+m_size); + } + + std::size_t size() const { return m_size; } + + DataT & operator[](const int index) { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + return m_ptr[index]; + } +}; + +template +class ShMemVector : public + boost::conditional< + SharedMemory, + SharedMemoryWrapper, + std::vector + >::type +{ }; + + +#endif //SHARED_MEMORY_VECTOR_WRAPPER_H diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h new file mode 100644 index 000000000..83cc6da81 --- /dev/null +++ b/Server/DataStructures/SharedDataType.h @@ -0,0 +1,26 @@ +/* + 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 SHARED_DATA_TYPE_H_ +#define SHARED_DATA_TYPE_H_ + +enum SharedDataType { NAMES_INDEX, NAMES_LIST }; + +#endif /* SHARED_DATA_TYPE_H_ */ From e19f54a378658767ca9b543472948a36d389bd52 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 14:23:06 +0200 Subject: [PATCH 002/127] Adding shared memory data types --- DataStructures/SharedMemoryFactory.h | 165 +++++++++++++++++++++ DataStructures/SharedMemoryVectorWrapper.h | 96 ++++++++++++ Server/DataStructures/SharedDataType.h | 26 ++++ 3 files changed, 287 insertions(+) create mode 100644 DataStructures/SharedMemoryFactory.h create mode 100644 DataStructures/SharedMemoryVectorWrapper.h create mode 100644 Server/DataStructures/SharedDataType.h diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h new file mode 100644 index 000000000..9c908a187 --- /dev/null +++ b/DataStructures/SharedMemoryFactory.h @@ -0,0 +1,165 @@ +/* + 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 SHARED_MEMORY_FACTORY_H +#define SHARED_MEMORY_FACTORY_H + +#include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" + +#include +#include +#include +#include + +#include +#include + +struct OSRMLockFile { + boost::filesystem::path operator()() { + boost::filesystem::path temp_dir = + boost::filesystem::temp_directory_path(); + SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; + boost::filesystem::path lock_file = temp_dir / "osrm.lock"; + SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; + return lock_file; + } +}; + +class SharedMemory : boost::noncopyable { + + //Remove shared memory on destruction + class shm_remove : boost::noncopyable { + private: + int m_shmid; + bool m_initialized; + public: + void SetID(int shmid) { + m_shmid = shmid; + m_initialized = true; + } + + shm_remove() : m_shmid(INT_MIN), m_initialized(false) {} + + ~shm_remove(){ + if(m_initialized) { + SimpleLogger().Write(logDEBUG) << + "automatic memory deallocation"; + boost::interprocess::xsi_shared_memory::remove(m_shmid); + } + } + + }; + +public: + void * Ptr() const { + return region.get_address(); + } + + template + SharedMemory( + const boost::filesystem::path & lock_file, + const IdentifierT id, + const unsigned size = 0 + ) : key( + lock_file.string().c_str(), + id + ) { + if( 0 == size ){ //read_only + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::open_only, + key + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_only + ); + } else { //writeable pointer + //remove previously allocated mem + RemoveSharedMemory(key); + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::create_only, + key, + size + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_write + ); + + remover.SetID( shm.get_shmid() ); + SimpleLogger().Write(logDEBUG) << + "writeable memory allocated " << size << " bytes"; + } + } + +private: + static void RemoveSharedMemory( + const boost::interprocess::xsi_key &key + ) { + try{ + SimpleLogger().Write(logDEBUG) << "deallocating prev memory"; + boost::interprocess::xsi_shared_memory xsi( + boost::interprocess::open_only, + key + ); + boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid()); + } catch(boost::interprocess::interprocess_exception &e){ + if(e.get_error_code() != boost::interprocess::not_found_error) { + throw; + } + } + } + + boost::interprocess::xsi_key key; + boost::interprocess::xsi_shared_memory shm; + boost::interprocess::mapped_region region; + shm_remove remover; +}; + +template +class SharedMemoryFactory_tmpl : boost::noncopyable { +public: + template + static SharedMemory * Get( + const IdentifierT & id, + const unsigned size = 0 + ) { + try { + LockFileT lock_file; + if(0 == size && !boost::filesystem::exists(lock_file()) ) { + throw OSRMException("lock file does not exist, exiting"); + } + return new SharedMemory(lock_file(), id, size); + } catch(const boost::interprocess::interprocess_exception &e){ + SimpleLogger().Write(logWARNING) << + "caught exception: " << e.what() << + ", code " << e.get_error_code(); + throw OSRMException(e.what()); + } + }; + +private: + SharedMemoryFactory_tmpl() {} +}; + +typedef SharedMemoryFactory_tmpl<> SharedMemoryFactory; + +#endif /* SHARED_MEMORY_POINTER_FACTORY_H */ diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h new file mode 100644 index 000000000..0773466d9 --- /dev/null +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -0,0 +1,96 @@ +/* + 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 SHARED_MEMORY_VECTOR_WRAPPER_H +#define SHARED_MEMORY_VECTOR_WRAPPER_H + +#include +#include +#include + +#include +#include + +template +class ShMemIterator : public std::iterator { + boost::shared_ptr p; +public: + ShMemIterator(boost::shared_ptr & x) :p(x) {} + ShMemIterator(const ShMemIterator & mit) : p(mit.p) {} + ShMemIterator& operator++() { + ++p; + return *this; + } + ShMemIterator operator++(int) { + ShMemIterator tmp(*this); + operator++(); + return tmp; + } + bool operator==(const ShMemIterator& rhs) { + return p==rhs.p; + } + bool operator!=(const ShMemIterator& rhs) { + return p!=rhs.p; + } + DataT& operator*() { + return *p; + } +}; + +template +class SharedMemoryWrapper { +private: + boost::shared_ptr m_ptr; + std::size_t m_size; + + SharedMemoryWrapper() {}; +public: + SharedMemoryWrapper(const DataT * ptr, std::size_t size) : + m_ptr(ptr), + m_size(size) + { } + + ShMemIterator begin() const { + return ShMemIterator(m_ptr); + } + + ShMemIterator end() const { + return ShMemIterator(m_ptr+m_size); + } + + std::size_t size() const { return m_size; } + + DataT & operator[](const int index) { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + return m_ptr[index]; + } +}; + +template +class ShMemVector : public + boost::conditional< + SharedMemory, + SharedMemoryWrapper, + std::vector + >::type +{ }; + + +#endif //SHARED_MEMORY_VECTOR_WRAPPER_H diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h new file mode 100644 index 000000000..83cc6da81 --- /dev/null +++ b/Server/DataStructures/SharedDataType.h @@ -0,0 +1,26 @@ +/* + 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 SHARED_DATA_TYPE_H_ +#define SHARED_DATA_TYPE_H_ + +enum SharedDataType { NAMES_INDEX, NAMES_LIST }; + +#endif /* SHARED_DATA_TYPE_H_ */ From 1e5c4b0d79ba2b513e2a6a2e88c5215e2110d3e2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:35:43 +0200 Subject: [PATCH 003/127] Facade base class to provide all data access --- Server/DataStructures/BaseDataFacade.h | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Server/DataStructures/BaseDataFacade.h diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h new file mode 100644 index 000000000..b8e4f415f --- /dev/null +++ b/Server/DataStructures/BaseDataFacade.h @@ -0,0 +1,75 @@ +/* + 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 QUERY_DATA_FACADE_H +#define QUERY_DATA_FACADE_H + +//Exposes all data access interfaces to the algorithms via base class ptr + +#include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/PhantomNodes.h" +#include "../../DataStructures/TurnInstructions.h" +#include "../../typedefs.h" + +#include + +class QueryDataFacade { +public: + QueryDataFacade() { } + virtual ~QueryDataFacade() { } + + //search graph access + //TODO + + //node and edge information access + virtual FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const = 0; + + virtual TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const = 0; + + virtual NodeID GetNumberOfNodes( ) const = 0; + + virtual bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const = 0; + + virtual bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const = 0; + + virtual unsigned GetCheckSum() const = 0; + + virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + virtual void GetName( + const unsigned name_id, + std::string & result + ) const = 0; + +}; + + +#endif // QUERY_DATA_FACADE_H From 66d58bf047c68f16e9c77afe7dd1dd39be9e2ab2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:37:08 +0200 Subject: [PATCH 004/127] instantiate different inherited class at bcp that provides all data --- Library/OSRM.cpp | 163 ++++++++++++++++++++++++++--------------------- Library/OSRM.h | 3 +- 2 files changed, 92 insertions(+), 74 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 79f6b869f..1ddb5e62d 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -20,80 +20,97 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRM.h" -OSRM::OSRM(const char * server_ini_path) { - if( !testDataFile(server_ini_path) ){ - std::string error_message = std::string(server_ini_path) + " not found"; - throw OSRMException(error_message.c_str()); +OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) + : use_shared_memory(use_shared_memory) +{ + if( !use_shared_memory ) { + if( !testDataFile(server_ini_path) ){ + std::string error_message = std::string(server_ini_path) + " not found"; + throw OSRMException(error_message.c_str()); + } + + IniFile serverConfig(server_ini_path); + + boost::filesystem::path base_path = + boost::filesystem::absolute(server_ini_path).parent_path(); + + if ( !serverConfig.Holds("hsgrData")) { + throw OSRMException("no ram index file name in server ini"); + } + if ( !serverConfig.Holds("ramIndex") ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( !serverConfig.Holds("fileIndex") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("nodesData") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("edgesData") ) { + throw OSRMException("no edges file name in server ini"); + } + + boost::filesystem::path hsgr_path = boost::filesystem::absolute( + serverConfig.GetParameter("hsgrData"), + base_path + ); + + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("ramIndex"), + base_path + ); + + boost::filesystem::path file_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("fileIndex"), + base_path + ); + + boost::filesystem::path node_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("nodesData"), + base_path + ); + boost::filesystem::path edge_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("edgesData"), + base_path + ); + boost::filesystem::path name_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("namesData"), + base_path + ); + boost::filesystem::path timestamp_path = boost::filesystem::absolute( + serverConfig.GetParameter("timestamp"), + base_path + ); + + objects = new QueryObjectsStorage( + hsgr_path.string(), + ram_index_path.string(), + file_index_path.string(), + node_data_path.string(), + edge_data_path.string(), + name_data_path.string(), + timestamp_path.string() + ); + + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin(objects)); + RegisterPlugin(new NearestPlugin(objects)); + RegisterPlugin(new TimestampPlugin(objects)); + RegisterPlugin(new ViaRoutePlugin(objects)); + + } else { + //TODO: fetch pointers from shared memory + + //TODO: objects = new QueryObjectsStorage() + + //TODO: generate shared memory plugins + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin(objects)); + RegisterPlugin(new NearestPlugin(objects)); + RegisterPlugin(new TimestampPlugin(objects)); + RegisterPlugin(new ViaRoutePlugin(objects)); + } - - IniFile serverConfig(server_ini_path); - - boost::filesystem::path base_path = - boost::filesystem::absolute(server_ini_path).parent_path(); - - if ( !serverConfig.Holds("hsgrData")) { - throw OSRMException("no ram index file name in server ini"); - } - if ( !serverConfig.Holds("ramIndex") ) { - throw OSRMException("no mem index file name in server ini"); - } - if ( !serverConfig.Holds("fileIndex") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("nodesData") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("edgesData") ) { - throw OSRMException("no edges file name in server ini"); - } - - boost::filesystem::path hsgr_path = boost::filesystem::absolute( - serverConfig.GetParameter("hsgrData"), - base_path - ); - - boost::filesystem::path ram_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("ramIndex"), - base_path - ); - - boost::filesystem::path file_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("fileIndex"), - base_path - ); - - boost::filesystem::path node_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("nodesData"), - base_path - ); - boost::filesystem::path edge_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("edgesData"), - base_path - ); - boost::filesystem::path name_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("namesData"), - base_path - ); - boost::filesystem::path timestamp_path = boost::filesystem::absolute( - serverConfig.GetParameter("timestamp"), - base_path - ); - - objects = new QueryObjectsStorage( - hsgr_path.string(), - ram_index_path.string(), - file_index_path.string(), - node_data_path.string(), - edge_data_path.string(), - name_data_path.string(), - timestamp_path.string() - ); - - RegisterPlugin(new HelloWorldPlugin()); - RegisterPlugin(new LocatePlugin(objects)); - RegisterPlugin(new NearestPlugin(objects)); - RegisterPlugin(new TimestampPlugin(objects)); - RegisterPlugin(new ViaRoutePlugin(objects)); } OSRM::~OSRM() { diff --git a/Library/OSRM.h b/Library/OSRM.h index bb3caa7d9..17e27a1c8 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -47,12 +47,13 @@ class OSRM : boost::noncopyable { typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; public: - OSRM(const char * server_ini_path); + OSRM(const char * server_ini_path, const bool use_shared_memory = false); ~OSRM(); void RunQuery(RouteParameters & route_parameters, http::Reply & reply); private: void RegisterPlugin(BasePlugin * plugin); PluginMap pluginMap; + const bool use_shared_memory; }; #endif //OSRM_H From 1bd24f7042713628858741a04b4477ef3278c4c8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:37:52 +0200 Subject: [PATCH 005/127] remove unneeded white spaces --- Server/DataStructures/QueryObjectsStorage.cpp | 2 +- Server/DataStructures/QueryObjectsStorage.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index e0ec72e40..fa17e5dbe 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -69,7 +69,7 @@ QueryObjectsStorage::QueryObjectsStorage( SimpleLogger().Write() << "Loading Timestamp"; std::ifstream timestampInStream(timestamp_path.c_str()); if(!timestampInStream) { - SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; } getline(timestampInStream, timestamp); diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index fd5419283..b9923dfce 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -36,7 +36,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include - struct QueryObjectsStorage { typedef StaticGraph QueryGraph; typedef QueryGraph::InputEdge InputEdge; From 8753dbdb0f2f57a796410f1bb9a9579e4e54c464 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:45:33 +0200 Subject: [PATCH 006/127] added graph data access --- Server/DataStructures/BaseDataFacade.h | 34 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index b8e4f415f..1c3c3c660 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -30,13 +30,43 @@ or see http://www.gnu.org/licenses/agpl.txt. #include +template class QueryDataFacade { public: QueryDataFacade() { } virtual ~QueryDataFacade() { } //search graph access - //TODO + virtual unsigned GetNumberOfNodes() const = 0; + + virtual unsigned GetNumberOfEdges() const = 0; + + virtual unsigned GetOutDegree( const NodeID n ) const = 0; + + virtual NodeID GetTarget( const EdgeID e ) const = 0; + + virtual EdgeDataT &GetEdgeData( const EdgeID e ) = 0; + + virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; + + virtual EdgeID BeginEdges( const NodeID n ) const = 0; + + virtual EdgeID EndEdges( const NodeID n ) const = 0; + + //searches for a specific edge + virtual EdgeID FindEdge( const NodeID from, const NodeID to ) const = 0; + + virtual EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const = 0; + + virtual EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const = 0; + //node and edge information access virtual FixedPointCoordinate GetCoordinateOfNode( @@ -47,8 +77,6 @@ public: const unsigned id ) const = 0; - virtual NodeID GetNumberOfNodes( ) const = 0; - virtual bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate& input_coordinate, FixedPointCoordinate& result, From f844e9e70258abdadd4885c44af64ca1317e7c8c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:55:53 +0200 Subject: [PATCH 007/127] plugging in base facade ptr --- Library/OSRM.h | 4 ++++ Server/DataStructures/BaseDataFacade.h | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index 17e27a1c8..5e37f2c6d 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/NearestPlugin.h" #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" +#include "../Server/DataStructures/BaseDataFacade.h" #include "../Server/DataStructures/RouteParameters.h" #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" @@ -44,8 +45,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include class OSRM : boost::noncopyable { +private: typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; + BaseDataFacade * query_data_facade; + public: OSRM(const char * server_ini_path, const bool use_shared_memory = false); ~OSRM(); diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 1c3c3c660..2316d27f3 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -31,10 +31,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include template -class QueryDataFacade { +class BaseDataFacade { public: - QueryDataFacade() { } - virtual ~QueryDataFacade() { } + BaseDataFacade() { } + virtual ~BaseDataFacade() { } //search graph access virtual unsigned GetNumberOfNodes() const = 0; @@ -67,7 +67,6 @@ public: bool & result ) const = 0; - //node and edge information access virtual FixedPointCoordinate GetCoordinateOfNode( const unsigned id @@ -96,7 +95,6 @@ public: const unsigned name_id, std::string & result ) const = 0; - }; From 003c1df53e5a3dbbaa3827dfb5be3ee6529208e9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 17:49:49 +0200 Subject: [PATCH 008/127] Mockups for data facades --- DataStructures/NodeInformationHelpDesk.h | 2 + DataStructures/StaticGraph.h | 27 ++++-- Library/OSRM.cpp | 1 + Library/OSRM.h | 3 + Server/DataStructures/BaseDataFacade.h | 1 + Server/DataStructures/InternalDataFacade.h | 94 +++++++++++++++++++++ Server/DataStructures/SharedDataFacade.h | 95 ++++++++++++++++++++++ 7 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 Server/DataStructures/InternalDataFacade.h create mode 100644 Server/DataStructures/SharedDataFacade.h diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 120f11ff6..cda10cd40 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ +//TODO: Umbauen in Private Data Facade + #ifndef NODEINFORMATIONHELPDESK_H_ #define NODEINFORMATIONHELPDESK_H_ diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 6a5d0a6a8..b193b3ef4 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -22,13 +22,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #define STATICGRAPH_H_INCLUDED #include "../DataStructures/Percent.h" +#include "../DataStructures/SharedMemoryVectorWrapper.h" #include "../Util/SimpleLogger.h" #include "../typedefs.h" #include #include -template< typename EdgeDataT> +template< typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph { public: typedef NodeID NodeIterator; @@ -40,8 +41,9 @@ public: NodeIterator source; NodeIterator target; bool operator<( const InputEdge& right ) const { - if ( source != right.source ) + if ( source != right.source ) { return source < right.source; + } return target < right.target; } }; @@ -82,16 +84,22 @@ public: } } - StaticGraph( std::vector<_StrNode> & nodes, std::vector<_StrEdge> & edges) { + StaticGraph( + ShMemVector<_StrNode, UseSharedMemory> & nodes, + ShMemVector<_StrEdge, UseSharedMemory> & edges + ) { _numNodes = nodes.size(); _numEdges = edges.size(); _nodes.swap(nodes); _edges.swap(edges); - //Add dummy node to end of _nodes array; - _nodes.push_back(_nodes.back()); - + if( !UseSharedMemory ) { + //Add dummy node to end of _nodes array; + _nodes.push_back(_nodes.back()); + } else { + //TODO: Move to graph array construction + } #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { @@ -176,8 +184,9 @@ public: EdgeIterator tmp = FindEdge( from, to ); if(UINT_MAX == tmp) { tmp = FindEdge( to, from ); - if(UINT_MAX != tmp) + if(UINT_MAX != tmp) { result = true; + } } return tmp; } @@ -187,8 +196,8 @@ private: NodeIterator _numNodes; EdgeIterator _numEdges; - std::vector< _StrNode > _nodes; - std::vector< _StrEdge > _edges; + ShMemVector< _StrNode, UseSharedMemory > _nodes; + ShMemVector< _StrEdge, UseSharedMemory > _edges; }; #endif // STATICGRAPH_H_INCLUDED diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 1ddb5e62d..bc5179fd2 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -102,6 +102,7 @@ OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) //TODO: fetch pointers from shared memory //TODO: objects = new QueryObjectsStorage() + query_data_facade = new SharedDataFacade(); //TODO: generate shared memory plugins RegisterPlugin(new HelloWorldPlugin()); diff --git a/Library/OSRM.h b/Library/OSRM.h index 5e37f2c6d..74e331f1c 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -30,6 +30,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" #include "../Server/DataStructures/BaseDataFacade.h" +#include "../Server/DataStructures/InternalDataFacade.h" +#include "../Server/DataStructures/SharedDataFacade.h" #include "../Server/DataStructures/RouteParameters.h" #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" @@ -40,6 +42,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include #include #include diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 2316d27f3..1812789a6 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/Coordinate.h" #include "../../DataStructures/PhantomNodes.h" #include "../../DataStructures/TurnInstructions.h" +#include "../../Util/OSRMException.h" #include "../../typedefs.h" #include diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h new file mode 100644 index 000000000..80c4d6ffb --- /dev/null +++ b/Server/DataStructures/InternalDataFacade.h @@ -0,0 +1,94 @@ +/* + 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 INTERNAL_DATA_FACADE +#define INTERNAL_DATA_FACADE + +#include "BaseDataFacade.h" + +template +class InternalDataFacade : public BaseDataFacade { + +private: + +public: + //search graph access + unsigned GetNumberOfNodes() const { return 0; } + + unsigned GetNumberOfEdges() const { return 0; } + + unsigned GetOutDegree( const NodeID n ) const { return 0; } + + NodeID GetTarget( const EdgeID e ) const { return 0; } + + EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + + const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + + EdgeID BeginEdges( const NodeID n ) const { return 0; } + + EdgeID EndEdges( const NodeID n ) const { return 0; } + + //searches for a specific edge + EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + + EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const { return 0; } + + EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const { return 0; } + + //node and edge information access + FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const { return FixedPointCoordinate(); }; + + TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const { return 0; } + + bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const { return false; } + + bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const { return false; } + + unsigned GetCheckSum() const { return 0; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + + void GetName( + const unsigned name_id, + std::string & result + ) const { return; }; +}; + +#endif // INTERNAL_DATA_FACADE diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h new file mode 100644 index 000000000..4f3bc8880 --- /dev/null +++ b/Server/DataStructures/SharedDataFacade.h @@ -0,0 +1,95 @@ +/* + 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 INTERNAL_DATA_FACADE +#define INTERNAL_DATA_FACADE + +#include "BaseDataFacade.h" + +template +class SharedDataFacade : public BaseDataFacade { + +private: + +public: + + //search graph access + unsigned GetNumberOfNodes() const { return 0; } + + unsigned GetNumberOfEdges() const { return 0; } + + unsigned GetOutDegree( const NodeID n ) const { return 0; } + + NodeID GetTarget( const EdgeID e ) const { return 0; } + + EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + + const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + + EdgeID BeginEdges( const NodeID n ) const { return 0; } + + EdgeID EndEdges( const NodeID n ) const { return 0; } + + //searches for a specific edge + EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + + EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const { return 0; } + + EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const { return 0; } + + //node and edge information access + FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const { return FixedPointCoordinate(); }; + + TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const { return 0; } + + bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const { return false; } + + bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const { return false; } + + unsigned GetCheckSum() const { return 0; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + + void GetName( + const unsigned name_id, + std::string & result + ) const { return; }; +}; + +#endif // INTERNAL_DATA_FACADE From d907be264b00362543a47cc389f11e6253de2218 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 18:32:50 +0200 Subject: [PATCH 009/127] make plugins templates that plug into data facade --- Plugins/LocatePlugin.h | 5 ++++- Plugins/NearestPlugin.h | 9 ++++++--- Plugins/TimestampPlugin.h | 6 ++++-- Plugins/ViaRoutePlugin.h | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 22a5ac3c5..ac559451f 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -29,9 +29,12 @@ or see http://www.gnu.org/licenses/agpl.txt. /* * This Plugin locates the nearest node in the road network for a given coordinate. */ +//TODO: Rework data access to go through facade + +template class LocatePlugin : public BasePlugin { public: - LocatePlugin(QueryObjectsStorage * objects) : descriptor_string("locate") { + LocatePlugin(DataFacadeT * objects) : descriptor_string("locate") { nodeHelpDesk = objects->nodeHelpDesk; } const std::string & GetDescriptor() const { return descriptor_string; } diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 1f011bd4b..d662b79c7 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -24,15 +24,18 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "../DataStructures/NodeInformationHelpDesk.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" /* * This Plugin locates the nearest point on a street in the road network for a given coordinate. */ + +//TODO: Rework data access to go through facade + +template class NearestPlugin : public BasePlugin { public: - NearestPlugin(QueryObjectsStorage * objects ) + NearestPlugin(DataFacadeT * objects ) : m_query_objects(objects), descriptor_string("nearest") @@ -114,7 +117,7 @@ public: } private: - QueryObjectsStorage * m_query_objects; + DataFacadeT * m_query_objects; HashTable descriptorTable; std::string descriptor_string; }; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index ba0510c3e..38514e957 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -22,10 +22,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #define TIMESTAMPPLUGIN_H_ #include "BasePlugin.h" +//TODO: Rework data access to go through facade +template class TimestampPlugin : public BasePlugin { public: - TimestampPlugin(QueryObjectsStorage * o) + TimestampPlugin(DataFacadeT * o) : objects(o), descriptor_string("timestamp") { } const std::string & GetDescriptor() const { return descriptor_string; } @@ -66,7 +68,7 @@ public: reply.headers[0].value = tmp; } private: - QueryObjectsStorage * objects; + DataFacadeT * objects; std::string descriptor_string; }; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 5233104b6..6b5f11d15 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -30,7 +30,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Descriptors/BaseDescriptor.h" #include "../Descriptors/GPXDescriptor.h" #include "../Descriptors/JSONDescriptor.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" @@ -41,6 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +//TODO: Rework data access to go through facade +template class ViaRoutePlugin : public BasePlugin { private: NodeInformationHelpDesk * nodeHelpDesk; @@ -49,7 +50,7 @@ private: SearchEngine * searchEnginePtr; public: - ViaRoutePlugin(QueryObjectsStorage * objects) + ViaRoutePlugin(DataFacadeT * objects) : // objects(objects), descriptor_string("viaroute") From e67541e82fc5589e6627f137fb906f45e1cf8cef Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 18:33:10 +0200 Subject: [PATCH 010/127] Further includes in Facades --- Server/DataStructures/BaseDataFacade.h | 1 - Server/DataStructures/InternalDataFacade.h | 4 ++++ Server/DataStructures/SharedDataFacade.h | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 1812789a6..53302b5be 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -98,5 +98,4 @@ public: ) const = 0; }; - #endif // QUERY_DATA_FACADE_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 80c4d6ffb..fd006bc5b 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -21,8 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INTERNAL_DATA_FACADE #define INTERNAL_DATA_FACADE +//implements all data storage when shared memory is _NOT_ used + #include "BaseDataFacade.h" +#include "../../DataStructures/StaticGraph.h" + template class InternalDataFacade : public BaseDataFacade { diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 4f3bc8880..4a23919b6 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -21,8 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INTERNAL_DATA_FACADE #define INTERNAL_DATA_FACADE +//implements all data storage when shared memory is _NOT_ used + #include "BaseDataFacade.h" +#include "../../DataStructures/StaticGraph.h" + template class SharedDataFacade : public BaseDataFacade { From cc94ab64116c828d9ed65cd4d766e7fd872d530b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 10:19:54 +0200 Subject: [PATCH 011/127] use empty() instead of comparisons --- Plugins/LocatePlugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index ac559451f..6f233a352 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -55,7 +55,7 @@ public: //json // JSONParameter = routeParameters.options.Find("jsonp"); - if("" != routeParameters.jsonpParameter) { + if(!routeParameters.jsonpParameter.empty()) { reply.content += routeParameters.jsonpParameter; reply.content += "("; } @@ -81,7 +81,7 @@ public: reply.content += ",\"transactionId\": \"OSRM Routing Engine JSON Locate (v0.3)\""; reply.content += ("}"); reply.headers.resize(3); - if("" != routeParameters.jsonpParameter) { + if(!routeParameters.jsonpParameter.empty()) { reply.content += ")"; reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; From a48aef40393f292210f4e9be6468fa07433c68a7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 14:23:06 +0200 Subject: [PATCH 012/127] Adding shared memory data types --- DataStructures/SharedMemoryFactory.h | 165 +++++++++++++++++++++ DataStructures/SharedMemoryVectorWrapper.h | 96 ++++++++++++ Server/DataStructures/SharedDataType.h | 26 ++++ 3 files changed, 287 insertions(+) create mode 100644 DataStructures/SharedMemoryFactory.h create mode 100644 DataStructures/SharedMemoryVectorWrapper.h create mode 100644 Server/DataStructures/SharedDataType.h diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h new file mode 100644 index 000000000..9c908a187 --- /dev/null +++ b/DataStructures/SharedMemoryFactory.h @@ -0,0 +1,165 @@ +/* + 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 SHARED_MEMORY_FACTORY_H +#define SHARED_MEMORY_FACTORY_H + +#include "../Util/OSRMException.h" +#include "../Util/SimpleLogger.h" + +#include +#include +#include +#include + +#include +#include + +struct OSRMLockFile { + boost::filesystem::path operator()() { + boost::filesystem::path temp_dir = + boost::filesystem::temp_directory_path(); + SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; + boost::filesystem::path lock_file = temp_dir / "osrm.lock"; + SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; + return lock_file; + } +}; + +class SharedMemory : boost::noncopyable { + + //Remove shared memory on destruction + class shm_remove : boost::noncopyable { + private: + int m_shmid; + bool m_initialized; + public: + void SetID(int shmid) { + m_shmid = shmid; + m_initialized = true; + } + + shm_remove() : m_shmid(INT_MIN), m_initialized(false) {} + + ~shm_remove(){ + if(m_initialized) { + SimpleLogger().Write(logDEBUG) << + "automatic memory deallocation"; + boost::interprocess::xsi_shared_memory::remove(m_shmid); + } + } + + }; + +public: + void * Ptr() const { + return region.get_address(); + } + + template + SharedMemory( + const boost::filesystem::path & lock_file, + const IdentifierT id, + const unsigned size = 0 + ) : key( + lock_file.string().c_str(), + id + ) { + if( 0 == size ){ //read_only + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::open_only, + key + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_only + ); + } else { //writeable pointer + //remove previously allocated mem + RemoveSharedMemory(key); + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::create_only, + key, + size + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_write + ); + + remover.SetID( shm.get_shmid() ); + SimpleLogger().Write(logDEBUG) << + "writeable memory allocated " << size << " bytes"; + } + } + +private: + static void RemoveSharedMemory( + const boost::interprocess::xsi_key &key + ) { + try{ + SimpleLogger().Write(logDEBUG) << "deallocating prev memory"; + boost::interprocess::xsi_shared_memory xsi( + boost::interprocess::open_only, + key + ); + boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid()); + } catch(boost::interprocess::interprocess_exception &e){ + if(e.get_error_code() != boost::interprocess::not_found_error) { + throw; + } + } + } + + boost::interprocess::xsi_key key; + boost::interprocess::xsi_shared_memory shm; + boost::interprocess::mapped_region region; + shm_remove remover; +}; + +template +class SharedMemoryFactory_tmpl : boost::noncopyable { +public: + template + static SharedMemory * Get( + const IdentifierT & id, + const unsigned size = 0 + ) { + try { + LockFileT lock_file; + if(0 == size && !boost::filesystem::exists(lock_file()) ) { + throw OSRMException("lock file does not exist, exiting"); + } + return new SharedMemory(lock_file(), id, size); + } catch(const boost::interprocess::interprocess_exception &e){ + SimpleLogger().Write(logWARNING) << + "caught exception: " << e.what() << + ", code " << e.get_error_code(); + throw OSRMException(e.what()); + } + }; + +private: + SharedMemoryFactory_tmpl() {} +}; + +typedef SharedMemoryFactory_tmpl<> SharedMemoryFactory; + +#endif /* SHARED_MEMORY_POINTER_FACTORY_H */ diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h new file mode 100644 index 000000000..0773466d9 --- /dev/null +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -0,0 +1,96 @@ +/* + 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 SHARED_MEMORY_VECTOR_WRAPPER_H +#define SHARED_MEMORY_VECTOR_WRAPPER_H + +#include +#include +#include + +#include +#include + +template +class ShMemIterator : public std::iterator { + boost::shared_ptr p; +public: + ShMemIterator(boost::shared_ptr & x) :p(x) {} + ShMemIterator(const ShMemIterator & mit) : p(mit.p) {} + ShMemIterator& operator++() { + ++p; + return *this; + } + ShMemIterator operator++(int) { + ShMemIterator tmp(*this); + operator++(); + return tmp; + } + bool operator==(const ShMemIterator& rhs) { + return p==rhs.p; + } + bool operator!=(const ShMemIterator& rhs) { + return p!=rhs.p; + } + DataT& operator*() { + return *p; + } +}; + +template +class SharedMemoryWrapper { +private: + boost::shared_ptr m_ptr; + std::size_t m_size; + + SharedMemoryWrapper() {}; +public: + SharedMemoryWrapper(const DataT * ptr, std::size_t size) : + m_ptr(ptr), + m_size(size) + { } + + ShMemIterator begin() const { + return ShMemIterator(m_ptr); + } + + ShMemIterator end() const { + return ShMemIterator(m_ptr+m_size); + } + + std::size_t size() const { return m_size; } + + DataT & operator[](const int index) { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + return m_ptr[index]; + } +}; + +template +class ShMemVector : public + boost::conditional< + SharedMemory, + SharedMemoryWrapper, + std::vector + >::type +{ }; + + +#endif //SHARED_MEMORY_VECTOR_WRAPPER_H diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h new file mode 100644 index 000000000..83cc6da81 --- /dev/null +++ b/Server/DataStructures/SharedDataType.h @@ -0,0 +1,26 @@ +/* + 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 SHARED_DATA_TYPE_H_ +#define SHARED_DATA_TYPE_H_ + +enum SharedDataType { NAMES_INDEX, NAMES_LIST }; + +#endif /* SHARED_DATA_TYPE_H_ */ From 5abe7bc7e578c1fc643c89b1a3faa782252e03ab Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:35:43 +0200 Subject: [PATCH 013/127] Facade base class to provide all data access --- Server/DataStructures/BaseDataFacade.h | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Server/DataStructures/BaseDataFacade.h diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h new file mode 100644 index 000000000..b8e4f415f --- /dev/null +++ b/Server/DataStructures/BaseDataFacade.h @@ -0,0 +1,75 @@ +/* + 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 QUERY_DATA_FACADE_H +#define QUERY_DATA_FACADE_H + +//Exposes all data access interfaces to the algorithms via base class ptr + +#include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/PhantomNodes.h" +#include "../../DataStructures/TurnInstructions.h" +#include "../../typedefs.h" + +#include + +class QueryDataFacade { +public: + QueryDataFacade() { } + virtual ~QueryDataFacade() { } + + //search graph access + //TODO + + //node and edge information access + virtual FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const = 0; + + virtual TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const = 0; + + virtual NodeID GetNumberOfNodes( ) const = 0; + + virtual bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const = 0; + + virtual bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const = 0; + + virtual unsigned GetCheckSum() const = 0; + + virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + virtual void GetName( + const unsigned name_id, + std::string & result + ) const = 0; + +}; + + +#endif // QUERY_DATA_FACADE_H From 34ee6411d5d900ffb149e24d76c32e0e4c611e09 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:37:08 +0200 Subject: [PATCH 014/127] instantiate different inherited class at bcp that provides all data --- Library/OSRM.cpp | 163 ++++++++++++++++++++++++++--------------------- Library/OSRM.h | 3 +- 2 files changed, 92 insertions(+), 74 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 79f6b869f..1ddb5e62d 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -20,80 +20,97 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRM.h" -OSRM::OSRM(const char * server_ini_path) { - if( !testDataFile(server_ini_path) ){ - std::string error_message = std::string(server_ini_path) + " not found"; - throw OSRMException(error_message.c_str()); +OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) + : use_shared_memory(use_shared_memory) +{ + if( !use_shared_memory ) { + if( !testDataFile(server_ini_path) ){ + std::string error_message = std::string(server_ini_path) + " not found"; + throw OSRMException(error_message.c_str()); + } + + IniFile serverConfig(server_ini_path); + + boost::filesystem::path base_path = + boost::filesystem::absolute(server_ini_path).parent_path(); + + if ( !serverConfig.Holds("hsgrData")) { + throw OSRMException("no ram index file name in server ini"); + } + if ( !serverConfig.Holds("ramIndex") ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( !serverConfig.Holds("fileIndex") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("nodesData") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !serverConfig.Holds("edgesData") ) { + throw OSRMException("no edges file name in server ini"); + } + + boost::filesystem::path hsgr_path = boost::filesystem::absolute( + serverConfig.GetParameter("hsgrData"), + base_path + ); + + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("ramIndex"), + base_path + ); + + boost::filesystem::path file_index_path = boost::filesystem::absolute( + serverConfig.GetParameter("fileIndex"), + base_path + ); + + boost::filesystem::path node_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("nodesData"), + base_path + ); + boost::filesystem::path edge_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("edgesData"), + base_path + ); + boost::filesystem::path name_data_path = boost::filesystem::absolute( + serverConfig.GetParameter("namesData"), + base_path + ); + boost::filesystem::path timestamp_path = boost::filesystem::absolute( + serverConfig.GetParameter("timestamp"), + base_path + ); + + objects = new QueryObjectsStorage( + hsgr_path.string(), + ram_index_path.string(), + file_index_path.string(), + node_data_path.string(), + edge_data_path.string(), + name_data_path.string(), + timestamp_path.string() + ); + + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin(objects)); + RegisterPlugin(new NearestPlugin(objects)); + RegisterPlugin(new TimestampPlugin(objects)); + RegisterPlugin(new ViaRoutePlugin(objects)); + + } else { + //TODO: fetch pointers from shared memory + + //TODO: objects = new QueryObjectsStorage() + + //TODO: generate shared memory plugins + RegisterPlugin(new HelloWorldPlugin()); + RegisterPlugin(new LocatePlugin(objects)); + RegisterPlugin(new NearestPlugin(objects)); + RegisterPlugin(new TimestampPlugin(objects)); + RegisterPlugin(new ViaRoutePlugin(objects)); + } - - IniFile serverConfig(server_ini_path); - - boost::filesystem::path base_path = - boost::filesystem::absolute(server_ini_path).parent_path(); - - if ( !serverConfig.Holds("hsgrData")) { - throw OSRMException("no ram index file name in server ini"); - } - if ( !serverConfig.Holds("ramIndex") ) { - throw OSRMException("no mem index file name in server ini"); - } - if ( !serverConfig.Holds("fileIndex") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("nodesData") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("edgesData") ) { - throw OSRMException("no edges file name in server ini"); - } - - boost::filesystem::path hsgr_path = boost::filesystem::absolute( - serverConfig.GetParameter("hsgrData"), - base_path - ); - - boost::filesystem::path ram_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("ramIndex"), - base_path - ); - - boost::filesystem::path file_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("fileIndex"), - base_path - ); - - boost::filesystem::path node_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("nodesData"), - base_path - ); - boost::filesystem::path edge_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("edgesData"), - base_path - ); - boost::filesystem::path name_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("namesData"), - base_path - ); - boost::filesystem::path timestamp_path = boost::filesystem::absolute( - serverConfig.GetParameter("timestamp"), - base_path - ); - - objects = new QueryObjectsStorage( - hsgr_path.string(), - ram_index_path.string(), - file_index_path.string(), - node_data_path.string(), - edge_data_path.string(), - name_data_path.string(), - timestamp_path.string() - ); - - RegisterPlugin(new HelloWorldPlugin()); - RegisterPlugin(new LocatePlugin(objects)); - RegisterPlugin(new NearestPlugin(objects)); - RegisterPlugin(new TimestampPlugin(objects)); - RegisterPlugin(new ViaRoutePlugin(objects)); } OSRM::~OSRM() { diff --git a/Library/OSRM.h b/Library/OSRM.h index bb3caa7d9..17e27a1c8 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -47,12 +47,13 @@ class OSRM : boost::noncopyable { typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; public: - OSRM(const char * server_ini_path); + OSRM(const char * server_ini_path, const bool use_shared_memory = false); ~OSRM(); void RunQuery(RouteParameters & route_parameters, http::Reply & reply); private: void RegisterPlugin(BasePlugin * plugin); PluginMap pluginMap; + const bool use_shared_memory; }; #endif //OSRM_H From 4900f3e54db1bfaeefe9e8784d76110f34dc303e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:37:52 +0200 Subject: [PATCH 015/127] remove unneeded white spaces --- Server/DataStructures/QueryObjectsStorage.cpp | 2 +- Server/DataStructures/QueryObjectsStorage.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp index e0ec72e40..fa17e5dbe 100644 --- a/Server/DataStructures/QueryObjectsStorage.cpp +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -69,7 +69,7 @@ QueryObjectsStorage::QueryObjectsStorage( SimpleLogger().Write() << "Loading Timestamp"; std::ifstream timestampInStream(timestamp_path.c_str()); if(!timestampInStream) { - SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; } getline(timestampInStream, timestamp); diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h index fd5419283..b9923dfce 100644 --- a/Server/DataStructures/QueryObjectsStorage.h +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -36,7 +36,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include - struct QueryObjectsStorage { typedef StaticGraph QueryGraph; typedef QueryGraph::InputEdge InputEdge; From a04f77e7e06a2aaaa14ead67c54bc07bb5feef20 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:45:33 +0200 Subject: [PATCH 016/127] added graph data access --- Server/DataStructures/BaseDataFacade.h | 34 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index b8e4f415f..1c3c3c660 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -30,13 +30,43 @@ or see http://www.gnu.org/licenses/agpl.txt. #include +template class QueryDataFacade { public: QueryDataFacade() { } virtual ~QueryDataFacade() { } //search graph access - //TODO + virtual unsigned GetNumberOfNodes() const = 0; + + virtual unsigned GetNumberOfEdges() const = 0; + + virtual unsigned GetOutDegree( const NodeID n ) const = 0; + + virtual NodeID GetTarget( const EdgeID e ) const = 0; + + virtual EdgeDataT &GetEdgeData( const EdgeID e ) = 0; + + virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; + + virtual EdgeID BeginEdges( const NodeID n ) const = 0; + + virtual EdgeID EndEdges( const NodeID n ) const = 0; + + //searches for a specific edge + virtual EdgeID FindEdge( const NodeID from, const NodeID to ) const = 0; + + virtual EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const = 0; + + virtual EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const = 0; + //node and edge information access virtual FixedPointCoordinate GetCoordinateOfNode( @@ -47,8 +77,6 @@ public: const unsigned id ) const = 0; - virtual NodeID GetNumberOfNodes( ) const = 0; - virtual bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate& input_coordinate, FixedPointCoordinate& result, From a08fef172eed35758363c759ece0465a7e8c36fa Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 17 Sep 2013 18:55:53 +0200 Subject: [PATCH 017/127] plugging in base facade ptr --- Library/OSRM.h | 4 ++++ Server/DataStructures/BaseDataFacade.h | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index 17e27a1c8..5e37f2c6d 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/NearestPlugin.h" #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" +#include "../Server/DataStructures/BaseDataFacade.h" #include "../Server/DataStructures/RouteParameters.h" #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" @@ -44,8 +45,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include class OSRM : boost::noncopyable { +private: typedef boost::unordered_map PluginMap; QueryObjectsStorage * objects; + BaseDataFacade * query_data_facade; + public: OSRM(const char * server_ini_path, const bool use_shared_memory = false); ~OSRM(); diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 1c3c3c660..2316d27f3 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -31,10 +31,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include template -class QueryDataFacade { +class BaseDataFacade { public: - QueryDataFacade() { } - virtual ~QueryDataFacade() { } + BaseDataFacade() { } + virtual ~BaseDataFacade() { } //search graph access virtual unsigned GetNumberOfNodes() const = 0; @@ -67,7 +67,6 @@ public: bool & result ) const = 0; - //node and edge information access virtual FixedPointCoordinate GetCoordinateOfNode( const unsigned id @@ -96,7 +95,6 @@ public: const unsigned name_id, std::string & result ) const = 0; - }; From 2ab04e7e2f935798b72a93f121a6f1df07084430 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 17:49:49 +0200 Subject: [PATCH 018/127] Mockups for data facades --- DataStructures/NodeInformationHelpDesk.h | 2 + DataStructures/StaticGraph.h | 27 ++++-- Library/OSRM.cpp | 1 + Library/OSRM.h | 3 + Server/DataStructures/BaseDataFacade.h | 1 + Server/DataStructures/InternalDataFacade.h | 94 +++++++++++++++++++++ Server/DataStructures/SharedDataFacade.h | 95 ++++++++++++++++++++++ 7 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 Server/DataStructures/InternalDataFacade.h create mode 100644 Server/DataStructures/SharedDataFacade.h diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 120f11ff6..cda10cd40 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ +//TODO: Umbauen in Private Data Facade + #ifndef NODEINFORMATIONHELPDESK_H_ #define NODEINFORMATIONHELPDESK_H_ diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 6a5d0a6a8..b193b3ef4 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -22,13 +22,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #define STATICGRAPH_H_INCLUDED #include "../DataStructures/Percent.h" +#include "../DataStructures/SharedMemoryVectorWrapper.h" #include "../Util/SimpleLogger.h" #include "../typedefs.h" #include #include -template< typename EdgeDataT> +template< typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph { public: typedef NodeID NodeIterator; @@ -40,8 +41,9 @@ public: NodeIterator source; NodeIterator target; bool operator<( const InputEdge& right ) const { - if ( source != right.source ) + if ( source != right.source ) { return source < right.source; + } return target < right.target; } }; @@ -82,16 +84,22 @@ public: } } - StaticGraph( std::vector<_StrNode> & nodes, std::vector<_StrEdge> & edges) { + StaticGraph( + ShMemVector<_StrNode, UseSharedMemory> & nodes, + ShMemVector<_StrEdge, UseSharedMemory> & edges + ) { _numNodes = nodes.size(); _numEdges = edges.size(); _nodes.swap(nodes); _edges.swap(edges); - //Add dummy node to end of _nodes array; - _nodes.push_back(_nodes.back()); - + if( !UseSharedMemory ) { + //Add dummy node to end of _nodes array; + _nodes.push_back(_nodes.back()); + } else { + //TODO: Move to graph array construction + } #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { @@ -176,8 +184,9 @@ public: EdgeIterator tmp = FindEdge( from, to ); if(UINT_MAX == tmp) { tmp = FindEdge( to, from ); - if(UINT_MAX != tmp) + if(UINT_MAX != tmp) { result = true; + } } return tmp; } @@ -187,8 +196,8 @@ private: NodeIterator _numNodes; EdgeIterator _numEdges; - std::vector< _StrNode > _nodes; - std::vector< _StrEdge > _edges; + ShMemVector< _StrNode, UseSharedMemory > _nodes; + ShMemVector< _StrEdge, UseSharedMemory > _edges; }; #endif // STATICGRAPH_H_INCLUDED diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 1ddb5e62d..bc5179fd2 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -102,6 +102,7 @@ OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) //TODO: fetch pointers from shared memory //TODO: objects = new QueryObjectsStorage() + query_data_facade = new SharedDataFacade(); //TODO: generate shared memory plugins RegisterPlugin(new HelloWorldPlugin()); diff --git a/Library/OSRM.h b/Library/OSRM.h index 5e37f2c6d..74e331f1c 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -30,6 +30,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" #include "../Server/DataStructures/BaseDataFacade.h" +#include "../Server/DataStructures/InternalDataFacade.h" +#include "../Server/DataStructures/SharedDataFacade.h" #include "../Server/DataStructures/RouteParameters.h" #include "../Util/IniFile.h" #include "../Util/InputFileUtil.h" @@ -40,6 +42,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include #include #include diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 2316d27f3..1812789a6 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/Coordinate.h" #include "../../DataStructures/PhantomNodes.h" #include "../../DataStructures/TurnInstructions.h" +#include "../../Util/OSRMException.h" #include "../../typedefs.h" #include diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h new file mode 100644 index 000000000..80c4d6ffb --- /dev/null +++ b/Server/DataStructures/InternalDataFacade.h @@ -0,0 +1,94 @@ +/* + 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 INTERNAL_DATA_FACADE +#define INTERNAL_DATA_FACADE + +#include "BaseDataFacade.h" + +template +class InternalDataFacade : public BaseDataFacade { + +private: + +public: + //search graph access + unsigned GetNumberOfNodes() const { return 0; } + + unsigned GetNumberOfEdges() const { return 0; } + + unsigned GetOutDegree( const NodeID n ) const { return 0; } + + NodeID GetTarget( const EdgeID e ) const { return 0; } + + EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + + const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + + EdgeID BeginEdges( const NodeID n ) const { return 0; } + + EdgeID EndEdges( const NodeID n ) const { return 0; } + + //searches for a specific edge + EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + + EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const { return 0; } + + EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const { return 0; } + + //node and edge information access + FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const { return FixedPointCoordinate(); }; + + TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const { return 0; } + + bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const { return false; } + + bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const { return false; } + + unsigned GetCheckSum() const { return 0; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + + void GetName( + const unsigned name_id, + std::string & result + ) const { return; }; +}; + +#endif // INTERNAL_DATA_FACADE diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h new file mode 100644 index 000000000..4f3bc8880 --- /dev/null +++ b/Server/DataStructures/SharedDataFacade.h @@ -0,0 +1,95 @@ +/* + 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 INTERNAL_DATA_FACADE +#define INTERNAL_DATA_FACADE + +#include "BaseDataFacade.h" + +template +class SharedDataFacade : public BaseDataFacade { + +private: + +public: + + //search graph access + unsigned GetNumberOfNodes() const { return 0; } + + unsigned GetNumberOfEdges() const { return 0; } + + unsigned GetOutDegree( const NodeID n ) const { return 0; } + + NodeID GetTarget( const EdgeID e ) const { return 0; } + + EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + + const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + + EdgeID BeginEdges( const NodeID n ) const { return 0; } + + EdgeID EndEdges( const NodeID n ) const { return 0; } + + //searches for a specific edge + EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + + EdgeID FindEdgeInEitherDirection( + const NodeID from, + const NodeID to + ) const { return 0; } + + EdgeID FindEdgeIndicateIfReverse( + const NodeID from, + const NodeID to, + bool & result + ) const { return 0; } + + //node and edge information access + FixedPointCoordinate GetCoordinateOfNode( + const unsigned id + ) const { return FixedPointCoordinate(); }; + + TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const { return 0; } + + bool LocateClosestEndPointForCoordinate( + const FixedPointCoordinate& input_coordinate, + FixedPointCoordinate& result, + const unsigned zoom_level = 18 + ) const { return false; } + + bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const { return false; } + + unsigned GetCheckSum() const { return 0; } + + unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + + void GetName( + const unsigned name_id, + std::string & result + ) const { return; }; +}; + +#endif // INTERNAL_DATA_FACADE From 547e942c66d2c4d9bf6ab7864d0718d231b6d705 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 18:32:50 +0200 Subject: [PATCH 019/127] make plugins templates that plug into data facade --- Plugins/LocatePlugin.h | 5 ++++- Plugins/NearestPlugin.h | 9 ++++++--- Plugins/TimestampPlugin.h | 6 ++++-- Plugins/ViaRoutePlugin.h | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 22a5ac3c5..ac559451f 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -29,9 +29,12 @@ or see http://www.gnu.org/licenses/agpl.txt. /* * This Plugin locates the nearest node in the road network for a given coordinate. */ +//TODO: Rework data access to go through facade + +template class LocatePlugin : public BasePlugin { public: - LocatePlugin(QueryObjectsStorage * objects) : descriptor_string("locate") { + LocatePlugin(DataFacadeT * objects) : descriptor_string("locate") { nodeHelpDesk = objects->nodeHelpDesk; } const std::string & GetDescriptor() const { return descriptor_string; } diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 1f011bd4b..d662b79c7 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -24,15 +24,18 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "../DataStructures/NodeInformationHelpDesk.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" /* * This Plugin locates the nearest point on a street in the road network for a given coordinate. */ + +//TODO: Rework data access to go through facade + +template class NearestPlugin : public BasePlugin { public: - NearestPlugin(QueryObjectsStorage * objects ) + NearestPlugin(DataFacadeT * objects ) : m_query_objects(objects), descriptor_string("nearest") @@ -114,7 +117,7 @@ public: } private: - QueryObjectsStorage * m_query_objects; + DataFacadeT * m_query_objects; HashTable descriptorTable; std::string descriptor_string; }; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index ba0510c3e..38514e957 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -22,10 +22,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #define TIMESTAMPPLUGIN_H_ #include "BasePlugin.h" +//TODO: Rework data access to go through facade +template class TimestampPlugin : public BasePlugin { public: - TimestampPlugin(QueryObjectsStorage * o) + TimestampPlugin(DataFacadeT * o) : objects(o), descriptor_string("timestamp") { } const std::string & GetDescriptor() const { return descriptor_string; } @@ -66,7 +68,7 @@ public: reply.headers[0].value = tmp; } private: - QueryObjectsStorage * objects; + DataFacadeT * objects; std::string descriptor_string; }; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 7efb06a10..cfca2878c 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -30,7 +30,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Descriptors/BaseDescriptor.h" #include "../Descriptors/GPXDescriptor.h" #include "../Descriptors/JSONDescriptor.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" @@ -41,6 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +//TODO: Rework data access to go through facade +template class ViaRoutePlugin : public BasePlugin { private: NodeInformationHelpDesk * nodeHelpDesk; @@ -49,7 +50,7 @@ private: SearchEngine * searchEnginePtr; public: - ViaRoutePlugin(QueryObjectsStorage * objects) + ViaRoutePlugin(DataFacadeT * objects) : // objects(objects), descriptor_string("viaroute") From c5824765f97c6be7aadd90d4157fe71ce6818cec Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 18 Sep 2013 18:33:10 +0200 Subject: [PATCH 020/127] Further includes in Facades --- Server/DataStructures/BaseDataFacade.h | 1 - Server/DataStructures/InternalDataFacade.h | 4 ++++ Server/DataStructures/SharedDataFacade.h | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 1812789a6..53302b5be 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -98,5 +98,4 @@ public: ) const = 0; }; - #endif // QUERY_DATA_FACADE_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 80c4d6ffb..fd006bc5b 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -21,8 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INTERNAL_DATA_FACADE #define INTERNAL_DATA_FACADE +//implements all data storage when shared memory is _NOT_ used + #include "BaseDataFacade.h" +#include "../../DataStructures/StaticGraph.h" + template class InternalDataFacade : public BaseDataFacade { diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 4f3bc8880..4a23919b6 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -21,8 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INTERNAL_DATA_FACADE #define INTERNAL_DATA_FACADE +//implements all data storage when shared memory is _NOT_ used + #include "BaseDataFacade.h" +#include "../../DataStructures/StaticGraph.h" + template class SharedDataFacade : public BaseDataFacade { From 39122bd61d40c9f5f3676777e7e91fccd784bf11 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 10:19:54 +0200 Subject: [PATCH 021/127] use empty() instead of comparisons --- Plugins/LocatePlugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index ac559451f..6f233a352 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -55,7 +55,7 @@ public: //json // JSONParameter = routeParameters.options.Find("jsonp"); - if("" != routeParameters.jsonpParameter) { + if(!routeParameters.jsonpParameter.empty()) { reply.content += routeParameters.jsonpParameter; reply.content += "("; } @@ -81,7 +81,7 @@ public: reply.content += ",\"transactionId\": \"OSRM Routing Engine JSON Locate (v0.3)\""; reply.content += ("}"); reply.headers.resize(3); - if("" != routeParameters.jsonpParameter) { + if(!routeParameters.jsonpParameter.empty()) { reply.content += ")"; reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; From ac14a7b0dad1b9615eacaa0c1c22d8299b284b80 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 13:59:09 +0200 Subject: [PATCH 022/127] corrected include fence --- Server/DataStructures/SharedDataFacade.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 4a23919b6..fcdc15908 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -18,8 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -#ifndef INTERNAL_DATA_FACADE -#define INTERNAL_DATA_FACADE +#ifndef SHARED_DATA_FACADE +#define SHARED_DATA_FACADE //implements all data storage when shared memory is _NOT_ used @@ -96,4 +96,4 @@ public: ) const { return; }; }; -#endif // INTERNAL_DATA_FACADE +#endif // SHARED_DATA_FACADE From 01d2d91ecc4c8754d893e7ac25513e86d8842af3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:52:42 +0200 Subject: [PATCH 023/127] Moving DataStructures to new data facade pattern --- DataStructures/NodeInformationHelpDesk.h | 3 +- DataStructures/SearchEngine.cpp | 84 ------------------------ DataStructures/SearchEngine.h | 50 +++++++------- DataStructures/SearchEngineData.cpp | 18 ++--- DataStructures/SearchEngineData.h | 27 ++++---- 5 files changed, 50 insertions(+), 132 deletions(-) delete mode 100644 DataStructures/SearchEngine.cpp diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index cda10cd40..ff539024f 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -195,8 +195,7 @@ private: edges_input_stream.close(); SimpleLogger().Write(logDEBUG) << "Loaded " << number_of_edges << " orig edges"; - SimpleLogger().Write(logDEBUG) - << "Opening NN indices"; + SimpleLogger().Write(logDEBUG) << "Opening NN indices"; } std::vector m_coordinate_list; diff --git a/DataStructures/SearchEngine.cpp b/DataStructures/SearchEngine.cpp deleted file mode 100644 index 334acc42a..000000000 --- a/DataStructures/SearchEngine.cpp +++ /dev/null @@ -1,84 +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 "SearchEngine.h" - -SearchEngine::SearchEngine( QueryObjectsStorage * query_objects ) : - _queryData(query_objects), - shortestPath(_queryData), - alternativePaths(_queryData) -{} - -SearchEngine::~SearchEngine() {} - -void SearchEngine::GetCoordinatesForNodeID( - NodeID id, - FixedPointCoordinate& result -) const { - result = _queryData.nodeHelpDesk->GetCoordinateOfNode(id); -} - -void SearchEngine::FindPhantomNodeForCoordinate( - const FixedPointCoordinate & location, - PhantomNode & result, - const unsigned zoomLevel -) const { - _queryData.nodeHelpDesk->FindPhantomNodeForCoordinate( - location, - result, zoomLevel - ); -} - -NodeID SearchEngine::GetNameIDForOriginDestinationNodeID( - const NodeID s, - const NodeID t -) const { - if(s == t) { - return 0; - } - - EdgeID e = _queryData.graph->FindEdge(s, t); - if(e == UINT_MAX) { - e = _queryData.graph->FindEdge( t, s ); - } - - if(UINT_MAX == e) { - return 0; - } - - assert(e != UINT_MAX); - const QueryEdge::EdgeData ed = _queryData.graph->GetEdgeData(e); - return ed.id; -} - -std::string SearchEngine::GetEscapedNameForNameID(const unsigned nameID) const { - std::string result; - _queryData.query_objects->GetName(nameID, result); - return HTMLEntitize(result); -} - -SearchEngineHeapPtr SearchEngineData::forwardHeap; -SearchEngineHeapPtr SearchEngineData::backwardHeap; - -SearchEngineHeapPtr SearchEngineData::forwardHeap2; -SearchEngineHeapPtr SearchEngineData::backwardHeap2; - -SearchEngineHeapPtr SearchEngineData::forwardHeap3; -SearchEngineHeapPtr SearchEngineData::backwardHeap3; diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 3aad89b22..f73624cd9 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -18,48 +18,54 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -#ifndef SEARCHENGINE_H_ -#define SEARCHENGINE_H_ +#ifndef SEARCHENGINE_H +#define SEARCHENGINE_H #include "Coordinate.h" #include "NodeInformationHelpDesk.h" +#include "SearchEngineData.h" #include "PhantomNodes.h" #include "QueryEdge.h" -#include "SearchEngineData.h" #include "../RoutingAlgorithms/AlternativePathRouting.h" #include "../RoutingAlgorithms/ShortestPathRouting.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" #include "../typedefs.h" +#include + #include #include #include +template class SearchEngine { private: - SearchEngineData _queryData; - + DataFacadeT * facade; + SearchEngineData engine_working_data; public: - ShortestPathRouting shortestPath; - AlternativeRouting alternativePaths; + ShortestPathRouting shortest_path; + AlternativeRouting alternative_path; - SearchEngine( QueryObjectsStorage * query_objects ); - ~SearchEngine(); + SearchEngine( DataFacadeT * facade ) + : + facade (facade), + engine_working_data(facade), + shortest_path (facade, engine_working_data), + alternative_path (facade, engine_working_data) + {} - void GetCoordinatesForNodeID(NodeID id, FixedPointCoordinate& result) const; + ~SearchEngine() {} - void FindPhantomNodeForCoordinate( - const FixedPointCoordinate & location, - PhantomNode & result, - unsigned zoomLevel - ) const; - - NodeID GetNameIDForOriginDestinationNodeID( - const NodeID s, const NodeID t) const; - - std::string GetEscapedNameForNameID(const unsigned nameID) const; }; -#endif /* SEARCHENGINE_H_ */ +SearchEngineHeapPtr SearchEngineData::forwardHeap; +SearchEngineHeapPtr SearchEngineData::backwardHeap; + +SearchEngineHeapPtr SearchEngineData::forwardHeap2; +SearchEngineHeapPtr SearchEngineData::backwardHeap2; + +SearchEngineHeapPtr SearchEngineData::forwardHeap3; +SearchEngineHeapPtr SearchEngineData::backwardHeap3; + +#endif // SEARCHENGINE_H diff --git a/DataStructures/SearchEngineData.cpp b/DataStructures/SearchEngineData.cpp index afb5241d9..6eb790696 100644 --- a/DataStructures/SearchEngineData.cpp +++ b/DataStructures/SearchEngineData.cpp @@ -20,40 +20,40 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "SearchEngineData.h" -void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() { +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap.get()) { - forwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap->Clear(); } if(!backwardHeap.get()) { - backwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap->Clear(); } } -void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() { +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap2.get()) { - forwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap2.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap2->Clear(); } if(!backwardHeap2.get()) { - backwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap2.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap2->Clear(); } } -void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() { +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap3.get()) { - forwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap3.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap3->Clear(); } if(!backwardHeap3.get()) { - backwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap3.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap3->Clear(); } diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h index 90c157d29..43ee455e3 100644 --- a/DataStructures/SearchEngineData.h +++ b/DataStructures/SearchEngineData.h @@ -18,10 +18,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ +#ifndef SEARCH_ENGINE_DATA_H +#define SEARCH_ENGINE_DATA_H + #include "BinaryHeap.h" #include "QueryEdge.h" #include "StaticGraph.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../typedefs.h" @@ -34,23 +36,16 @@ struct _HeapData { NodeID parent; _HeapData( NodeID p ) : parent(p) { } }; + typedef StaticGraph QueryGraph; typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage > QueryHeapType; typedef boost::thread_specific_ptr SearchEngineHeapPtr; struct SearchEngineData { - typedef QueryGraph Graph; - typedef QueryHeapType QueryHeap; - SearchEngineData(QueryObjectsStorage * query_objects) - : - query_objects(query_objects), - graph(query_objects->graph), - nodeHelpDesk(query_objects->nodeHelpDesk) - {} + typedef QueryGraph QueryGraph; + typedef QueryHeapType QueryHeap; - const QueryObjectsStorage * query_objects; - const QueryGraph * graph; - const NodeInformationHelpDesk * nodeHelpDesk; + SearchEngineData() { } static SearchEngineHeapPtr forwardHeap; static SearchEngineHeapPtr backwardHeap; @@ -59,9 +54,11 @@ struct SearchEngineData { static SearchEngineHeapPtr forwardHeap3; static SearchEngineHeapPtr backwardHeap3; - void InitializeOrClearFirstThreadLocalStorage(); + void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes); - void InitializeOrClearSecondThreadLocalStorage(); + void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes); - void InitializeOrClearThirdThreadLocalStorage(); + void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes); }; + +#endif // SEARCH_ENGINE_DATA_H From 7599124aa0a72bd54b5ca35557811d2f4c219cb4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:53:10 +0200 Subject: [PATCH 024/127] Rewiring query plugins --- Plugins/LocatePlugin.h | 23 ++++++------ Plugins/NearestPlugin.h | 19 +++++----- Plugins/TimestampPlugin.h | 8 ++--- Plugins/ViaRoutePlugin.h | 74 ++++++++++++++++++++++----------------- 4 files changed, 67 insertions(+), 57 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 6f233a352..35261a9d5 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -26,19 +26,23 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" -/* - * This Plugin locates the nearest node in the road network for a given coordinate. - */ +//locates the nearest node in the road network for a given coordinate. //TODO: Rework data access to go through facade template class LocatePlugin : public BasePlugin { public: - LocatePlugin(DataFacadeT * objects) : descriptor_string("locate") { - nodeHelpDesk = objects->nodeHelpDesk; - } + LocatePlugin(DataFacadeT * facade) + : + descriptor_string("locate"), + facade(facade) + { } const std::string & GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { + + void HandleRequest( + const RouteParameters & routeParameters, + http::Reply& reply + ) { //check number of parameters if(!routeParameters.coordinates.size()) { reply = http::Reply::stockReply(http::Reply::badRequest); @@ -54,7 +58,6 @@ public: std::string tmp; //json -// JSONParameter = routeParameters.options.Find("jsonp"); if(!routeParameters.jsonpParameter.empty()) { reply.content += routeParameters.jsonpParameter; reply.content += "("; @@ -62,7 +65,7 @@ public: reply.status = http::Reply::ok; reply.content += ("{"); reply.content += ("\"version\":0.3,"); - if(!nodeHelpDesk->LocateClosestEndPointForCoordinate(routeParameters.coordinates[0], result)) { + if(!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates[0], result)) { reply.content += ("\"status\":207,"); reply.content += ("\"mapped_coordinate\":[]"); } else { @@ -100,8 +103,8 @@ public: } private: - NodeInformationHelpDesk * nodeHelpDesk; std::string descriptor_string; + DataFacadeT * facade; }; #endif /* LOCATEPLUGIN_H_ */ diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index d662b79c7..45c1c90d0 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -30,14 +30,12 @@ or see http://www.gnu.org/licenses/agpl.txt. * This Plugin locates the nearest point on a street in the road network for a given coordinate. */ -//TODO: Rework data access to go through facade - template class NearestPlugin : public BasePlugin { public: - NearestPlugin(DataFacadeT * objects ) + NearestPlugin(DataFacadeT * facade ) : - m_query_objects(objects), + facade(facade), descriptor_string("nearest") { descriptorTable.insert(std::make_pair("" , 0)); //default descriptor @@ -50,14 +48,13 @@ public: reply = http::Reply::stockReply(http::Reply::badRequest); return; } - if(false == checkCoord(routeParameters.coordinates[0])) { + if( !checkCoord(routeParameters.coordinates[0]) ) { reply = http::Reply::stockReply(http::Reply::badRequest); return; } - NodeInformationHelpDesk * nodeHelpDesk = m_query_objects->nodeHelpDesk; - //query to helpdesk + PhantomNode result; - nodeHelpDesk->FindPhantomNodeForCoordinate( + facade->FindPhantomNodeForCoordinate( routeParameters.coordinates[0], result, routeParameters.zoomLevel @@ -92,14 +89,14 @@ public: reply.content += "],"; reply.content += "\"name\":\""; if(UINT_MAX != result.edgeBasedNode) { - m_query_objects->GetName(result.nodeBasedEdgeNameID, temp_string); + facade->GetName(result.nodeBasedEdgeNameID, temp_string); reply.content += temp_string; } reply.content += "\""; reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON Nearest (v0.3)\""; reply.content += ("}"); reply.headers.resize(3); - if("" != routeParameters.jsonpParameter) { + if( !routeParameters.jsonpParameter.empty() ) { reply.content += ")"; reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; @@ -117,7 +114,7 @@ public: } private: - DataFacadeT * m_query_objects; + DataFacadeT * facade; HashTable descriptorTable; std::string descriptor_string; }; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 38514e957..b6a9b6b4f 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -27,8 +27,8 @@ or see http://www.gnu.org/licenses/agpl.txt. template class TimestampPlugin : public BasePlugin { public: - TimestampPlugin(DataFacadeT * o) - : objects(o), descriptor_string("timestamp") + TimestampPlugin(const DataFacadeT * facade) + : facade(facade), descriptor_string("timestamp") { } const std::string & GetDescriptor() const { return descriptor_string; } void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { @@ -46,7 +46,7 @@ public: reply.content += ("\"status\":"); reply.content += "0,"; reply.content += ("\"timestamp\":\""); - reply.content += objects->timestamp; + reply.content += facade->GetTimestamp(); reply.content += "\""; reply.content += ",\"transactionId\":\"OSRM Routing Engine JSON timestamp (v0.3)\""; reply.content += ("}"); @@ -68,7 +68,7 @@ public: reply.headers[0].value = tmp; } private: - DataFacadeT * objects; + const DataFacadeT * facade; std::string descriptor_string; }; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index cfca2878c..e36549448 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -44,34 +44,32 @@ or see http://www.gnu.org/licenses/agpl.txt. template class ViaRoutePlugin : public BasePlugin { private: - NodeInformationHelpDesk * nodeHelpDesk; - StaticGraph * graph; - HashTable descriptorTable; - SearchEngine * searchEnginePtr; + boost::unordered_map descriptorTable; + SearchEngine * search_engine_ptr; public: - ViaRoutePlugin(DataFacadeT * objects) + ViaRoutePlugin(DataFacadeT * facade) : - // objects(objects), - descriptor_string("viaroute") + descriptor_string("viaroute"), + facade(facade) { - nodeHelpDesk = objects->nodeHelpDesk; - graph = objects->graph; + //TODO: set up an engine for each thread!! + search_engine_ptr = new SearchEngine(facade); - searchEnginePtr = new SearchEngine(objects); - - // descriptorTable.emplace("" , 0); descriptorTable.emplace("json", 0); descriptorTable.emplace("gpx" , 1); } virtual ~ViaRoutePlugin() { - delete searchEnginePtr; + delete search_engine_ptr; } const std::string & GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { + void HandleRequest( + const RouteParameters & routeParameters, + http::Reply& reply + ) { //check number of parameters if( 2 > routeParameters.coordinates.size() ) { reply = http::Reply::stockReply(http::Reply::badRequest); @@ -79,11 +77,11 @@ public: } RawRouteData rawRoute; - rawRoute.checkSum = nodeHelpDesk->GetCheckSum(); + rawRoute.checkSum = facade->GetCheckSum(); bool checksumOK = (routeParameters.checkSum == rawRoute.checkSum); std::vector textCoord; for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) { - if(false == checkCoord(routeParameters.coordinates[i])) { + if( !checkCoord(routeParameters.coordinates[i]) ) { reply = http::Reply::stockReply(http::Reply::badRequest); return; } @@ -94,13 +92,17 @@ public: if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) { // SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i; DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]); - if(phantomNodeVector[i].isValid(nodeHelpDesk->GetNumberOfNodes())) { + if(phantomNodeVector[i].isValid(facade->GetNumberOfNodes())) { // SimpleLogger().Write() << "Decoded hint " << i << " successfully"; continue; } } // SimpleLogger().Write() << "Brute force lookup of coordinate " << i; - searchEnginePtr->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i], routeParameters.zoomLevel); + facade->FindPhantomNodeForCoordinate( + rawRoute.rawViaNodeCoordinates[i], + phantomNodeVector[i], + routeParameters.zoomLevel + ); } for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) { @@ -109,22 +111,29 @@ public: segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1]; rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes); } - if( ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) { -// SimpleLogger().Write() << "Checking for alternative paths"; - searchEnginePtr->alternativePaths(rawRoute.segmentEndCoordinates[0], rawRoute); - + if( + ( routeParameters.alternateRoute ) && + (1 == rawRoute.segmentEndCoordinates.size()) + ) { + search_engine_ptr->alternativePaths( + rawRoute.segmentEndCoordinates[0], + rawRoute + ); } else { - searchEnginePtr->shortestPath(rawRoute.segmentEndCoordinates, rawRoute); + search_engine_ptr->shortestPath( + rawRoute.segmentEndCoordinates, + rawRoute + ); } - if(INT_MAX == rawRoute.lengthOfShortestPath ) { - SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found"; + SimpleLogger().Write(logDEBUG) << + "Error occurred, single path not found"; } reply.status = http::Reply::ok; //TODO: Move to member as smart pointer - BaseDescriptor * desc; + BaseDescriptor * desc; if("" != routeParameters.jsonpParameter) { reply.content += routeParameters.jsonpParameter; reply.content += "("; @@ -143,15 +152,15 @@ public: switch(descriptorType){ case 0: - desc = new JSONDescriptor(); + desc = new JSONDescriptor(); break; case 1: - desc = new GPXDescriptor(); + desc = new GPXDescriptor(); break; default: - desc = new JSONDescriptor(); + desc = new JSONDescriptor(); break; } @@ -164,7 +173,7 @@ public: // SimpleLogger().Write() << "Number of segments: " << rawRoute.segmentEndCoordinates.size(); desc->SetConfig(descriptorConfig); - desc->Run(reply, rawRoute, phantomNodes, *searchEnginePtr); + desc->Run(reply, rawRoute, phantomNodes, facade); if("" != routeParameters.jsonpParameter) { reply.content += ")\n"; } @@ -175,7 +184,7 @@ public: reply.headers[0].value = tmp; switch(descriptorType){ case 0: - if("" != routeParameters.jsonpParameter){ + if( !routeParameters.jsonpParameter.empty() ){ reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; reply.headers[2].name = "Content-Disposition"; @@ -196,7 +205,7 @@ public: break; default: - if("" != routeParameters.jsonpParameter){ + if( !routeParameters.jsonpParameter.empty() ){ reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; reply.headers[2].name = "Content-Disposition"; @@ -215,6 +224,7 @@ public: } private: std::string descriptor_string; + DataFacadeT * facade; }; From 1194bb8ae33ae98ba245ed5fd8910aeb729b720f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:53:34 +0200 Subject: [PATCH 025/127] Rewiring routing algorithms --- RoutingAlgorithms/AlternativePathRouting.h | 15 +++-- RoutingAlgorithms/BasicRoutingInterface.h | 77 +++++++++++++--------- RoutingAlgorithms/ShortestPathRouting.h | 5 +- 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 8b54a3de5..49c935604 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -22,6 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #define ALTERNATIVEROUTES_H_ #include "BasicRoutingInterface.h" +#include "../DataStructures/SearchEngineData.h" #include #include #include @@ -30,11 +31,11 @@ const double VIAPATH_ALPHA = 0.15; const double VIAPATH_EPSILON = 0.10; //alternative at most 15% longer const double VIAPATH_GAMMA = 0.75; //alternative shares at most 75% with the shortest. -template -class AlternativeRouting : private BasicRoutingInterface { - typedef BasicRoutingInterface super; - typedef typename QueryDataT::Graph SearchGraph; - typedef typename QueryDataT::QueryHeap QueryHeap; +template +class AlternativeRouting : private BasicRoutingInterface { + typedef BasicRoutingInterface super; + typedef SearchEngineData::QueryGraph SearchGraph; + typedef SearchEngineData::QueryHeap QueryHeap; typedef std::pair SearchSpaceEdge; struct RankedCandidateNode { @@ -48,10 +49,10 @@ class AlternativeRouting : private BasicRoutingInterface { }; const SearchGraph * search_graph; - + SearchEngineData & engine_working_data; public: - AlternativeRouting(QueryDataT & qd) : super(qd), search_graph(qd.graph) { } + AlternativeRouting(DataFacadeT & qd, SearchEngineData & engine_working_data) : super(qd), search_graph(qd.graph), engine_working_data(engine_working_data) { } ~AlternativeRouting() {} diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 3c0955aea..b182265e1 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -24,6 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #define BASICROUTINGINTERFACE_H_ #include "../DataStructures/RawRouteData.h" +#include "../DataStructures/SearchEngineData.h" #include "../Util/ContainerUtils.h" #include "../Util/SimpleLogger.h" @@ -34,15 +35,22 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -template +template class BasicRoutingInterface : boost::noncopyable{ protected: - QueryDataT & _queryData; + SearchEngineDataT * engine_working_data; public: - BasicRoutingInterface(QueryDataT & qd) : _queryData(qd) { } + BasicRoutingInterface(SearchEngineDataT * engine_working_data) : engine_working_data(engine_working_data) { } virtual ~BasicRoutingInterface(){ }; - inline void RoutingStep(typename QueryDataT::QueryHeap & _forwardHeap, typename QueryDataT::QueryHeap & _backwardHeap, NodeID *middle, int *_upperbound, const int edgeBasedOffset, const bool forwardDirection) const { + inline void RoutingStep( + SearchEngineData::QueryHeap & _forwardHeap, + SearchEngineData::QueryHeap & _backwardHeap, + NodeID *middle, + int *_upperbound, + const int edgeBasedOffset, + const bool forwardDirection + ) const { const NodeID node = _forwardHeap.DeleteMin(); const int distance = _forwardHeap.GetKey(node); //SimpleLogger().Write() << "Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance; @@ -63,11 +71,15 @@ public: } //Stalling - for ( typename QueryDataT::Graph::EdgeIterator edge = _queryData.graph->BeginEdges( node ); edge < _queryData.graph->EndEdges(node); ++edge ) { - const typename QueryDataT::Graph::EdgeData & data = _queryData.graph->GetEdgeData(edge); + for( + EdgeID edge = engine_working_data->BeginEdges( node ); + edge < engine_working_data->EndEdges(node); + ++edge + ) { + const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward; if(backwardDirectionFlag) { - const NodeID to = _queryData.graph->GetTarget(edge); + const NodeID to = engine_working_data->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -80,12 +92,12 @@ public: } } - for ( typename QueryDataT::Graph::EdgeIterator edge = _queryData.graph->BeginEdges( node ); edge < _queryData.graph->EndEdges(node); ++edge ) { - const typename QueryDataT::Graph::EdgeData & data = _queryData.graph->GetEdgeData(edge); + for ( EdgeID edge = engine_working_data->BeginEdges( node ); edge < engine_working_data->EndEdges(node); ++edge ) { + const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { - const NodeID to = _queryData.graph->GetTarget(edge); + const NodeID to = engine_working_data->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -119,20 +131,20 @@ public: edge = recursionStack.top(); recursionStack.pop(); - typename QueryDataT::Graph::EdgeIterator smallestEdge = SPECIAL_EDGEID; + EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(typename QueryDataT::Graph::EdgeIterator eit = _queryData.graph->BeginEdges(edge.first);eit < _queryData.graph->EndEdges(edge.first);++eit){ - const int weight = _queryData.graph->GetEdgeData(eit).distance; - if(_queryData.graph->GetTarget(eit) == edge.second && weight < smallestWeight && _queryData.graph->GetEdgeData(eit).forward){ + for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ + const int weight = engine_working_data->GetEdgeData(eit).distance; + if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(typename QueryDataT::Graph::EdgeIterator eit = _queryData.graph->BeginEdges(edge.second);eit < _queryData.graph->EndEdges(edge.second);++eit){ - const int weight = _queryData.graph->GetEdgeData(eit).distance; - if(_queryData.graph->GetTarget(eit) == edge.first && weight < smallestWeight && _queryData.graph->GetEdgeData(eit).backward){ + for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ + const int weight = engine_working_data->GetEdgeData(eit).distance; + if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -140,7 +152,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename QueryDataT::Graph::EdgeData& ed = _queryData.graph->GetEdgeData(smallestEdge); + const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order @@ -151,8 +163,8 @@ public: unpackedPath.push_back( _PathData( ed.id, - _queryData.nodeHelpDesk->GetNameIndexFromEdgeID(ed.id), - _queryData.nodeHelpDesk->GetTurnInstructionForEdgeID(ed.id), + engine_working_data->GetNameIndexFromEdgeID(ed.id), + engine_working_data->GetTurnInstructionForEdgeID(ed.id), ed.distance ) ); @@ -169,20 +181,20 @@ public: edge = recursionStack.top(); recursionStack.pop(); - typename QueryDataT::Graph::EdgeIterator smallestEdge = SPECIAL_EDGEID; + EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(typename QueryDataT::Graph::EdgeIterator eit = _queryData.graph->BeginEdges(edge.first);eit < _queryData.graph->EndEdges(edge.first);++eit){ - const int weight = _queryData.graph->GetEdgeData(eit).distance; - if(_queryData.graph->GetTarget(eit) == edge.second && weight < smallestWeight && _queryData.graph->GetEdgeData(eit).forward){ + for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ + const int weight = engine_working_data->GetEdgeData(eit).distance; + if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(typename QueryDataT::Graph::EdgeIterator eit = _queryData.graph->BeginEdges(edge.second);eit < _queryData.graph->EndEdges(edge.second);++eit){ - const int weight = _queryData.graph->GetEdgeData(eit).distance; - if(_queryData.graph->GetTarget(eit) == edge.first && weight < smallestWeight && _queryData.graph->GetEdgeData(eit).backward){ + for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ + const int weight = engine_working_data->GetEdgeData(eit).distance; + if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -190,7 +202,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename QueryDataT::Graph::EdgeData& ed = _queryData.graph->GetEdgeData(smallestEdge); + const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order @@ -204,7 +216,12 @@ public: unpackedPath.push_back(t); } - inline void RetrievePackedPathFromHeap(typename QueryDataT::QueryHeap & _fHeap, typename QueryDataT::QueryHeap & _bHeap, const NodeID middle, std::vector& packedPath) const { + inline void RetrievePackedPathFromHeap( + SearchEngineData::QueryHeap & _fHeap, + SearchEngineData::QueryHeap & _bHeap, + const NodeID middle, + std::vector & packedPath + ) const { NodeID pathNode = middle; while(pathNode != _fHeap.GetData(pathNode).parent) { pathNode = _fHeap.GetData(pathNode).parent; @@ -220,7 +237,7 @@ public: } } - inline void RetrievePackedPathFromSingleHeap(typename QueryDataT::QueryHeap & search_heap, const NodeID middle, std::vector& packed_path) const { + inline void RetrievePackedPathFromSingleHeap(SearchEngineData::QueryHeap & search_heap, const NodeID middle, std::vector& packed_path) const { NodeID pathNode = middle; while(pathNode != search_heap.GetData(pathNode).parent) { pathNode = search_heap.GetData(pathNode).parent; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index dc69ed31f..8c870aab0 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -25,12 +25,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasicRoutingInterface.h" +#include "../DataStructures/SearchEngineData.h" + template class ShortestPathRouting : public BasicRoutingInterface{ typedef BasicRoutingInterface super; typedef typename QueryDataT::QueryHeap QueryHeap; + SearchEngineData & engine_working_data; public: - ShortestPathRouting( QueryDataT & qd) : super(qd) {} + ShortestPathRouting( QueryDataT & qd, SearchEngineData & engine_working_data) : super(qd), engine_working_data(engine_working_data) {} ~ShortestPathRouting() {} From 29da133726c405adf27873ab2154d30d5218b7e4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:54:09 +0200 Subject: [PATCH 026/127] Don't build deleted classes --- CMakeLists.txt | 4 +--- cmake/UUID-Config.cmake | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62030dfd9..18e222cbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,10 +46,8 @@ 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}) +set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob}) add_library(OSRM SHARED ${OSRMSources}) add_library(UUID STATIC Util/UUID.cpp) add_dependencies( UUID UUIDConfigure ) diff --git a/cmake/UUID-Config.cmake b/cmake/UUID-Config.cmake index fce2e7466..3a4d819ef 100644 --- a/cmake/UUID-Config.cmake +++ b/cmake/UUID-Config.cmake @@ -6,6 +6,6 @@ file(MD5 ${SOURCE_DIR}/createHierarchy.cpp MD5PREPARE) file(MD5 ${SOURCE_DIR}/DataStructures/StaticRTree.h MD5RTREE) file(MD5 ${SOURCE_DIR}/DataStructures/NodeInformationHelpDesk.h MD5NODEINFO) file(MD5 ${SOURCE_DIR}/Util/GraphLoader.h MD5GRAPH) -file(MD5 ${SOURCE_DIR}/Server/DataStructures/QueryObjectsStorage.cpp MD5OBJECTS) +file(MD5 ${SOURCE_DIR}/Server/DataStructures/InternalDataFacade.h MD5OBJECTS) CONFIGURE_FILE( ${SOURCE_DIR}/Util/UUID.cpp.in ${SOURCE_DIR}/Util/UUID.cpp ) From 49a665488eb6b83d8147548145f66d9160c3008a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:54:30 +0200 Subject: [PATCH 027/127] Use new data facade in all descriptors --- Descriptors/BaseDescriptor.h | 3 +- Descriptors/DescriptionFactory.cpp | 208 ++++++++++++++--------------- Descriptors/DescriptionFactory.h | 134 ++++++++++++++++++- Descriptors/GPXDescriptor.h | 54 ++++++-- Descriptors/JSONDescriptor.h | 74 +++++++--- 5 files changed, 332 insertions(+), 141 deletions(-) diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 0d1359a10..12a9a15af 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -44,12 +44,13 @@ struct _DescriptorConfig { unsigned short z; }; +template class BaseDescriptor { public: BaseDescriptor() { } //Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BaseDescriptor() { } - virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) = 0; + virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, const DataFacadeT * facade) = 0; virtual void SetConfig(const _DescriptorConfig & config) = 0; }; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 1acf83a66..8cf8664d4 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -85,126 +85,126 @@ void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) { pc.printUnencodedString(pathDescription, output); } -void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) { +// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) { - if(0 == pathDescription.size()) - return; +// if(0 == pathDescription.size()) +// return; -// unsigned entireLength = 0; - /** starts at index 1 */ - pathDescription[0].length = 0; - for(unsigned i = 1; i < pathDescription.size(); ++i) { - pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); - } +// // unsigned entireLength = 0; +// /** starts at index 1 */ +// pathDescription[0].length = 0; +// for(unsigned i = 1; i < pathDescription.size(); ++i) { +// pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); +// } - double lengthOfSegment = 0; - unsigned durationOfSegment = 0; - unsigned indexOfSegmentBegin = 0; +// double lengthOfSegment = 0; +// unsigned durationOfSegment = 0; +// unsigned indexOfSegmentBegin = 0; - std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].nameID); - std::string string1; +// std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].nameID); +// std::string string1; - /*Simplify turn instructions - Input : - 10. Turn left on B 36 for 20 km - 11. Continue on B 35; B 36 for 2 km - 12. Continue on B 36 for 13 km +// /*Simplify turn instructions +// Input : +// 10. Turn left on B 36 for 20 km +// 11. Continue on B 35; B 36 for 2 km +// 12. Continue on B 36 for 13 km - becomes: - 10. Turn left on B 36 for 35 km - */ -//TODO: rework to check only end and start of string. -// stl string is way to expensive +// becomes: +// 10. Turn left on B 36 for 35 km +// */ +// //TODO: rework to check only end and start of string. +// // stl string is way to expensive -// unsigned lastTurn = 0; -// for(unsigned i = 1; i < pathDescription.size(); ++i) { -// string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); -// if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { -// if(std::string::npos != string0.find(string1+";") -// || std::string::npos != string0.find(";"+string1) -// || std::string::npos != string0.find(string1+" ;") -// || std::string::npos != string0.find("; "+string1) -// ){ -// SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; -// for(; lastTurn != i; ++lastTurn) -// pathDescription[lastTurn].nameID = pathDescription[i].nameID; -// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; -// } else if(std::string::npos != string1.find(string0+";") -// || std::string::npos != string1.find(";"+string0) -// || std::string::npos != string1.find(string0+" ;") -// || std::string::npos != string1.find("; "+string0) -// ){ -// SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; -// pathDescription[i].nameID = pathDescription[i-1].nameID; -// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; -// } -// } -// if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { -// lastTurn = i; -// } -// string0 = string1; -// } +// // unsigned lastTurn = 0; +// // for(unsigned i = 1; i < pathDescription.size(); ++i) { +// // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); +// // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { +// // if(std::string::npos != string0.find(string1+";") +// // || std::string::npos != string0.find(";"+string1) +// // || std::string::npos != string0.find(string1+" ;") +// // || std::string::npos != string0.find("; "+string1) +// // ){ +// // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; +// // for(; lastTurn != i; ++lastTurn) +// // pathDescription[lastTurn].nameID = pathDescription[i].nameID; +// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; +// // } else if(std::string::npos != string1.find(string0+";") +// // || std::string::npos != string1.find(";"+string0) +// // || std::string::npos != string1.find(string0+" ;") +// // || std::string::npos != string1.find("; "+string0) +// // ){ +// // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; +// // pathDescription[i].nameID = pathDescription[i-1].nameID; +// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; +// // } +// // } +// // if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { +// // lastTurn = i; +// // } +// // string0 = string1; +// // } - for(unsigned i = 1; i < pathDescription.size(); ++i) { - entireLength += pathDescription[i].length; - lengthOfSegment += pathDescription[i].length; - durationOfSegment += pathDescription[i].duration; - pathDescription[indexOfSegmentBegin].length = lengthOfSegment; - pathDescription[indexOfSegmentBegin].duration = durationOfSegment; +// for(unsigned i = 1; i < pathDescription.size(); ++i) { +// entireLength += pathDescription[i].length; +// lengthOfSegment += pathDescription[i].length; +// durationOfSegment += pathDescription[i].duration; +// pathDescription[indexOfSegmentBegin].length = lengthOfSegment; +// pathDescription[indexOfSegmentBegin].duration = durationOfSegment; - if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { - //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; - assert(pathDescription[i].necessary); - lengthOfSegment = 0; - durationOfSegment = 0; - indexOfSegmentBegin = i; - } - } - // SimpleLogger().Write() << "#segs: " << pathDescription.size(); +// if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { +// //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; +// assert(pathDescription[i].necessary); +// lengthOfSegment = 0; +// durationOfSegment = 0; +// indexOfSegmentBegin = i; +// } +// } +// // SimpleLogger().Write() << "#segs: " << pathDescription.size(); - //Post-processing to remove empty or nearly empty path segments - if(FLT_EPSILON > pathDescription.back().length) { - // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; - if(pathDescription.size() > 2){ - pathDescription.pop_back(); - pathDescription.back().necessary = true; - pathDescription.back().turnInstruction = TurnInstructions.NoTurn; - targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; - // SimpleLogger().Write() << "Deleting last turn instruction"; - } - } else { - pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); - } - if(FLT_EPSILON > pathDescription[0].length) { - //TODO: this is never called actually? - if(pathDescription.size() > 2) { - pathDescription.erase(pathDescription.begin()); - pathDescription[0].turnInstruction = TurnInstructions.HeadOn; - pathDescription[0].necessary = true; - startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; - // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; - } - } else { - pathDescription[0].duration *= startPhantom.ratio; - } +// //Post-processing to remove empty or nearly empty path segments +// if(FLT_EPSILON > pathDescription.back().length) { +// // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; +// if(pathDescription.size() > 2){ +// pathDescription.pop_back(); +// pathDescription.back().necessary = true; +// pathDescription.back().turnInstruction = TurnInstructions.NoTurn; +// targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; +// // SimpleLogger().Write() << "Deleting last turn instruction"; +// } +// } else { +// pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); +// } +// if(FLT_EPSILON > pathDescription[0].length) { +// //TODO: this is never called actually? +// if(pathDescription.size() > 2) { +// pathDescription.erase(pathDescription.begin()); +// pathDescription[0].turnInstruction = TurnInstructions.HeadOn; +// pathDescription[0].necessary = true; +// startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; +// // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; +// } +// } else { +// pathDescription[0].duration *= startPhantom.ratio; +// } - //Generalize poly line - dp.Run(pathDescription, zoomLevel); +// //Generalize poly line +// dp.Run(pathDescription, zoomLevel); - //fix what needs to be fixed else - for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ - if(pathDescription[i].necessary) { - double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); - pathDescription[i].bearing = angle; - } - } +// //fix what needs to be fixed else +// for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ +// if(pathDescription[i].necessary) { +// double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); +// pathDescription[i].bearing = angle; +// } +// } -// BuildRouteSummary(entireLength, duration); - return; -} +// // BuildRouteSummary(entireLength, duration); +// return; +// } void DescriptionFactory::BuildRouteSummary(const double distance, const unsigned time) { summary.startName = startPhantom.nodeBasedEdgeNameID; diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 68182a881..80b75a2a3 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -43,12 +43,18 @@ class DescriptionFactory { double DegreeToRadian(const double degree) const; double RadianToDegree(const double degree) const; public: - struct _RouteSummary { + struct RouteSummary { std::string lengthString; std::string durationString; unsigned startName; unsigned destName; - _RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {} + RouteSummary() : + lengthString("0"), + durationString("0"), + startName(0), + destName(0) + {} + void BuildDurationAndLengthStrings(const double distance, const unsigned time) { //compute distance/duration for route summary intToString(round(distance), lengthString); @@ -71,7 +77,129 @@ public: void SetStartSegment(const PhantomNode & startPhantom); void SetEndSegment(const PhantomNode & startPhantom); void AppendEncodedPolylineString(std::string & output, bool isEncoded); - void Run(const SearchEngine &sEngine, const unsigned zoomLevel); + + template + void Run(const DataFacadeT * facade, const unsigned zoomLevel) { + + if( pathDescription.empty() ) { + return; + } + + // unsigned entireLength = 0; + /** starts at index 1 */ + pathDescription[0].length = 0; + for(unsigned i = 1; i < pathDescription.size(); ++i) { + pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); + } + + double lengthOfSegment = 0; + unsigned durationOfSegment = 0; + unsigned indexOfSegmentBegin = 0; + + std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].nameID); + std::string string1; + + + /*Simplify turn instructions + Input : + 10. Turn left on B 36 for 20 km + 11. Continue on B 35; B 36 for 2 km + 12. Continue on B 36 for 13 km + + becomes: + 10. Turn left on B 36 for 35 km + */ + //TODO: rework to check only end and start of string. + // stl string is way to expensive + + // unsigned lastTurn = 0; + // for(unsigned i = 1; i < pathDescription.size(); ++i) { + // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); + // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { + // if(std::string::npos != string0.find(string1+";") + // || std::string::npos != string0.find(";"+string1) + // || std::string::npos != string0.find(string1+" ;") + // || std::string::npos != string0.find("; "+string1) + // ){ + // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; + // for(; lastTurn != i; ++lastTurn) + // pathDescription[lastTurn].nameID = pathDescription[i].nameID; + // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; + // } else if(std::string::npos != string1.find(string0+";") + // || std::string::npos != string1.find(";"+string0) + // || std::string::npos != string1.find(string0+" ;") + // || std::string::npos != string1.find("; "+string0) + // ){ + // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; + // pathDescription[i].nameID = pathDescription[i-1].nameID; + // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; + // } + // } + // if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { + // lastTurn = i; + // } + // string0 = string1; + // } + + + for(unsigned i = 1; i < pathDescription.size(); ++i) { + entireLength += pathDescription[i].length; + lengthOfSegment += pathDescription[i].length; + durationOfSegment += pathDescription[i].duration; + pathDescription[indexOfSegmentBegin].length = lengthOfSegment; + pathDescription[indexOfSegmentBegin].duration = durationOfSegment; + + + if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { + //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; + assert(pathDescription[i].necessary); + lengthOfSegment = 0; + durationOfSegment = 0; + indexOfSegmentBegin = i; + } + } + // SimpleLogger().Write() << "#segs: " << pathDescription.size(); + + //Post-processing to remove empty or nearly empty path segments + if(FLT_EPSILON > pathDescription.back().length) { + // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; + if(pathDescription.size() > 2){ + pathDescription.pop_back(); + pathDescription.back().necessary = true; + pathDescription.back().turnInstruction = TurnInstructions.NoTurn; + targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; + // SimpleLogger().Write() << "Deleting last turn instruction"; + } + } else { + pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); + } + if(FLT_EPSILON > pathDescription[0].length) { + //TODO: this is never called actually? + if(pathDescription.size() > 2) { + pathDescription.erase(pathDescription.begin()); + pathDescription[0].turnInstruction = TurnInstructions.HeadOn; + pathDescription[0].necessary = true; + startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; + // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; + } + } else { + pathDescription[0].duration *= startPhantom.ratio; + } + + //Generalize poly line + dp.Run(pathDescription, zoomLevel); + + //fix what needs to be fixed else + for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ + if(pathDescription[i].necessary) { + double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); + pathDescription[i].bearing = angle; + } + } + + // BuildRouteSummary(entireLength, duration); + return; + } }; #endif /* DESCRIPTIONFACTORY_H_ */ diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index 9c3caa77b..fc91c9e97 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -25,7 +25,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -class GPXDescriptor : public BaseDescriptor{ +template +class GPXDescriptor : public BaseDescriptor { private: _DescriptorConfig config; FixedPointCoordinate current; @@ -33,34 +34,63 @@ private: std::string tmp; public: void SetConfig(const _DescriptorConfig& c) { config = c; } - void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) { + + //TODO: reorder parameters + void Run( + http::Reply & reply, + const RawRouteData &rawRoute, + PhantomNodes &phantomNodes, + const DataFacadeT * facade + ) { reply.content += (""); - reply.content += ""; - reply.content += "Data (c) OpenStreetMap contributors (ODbL)"; + reply.content += + "Data (c)" + " OpenStreetMap contributors (ODbL)" + ""; reply.content += ""; - if(rawRoute.lengthOfShortestPath != INT_MAX && rawRoute.computedShortestPath.size()) { - convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp); + bool found_route = (rawRoute.lengthOfShortestPath != INT_MAX) && + (rawRoute.computedShortestPath.size() ); + if( found_route ) { + convertInternalLatLonToString( + phantomNodes.startPhantom.location.lat, + tmp + ); reply.content += ""; - BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + BOOST_FOREACH( + const _PathData & pathData, + rawRoute.computedShortestPath + ) { + current = facade->GetCoordinateOfNode(pathData.node); convertInternalLatLonToString(current.lat, tmp); reply.content += ""; } - convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp); + convertInternalLatLonToString( + phantomNodes.targetPhantom.location.lat, + tmp + ); reply.content += ""; } reply.content += ""; } }; -#endif /* GPX_DESCRIPTOR_H_ */ +#endif // GPX_DESCRIPTOR_H_ diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index a45d478ed..c7d8eaaae 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -34,7 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -class JSONDescriptor : public BaseDescriptor{ +template +class JSONDescriptor : public BaseDescriptor { private: _DescriptorConfig config; DescriptionFactory descriptionFactory; @@ -72,7 +73,12 @@ public: JSONDescriptor() : numberOfEnteredRestrictedAreas(0) {} void SetConfig(const _DescriptorConfig & c) { config = c; } - void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) { + void Run( + http::Reply & reply, + const RawRouteData &rawRoute, + PhantomNodes &phantomNodes, + const DataFacadeT * facade + ) { WriteHeaderToOutput(reply.content); @@ -83,7 +89,7 @@ public: //Get all the coordinates for the computed route BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + current = facade->GetCoordinateOfNode(pathData.node); descriptionFactory.AppendSegment(current, pathData ); } descriptionFactory.SetEndSegment(phantomNodes.targetPhantom); @@ -93,7 +99,7 @@ public: "\"status_message\": \"Cannot find route between points\","; } - descriptionFactory.Run(sEngine, config.z); + descriptionFactory.Run(facade, config.z); reply.content += "\"route_geometry\": "; if(config.geometry) { descriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); @@ -105,7 +111,7 @@ public: "\"route_instructions\": ["; numberOfEnteredRestrictedAreas = 0; if(config.instructions) { - BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, sEngine, shortestSegments); + BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, facade, shortestSegments); } else { BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) { TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; @@ -124,10 +130,10 @@ public: reply.content += descriptionFactory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); reply.content += "\"," "\"end_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); reply.content += "\""; reply.content += "}"; reply.content +=","; @@ -138,12 +144,12 @@ public: alternateDescriptionFactory.SetStartSegment(phantomNodes.startPhantom); //Get all the coordinates for the computed route BOOST_FOREACH(const _PathData & pathData, rawRoute.computedAlternativePath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + current = facade->GetCoordinateOfNode(pathData.node); alternateDescriptionFactory.AppendSegment(current, pathData ); } alternateDescriptionFactory.SetEndSegment(phantomNodes.targetPhantom); } - alternateDescriptionFactory.Run(sEngine, config.z); + alternateDescriptionFactory.Run(facade, config.z); //give an array of alternative routes reply.content += "\"alternative_geometries\": ["; @@ -158,7 +164,13 @@ public: reply.content += "["; //Generate instructions for each alternative if(config.instructions) { - BuildTextualDescription(alternateDescriptionFactory, reply, rawRoute.lengthOfAlternativePath, sEngine, alternativeSegments); + BuildTextualDescription( + alternateDescriptionFactory, + reply, + rawRoute.lengthOfAlternativePath, + facade, + alternativeSegments + ); } else { BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) { TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; @@ -180,10 +192,10 @@ public: reply.content += alternateDescriptionFactory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); reply.content += "\"," "\"end_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); reply.content += "\""; reply.content += "}"; } @@ -191,7 +203,7 @@ public: //Get Names for both routes RouteNames routeNames; - GetRouteNames(shortestSegments, alternativeSegments, sEngine, routeNames); + GetRouteNames(shortestSegments, alternativeSegments, facade, routeNames); reply.content += "\"route_name\":[\""; reply.content += routeNames.shortestPathName1; @@ -250,8 +262,13 @@ public: reply.content += "}"; } - void GetRouteNames(std::vector & shortestSegments, std::vector & alternativeSegments, const SearchEngine &sEngine, RouteNames & routeNames) { - /*** extract names for both alternatives ***/ + // construct routes names + void GetRouteNames( + std::vector & shortestSegments, + std::vector & alternativeSegments, + const DataFacadeT * facade, + RouteNames & routeNames + ) { Segment shortestSegment1, shortestSegment2; Segment alternativeSegment1, alternativeSegment2; @@ -294,11 +311,19 @@ public: if(alternativeSegment1.position > alternativeSegment2.position) std::swap(alternativeSegment1, alternativeSegment2); - routeNames.shortestPathName1 = sEngine.GetEscapedNameForNameID(shortestSegment1.nameID); - routeNames.shortestPathName2 = sEngine.GetEscapedNameForNameID(shortestSegment2.nameID); + routeNames.shortestPathName1 = facade->GetEscapedNameForNameID( + shortestSegment1.nameID + ); + routeNames.shortestPathName2 = facade->GetEscapedNameForNameID( + shortestSegment2.nameID + ); - routeNames.alternativePathName1 = sEngine.GetEscapedNameForNameID(alternativeSegment1.nameID); - routeNames.alternativePathName2 = sEngine.GetEscapedNameForNameID(alternativeSegment2.nameID); + routeNames.alternativePathName1 = facade->GetEscapedNameForNameID( + alternativeSegment1.nameID + ); + routeNames.alternativePathName2 = facade->GetEscapedNameForNameID( + alternativeSegment2.nameID + ); } } @@ -308,7 +333,14 @@ public: "\"status\":"; } - inline void BuildTextualDescription(DescriptionFactory & descriptionFactory, http::Reply & reply, const int lengthOfRoute, const SearchEngine &sEngine, std::vector & segmentVector) { + //TODO: reorder parameters + inline void BuildTextualDescription( + DescriptionFactory & descriptionFactory, + http::Reply & reply, + const int lengthOfRoute, + const DataFacadeT * facade, + std::vector & segmentVector + ) { //Segment information has following format: //["instruction","streetname",length,position,time,"length","earth_direction",azimuth] //Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5] @@ -344,7 +376,7 @@ public: reply.content += "\",\""; - reply.content += sEngine.GetEscapedNameForNameID(segment.nameID); + reply.content += facade->GetEscapedNameForNameID(segment.nameID); reply.content += "\","; intToString(segment.length, tmpDist); reply.content += tmpDist; From 370f4f62575df5ac3442eb1dd3b5692d515e3efb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:55:19 +0200 Subject: [PATCH 028/127] Properly instantiate plugins --- Library/OSRM.cpp | 72 +++++++++++++++++++++++++----------------------- Library/OSRM.h | 9 ++++-- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index bc5179fd2..9ece830f9 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -25,8 +25,9 @@ OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) { if( !use_shared_memory ) { if( !testDataFile(server_ini_path) ){ - std::string error_message = std::string(server_ini_path) + " not found"; - throw OSRMException(error_message.c_str()); + std::string error_message(server_ini_path); + error_message += " not found"; + throw OSRMException(error_message); } IniFile serverConfig(server_ini_path); @@ -82,56 +83,59 @@ OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) base_path ); - objects = new QueryObjectsStorage( - hsgr_path.string(), - ram_index_path.string(), - file_index_path.string(), - node_data_path.string(), - edge_data_path.string(), - name_data_path.string(), - timestamp_path.string() - ); - - RegisterPlugin(new HelloWorldPlugin()); - RegisterPlugin(new LocatePlugin(objects)); - RegisterPlugin(new NearestPlugin(objects)); - RegisterPlugin(new TimestampPlugin(objects)); - RegisterPlugin(new ViaRoutePlugin(objects)); + query_data_facade = new InternalDataFacade(); } else { //TODO: fetch pointers from shared memory - - //TODO: objects = new QueryObjectsStorage() query_data_facade = new SharedDataFacade(); - - //TODO: generate shared memory plugins - RegisterPlugin(new HelloWorldPlugin()); - RegisterPlugin(new LocatePlugin(objects)); - RegisterPlugin(new NearestPlugin(objects)); - RegisterPlugin(new TimestampPlugin(objects)); - RegisterPlugin(new ViaRoutePlugin(objects)); - } + + //The following plugins handle all requests. + RegisterPlugin( + new HelloWorldPlugin() + ); + RegisterPlugin( + new LocatePlugin >( + query_data_facade + ) + ); + RegisterPlugin( + new NearestPlugin >( + query_data_facade + ) + ); + RegisterPlugin( + new TimestampPlugin >( + query_data_facade + ) + ); + RegisterPlugin( + new ViaRoutePlugin >( + query_data_facade + ) + ); } OSRM::~OSRM() { - BOOST_FOREACH(PluginMap::value_type & plugin_pointer, pluginMap) { + BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) { delete plugin_pointer.second; } - delete objects; } void OSRM::RegisterPlugin(BasePlugin * plugin) { SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); - if( pluginMap.find(plugin->GetDescriptor()) != pluginMap.end() ) { - delete pluginMap.find(plugin->GetDescriptor())->second; + if( plugin_map.find(plugin->GetDescriptor()) != plugin_map.end() ) { + delete plugin_map.find(plugin->GetDescriptor())->second; } - pluginMap.emplace(plugin->GetDescriptor(), plugin); + plugin_map.emplace(plugin->GetDescriptor(), plugin); } void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { - const PluginMap::const_iterator & iter = pluginMap.find(route_parameters.service); - if(pluginMap.end() != iter) { + const PluginMap::const_iterator & iter = plugin_map.find( + route_parameters.service + ); + + if(plugin_map.end() != iter) { reply.status = http::Reply::ok; iter->second->HandleRequest(route_parameters, reply ); } else { diff --git a/Library/OSRM.h b/Library/OSRM.h index 74e331f1c..c58958934 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -50,17 +50,20 @@ or see http://www.gnu.org/licenses/agpl.txt. class OSRM : boost::noncopyable { private: typedef boost::unordered_map PluginMap; - QueryObjectsStorage * objects; - BaseDataFacade * query_data_facade; public: OSRM(const char * server_ini_path, const bool use_shared_memory = false); ~OSRM(); void RunQuery(RouteParameters & route_parameters, http::Reply & reply); + private: void RegisterPlugin(BasePlugin * plugin); - PluginMap pluginMap; + //base class pointer to the objects + BaseDataFacade * query_data_facade; + + PluginMap plugin_map; const bool use_shared_memory; + }; #endif //OSRM_H From d5c91b9bda7ed12fd616cea120e88fc7e6e3e013 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 18:55:49 +0200 Subject: [PATCH 029/127] further implementation of data facades --- Server/DataStructures/BaseDataFacade.h | 11 +++++++++++ Server/DataStructures/InternalDataFacade.h | 5 +++++ Server/DataStructures/SharedDataFacade.h | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 53302b5be..b3f1aee97 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/PhantomNodes.h" #include "../../DataStructures/TurnInstructions.h" #include "../../Util/OSRMException.h" +#include "../../Util/StringUtil.h" #include "../../typedefs.h" #include @@ -34,6 +35,7 @@ or see http://www.gnu.org/licenses/agpl.txt. template class BaseDataFacade { public: + typedef EdgeDataT EdgeData; BaseDataFacade() { } virtual ~BaseDataFacade() { } @@ -92,10 +94,19 @@ public: virtual unsigned GetCheckSum() const = 0; virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + virtual void GetName( const unsigned name_id, std::string & result ) const = 0; + + std::string GetEscapedNameForNameID(const unsigned name_id) const { + std::string temporary_string; + GetName(name_id, temporary_string); + return HTMLEntitize(temporary_string); + } + + virtual std::string GetTimestamp() const = 0; }; #endif // QUERY_DATA_FACADE_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index fd006bc5b..e4fc77525 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -93,6 +93,11 @@ public: const unsigned name_id, std::string & result ) const { return; }; + + std::string GetTimestamp() const { + return ""; + }; + }; #endif // INTERNAL_DATA_FACADE diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index fcdc15908..34700bca5 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -94,6 +94,11 @@ public: const unsigned name_id, std::string & result ) const { return; }; + + std::string GetTimestamp() const { + return ""; + }; + }; #endif // SHARED_DATA_FACADE From 387014dd3774a6a77616298d957e6f87658ee8e5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 19:07:18 +0200 Subject: [PATCH 030/127] initial refactoring of variable names --- Descriptors/JSONDescriptor.h | 226 +++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 102 deletions(-) diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index c7d8eaaae..25d6e7b58 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -38,29 +38,29 @@ template class JSONDescriptor : public BaseDescriptor { private: _DescriptorConfig config; - DescriptionFactory descriptionFactory; + DescriptionFactory description_factory; DescriptionFactory alternateDescriptionFactory; FixedPointCoordinate current; - unsigned numberOfEnteredRestrictedAreas; + unsigned entered_restricted_area_count; struct RoundAbout{ RoundAbout() : - startIndex(INT_MAX), - nameID(INT_MAX), - leaveAtExit(INT_MAX) + start_index(INT_MAX), + name_id(INT_MAX), + leave_at_exit(INT_MAX) {} - int startIndex; - int nameID; - int leaveAtExit; + int start_index; + int name_id; + int leave_at_exit; } roundAbout; struct Segment { - Segment() : nameID(-1), length(-1), position(-1) {} - Segment(int n, int l, int p) : nameID(n), length(l), position(p) {} - int nameID; + Segment() : name_id(-1), length(-1), position(-1) {} + Segment(int n, int l, int p) : name_id(n), length(l), position(p) {} + int name_id; int length; int position; }; - std::vector shortestSegments, alternativeSegments; + std::vector shortest_path_segments, alternative_path_segments; struct RouteNames { std::string shortestPathName1; @@ -70,120 +70,137 @@ private: }; public: - JSONDescriptor() : numberOfEnteredRestrictedAreas(0) {} + JSONDescriptor() : entered_restricted_area_count(0) {} void SetConfig(const _DescriptorConfig & c) { config = c; } + //TODO: reorder void Run( http::Reply & reply, - const RawRouteData &rawRoute, - PhantomNodes &phantomNodes, + const RawRouteData & raw_route_information, + PhantomNodes & phantom_nodes, const DataFacadeT * facade ) { WriteHeaderToOutput(reply.content); - if(rawRoute.lengthOfShortestPath != INT_MAX) { - descriptionFactory.SetStartSegment(phantomNodes.startPhantom); + if(raw_route_information.lengthOfShortestPath != INT_MAX) { + description_factory.SetStartSegment(phantom_nodes.startPhantom); reply.content += "0," "\"status_message\": \"Found route between points\","; //Get all the coordinates for the computed route - BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) { - current = facade->GetCoordinateOfNode(pathData.node); - descriptionFactory.AppendSegment(current, pathData ); + BOOST_FOREACH(const _PathData & path_data, raw_route_information.computedShortestPath) { + current = facade->GetCoordinateOfNode(path_data.node); + description_factory.AppendSegment(current, path_data ); } - descriptionFactory.SetEndSegment(phantomNodes.targetPhantom); + description_factory.SetEndSegment(phantom_nodes.targetPhantom); } else { //We do not need to do much, if there is no route ;-) reply.content += "207," "\"status_message\": \"Cannot find route between points\","; } - descriptionFactory.Run(facade, config.z); + description_factory.Run(facade, config.z); reply.content += "\"route_geometry\": "; if(config.geometry) { - descriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); + description_factory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); } else { reply.content += "[]"; } reply.content += "," "\"route_instructions\": ["; - numberOfEnteredRestrictedAreas = 0; + entered_restricted_area_count = 0; if(config.instructions) { - BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, facade, shortestSegments); + BuildTextualDescription( + description_factory, + reply, + raw_route_information.lengthOfShortestPath, + facade, + shortest_path_segments + ); } else { - BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) { - TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; - numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction); + BOOST_FOREACH( + const SegmentInformation & segment, + description_factory.pathDescription + ) { + TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; + entered_restricted_area_count += (current_instruction != segment.turnInstruction); } } reply.content += "],"; - descriptionFactory.BuildRouteSummary(descriptionFactory.entireLength, rawRoute.lengthOfShortestPath - ( numberOfEnteredRestrictedAreas*TurnInstructions.AccessRestrictionPenalty)); + description_factory.BuildRouteSummary( + description_factory.entireLength, + raw_route_information.lengthOfShortestPath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty) + ); reply.content += "\"route_summary\":"; reply.content += "{"; reply.content += "\"total_distance\":"; - reply.content += descriptionFactory.summary.lengthString; + reply.content += description_factory.summary.lengthString; reply.content += "," "\"total_time\":"; - reply.content += descriptionFactory.summary.durationString; + reply.content += description_factory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID( + description_factory.summary.startName + ); reply.content += "\"," "\"end_point\":\""; - reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID( + description_factory.summary.destName + ); reply.content += "\""; reply.content += "}"; reply.content +=","; //only one alternative route is computed at this time, so this is hardcoded - if(rawRoute.lengthOfAlternativePath != INT_MAX) { - alternateDescriptionFactory.SetStartSegment(phantomNodes.startPhantom); + if(raw_route_information.lengthOfAlternativePath != INT_MAX) { + alternateDescriptionFactory.SetStartSegment(phantom_nodes.startPhantom); //Get all the coordinates for the computed route - BOOST_FOREACH(const _PathData & pathData, rawRoute.computedAlternativePath) { - current = facade->GetCoordinateOfNode(pathData.node); - alternateDescriptionFactory.AppendSegment(current, pathData ); + BOOST_FOREACH(const _PathData & path_data, raw_route_information.computedAlternativePath) { + current = facade->GetCoordinateOfNode(path_data.node); + alternateDescriptionFactory.AppendSegment(current, path_data ); } - alternateDescriptionFactory.SetEndSegment(phantomNodes.targetPhantom); + alternateDescriptionFactory.SetEndSegment(phantom_nodes.targetPhantom); } alternateDescriptionFactory.Run(facade, config.z); //give an array of alternative routes reply.content += "\"alternative_geometries\": ["; - if(config.geometry && INT_MAX != rawRoute.lengthOfAlternativePath) { + if(config.geometry && INT_MAX != raw_route_information.lengthOfAlternativePath) { //Generate the linestrings for each alternative alternateDescriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); } reply.content += "],"; reply.content += "\"alternative_instructions\":["; - numberOfEnteredRestrictedAreas = 0; - if(INT_MAX != rawRoute.lengthOfAlternativePath) { + entered_restricted_area_count = 0; + if(INT_MAX != raw_route_information.lengthOfAlternativePath) { reply.content += "["; //Generate instructions for each alternative if(config.instructions) { BuildTextualDescription( alternateDescriptionFactory, reply, - rawRoute.lengthOfAlternativePath, + raw_route_information.lengthOfAlternativePath, facade, - alternativeSegments + alternative_path_segments ); } else { BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) { - TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; - numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction); + TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; + entered_restricted_area_count += (current_instruction != segment.turnInstruction); } } reply.content += "]"; } reply.content += "],"; reply.content += "\"alternative_summaries\":["; - if(INT_MAX != rawRoute.lengthOfAlternativePath) { + if(INT_MAX != raw_route_information.lengthOfAlternativePath) { //Generate route summary (length, duration) for each alternative - alternateDescriptionFactory.BuildRouteSummary(alternateDescriptionFactory.entireLength, rawRoute.lengthOfAlternativePath - ( numberOfEnteredRestrictedAreas*TurnInstructions.AccessRestrictionPenalty)); + alternateDescriptionFactory.BuildRouteSummary(alternateDescriptionFactory.entireLength, raw_route_information.lengthOfAlternativePath - ( entered_restricted_area_count*TurnInstructions.AccessRestrictionPenalty)); reply.content += "{"; reply.content += "\"total_distance\":"; reply.content += alternateDescriptionFactory.summary.lengthString; @@ -192,10 +209,10 @@ public: reply.content += alternateDescriptionFactory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID(description_factory.summary.startName); reply.content += "\"," "\"end_point\":\""; - reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID(description_factory.summary.destName); reply.content += "\""; reply.content += "}"; } @@ -203,7 +220,7 @@ public: //Get Names for both routes RouteNames routeNames; - GetRouteNames(shortestSegments, alternativeSegments, facade, routeNames); + GetRouteNames(shortest_path_segments, alternative_path_segments, facade, routeNames); reply.content += "\"route_name\":[\""; reply.content += routeNames.shortestPathName1; @@ -220,40 +237,40 @@ public: //list all viapoints so that the client may display it reply.content += "\"via_points\":["; std::string tmp; - if(config.geometry && INT_MAX != rawRoute.lengthOfShortestPath) { - for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) { + if(config.geometry && INT_MAX != raw_route_information.lengthOfShortestPath) { + for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) { reply.content += "["; - if(rawRoute.segmentEndCoordinates[i].startPhantom.location.isSet()) - convertInternalReversedCoordinateToString(rawRoute.segmentEndCoordinates[i].startPhantom.location, tmp); + if(raw_route_information.segmentEndCoordinates[i].startPhantom.location.isSet()) + convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates[i].startPhantom.location, tmp); else - convertInternalReversedCoordinateToString(rawRoute.rawViaNodeCoordinates[i], tmp); + convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates[i], tmp); reply.content += tmp; reply.content += "],"; } reply.content += "["; - if(rawRoute.segmentEndCoordinates.back().startPhantom.location.isSet()) - convertInternalReversedCoordinateToString(rawRoute.segmentEndCoordinates.back().targetPhantom.location, tmp); + if(raw_route_information.segmentEndCoordinates.back().startPhantom.location.isSet()) + convertInternalReversedCoordinateToString(raw_route_information.segmentEndCoordinates.back().targetPhantom.location, tmp); else - convertInternalReversedCoordinateToString(rawRoute.rawViaNodeCoordinates.back(), tmp); + convertInternalReversedCoordinateToString(raw_route_information.rawViaNodeCoordinates.back(), tmp); reply.content += tmp; reply.content += "]"; } reply.content += "],"; reply.content += "\"hint_data\": {"; reply.content += "\"checksum\":"; - intToString(rawRoute.checkSum, tmp); + intToString(raw_route_information.checkSum, tmp); reply.content += tmp; reply.content += ", \"locations\": ["; std::string hint; - for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) { + for(unsigned i = 0; i < raw_route_information.segmentEndCoordinates.size(); ++i) { reply.content += "\""; - EncodeObjectToBase64(rawRoute.segmentEndCoordinates[i].startPhantom, hint); + EncodeObjectToBase64(raw_route_information.segmentEndCoordinates[i].startPhantom, hint); reply.content += hint; reply.content += "\", "; } - EncodeObjectToBase64(rawRoute.segmentEndCoordinates.back().targetPhantom, hint); + EncodeObjectToBase64(raw_route_information.segmentEndCoordinates.back().targetPhantom, hint); reply.content += "\""; reply.content += hint; reply.content += "\"]"; @@ -264,8 +281,8 @@ public: // construct routes names void GetRouteNames( - std::vector & shortestSegments, - std::vector & alternativeSegments, + std::vector & shortest_path_segments, + std::vector & alternative_path_segments, const DataFacadeT * facade, RouteNames & routeNames ) { @@ -273,20 +290,20 @@ public: Segment shortestSegment1, shortestSegment2; Segment alternativeSegment1, alternativeSegment2; - if(0 < shortestSegments.size()) { - sort(shortestSegments.begin(), shortestSegments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) ); - shortestSegment1 = shortestSegments[0]; - if(0 < alternativeSegments.size()) { - sort(alternativeSegments.begin(), alternativeSegments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) ); - alternativeSegment1 = alternativeSegments[0]; + if(0 < shortest_path_segments.size()) { + sort(shortest_path_segments.begin(), shortest_path_segments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) ); + shortestSegment1 = shortest_path_segments[0]; + if(0 < alternative_path_segments.size()) { + sort(alternative_path_segments.begin(), alternative_path_segments.end(), boost::bind(&Segment::length, _1) > boost::bind(&Segment::length, _2) ); + alternativeSegment1 = alternative_path_segments[0]; } - std::vector shortestDifference(shortestSegments.size()); - std::vector alternativeDifference(alternativeSegments.size()); - std::set_difference(shortestSegments.begin(), shortestSegments.end(), alternativeSegments.begin(), alternativeSegments.end(), shortestDifference.begin(), boost::bind(&Segment::nameID, _1) < boost::bind(&Segment::nameID, _2) ); + std::vector shortestDifference(shortest_path_segments.size()); + std::vector alternativeDifference(alternative_path_segments.size()); + std::set_difference(shortest_path_segments.begin(), shortest_path_segments.end(), alternative_path_segments.begin(), alternative_path_segments.end(), shortestDifference.begin(), boost::bind(&Segment::name_id, _1) < boost::bind(&Segment::name_id, _2) ); int size_of_difference = shortestDifference.size(); if(0 < size_of_difference ) { int i = 0; - while( i < size_of_difference && shortestDifference[i].nameID == shortestSegments[0].nameID) { + while( i < size_of_difference && shortestDifference[i].name_id == shortest_path_segments[0].name_id) { ++i; } if(i < size_of_difference ) { @@ -294,11 +311,11 @@ public: } } - std::set_difference(alternativeSegments.begin(), alternativeSegments.end(), shortestSegments.begin(), shortestSegments.end(), alternativeDifference.begin(), boost::bind(&Segment::nameID, _1) < boost::bind(&Segment::nameID, _2) ); + std::set_difference(alternative_path_segments.begin(), alternative_path_segments.end(), shortest_path_segments.begin(), shortest_path_segments.end(), alternativeDifference.begin(), boost::bind(&Segment::name_id, _1) < boost::bind(&Segment::name_id, _2) ); size_of_difference = alternativeDifference.size(); if(0 < size_of_difference ) { int i = 0; - while( i < size_of_difference && alternativeDifference[i].nameID == alternativeSegments[0].nameID) { + while( i < size_of_difference && alternativeDifference[i].name_id == alternative_path_segments[0].name_id) { ++i; } if(i < size_of_difference ) { @@ -312,17 +329,17 @@ public: std::swap(alternativeSegment1, alternativeSegment2); routeNames.shortestPathName1 = facade->GetEscapedNameForNameID( - shortestSegment1.nameID + shortestSegment1.name_id ); routeNames.shortestPathName2 = facade->GetEscapedNameForNameID( - shortestSegment2.nameID + shortestSegment2.name_id ); routeNames.alternativePathName1 = facade->GetEscapedNameForNameID( - alternativeSegment1.nameID + alternativeSegment1.name_id ); routeNames.alternativePathName2 = facade->GetEscapedNameForNameID( - alternativeSegment2.nameID + alternativeSegment2.name_id ); } } @@ -335,46 +352,45 @@ public: //TODO: reorder parameters inline void BuildTextualDescription( - DescriptionFactory & descriptionFactory, + DescriptionFactory & description_factory, http::Reply & reply, - const int lengthOfRoute, + const int route_length, const DataFacadeT * facade, - std::vector & segmentVector + std::vector & route_segments_list ) { //Segment information has following format: //["instruction","streetname",length,position,time,"length","earth_direction",azimuth] //Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5] //See also: http://developers.cloudmade.com/wiki/navengine/JSON_format unsigned prefixSumOfNecessarySegments = 0; - roundAbout.leaveAtExit = 0; - roundAbout.nameID = 0; + roundAbout.leave_at_exit = 0; + roundAbout.name_id = 0; std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction; //Fetch data from Factory and generate a string from it. - BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) { - TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; - numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction); - if(TurnInstructions.TurnIsNecessary( currentInstruction) ) { - if(TurnInstructions.EnterRoundAbout == currentInstruction) { - roundAbout.nameID = segment.nameID; - roundAbout.startIndex = prefixSumOfNecessarySegments; + BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) { + TurnInstruction current_instruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; + entered_restricted_area_count += (current_instruction != segment.turnInstruction); + if(TurnInstructions.TurnIsNecessary( current_instruction) ) { + if(TurnInstructions.EnterRoundAbout == current_instruction) { + roundAbout.name_id = segment.nameID; + roundAbout.start_index = prefixSumOfNecessarySegments; } else { if(0 != prefixSumOfNecessarySegments){ reply.content += ","; } reply.content += "[\""; - if(TurnInstructions.LeaveRoundAbout == currentInstruction) { + if(TurnInstructions.LeaveRoundAbout == current_instruction) { intToString(TurnInstructions.EnterRoundAbout, tmpInstruction); reply.content += tmpInstruction; reply.content += "-"; - intToString(roundAbout.leaveAtExit+1, tmpInstruction); + intToString(roundAbout.leave_at_exit+1, tmpInstruction); reply.content += tmpInstruction; - roundAbout.leaveAtExit = 0; + roundAbout.leave_at_exit = 0; } else { - intToString(currentInstruction, tmpInstruction); + intToString(current_instruction, tmpInstruction); reply.content += tmpInstruction; } - reply.content += "\",\""; reply.content += facade->GetEscapedNameForNameID(segment.nameID); reply.content += "\","; @@ -396,15 +412,21 @@ public: reply.content += tmpBearing; reply.content += "]"; - segmentVector.push_back( Segment(segment.nameID, segment.length, segmentVector.size() )); + route_segments_list.push_back( + Segment( + segment.nameID, + segment.length, + route_segments_list.size() + ) + ); } - } else if(TurnInstructions.StayOnRoundAbout == currentInstruction) { - ++roundAbout.leaveAtExit; + } else if(TurnInstructions.StayOnRoundAbout == current_instruction) { + ++roundAbout.leave_at_exit; } if(segment.necessary) ++prefixSumOfNecessarySegments; } - if(INT_MAX != lengthOfRoute) { + if(INT_MAX != route_length) { reply.content += ",[\""; intToString(TurnInstructions.ReachedYourDestination, tmpInstruction); reply.content += tmpInstruction; From 27b6627110fd5b5006a49e0cacaad583c157fb07 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 22:10:49 +0200 Subject: [PATCH 031/127] renamed utility class --- Descriptors/BaseDescriptor.h | 6 +++--- Descriptors/GPXDescriptor.h | 4 ++-- Descriptors/JSONDescriptor.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 12a9a15af..6c54f2f3f 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -36,8 +36,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -struct _DescriptorConfig { - _DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(true), z(18) {} +struct DescriptorConfig { + DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(true), z(18) {} bool instructions; bool geometry; bool encodeGeometry; @@ -51,7 +51,7 @@ public: //Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BaseDescriptor() { } virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, const DataFacadeT * facade) = 0; - virtual void SetConfig(const _DescriptorConfig & config) = 0; + virtual void SetConfig(const DescriptorConfig & config) = 0; }; #endif /* BASE_DESCRIPTOR_H_ */ diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index fc91c9e97..7cf394bc2 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -28,12 +28,12 @@ or see http://www.gnu.org/licenses/agpl.txt. template class GPXDescriptor : public BaseDescriptor { private: - _DescriptorConfig config; + DescriptorConfig config; FixedPointCoordinate current; std::string tmp; public: - void SetConfig(const _DescriptorConfig& c) { config = c; } + void SetConfig(const DescriptorConfig& c) { config = c; } //TODO: reorder parameters void Run( diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 25d6e7b58..0f4c2c6af 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -37,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. template class JSONDescriptor : public BaseDescriptor { private: - _DescriptorConfig config; + DescriptorConfig config; DescriptionFactory description_factory; DescriptionFactory alternateDescriptionFactory; FixedPointCoordinate current; @@ -71,7 +71,7 @@ private: public: JSONDescriptor() : entered_restricted_area_count(0) {} - void SetConfig(const _DescriptorConfig & c) { config = c; } + void SetConfig(const DescriptorConfig & c) { config = c; } //TODO: reorder void Run( From 12b4fff81e9c9f3e212b4597fbf95090df1fe13c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 19 Sep 2013 22:28:02 +0200 Subject: [PATCH 032/127] Refactoring base descriptor class --- Descriptors/BaseDescriptor.h | 18 ++++++++++++++---- Descriptors/GPXDescriptor.h | 2 +- Descriptors/JSONDescriptor.h | 14 ++++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 6c54f2f3f..bf9138029 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -37,11 +37,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #include struct DescriptorConfig { - DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(true), z(18) {} + DescriptorConfig() : + instructions(true), + geometry(true), + encode_geometry(true), + zoom_level(18) + { } bool instructions; bool geometry; - bool encodeGeometry; - unsigned short z; + bool encode_geometry; + unsigned short zoom_level; }; template @@ -50,7 +55,12 @@ public: BaseDescriptor() { } //Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BaseDescriptor() { } - virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, const DataFacadeT * facade) = 0; + virtual void Run( + http::Reply & reply, + const RawRouteData &rawRoute, + PhantomNodes &phantomNodes, + const DataFacadeT * facade + ) = 0; virtual void SetConfig(const DescriptorConfig & config) = 0; }; diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index 7cf394bc2..0752836f7 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -33,7 +33,7 @@ private: std::string tmp; public: - void SetConfig(const DescriptorConfig& c) { config = c; } + void SetConfig(const DescriptorConfig & c) { config = c; } //TODO: reorder parameters void Run( diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 0f4c2c6af..518f82e57 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -100,10 +100,13 @@ public: "\"status_message\": \"Cannot find route between points\","; } - description_factory.Run(facade, config.z); + description_factory.Run(facade, config.zoom_level); reply.content += "\"route_geometry\": "; if(config.geometry) { - description_factory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); + description_factory.AppendEncodedPolylineString( + reply.content, + config.encode_geometry + ); } else { reply.content += "[]"; } @@ -166,13 +169,16 @@ public: } alternateDescriptionFactory.SetEndSegment(phantom_nodes.targetPhantom); } - alternateDescriptionFactory.Run(facade, config.z); + alternateDescriptionFactory.Run(facade, config.zoom_level); //give an array of alternative routes reply.content += "\"alternative_geometries\": ["; if(config.geometry && INT_MAX != raw_route_information.lengthOfAlternativePath) { //Generate the linestrings for each alternative - alternateDescriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); + alternateDescriptionFactory.AppendEncodedPolylineString( + reply.content, + config.encode_geometry + ); } reply.content += "],"; reply.content += "\"alternative_instructions\":["; From 0cabc8169326ab229f1ecc039f1b23f5d286564e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 11:09:07 +0200 Subject: [PATCH 033/127] Reworking data access to go always through facades --- DataStructures/SearchEngine.h | 1 - Descriptors/JSONDescriptor.h | 2 +- Plugins/ViaRoutePlugin.h | 10 ++-- RoutingAlgorithms/AlternativePathRouting.h | 66 ++++++++++++---------- RoutingAlgorithms/BasicRoutingInterface.h | 52 ++++++++--------- RoutingAlgorithms/ShortestPathRouting.h | 10 ++-- 6 files changed, 73 insertions(+), 68 deletions(-) diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index f73624cd9..894ea8715 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -50,7 +50,6 @@ public: SearchEngine( DataFacadeT * facade ) : facade (facade), - engine_working_data(facade), shortest_path (facade, engine_working_data), alternative_path (facade, engine_working_data) {} diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 518f82e57..62fda69cb 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -73,7 +73,7 @@ public: JSONDescriptor() : entered_restricted_area_count(0) {} void SetConfig(const DescriptorConfig & c) { config = c; } - //TODO: reorder + //TODO: reorder parameters void Run( http::Reply & reply, const RawRouteData & raw_route_information, diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index e36549448..598d67c1d 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -115,12 +115,12 @@ public: ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) { - search_engine_ptr->alternativePaths( + search_engine_ptr->alternative_paths( rawRoute.segmentEndCoordinates[0], rawRoute ); } else { - search_engine_ptr->shortestPath( + search_engine_ptr->shortest_path( rawRoute.segmentEndCoordinates, rawRoute ); @@ -139,16 +139,16 @@ public: reply.content += "("; } - _DescriptorConfig descriptorConfig; + DescriptorConfig descriptorConfig; unsigned descriptorType = 0; if(descriptorTable.find(routeParameters.outputFormat) != descriptorTable.end() ) { descriptorType = descriptorTable.find(routeParameters.outputFormat)->second; } - descriptorConfig.z = routeParameters.zoomLevel; + descriptorConfig.zoom_level = routeParameters.zoomLevel; descriptorConfig.instructions = routeParameters.printInstructions; descriptorConfig.geometry = routeParameters.geometry; - descriptorConfig.encodeGeometry = routeParameters.compression; + descriptorConfig.encode_geometry = routeParameters.compression; switch(descriptorType){ case 0: diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 49c935604..96c0a3737 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -47,12 +47,18 @@ class AlternativeRouting : private BasicRoutingInterface { return (2*length + sharing) < (2*other.length + other.sharing); } }; - - const SearchGraph * search_graph; + DataFacadeT * facade; SearchEngineData & engine_working_data; public: - AlternativeRouting(DataFacadeT & qd, SearchEngineData & engine_working_data) : super(qd), search_graph(qd.graph), engine_working_data(engine_working_data) { } + AlternativeRouting( + DataFacadeT * facade, + SearchEngineData & engine_working_data + ) : + super(facade), + facade(facade), + engine_working_data(engine_working_data) + { } ~AlternativeRouting() {} @@ -252,8 +258,8 @@ private: //First partially unpack s-->v until paths deviate, note length of common path. for (unsigned i = 0, lengthOfPackedPath = std::min( packed_s_v_path.size(), packed_shortest_path.size()) - 1; (i < lengthOfPackedPath); ++i) { if (packed_s_v_path[i] == packed_shortest_path[i] && packed_s_v_path[i + 1] == packed_shortest_path[i + 1]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packed_s_v_path[i], packed_s_v_path[i + 1]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packed_s_v_path[i], packed_s_v_path[i + 1]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { if (packed_s_v_path[i] == packed_shortest_path[i]) { super::UnpackEdge(packed_s_v_path[i], packed_s_v_path[i+1], partiallyUnpackedViaPath); @@ -264,8 +270,8 @@ private: } //traverse partially unpacked edge and note common prefix for (int i = 0, lengthOfPackedPath = std::min( partiallyUnpackedViaPath.size(), partiallyUnpackedShortestPath.size()) - 1; (i < lengthOfPackedPath) && (partiallyUnpackedViaPath[i] == partiallyUnpackedShortestPath[i] && partiallyUnpackedViaPath[i+1] == partiallyUnpackedShortestPath[i+1]); ++i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } //Second, partially unpack v-->t in reverse order until paths deviate and note lengths @@ -273,8 +279,8 @@ private: int shortestPathIndex = packed_shortest_path.size() - 1; for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex ) { if (packed_v_t_path[viaPathIndex - 1] == packed_shortest_path[shortestPathIndex - 1] && packed_v_t_path[viaPathIndex] == packed_shortest_path[shortestPathIndex]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_v_t_path[viaPathIndex - 1], packed_v_t_path[viaPathIndex]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[viaPathIndex - 1], packed_v_t_path[viaPathIndex]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { if (packed_v_t_path[viaPathIndex] == packed_shortest_path[shortestPathIndex]) { super::UnpackEdge(packed_v_t_path[viaPathIndex-1], packed_v_t_path[viaPathIndex], partiallyUnpackedViaPath); @@ -288,8 +294,8 @@ private: shortestPathIndex = partiallyUnpackedShortestPath.size() - 1; for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex) { if (partiallyUnpackedViaPath[viaPathIndex - 1] == partiallyUnpackedShortestPath[shortestPathIndex - 1] && partiallyUnpackedViaPath[viaPathIndex] == partiallyUnpackedShortestPath[shortestPathIndex]) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); - *sharing_of_via_path += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); + *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { break; } @@ -309,8 +315,8 @@ private: //compute forward sharing while( (packedAlternativePath[aindex] == packedShortestPath[aindex]) && (packedAlternativePath[aindex+1] == packedShortestPath[aindex+1]) ) { // SimpleLogger().Write() << "retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"; - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); - sharing += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); + sharing += facade->GetEdgeData(edgeID).distance; ++aindex; } @@ -318,8 +324,8 @@ private: int bindex = packedShortestPath.size()-1; //compute backward sharing while( aindex > 0 && bindex > 0 && (packedAlternativePath[aindex] == packedShortestPath[bindex]) && (packedAlternativePath[aindex-1] == packedShortestPath[bindex-1]) ) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); - sharing += search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); + sharing += facade->GetEdgeData(edgeID).distance; --aindex; --bindex; } return sharing; @@ -357,12 +363,12 @@ private: } } - for ( typename SearchGraph::EdgeIterator edge = search_graph->BeginEdges( node ); edge < search_graph->EndEdges(node); edge++ ) { - const typename SearchGraph::EdgeData & data = search_graph->GetEdgeData(edge); + for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); edge++ ) { + const typename SearchGraph::EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { - const NodeID to = search_graph->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -432,8 +438,8 @@ private: std::stack unpackStack; //Traverse path s-->v for (unsigned i = packed_s_v_path.size() - 1; (i > 0) && unpackStack.empty(); --i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_s_v_path[i - 1], packed_s_v_path[i]); - int lengthOfCurrentEdge = search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_s_v_path[i - 1], packed_s_v_path[i]); + int lengthOfCurrentEdge = facade->GetEdgeData(edgeID).distance; if (lengthOfCurrentEdge + unpackedUntilDistance >= T_threshold) { unpackStack.push(std::make_pair(packed_s_v_path[i - 1], packed_s_v_path[i])); } else { @@ -445,15 +451,15 @@ private: while (!unpackStack.empty()) { const SearchSpaceEdge viaPathEdge = unpackStack.top(); unpackStack.pop(); - typename SearchGraph::EdgeIterator edgeIDInViaPath = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); + EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = search_graph->GetEdgeData(edgeIDInViaPath); + typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; - typename SearchGraph::EdgeIterator edgeIDOfSecondSegment = search_graph->FindEdgeInEitherDirection(middleOfViaPath, viaPathEdge.second); - int lengthOfSecondSegment = search_graph->GetEdgeData(edgeIDOfSecondSegment).distance; + EdgeID edgeIDOfSecondSegment = facade->FindEdgeInEitherDirection(middleOfViaPath, viaPathEdge.second); + int lengthOfSecondSegment = facade->GetEdgeData(edgeIDOfSecondSegment).distance; //attention: !unpacking in reverse! //Check if second segment is the one to go over treshold? if yes add second segment to stack, else push first segment to stack and add distance of second one. if (unpackedUntilDistance + lengthOfSecondSegment >= T_threshold) { @@ -473,8 +479,8 @@ private: unpackedUntilDistance = 0; //Traverse path s-->v for (unsigned i = 0, lengthOfPackedPath = packed_v_t_path.size() - 1; (i < lengthOfPackedPath) && unpackStack.empty(); ++i) { - typename SearchGraph::EdgeIterator edgeID = search_graph->FindEdgeInEitherDirection( packed_v_t_path[i], packed_v_t_path[i + 1]); - int lengthOfCurrentEdge = search_graph->GetEdgeData(edgeID).distance; + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[i], packed_v_t_path[i + 1]); + int lengthOfCurrentEdge = facade->GetEdgeData(edgeID).distance; if (lengthOfCurrentEdge + unpackedUntilDistance >= T_threshold) { unpackStack.push( std::make_pair(packed_v_t_path[i], packed_v_t_path[i + 1])); } else { @@ -486,15 +492,15 @@ private: while (!unpackStack.empty()) { const SearchSpaceEdge viaPathEdge = unpackStack.top(); unpackStack.pop(); - typename SearchGraph::EdgeIterator edgeIDInViaPath = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); + EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = search_graph->GetEdgeData(edgeIDInViaPath); + typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); const bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; - typename SearchGraph::EdgeIterator edgeIDOfFirstSegment = search_graph->FindEdgeInEitherDirection(viaPathEdge.first, middleOfViaPath); - int lengthOfFirstSegment = search_graph->GetEdgeData( edgeIDOfFirstSegment).distance; + EdgeID edgeIDOfFirstSegment = facade->FindEdgeInEitherDirection(viaPathEdge.first, middleOfViaPath); + int lengthOfFirstSegment = facade->GetEdgeData( edgeIDOfFirstSegment).distance; //Check if first segment is the one to go over treshold? if yes first segment to stack, else push second segment to stack and add distance of first one. if (unpackedUntilDistance + lengthOfFirstSegment >= T_threshold) { unpackStack.push( std::make_pair(viaPathEdge.first, middleOfViaPath)); diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index b182265e1..dc132223d 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -35,12 +35,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -template +template class BasicRoutingInterface : boost::noncopyable{ protected: - SearchEngineDataT * engine_working_data; + DataFacadeT * facade; public: - BasicRoutingInterface(SearchEngineDataT * engine_working_data) : engine_working_data(engine_working_data) { } + BasicRoutingInterface(DataFacadeT * facade) : facade(facade) { } virtual ~BasicRoutingInterface(){ }; inline void RoutingStep( @@ -72,14 +72,14 @@ public: //Stalling for( - EdgeID edge = engine_working_data->BeginEdges( node ); - edge < engine_working_data->EndEdges(node); + EdgeID edge = facade->BeginEdges( node ); + edge < facade->EndEdges(node); ++edge ) { - const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); + const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward; if(backwardDirectionFlag) { - const NodeID to = engine_working_data->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -92,12 +92,12 @@ public: } } - for ( EdgeID edge = engine_working_data->BeginEdges( node ); edge < engine_working_data->EndEdges(node); ++edge ) { - const typename SearchEngineDataT::EdgeData & data = engine_working_data->GetEdgeData(edge); + for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { + const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { - const NodeID to = engine_working_data->GetTarget(edge); + const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; assert( edgeWeight > 0 ); @@ -133,18 +133,18 @@ public: EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ + for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ + for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -152,7 +152,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order @@ -163,8 +163,8 @@ public: unpackedPath.push_back( _PathData( ed.id, - engine_working_data->GetNameIndexFromEdgeID(ed.id), - engine_working_data->GetTurnInstructionForEdgeID(ed.id), + facade->GetNameIndexFromEdgeID(ed.id), + facade->GetTurnInstructionForEdgeID(ed.id), ed.distance ) ); @@ -183,18 +183,18 @@ public: EdgeID smallestEdge = SPECIAL_EDGEID; int smallestWeight = INT_MAX; - for(EdgeID eit = engine_working_data->BeginEdges(edge.first);eit < engine_working_data->EndEdges(edge.first);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.second && weight < smallestWeight && engine_working_data->GetEdgeData(eit).forward){ + for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ smallestEdge = eit; smallestWeight = weight; } } if(smallestEdge == SPECIAL_EDGEID){ - for(EdgeID eit = engine_working_data->BeginEdges(edge.second);eit < engine_working_data->EndEdges(edge.second);++eit){ - const int weight = engine_working_data->GetEdgeData(eit).distance; - if(engine_working_data->GetTarget(eit) == edge.first && weight < smallestWeight && engine_working_data->GetEdgeData(eit).backward){ + for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ + const int weight = facade->GetEdgeData(eit).distance; + if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ smallestEdge = eit; smallestWeight = weight; } @@ -202,7 +202,7 @@ public: } assert(smallestWeight != INT_MAX); - const typename SearchEngineDataT::EdgeData& ed = engine_working_data->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack const NodeID middle = ed.id; //again, we need to this in reversed order diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 8c870aab0..3426772d9 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -27,13 +27,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/SearchEngineData.h" -template -class ShortestPathRouting : public BasicRoutingInterface{ - typedef BasicRoutingInterface super; - typedef typename QueryDataT::QueryHeap QueryHeap; +template +class ShortestPathRouting : public BasicRoutingInterface{ + typedef BasicRoutingInterface super; + typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; public: - ShortestPathRouting( QueryDataT & qd, SearchEngineData & engine_working_data) : super(qd), engine_working_data(engine_working_data) {} + ShortestPathRouting( DataFacadeT * facade, SearchEngineData & engine_working_data) : super(facade), engine_working_data(engine_working_data) {} ~ShortestPathRouting() {} From c85f6c122840aa55261976c727c652dd137151f1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 11:35:59 +0200 Subject: [PATCH 034/127] replacing cassert by boost asserts --- RoutingAlgorithms/BasicRoutingInterface.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index dc132223d..df1268218 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -28,9 +28,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/ContainerUtils.h" #include "../Util/SimpleLogger.h" +#include #include -#include #include #include @@ -82,7 +82,7 @@ public: const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; - assert( edgeWeight > 0 ); + BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); if(_forwardHeap.WasInserted( to )) { if(_forwardHeap.GetKey( to ) + edgeWeight < distance) { @@ -100,7 +100,7 @@ public: const NodeID to = facade->GetTarget(edge); const int edgeWeight = data.distance; - assert( edgeWeight > 0 ); + BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); const int toDistance = distance + edgeWeight; //New Node discovered -> Add to Heap + Node Info Storage @@ -150,7 +150,7 @@ public: } } } - assert(smallestWeight != INT_MAX); + BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge id invalid"); const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack @@ -159,7 +159,7 @@ public: recursionStack.push(std::make_pair(middle, edge.second)); recursionStack.push(std::make_pair(edge.first, middle)); } else { - assert(!ed.shortcut); + BOOST_ASSERT_MSG(!ed.shortcut, "edge must be a shortcut"); unpackedPath.push_back( _PathData( ed.id, @@ -200,7 +200,7 @@ public: } } } - assert(smallestWeight != INT_MAX); + BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge weight invalid"); const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); if(ed.shortcut) {//unpack @@ -209,7 +209,7 @@ public: recursionStack.push(std::make_pair(middle, edge.second)); recursionStack.push(std::make_pair(edge.first, middle)); } else { - assert(!ed.shortcut); + BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut"); unpackedPath.push_back(edge.first ); } } From 0ef4f36d442b1d9b623e55b5648b58e18d106ec0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 13:08:18 +0200 Subject: [PATCH 035/127] further refactoring of variable names --- RoutingAlgorithms/BasicRoutingInterface.h | 228 ++++++++++++---------- 1 file changed, 127 insertions(+), 101 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index df1268218..a11a75a2a 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -36,37 +36,36 @@ or see http://www.gnu.org/licenses/agpl.txt. #include template -class BasicRoutingInterface : boost::noncopyable{ +class BasicRoutingInterface : boost::noncopyable { protected: DataFacadeT * facade; public: - BasicRoutingInterface(DataFacadeT * facade) : facade(facade) { } + BasicRoutingInterface( DataFacadeT * facade ) : facade(facade) { } virtual ~BasicRoutingInterface(){ }; inline void RoutingStep( - SearchEngineData::QueryHeap & _forwardHeap, - SearchEngineData::QueryHeap & _backwardHeap, - NodeID *middle, - int *_upperbound, - const int edgeBasedOffset, - const bool forwardDirection + SearchEngineData::QueryHeap & forward_heap, + SearchEngineData::QueryHeap & reverse_heap, + NodeID * middle_node_id, + int * upper_bound, + const int edge_expansion_offset, + const bool forward_direction ) const { - const NodeID node = _forwardHeap.DeleteMin(); - const int distance = _forwardHeap.GetKey(node); - //SimpleLogger().Write() << "Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance; - if(_backwardHeap.WasInserted(node) ){ - const int newDistance = _backwardHeap.GetKey(node) + distance; - if(newDistance < *_upperbound ){ - if(newDistance>=0 ) { - *middle = node; - *_upperbound = newDistance; - } else { + const NodeID node = forward_heap.DeleteMin(); + const int distance = forward_heap.GetKey(node); + //SimpleLogger().Write() << "Settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; + if(reverse_heap.WasInserted(node) ){ + const int new_distance = reverse_heap.GetKey(node) + distance; + if(new_distance < *upper_bound ){ + if( new_distance >= 0 ) { + *middle_node_id = node; + *upper_bound = new_distance; } } } - if(distance-edgeBasedOffset > *_upperbound){ - _forwardHeap.DeleteAll(); + if( (distance-edge_expansion_offset) > *upper_bound){ + forward_heap.DeleteAll(); return; } @@ -77,15 +76,15 @@ public: ++edge ) { const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); - bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward; + bool backwardDirectionFlag = (!forward_direction) ? data.forward : data.backward; if(backwardDirectionFlag) { const NodeID to = facade->GetTarget(edge); - const int edgeWeight = data.distance; + const int edge_weight = data.distance; - BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); + BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" ); - if(_forwardHeap.WasInserted( to )) { - if(_forwardHeap.GetKey( to ) + edgeWeight < distance) { + if(forward_heap.WasInserted( to )) { + if(forward_heap.GetKey( to ) + edge_weight < distance) { return; } } @@ -94,73 +93,84 @@ public: for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); - bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); - if(forwardDirectionFlag) { + bool forward_directionFlag = (forward_direction ? data.forward : data.backward ); + if(forward_directionFlag) { const NodeID to = facade->GetTarget(edge); - const int edgeWeight = data.distance; + const int edge_weight = data.distance; - BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); - const int toDistance = distance + edgeWeight; + BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" ); + const int to_distance = distance + edge_weight; //New Node discovered -> Add to Heap + Node Info Storage - if ( !_forwardHeap.WasInserted( to ) ) { - _forwardHeap.Insert( to, toDistance, node ); + if ( !forward_heap.WasInserted( to ) ) { + forward_heap.Insert( to, to_distance, node ); } //Found a shorter Path -> Update distance - else if ( toDistance < _forwardHeap.GetKey( to ) ) { - _forwardHeap.GetData( to ).parent = node; - _forwardHeap.DecreaseKey( to, toDistance ); + else if ( to_distance < forward_heap.GetKey( to ) ) { + forward_heap.GetData( to ).parent = node; + forward_heap.DecreaseKey( to, to_distance ); //new parent } } } } - inline void UnpackPath(const std::vector & packedPath, std::vector<_PathData> & unpackedPath) const { - const unsigned sizeOfPackedPath = packedPath.size(); - std::stack > recursionStack; + inline void UnpackPath( + const std::vector & packed_path, + std::vector<_PathData> & unpacked_path + ) const { + const unsigned packed_path_size = packed_path.size(); + std::stack > recursion_stack; //We have to push the path in reverse order onto the stack because it's LIFO. - for(unsigned i = sizeOfPackedPath-1; i > 0; --i){ - recursionStack.push(std::make_pair(packedPath[i-1], packedPath[i])); + for(unsigned i = packed_path_size-1; i > 0; --i){ + recursion_stack.push(std::make_pair(packed_path[i-1], packed_path[i])); } std::pair edge; - while(!recursionStack.empty()) { - edge = recursionStack.top(); - recursionStack.pop(); + while(!recursion_stack.empty()) { + edge = recursion_stack.top(); + recursion_stack.pop(); - EdgeID smallestEdge = SPECIAL_EDGEID; - int smallestWeight = INT_MAX; + EdgeID smaller_edge_id = SPECIAL_EDGEID; + int edge_weight = INT_MAX; for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ const int weight = facade->GetEdgeData(eit).distance; - if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ - smallestEdge = eit; - smallestWeight = weight; + if( + (facade->GetTarget(eit) == edge.second) && + (weight < edge_weight) && + facade->GetEdgeData(eit).forward + ){ + smaller_edge_id = eit; + edge_weight = weight; } } - if(smallestEdge == SPECIAL_EDGEID){ - for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ + if(smaller_edge_id == SPECIAL_EDGEID){ + for(EdgeID eit = facade->BeginEdges(edge.second); eit < facade->EndEdges(edge.second); ++eit){ const int weight = facade->GetEdgeData(eit).distance; - if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ - smallestEdge = eit; - smallestWeight = weight; + if( + (facade->GetTarget(eit) == edge.first) && + (weight < edge_weight) && + facade->GetEdgeData(eit).backward + ){ + smaller_edge_id = eit; + edge_weight = weight; } } } - BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge id invalid"); + BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); - const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if(ed.shortcut) {//unpack - const NodeID middle = ed.id; + const NodeID middle_node_id = ed.id; //again, we need to this in reversed order - recursionStack.push(std::make_pair(middle, edge.second)); - recursionStack.push(std::make_pair(edge.first, middle)); + recursion_stack.push(std::make_pair(middle_node_id, edge.second)); + recursion_stack.push(std::make_pair(edge.first, middle_node_id)); } else { BOOST_ASSERT_MSG(!ed.shortcut, "edge must be a shortcut"); - unpackedPath.push_back( + unpacked_path.push_back( _PathData( ed.id, facade->GetNameIndexFromEdgeID(ed.id), @@ -172,79 +182,95 @@ public: } } - inline void UnpackEdge(const NodeID s, const NodeID t, std::vector & unpackedPath) const { - std::stack > recursionStack; - recursionStack.push(std::make_pair(s,t)); + inline void UnpackEdge( + const NodeID s, + const NodeID t, + std::vector & unpacked_path + ) const { + std::stack > recursion_stack; + recursion_stack.push(std::make_pair(s,t)); std::pair edge; - while(!recursionStack.empty()) { - edge = recursionStack.top(); - recursionStack.pop(); + while(!recursion_stack.empty()) { + edge = recursion_stack.top(); + recursion_stack.pop(); - EdgeID smallestEdge = SPECIAL_EDGEID; - int smallestWeight = INT_MAX; + EdgeID smaller_edge_id = SPECIAL_EDGEID; + int edge_weight = INT_MAX; for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ const int weight = facade->GetEdgeData(eit).distance; - if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ - smallestEdge = eit; - smallestWeight = weight; + if( + (facade->GetTarget(eit) == edge.second) && + (weight < edge_weight) && + facade->GetEdgeData(eit).forward + ){ + smaller_edge_id = eit; + edge_weight = weight; } } - if(smallestEdge == SPECIAL_EDGEID){ + if(smaller_edge_id == SPECIAL_EDGEID){ for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ const int weight = facade->GetEdgeData(eit).distance; - if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ - smallestEdge = eit; - smallestWeight = weight; + if( + (facade->GetTarget(eit) == edge.first) && + (weight < edge_weight) && + facade->GetEdgeData(eit).backward + ){ + smaller_edge_id = eit; + edge_weight = weight; } } } - BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge weight invalid"); + BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); - const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); + const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if(ed.shortcut) {//unpack - const NodeID middle = ed.id; + const NodeID middle_node_id = ed.id; //again, we need to this in reversed order - recursionStack.push(std::make_pair(middle, edge.second)); - recursionStack.push(std::make_pair(edge.first, middle)); + recursion_stack.push(std::make_pair(middle_node_id, edge.second)); + recursion_stack.push(std::make_pair(edge.first, middle_node_id)); } else { BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut"); - unpackedPath.push_back(edge.first ); + unpacked_path.push_back(edge.first ); } } - unpackedPath.push_back(t); + unpacked_path.push_back(t); } inline void RetrievePackedPathFromHeap( - SearchEngineData::QueryHeap & _fHeap, - SearchEngineData::QueryHeap & _bHeap, - const NodeID middle, - std::vector & packedPath + SearchEngineData::QueryHeap & forward_heap, + SearchEngineData::QueryHeap & reverse_heap, + const NodeID middle_node_id, + std::vector & packed_path ) const { - NodeID pathNode = middle; - while(pathNode != _fHeap.GetData(pathNode).parent) { - pathNode = _fHeap.GetData(pathNode).parent; - packedPath.push_back(pathNode); + NodeID current_node_id = middle_node_id; + while(current_node_id != forward_heap.GetData(current_node_id).parent) { + current_node_id = forward_heap.GetData(current_node_id).parent; + packed_path.push_back(current_node_id); } - std::reverse(packedPath.begin(), packedPath.end()); - packedPath.push_back(middle); - pathNode = middle; - while (pathNode != _bHeap.GetData(pathNode).parent){ - pathNode = _bHeap.GetData(pathNode).parent; - packedPath.push_back(pathNode); + std::reverse(packed_path.begin(), packed_path.end()); + packed_path.push_back(middle_node_id); + current_node_id = middle_node_id; + while (current_node_id != reverse_heap.GetData(current_node_id).parent){ + current_node_id = reverse_heap.GetData(current_node_id).parent; + packed_path.push_back(current_node_id); } } - inline void RetrievePackedPathFromSingleHeap(SearchEngineData::QueryHeap & search_heap, const NodeID middle, std::vector& packed_path) const { - NodeID pathNode = middle; - while(pathNode != search_heap.GetData(pathNode).parent) { - pathNode = search_heap.GetData(pathNode).parent; - packed_path.push_back(pathNode); +//TODO: reorder parameters + inline void RetrievePackedPathFromSingleHeap( + SearchEngineData::QueryHeap & search_heap, + const NodeID middle_node_id, + std::vector& packed_path + ) const { + NodeID current_node_id = middle_node_id; + while(current_node_id != search_heap.GetData(current_node_id).parent) { + current_node_id = search_heap.GetData(current_node_id).parent; + packed_path.push_back(current_node_id); } } }; - #endif /* BASICROUTINGINTERFACE_H_ */ From 375c81d38dc96ebd99bd5343cb7f922e538381f0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 13:09:33 +0200 Subject: [PATCH 036/127] further refactoring of variable names --- RoutingAlgorithms/BasicRoutingInterface.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index a11a75a2a..0f6c71e45 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -228,8 +228,12 @@ public: if(ed.shortcut) {//unpack const NodeID middle_node_id = ed.id; //again, we need to this in reversed order - recursion_stack.push(std::make_pair(middle_node_id, edge.second)); - recursion_stack.push(std::make_pair(edge.first, middle_node_id)); + recursion_stack.push( + std::make_pair(middle_node_id, edge.second) + ); + recursion_stack.push( + std::make_pair(edge.first, middle_node_id) + ); } else { BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut"); unpacked_path.push_back(edge.first ); From 8d689974a733e99f78f01df663b8bde3849ad852 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 13:11:23 +0200 Subject: [PATCH 037/127] further refactoring of variable names --- RoutingAlgorithms/BasicRoutingInterface.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 0f6c71e45..47db5bf5c 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -64,7 +64,7 @@ public: } } - if( (distance-edge_expansion_offset) > *upper_bound){ + if( (distance-edge_expansion_offset) > *upper_bound ){ forward_heap.DeleteAll(); return; } @@ -76,8 +76,8 @@ public: ++edge ) { const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); - bool backwardDirectionFlag = (!forward_direction) ? data.forward : data.backward; - if(backwardDirectionFlag) { + bool reverse_flag = (!forward_direction) ? data.forward : data.backward; + if( reverse_flag ) { const NodeID to = facade->GetTarget(edge); const int edge_weight = data.distance; @@ -94,7 +94,7 @@ public: for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool forward_directionFlag = (forward_direction ? data.forward : data.backward ); - if(forward_directionFlag) { + if( forward_directionFlag ) { const NodeID to = facade->GetTarget(edge); const int edge_weight = data.distance; @@ -147,7 +147,7 @@ public: } } - if(smaller_edge_id == SPECIAL_EDGEID){ + if( SPECIAL_EDGEID == smaller_edge_id ){ for(EdgeID eit = facade->BeginEdges(edge.second); eit < facade->EndEdges(edge.second); ++eit){ const int weight = facade->GetEdgeData(eit).distance; if( @@ -209,7 +209,7 @@ public: } } - if(smaller_edge_id == SPECIAL_EDGEID){ + if( SPECIAL_EDGEID == smaller_edge_id ){ for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ const int weight = facade->GetEdgeData(eit).distance; if( From 0b0fb249bfd19f2d9f4b7204c992a2b5f3340752 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 13:13:06 +0200 Subject: [PATCH 038/127] further refactoring of variable names --- RoutingAlgorithms/BasicRoutingInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 47db5bf5c..6dcdcdd1b 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -163,7 +163,7 @@ public: BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); - if(ed.shortcut) {//unpack + if( ed.shortcut ) {//unpack const NodeID middle_node_id = ed.id; //again, we need to this in reversed order recursion_stack.push(std::make_pair(middle_node_id, edge.second)); From b343a17b294f5a8f077eccfed13107bee51fe488 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 18:30:47 +0200 Subject: [PATCH 039/127] Implementation of internal data storage --- DataStructures/NodeInformationHelpDesk.h | 2 +- DataStructures/SearchEngine.h | 1 - DataStructures/StaticGraph.h | 18 +- DataStructures/StaticRTree.h | 8 +- Library/OSRM.cpp | 80 ++---- Library/OSRM.h | 1 - Plugins/LocatePlugin.h | 2 - Plugins/NearestPlugin.h | 3 +- Plugins/ViaRoutePlugin.h | 2 +- RoutingAlgorithms/AlternativePathRouting.h | 40 +-- RoutingAlgorithms/BasicRoutingInterface.h | 4 +- RoutingAlgorithms/ShortestPathRouting.h | 20 +- Server/DataStructures/BaseDataFacade.h | 4 +- Server/DataStructures/InternalDataFacade.h | 267 +++++++++++++++++++-- Server/DataStructures/SharedDataFacade.h | 11 +- Util/GraphLoader.h | 3 +- Util/IniFile.h | 4 + 17 files changed, 340 insertions(+), 130 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index ff539024f..bdaa21b35 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -203,7 +203,7 @@ private: std::vector m_name_ID_list; std::vector m_turn_instruction_list; - StaticRTree * m_ro_rtree_ptr; + StaticRTree * m_ro_rtree_ptr; const unsigned m_number_of_nodes; const unsigned m_check_sum; }; diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 894ea8715..34bbeb556 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define SEARCHENGINE_H #include "Coordinate.h" -#include "NodeInformationHelpDesk.h" #include "SearchEngineData.h" #include "PhantomNodes.h" #include "QueryEdge.h" diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index b193b3ef4..3558fad9a 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -137,32 +137,32 @@ public: return _numEdges; } - unsigned GetOutDegree( const NodeIterator &n ) const { + unsigned GetOutDegree( const NodeIterator n ) const { return BeginEdges(n)-EndEdges(n) - 1; } - inline NodeIterator GetTarget( const EdgeIterator &e ) const { + inline NodeIterator GetTarget( const EdgeIterator e ) const { return NodeIterator( _edges[e].target ); } - inline EdgeDataT &GetEdgeData( const EdgeIterator &e ) { + inline EdgeDataT &GetEdgeData( const EdgeIterator e ) { return _edges[e].data; } - const EdgeDataT &GetEdgeData( const EdgeIterator &e ) const { + const EdgeDataT &GetEdgeData( const EdgeIterator e ) const { return _edges[e].data; } - EdgeIterator BeginEdges( const NodeIterator &n ) const { + EdgeIterator BeginEdges( const NodeIterator n ) const { return EdgeIterator( _nodes[n].firstEdge ); } - EdgeIterator EndEdges( const NodeIterator &n ) const { + EdgeIterator EndEdges( const NodeIterator n ) const { return EdgeIterator( _nodes[n+1].firstEdge ); } //searches for a specific edge - EdgeIterator FindEdge( const NodeIterator &from, const NodeIterator &to ) const { + EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const { EdgeIterator smallestEdge = SPECIAL_EDGEID; EdgeWeight smallestWeight = UINT_MAX; for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) { @@ -175,12 +175,12 @@ public: return smallestEdge; } - EdgeIterator FindEdgeInEitherDirection( const NodeIterator &from, const NodeIterator &to ) const { + EdgeIterator FindEdgeInEitherDirection( const NodeIterator from, const NodeIterator to ) const { EdgeIterator tmp = FindEdge( from, to ); return (UINT_MAX != tmp ? tmp : FindEdge( to, from )); } - EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator &from, const NodeIterator &to, bool & result ) const { + EdgeIterator FindEdgeIndicateIfReverse( const NodeIterator from, const NodeIterator to, bool & result ) const { EdgeIterator tmp = FindEdge( from, to ); if(UINT_MAX == tmp) { tmp = FindEdge( to, from ); diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 5bf27b434..82e4f726a 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -410,11 +410,10 @@ public: //Read-only operation for queries explicit StaticRTree( - const std::string & node_filename, - const std::string & leaf_filename - ) : m_leaf_node_filename(leaf_filename) { + const boost::filesystem::path & node_file, + const boost::filesystem::path & leaf_file + ) : m_leaf_node_filename(leaf_file.string()) { //open tree node file and load into RAM. - boost::filesystem::path node_file(node_filename); if ( !boost::filesystem::exists( node_file ) ) { throw OSRMException("ram index file does not exist"); @@ -432,7 +431,6 @@ public: tree_node_file.close(); //open leaf node file and store thread specific pointer - boost::filesystem::path leaf_file(leaf_filename); if ( !boost::filesystem::exists( leaf_file ) ) { throw OSRMException("mem index file does not exist"); } diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 9ece830f9..3e4509362 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -20,74 +20,26 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRM.h" -OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) - : use_shared_memory(use_shared_memory) +OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) : + use_shared_memory(use_shared_memory) { + + if( !testDataFile(server_ini_path) ){ + std::string error_message(server_ini_path); + error_message += " not found"; + throw OSRMException(error_message); + } + boost::filesystem::path base_path = boost::filesystem::absolute(server_ini_path).parent_path(); + IniFile server_config(server_ini_path); + if( !use_shared_memory ) { - if( !testDataFile(server_ini_path) ){ - std::string error_message(server_ini_path); - error_message += " not found"; - throw OSRMException(error_message); - } - - IniFile serverConfig(server_ini_path); - - boost::filesystem::path base_path = - boost::filesystem::absolute(server_ini_path).parent_path(); - - if ( !serverConfig.Holds("hsgrData")) { - throw OSRMException("no ram index file name in server ini"); - } - if ( !serverConfig.Holds("ramIndex") ) { - throw OSRMException("no mem index file name in server ini"); - } - if ( !serverConfig.Holds("fileIndex") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("nodesData") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !serverConfig.Holds("edgesData") ) { - throw OSRMException("no edges file name in server ini"); - } - - boost::filesystem::path hsgr_path = boost::filesystem::absolute( - serverConfig.GetParameter("hsgrData"), - base_path + query_data_facade = new InternalDataFacade( + server_config, base_path ); - - boost::filesystem::path ram_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("ramIndex"), - base_path - ); - - boost::filesystem::path file_index_path = boost::filesystem::absolute( - serverConfig.GetParameter("fileIndex"), - base_path - ); - - boost::filesystem::path node_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("nodesData"), - base_path - ); - boost::filesystem::path edge_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("edgesData"), - base_path - ); - boost::filesystem::path name_data_path = boost::filesystem::absolute( - serverConfig.GetParameter("namesData"), - base_path - ); - boost::filesystem::path timestamp_path = boost::filesystem::absolute( - serverConfig.GetParameter("timestamp"), - base_path - ); - - query_data_facade = new InternalDataFacade(); - } else { - //TODO: fetch pointers from shared memory - query_data_facade = new SharedDataFacade(); + query_data_facade = new SharedDataFacade( + server_config, base_path + ); } //The following plugins handle all requests. diff --git a/Library/OSRM.h b/Library/OSRM.h index c58958934..df2c8ad93 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -63,7 +63,6 @@ private: PluginMap plugin_map; const bool use_shared_memory; - }; #endif //OSRM_H diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 35261a9d5..ed2a89a4e 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -22,8 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define LOCATEPLUGIN_H_ #include "BasePlugin.h" -#include "../DataStructures/NodeInformationHelpDesk.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" //locates the nearest node in the road network for a given coordinate. diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 45c1c90d0..903d0e745 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -22,8 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #define NearestPlugin_H_ #include "BasePlugin.h" - -#include "../DataStructures/NodeInformationHelpDesk.h" +#include "../DataStructures/PhantomNodes.h" #include "../Util/StringUtil.h" /* diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 598d67c1d..dc9dd7918 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -115,7 +115,7 @@ public: ( routeParameters.alternateRoute ) && (1 == rawRoute.segmentEndCoordinates.size()) ) { - search_engine_ptr->alternative_paths( + search_engine_ptr->alternative_path( rawRoute.segmentEndCoordinates[0], rawRoute ); diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 96c0a3737..167954739 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -74,14 +74,20 @@ public: std::vector reverse_search_space; //Initialize Queues, semi-expensive because access to TSS invokes a system call - super::_queryData.InitializeOrClearFirstThreadLocalStorage(); - super::_queryData.InitializeOrClearSecondThreadLocalStorage(); - super::_queryData.InitializeOrClearThirdThreadLocalStorage(); + engine_working_data.InitializeOrClearFirstThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); + engine_working_data.InitializeOrClearSecondThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); + engine_working_data.InitializeOrClearThirdThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); - QueryHeap & forward_heap1 = *(super::_queryData.forwardHeap); - QueryHeap & reverse_heap1 = *(super::_queryData.backwardHeap); - QueryHeap & forward_heap2 = *(super::_queryData.forwardHeap2); - QueryHeap & reverse_heap2 = *(super::_queryData.backwardHeap2); + QueryHeap & forward_heap1 = *(engine_working_data.forwardHeap); + QueryHeap & reverse_heap1 = *(engine_working_data.backwardHeap); + QueryHeap & forward_heap2 = *(engine_working_data.forwardHeap2); + QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); int upper_bound_to_shortest_path_distance = INT_MAX; NodeID middle_node = UINT_MAX; @@ -219,12 +225,14 @@ private: const int offset, const std::vector & packed_shortest_path) { //compute and unpack and by exploring search spaces from v and intersecting against queues //only half-searches have to be done at this stage - super::_queryData.InitializeOrClearSecondThreadLocalStorage(); + engine_working_data.InitializeOrClearSecondThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); - QueryHeap & existingForwardHeap = *super::_queryData.forwardHeap; - QueryHeap & existingBackwardHeap = *super::_queryData.backwardHeap; - QueryHeap & newForwardHeap = *super::_queryData.forwardHeap2; - QueryHeap & newBackwardHeap = *super::_queryData.backwardHeap2; + QueryHeap & existingForwardHeap = *engine_working_data.forwardHeap; + QueryHeap & existingBackwardHeap = *engine_working_data.backwardHeap; + QueryHeap & newForwardHeap = *engine_working_data.forwardHeap2; + QueryHeap & newBackwardHeap = *engine_working_data.backwardHeap2; std::vector < NodeID > packed_s_v_path; std::vector < NodeID > packed_v_t_path; @@ -517,10 +525,12 @@ private: lengthOfPathT_Test_Path += unpackedUntilDistance; //Run actual T-Test query and compare if distances equal. - super::_queryData.InitializeOrClearThirdThreadLocalStorage(); + engine_working_data.InitializeOrClearThirdThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); - QueryHeap& forward_heap3 = *super::_queryData.forwardHeap3; - QueryHeap& backward_heap3 = *super::_queryData.backwardHeap3; + QueryHeap& forward_heap3 = *engine_working_data.forwardHeap3; + QueryHeap& backward_heap3 = *engine_working_data.backwardHeap3; int _upperBound = INT_MAX; NodeID middle = UINT_MAX; forward_heap3.Insert(s_P, 0, s_P); diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 6dcdcdd1b..8661e9747 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -125,7 +125,9 @@ public: //We have to push the path in reverse order onto the stack because it's LIFO. for(unsigned i = packed_path_size-1; i > 0; --i){ - recursion_stack.push(std::make_pair(packed_path[i-1], packed_path[i])); + recursion_stack.push( + std::make_pair(packed_path[i-1], packed_path[i]) + ); } std::pair edge; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 3426772d9..2678a38fb 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -54,14 +54,20 @@ public: std::vector packedPath1; std::vector packedPath2; - super::_queryData.InitializeOrClearFirstThreadLocalStorage(); - super::_queryData.InitializeOrClearSecondThreadLocalStorage(); - super::_queryData.InitializeOrClearThirdThreadLocalStorage(); + engine_working_data.InitializeOrClearFirstThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); + engine_working_data.InitializeOrClearSecondThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); + engine_working_data.InitializeOrClearThirdThreadLocalStorage( + super::facade->GetNumberOfNodes() + ); - QueryHeap & forward_heap1 = *(super::_queryData.forwardHeap); - QueryHeap & reverse_heap1 = *(super::_queryData.backwardHeap); - QueryHeap & forward_heap2 = *(super::_queryData.forwardHeap2); - QueryHeap & reverse_heap2 = *(super::_queryData.backwardHeap2); + QueryHeap & forward_heap1 = *(engine_working_data.forwardHeap); + QueryHeap & reverse_heap1 = *(engine_working_data.backwardHeap); + QueryHeap & forward_heap2 = *(engine_working_data.forwardHeap2); + QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); //Get distance to next pair of target nodes. BOOST_FOREACH(const PhantomNodes & phantomNodePair, phantomNodesVector) { diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index b3f1aee97..d04a17b66 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. //Exposes all data access interfaces to the algorithms via base class ptr +#include "../../Contractor/EdgeBasedGraphFactory.h" #include "../../DataStructures/Coordinate.h" #include "../../DataStructures/PhantomNodes.h" #include "../../DataStructures/TurnInstructions.h" @@ -35,8 +36,9 @@ or see http://www.gnu.org/licenses/agpl.txt. template class BaseDataFacade { public: + typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; typedef EdgeDataT EdgeData; - BaseDataFacade() { } + BaseDataFacade( ) { } virtual ~BaseDataFacade() { } //search graph access diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index e4fc77525..86500ae8e 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -25,67 +25,300 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BaseDataFacade.h" +#include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/QueryNode.h" +#include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" +#include "../../DataStructures/StaticRTree.h" +#include "../../Util/BoostFilesystemFix.h" +#include "../../Util/GraphLoader.h" +#include "../../Util/IniFile.h" +#include "../../Util/SimpleLogger.h" template class InternalDataFacade : public BaseDataFacade { private: + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + + InternalDataFacade() { } + + unsigned m_check_sum; + unsigned m_number_of_nodes; + QueryGraph * m_query_graph; + std::string m_timestamp; + + std::vector m_coordinate_list; + std::vector m_via_node_list; + std::vector m_name_ID_list; + std::vector m_turn_instruction_list; + StaticRTree * m_static_rtree; + + + void LoadTimestamp(const boost::filesystem::path & timestamp_path) { + if( boost::filesystem::exists(timestamp_path) ) { + SimpleLogger().Write() << "Loading Timestamp"; + boost::filesystem::ifstream timestampInStream( timestamp_path ); + if(!timestampInStream) { + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + } + getline(timestampInStream, m_timestamp); + timestampInStream.close(); + } + if(m_timestamp.empty()) { + m_timestamp = "n/a"; + } + if(25 < m_timestamp.length()) { + m_timestamp.resize(25); + } + } + + void LoadGraph(const boost::filesystem::path & hsgr_path) { + ShMemVector node_list; + ShMemVector< typename QueryGraph::_StrEdge> edge_list; + + m_number_of_nodes = readHSGRFromStream( + hsgr_path, + node_list, + edge_list, + &m_check_sum + ); + BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); + BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed"); + + m_query_graph = new QueryGraph(node_list, edge_list); + SimpleLogger().Write() << "Data checksum is " << m_check_sum; + } + + void LoadNodeAndEdgeInformation( + const boost::filesystem::path nodes_file, + const boost::filesystem::path edges_file + ) { + boost::filesystem::ifstream nodes_input_stream( + nodes_file, + std::ios::binary + ); + boost::filesystem::ifstream edges_input_stream( + edges_file, + std::ios::binary + ); + + SimpleLogger().Write(logDEBUG) << "Loading node data"; + NodeInfo current_node; + while(!nodes_input_stream.eof()) { + nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + m_coordinate_list.push_back( + FixedPointCoordinate( + current_node.lat, + current_node.lon + ) + ); + } + std::vector(m_coordinate_list).swap(m_coordinate_list); + nodes_input_stream.close(); + + SimpleLogger().Write(logDEBUG) + << "Loading edge data"; + unsigned number_of_edges = 0; + edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); + m_via_node_list.resize(number_of_edges); + m_name_ID_list.resize(number_of_edges); + m_turn_instruction_list.resize(number_of_edges); + + OriginalEdgeData current_edge_data; + for(unsigned i = 0; i < number_of_edges; ++i) { + edges_input_stream.read( + (char*)&(current_edge_data), + sizeof(OriginalEdgeData) + ); + m_via_node_list[i] = current_edge_data.viaNode; + m_name_ID_list[i] = current_edge_data.nameID; + m_turn_instruction_list[i] = current_edge_data.turnInstruction; + } + edges_input_stream.close(); + SimpleLogger().Write(logDEBUG) + << "Loaded " << number_of_edges << " orig edges"; + SimpleLogger().Write(logDEBUG) << "Opening NN indices"; + } + + void LoadRTree( + const boost::filesystem::path & ram_index_path, + const boost::filesystem::path & file_index_path + ) { + m_static_rtree = new StaticRTree( + ram_index_path, + file_index_path + ); + } public: + ~InternalDataFacade() { + delete m_query_graph; + delete m_static_rtree; + } + + InternalDataFacade( + const IniFile & server_config, + const boost::filesystem::path & base_path + ) { + //check contents of config file + if ( !server_config.Holds("hsgrData")) { + throw OSRMException("no ram index file name in server ini"); + } + if ( !server_config.Holds("ramIndex") ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( !server_config.Holds("fileIndex") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !server_config.Holds("nodesData") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !server_config.Holds("edgesData") ) { + throw OSRMException("no edges file name in server ini"); + } + + //generate paths of data files + boost::filesystem::path hsgr_path = boost::filesystem::absolute( + server_config.GetParameter("hsgrData"), + base_path + ); + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + server_config.GetParameter("ramIndex"), + base_path + ); + boost::filesystem::path file_index_path = boost::filesystem::absolute( + server_config.GetParameter("fileIndex"), + base_path + ); + boost::filesystem::path node_data_path = boost::filesystem::absolute( + server_config.GetParameter("nodesData"), + base_path + ); + boost::filesystem::path edge_data_path = boost::filesystem::absolute( + server_config.GetParameter("edgesData"), + base_path + ); + boost::filesystem::path name_data_path = boost::filesystem::absolute( + server_config.GetParameter("namesData"), + base_path + ); + boost::filesystem::path timestamp_path = boost::filesystem::absolute( + server_config.GetParameter("timestamp"), + base_path + ); + + // check if data files empty + if ( 0 == boost::filesystem::file_size( node_data_path ) ) { + throw OSRMException("nodes file is empty"); + } + if ( 0 == boost::filesystem::file_size( edge_data_path ) ) { + throw OSRMException("edges file is empty"); + } + + + //load data + SimpleLogger().Write() << "loading graph data"; + LoadGraph(hsgr_path); + LoadNodeAndEdgeInformation(node_data_path, edge_data_path); + LoadRTree(ram_index_path, file_index_path); + LoadTimestamp(hsgr_path); + } + //search graph access - unsigned GetNumberOfNodes() const { return 0; } + unsigned GetNumberOfNodes() const { + return m_query_graph->GetNumberOfNodes(); + } - unsigned GetNumberOfEdges() const { return 0; } + unsigned GetNumberOfEdges() const { + return m_query_graph->GetNumberOfEdges(); + } - unsigned GetOutDegree( const NodeID n ) const { return 0; } + unsigned GetOutDegree( const NodeID n ) const { + return m_query_graph->GetOutDegree(n); + } - NodeID GetTarget( const EdgeID e ) const { return 0; } + NodeID GetTarget( const EdgeID e ) const { + return m_query_graph->GetTarget(e); } - EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + EdgeDataT &GetEdgeData( const EdgeID e ) { + return m_query_graph->GetEdgeData(e); + } - const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + const EdgeDataT &GetEdgeData( const EdgeID e ) const { + return m_query_graph->GetEdgeData(e); + } - EdgeID BeginEdges( const NodeID n ) const { return 0; } + EdgeID BeginEdges( const NodeID n ) const { + return m_query_graph->BeginEdges(n); + } - EdgeID EndEdges( const NodeID n ) const { return 0; } + EdgeID EndEdges( const NodeID n ) const { + return m_query_graph->EndEdges(n); + } //searches for a specific edge - EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + EdgeID FindEdge( const NodeID from, const NodeID to ) const { + return m_query_graph->FindEdge(from, to); + } EdgeID FindEdgeInEitherDirection( const NodeID from, const NodeID to - ) const { return 0; } + ) const { + return m_query_graph->FindEdgeInEitherDirection(from, to); + } EdgeID FindEdgeIndicateIfReverse( const NodeID from, const NodeID to, bool & result - ) const { return 0; } + ) const { + return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); + } //node and edge information access FixedPointCoordinate GetCoordinateOfNode( const unsigned id - ) const { return FixedPointCoordinate(); }; + ) const { + const NodeID node = m_via_node_list.at(id); + return m_coordinate_list.at(node); + }; TurnInstruction GetTurnInstructionForEdgeID( const unsigned id - ) const { return 0; } + ) const { + return m_turn_instruction_list.at(id); + } bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate& input_coordinate, FixedPointCoordinate& result, const unsigned zoom_level = 18 - ) const { return false; } + ) const { + return m_static_rtree->LocateClosestEndPointForCoordinate( + input_coordinate, + result, + zoom_level + ); + } bool FindPhantomNodeForCoordinate( const FixedPointCoordinate & input_coordinate, PhantomNode & resulting_phantom_node, const unsigned zoom_level - ) const { return false; } + ) const { + return m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, + zoom_level + ); + } - unsigned GetCheckSum() const { return 0; } + unsigned GetCheckSum() const { return m_check_sum; } unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; @@ -95,7 +328,7 @@ public: ) const { return; }; std::string GetTimestamp() const { - return ""; + return m_timestamp; }; }; diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 34700bca5..66f870f10 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -26,13 +26,22 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BaseDataFacade.h" #include "../../DataStructures/StaticGraph.h" +#include "../../Util/BoostFilesystemFix.h" +#include "../../Util/IniFile.h" +#include "../../Util/SimpleLogger.h" template class SharedDataFacade : public BaseDataFacade { private: - + SharedDataFacade() { } public: + SharedDataFacade( + const IniFile & configuration, + const boost::filesystem::path base_path + ) { + //TODO: load data + } //search graph access unsigned GetNumberOfNodes() const { return 0; } diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 4c9621302..23fd40236 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -403,12 +403,11 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, s template unsigned readHSGRFromStream( - const std::string & hsgr_filename, + const boost::filesystem::path & hsgr_file, std::vector & node_list, std::vector & edge_list, unsigned * check_sum ) { - boost::filesystem::path hsgr_file(hsgr_filename); if ( !boost::filesystem::exists( hsgr_file ) ) { throw OSRMException("hsgr file does not exist"); } diff --git a/Util/IniFile.h b/Util/IniFile.h index 582cc273c..a4923cea4 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -64,6 +64,10 @@ public: return parameters.Find(key); } + std::string GetParameter(const std::string & key) const { + return parameters.Find(key); + } + bool Holds(const std::string & key) const { return parameters.Holds(key); } From c4463036c3fdd6d6fe5e1acd885eb2e2fba3a062 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 20 Sep 2013 19:41:45 +0200 Subject: [PATCH 040/127] Workarounds for various boost versions and their lovely quirks --- Util/BoostFileSystemFix.h | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Util/BoostFileSystemFix.h diff --git a/Util/BoostFileSystemFix.h b/Util/BoostFileSystemFix.h new file mode 100644 index 000000000..d7299d660 --- /dev/null +++ b/Util/BoostFileSystemFix.h @@ -0,0 +1,53 @@ +/* + 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 BOOST_FILE_SYSTEM_FIX_H +#define BOOST_FILE_SYSTEM_FIX_H + +#include + +//This is one big workaround for latest boost renaming woes. + +#if BOOST_FILESYSTEM_VERSION < 3 +#warning Boost Installation with Filesystem3 missing, activating workaround +#include +namespace boost { +namespace filesystem { +inline path temp_directory_path() { + char * buffer; + buffer = tmpnam (NULL); + + return path(buffer); +} + +inline path unique_path(const path&) { + return temp_directory_path(); +} + +} +} + +#endif + +#ifndef BOOST_FILESYSTEM_VERSION +#define BOOST_FILESYSTEM_VERSION 3 +#endif + +#endif /* BOOST_FILE_SYSTEM_FIX_H */ From 71fcfa4935d81bd2df7457bce756cf17ba52dcf3 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 20 Sep 2013 21:05:47 +0200 Subject: [PATCH 041/127] fixing include typos --- Server/DataStructures/InternalDataFacade.h | 2 +- Server/DataStructures/SharedDataFacade.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 86500ae8e..d62f789db 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -30,7 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/StaticGraph.h" #include "../../DataStructures/StaticRTree.h" -#include "../../Util/BoostFilesystemFix.h" +#include "../../Util/BoostFileSystemFix.h" #include "../../Util/GraphLoader.h" #include "../../Util/IniFile.h" #include "../../Util/SimpleLogger.h" diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 66f870f10..1fdb3afa1 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BaseDataFacade.h" #include "../../DataStructures/StaticGraph.h" -#include "../../Util/BoostFilesystemFix.h" +#include "../../Util/BoostFileSystemFix.h" #include "../../Util/IniFile.h" #include "../../Util/SimpleLogger.h" From e72dc38d77ab495a98299f177fd8406b5481eb0c Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 20 Sep 2013 21:07:57 +0200 Subject: [PATCH 042/127] Styleguide refactoring --- Util/StringUtil.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 29b125578..afe61d218 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -125,7 +125,10 @@ static inline void doubleToString(const double value, std::string & output){ boost::spirit::karma::generate(sink, boost::spirit::karma::double_, value); } -static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string & output){ +static inline void doubleToStringWithTwoDigitsBehindComma( + const double 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 char buffer[12] ; @@ -133,11 +136,19 @@ static inline void doubleToStringWithTwoDigitsBehindComma(const double value, st output = buffer ; } -inline void replaceAll(std::string &s, const std::string &sub, const std::string &other) { +inline void replaceAll( + std::string & s, + const std::string & sub, + const std::string & other +) { boost::replace_all(s, sub, other); } -inline void stringSplit(const std::string &s, const char delim, std::vector& result) { +inline void stringSplit( + const std::string &s, + const char delim, + std::vector& result +) { boost::split(result, s, boost::is_any_of(std::string(&delim))); } @@ -159,7 +170,10 @@ inline std::string HTMLDeEntitize( std::string & result) { return result; } -inline bool StringStartsWith(const std::string & input, const std::string & prefix) { +inline bool StringStartsWith( + const std::string & input, + const std::string & prefix +) { return boost::starts_with(input, prefix); } From 5679b5862f32065611aedd749d45794e8fdf3f2a Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 20 Sep 2013 21:40:27 +0200 Subject: [PATCH 043/127] superflous typedef changed meaning of name for GCC --- DataStructures/SearchEngineData.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h index 43ee455e3..921140e6a 100644 --- a/DataStructures/SearchEngineData.h +++ b/DataStructures/SearchEngineData.h @@ -37,12 +37,12 @@ struct _HeapData { _HeapData( NodeID p ) : parent(p) { } }; -typedef StaticGraph QueryGraph; +// typedef StaticGraph QueryGraph; typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage > QueryHeapType; typedef boost::thread_specific_ptr SearchEngineHeapPtr; struct SearchEngineData { - typedef QueryGraph QueryGraph; + typedef StaticGraph QueryGraph; typedef QueryHeapType QueryHeap; SearchEngineData() { } From 4520e04d371cb0b009cce274f7b8a9bd1fe9b191 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 21 Sep 2013 21:51:07 +0200 Subject: [PATCH 044/127] added auxiliary Empty() function --- DataStructures/BinaryHeap.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index b1e838b8f..5978cd889 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -125,6 +125,10 @@ public: return static_cast( heap.size() - 1 ); } + bool Empty() const { + return 0 == Size(); + } + void Insert( NodeID node, Weight weight, const Data &data ) { HeapElement element; element.index = static_cast(insertedNodes.size()); From 9812eaaca7334d9d82edb8a2e20e4d95e7d1c4b2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 21 Sep 2013 22:10:41 +0200 Subject: [PATCH 045/127] Refactoring shortest path search variable names --- RoutingAlgorithms/ShortestPathRouting.h | 266 +++++++++++++++++------- 1 file changed, 186 insertions(+), 80 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 2678a38fb..6b6d6b1db 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -32,27 +32,41 @@ class ShortestPathRouting : public BasicRoutingInterface{ typedef BasicRoutingInterface super; typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; + public: - ShortestPathRouting( DataFacadeT * facade, SearchEngineData & engine_working_data) : super(facade), engine_working_data(engine_working_data) {} + ShortestPathRouting( + DataFacadeT * facade, + SearchEngineData & engine_working_data + ) : + super(facade), + engine_working_data(engine_working_data) + {} ~ShortestPathRouting() {} - void operator()(std::vector & phantomNodesVector, RawRouteData & rawRouteData) const { - BOOST_FOREACH(const PhantomNodes & phantomNodePair, phantomNodesVector) { - if(!phantomNodePair.AtLeastOnePhantomNodeIsUINTMAX()) { - rawRouteData.lengthOfShortestPath = rawRouteData.lengthOfAlternativePath = INT_MAX; + void operator()( + std::vector & phantom_nodes_vector, + RawRouteData & raw_route_data + ) const { + BOOST_FOREACH( + const PhantomNodes & phantom_node_pair, + phantom_nodes_vector + ){ + if(!phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX()) { + raw_route_data.lengthOfShortestPath = INT_MAX; + raw_route_data.lengthOfAlternativePath = INT_MAX; return; } } int distance1 = 0; int distance2 = 0; - bool searchFrom1stStartNode = true; - bool searchFrom2ndStartNode = true; + bool search_from_1st_node = true; + bool search_from_2nd_node = true; NodeID middle1 = UINT_MAX; NodeID middle2 = UINT_MAX; - std::vector packedPath1; - std::vector packedPath2; + std::vector packed_path1; + std::vector packed_path2; engine_working_data.InitializeOrClearFirstThreadLocalStorage( super::facade->GetNumberOfNodes() @@ -70,139 +84,231 @@ public: QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); //Get distance to next pair of target nodes. - BOOST_FOREACH(const PhantomNodes & phantomNodePair, phantomNodesVector) { + BOOST_FOREACH(const PhantomNodes & phantom_node_pair, phantom_nodes_vector){ forward_heap1.Clear(); forward_heap2.Clear(); reverse_heap1.Clear(); reverse_heap2.Clear(); - int _localUpperbound1 = INT_MAX; - int _localUpperbound2 = INT_MAX; + int local_upper_bound1 = INT_MAX; + int local_upper_bound2 = INT_MAX; middle1 = UINT_MAX; middle2 = UINT_MAX; //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); - forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); - // INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1); + if(search_from_1st_node) { + forward_heap1.Insert( + phantom_node_pair.startPhantom.edgeBasedNode, + -phantom_node_pair.startPhantom.weight1, + phantom_node_pair.startPhantom.edgeBasedNode + ); + // INFO("fw1: " << phantom_node_pair.startPhantom.edgeBasedNode << "´, w: " << -phantom_node_pair.startPhantom.weight1); + forward_heap2.Insert( + phantom_node_pair.startPhantom.edgeBasedNode, + -phantom_node_pair.startPhantom.weight1, + phantom_node_pair.startPhantom.edgeBasedNode + ); + // INFO("fw2: " << phantom_node_pair.startPhantom.edgeBasedNode << "´, w: " << -phantom_node_pair.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); - forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); - // INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2); + if(phantom_node_pair.startPhantom.isBidirected() && search_from_2nd_node) { + forward_heap1.Insert( + phantom_node_pair.startPhantom.edgeBasedNode+1, + -phantom_node_pair.startPhantom.weight2, + phantom_node_pair.startPhantom.edgeBasedNode+1 + ); + // INFO("fw1: " << phantom_node_pair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantom_node_pair.startPhantom.weight2); + forward_heap2.Insert( + phantom_node_pair.startPhantom.edgeBasedNode+1, + -phantom_node_pair.startPhantom.weight2, + phantom_node_pair.startPhantom.edgeBasedNode+1 + ); + // INFO("fw2: " << phantom_node_pair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantom_node_pair.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 ); - 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 ); + reverse_heap1.Insert( + phantom_node_pair.targetPhantom.edgeBasedNode, + phantom_node_pair.targetPhantom.weight1, + phantom_node_pair.targetPhantom.edgeBasedNode + ); + // INFO("rv1: " << phantom_node_pair.targetPhantom.edgeBasedNode << ", w;" << phantom_node_pair.targetPhantom.weight1 ); + if(phantom_node_pair.targetPhantom.isBidirected() ) { + reverse_heap2.Insert( + phantom_node_pair.targetPhantom.edgeBasedNode+1, + phantom_node_pair.targetPhantom.weight2, + phantom_node_pair.targetPhantom.edgeBasedNode+1 + ); + // INFO("rv2: " << phantom_node_pair.targetPhantom.edgeBasedNode+1 << ", w;" << phantom_node_pair.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); + const int forward_offset = phantom_node_pair.startPhantom.weight1 + (phantom_node_pair.startPhantom.isBidirected() ? phantom_node_pair.startPhantom.weight2 : 0); + const int reverse_offset = phantom_node_pair.targetPhantom.weight1 + (phantom_node_pair.targetPhantom.isBidirected() ? phantom_node_pair.targetPhantom.weight2 : 0); //run two-Target Dijkstra routing step. while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){ - if(0 < forward_heap1.Size()){ - super::RoutingStep(forward_heap1, reverse_heap1, &middle1, &_localUpperbound1, forward_offset, true); + if( !forward_heap1.Empty()){ + super::RoutingStep( + forward_heap1, + reverse_heap1, + &middle1, + &local_upper_bound1, + forward_offset, + true + ); } - if(0 < reverse_heap1.Size() ){ - super::RoutingStep(reverse_heap1, forward_heap1, &middle1, &_localUpperbound1, reverse_offset, false); + if( !reverse_heap1.Empty() ){ + super::RoutingStep( + reverse_heap1, + forward_heap1, + &middle1, + &local_upper_bound1, + reverse_offset, + false + ); } } - if(0 < reverse_heap2.Size()) { + if( !reverse_heap2.Empty() ) { while(0 < (forward_heap2.Size() + reverse_heap2.Size() )){ - if(0 < forward_heap2.Size()){ - super::RoutingStep(forward_heap2, reverse_heap2, &middle2, &_localUpperbound2, forward_offset, true); + if( !forward_heap2.Empty() ){ + super::RoutingStep( + forward_heap2, + reverse_heap2, + &middle2, + &local_upper_bound2, + forward_offset, + true + ); } - if(0 < reverse_heap2.Size()){ - super::RoutingStep(reverse_heap2, forward_heap2, &middle2, &_localUpperbound2, reverse_offset, false); + if( !reverse_heap2.Empty() ){ + super::RoutingStep( + reverse_heap2, + forward_heap2, + &middle2, + &local_upper_bound2, + reverse_offset, + false + ); } } } //No path found for both target nodes? - if((INT_MAX == _localUpperbound1) && (INT_MAX == _localUpperbound2)) { - rawRouteData.lengthOfShortestPath = rawRouteData.lengthOfAlternativePath = INT_MAX; + if( + (INT_MAX == local_upper_bound1) && + (INT_MAX == local_upper_bound2) + ) { + raw_route_data.lengthOfShortestPath = INT_MAX; + raw_route_data.lengthOfAlternativePath = INT_MAX; return; } if(UINT_MAX == middle1) { - searchFrom1stStartNode = false; + search_from_1st_node = false; } if(UINT_MAX == middle2) { - searchFrom2ndStartNode = false; + search_from_2nd_node = false; } //Was at most one of the two paths not found? - assert(!(INT_MAX == distance1 && INT_MAX == distance2)); + assert(INT_MAX != distance1 || INT_MAX != distance2); //Unpack paths if they exist - std::vector temporaryPackedPath1; - std::vector temporaryPackedPath2; - if(INT_MAX != _localUpperbound1) { - super::RetrievePackedPathFromHeap(forward_heap1, reverse_heap1, middle1, temporaryPackedPath1); + std::vector temporary_packed_path1; + std::vector temporary_packed_path2; + if(INT_MAX != local_upper_bound1) { + super::RetrievePackedPathFromHeap( + forward_heap1, + reverse_heap1, + middle1, + temporary_packed_path1 + ); } - if(INT_MAX != _localUpperbound2) { - super::RetrievePackedPathFromHeap(forward_heap2, reverse_heap2, middle2, temporaryPackedPath2); + if(INT_MAX != local_upper_bound2) { + super::RetrievePackedPathFromHeap( + forward_heap2, + reverse_heap2, + middle2, + temporary_packed_path2 + ); } //if one of the paths was not found, replace it with the other one. - if(0 == temporaryPackedPath1.size()) { - temporaryPackedPath1.insert(temporaryPackedPath1.end(), temporaryPackedPath2.begin(), temporaryPackedPath2.end()); - _localUpperbound1 = _localUpperbound2; + if( temporary_packed_path1.empty() ) { + temporary_packed_path1.insert( + temporary_packed_path1.end(), + temporary_packed_path2.begin(), + temporary_packed_path2.end() + ); + local_upper_bound1 = local_upper_bound2; } - if(0 == temporaryPackedPath2.size()) { - temporaryPackedPath2.insert(temporaryPackedPath2.end(), temporaryPackedPath1.begin(), temporaryPackedPath1.end()); - _localUpperbound2 = _localUpperbound1; + if( temporary_packed_path2.empty() ) { + temporary_packed_path2.insert( + temporary_packed_path2.end(), + temporary_packed_path1.begin(), + temporary_packed_path1.end() + ); + local_upper_bound2 = local_upper_bound1; } - assert(0 < temporaryPackedPath1.size() && 0 < temporaryPackedPath2.size()); + assert(temporary_packed_path1.empty() && temporary_packed_path2.empty()); //Plug paths together, s.t. end of packed path is begin of temporary packed path - if(0 < packedPath1.size() && 0 < packedPath2.size() ) { - if( *(temporaryPackedPath1.begin()) == *(temporaryPackedPath2.begin())) { + if( !packed_path1.empty() && !packed_path2.empty() ) { + if( temporary_packed_path1.front() == temporary_packed_path2.front() ) { //both new route segments start with the same node, thus one of the packedPath must go. - assert( (packedPath1.size() == packedPath2.size() ) || (*(packedPath1.end()-1) != *(packedPath2.end()-1)) ); - if( *(packedPath1.end()-1) == *(temporaryPackedPath1.begin())) { - packedPath2.clear(); - packedPath2.insert(packedPath2.end(), packedPath1.begin(), packedPath1.end()); + assert( (packed_path1.size() == packed_path2.size() ) || (*(packed_path1.end()-1) != *(packed_path2.end()-1)) ); + if( packed_path1.back() == temporary_packed_path1.front()) { + packed_path2.clear(); + packed_path2.insert( + packed_path2.end(), + packed_path1.begin(), + packed_path1.end() + ); distance2 = distance1; } else { - packedPath1.clear(); - packedPath1.insert(packedPath1.end(), packedPath2.begin(), packedPath2.end()); + packed_path1.clear(); + packed_path1.insert( + packed_path1.end(), + packed_path2.begin(), + packed_path2.end() + ); distance1 = distance2; } } else { //packed paths 1 and 2 may need to switch. - if(*(packedPath1.end()-1) != *(temporaryPackedPath1.begin())) { - packedPath1.swap(packedPath2); + if(packed_path1.back() != temporary_packed_path1.front()) { + packed_path1.swap(packed_path2); std::swap(distance1, distance2); } } } - packedPath1.insert(packedPath1.end(), temporaryPackedPath1.begin(), temporaryPackedPath1.end()); - packedPath2.insert(packedPath2.end(), temporaryPackedPath2.begin(), temporaryPackedPath2.end()); + packed_path1.insert( + packed_path1.end(), + temporary_packed_path1.begin(), + temporary_packed_path1.end() + ); + packed_path2.insert( + packed_path2.end(), + temporary_packed_path2.begin(), + temporary_packed_path2.end() + ); - if( (packedPath1.back() == packedPath2.back()) && phantomNodePair.targetPhantom.isBidirected() ) { - - NodeID lastNodeID = packedPath2.back(); - searchFrom1stStartNode &= !(lastNodeID == phantomNodePair.targetPhantom.edgeBasedNode+1); - searchFrom2ndStartNode &= !(lastNodeID == phantomNodePair.targetPhantom.edgeBasedNode); + if( + (packed_path1.back() == packed_path2.back()) && + phantom_node_pair.targetPhantom.isBidirected() + ) { + NodeID last_node_id = packed_path2.back(); + search_from_1st_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode+1); + search_from_2nd_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode); } - distance1 += _localUpperbound1; - distance2 += _localUpperbound2; + distance1 += local_upper_bound1; + distance2 += local_upper_bound2; } - if(distance1 > distance2){ - std::swap(packedPath1, packedPath2); + if( distance1 > distance2 ){ + std::swap( packed_path1, packed_path2 ); } - remove_consecutive_duplicates_from_vector(packedPath1); - super::UnpackPath(packedPath1, rawRouteData.computedShortestPath); - rawRouteData.lengthOfShortestPath = std::min(distance1, distance2); + remove_consecutive_duplicates_from_vector(packed_path1); + super::UnpackPath(packed_path1, raw_route_data.computedShortestPath); + raw_route_data.lengthOfShortestPath = std::min(distance1, distance2); return; } }; From d1e1190cbda5666bccbd9c701c33e5779d87c320 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 21 Sep 2013 22:18:27 +0200 Subject: [PATCH 046/127] replace cassert by boost asserts --- RoutingAlgorithms/ShortestPathRouting.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 6b6d6b1db..d62920c13 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -23,8 +23,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SHORTESTPATHROUTING_H_ #define SHORTESTPATHROUTING_H_ -#include "BasicRoutingInterface.h" +#include +#include "BasicRoutingInterface.h" #include "../DataStructures/SearchEngineData.h" template @@ -206,7 +207,10 @@ public: } //Was at most one of the two paths not found? - assert(INT_MAX != distance1 || INT_MAX != distance2); + BOOST_ASSERT_MSG( + (INT_MAX != distance1 || INT_MAX != distance2), + "no path found" + ); //Unpack paths if they exist std::vector temporary_packed_path1; @@ -247,13 +251,22 @@ public: local_upper_bound2 = local_upper_bound1; } - assert(temporary_packed_path1.empty() && temporary_packed_path2.empty()); + BOOST_ASSERT_MSG( + temporary_packed_path1.empty() && + temporary_packed_path2.empty(), + "tempory packed paths not empty" + ); //Plug paths together, s.t. end of packed path is begin of temporary packed path if( !packed_path1.empty() && !packed_path2.empty() ) { if( temporary_packed_path1.front() == temporary_packed_path2.front() ) { //both new route segments start with the same node, thus one of the packedPath must go. - assert( (packed_path1.size() == packed_path2.size() ) || (*(packed_path1.end()-1) != *(packed_path2.end()-1)) ); + BOOST_ASSERT_MSG( + (packed_path1.size() == packed_path2.size() ) || + (packed_path1.back() != packed_path2.back() ), + "packed paths must be different" + ); + if( packed_path1.back() == temporary_packed_path1.front()) { packed_path2.clear(); packed_path2.insert( From b5b262c7229077996ed016aa3cc9a4711adb5aa2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 21 Sep 2013 22:21:33 +0200 Subject: [PATCH 047/127] further minor refactoring --- RoutingAlgorithms/ShortestPathRouting.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index d62920c13..b5157fb1d 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -85,7 +85,10 @@ public: QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); //Get distance to next pair of target nodes. - BOOST_FOREACH(const PhantomNodes & phantom_node_pair, phantom_nodes_vector){ + BOOST_FOREACH( + const PhantomNodes & phantom_node_pair, + phantom_nodes_vector + ){ forward_heap1.Clear(); forward_heap2.Clear(); reverse_heap1.Clear(); reverse_heap2.Clear(); int local_upper_bound1 = INT_MAX; @@ -260,7 +263,8 @@ public: //Plug paths together, s.t. end of packed path is begin of temporary packed path if( !packed_path1.empty() && !packed_path2.empty() ) { if( temporary_packed_path1.front() == temporary_packed_path2.front() ) { - //both new route segments start with the same node, thus one of the packedPath must go. + //both new route segments start with the same node + //thus, one of the packedPath must go. BOOST_ASSERT_MSG( (packed_path1.size() == packed_path2.size() ) || (packed_path1.back() != packed_path2.back() ), @@ -286,7 +290,7 @@ public: } } else { //packed paths 1 and 2 may need to switch. - if(packed_path1.back() != temporary_packed_path1.front()) { + if( packed_path1.back() != temporary_packed_path1.front()) { packed_path1.swap(packed_path2); std::swap(distance1, distance2); } @@ -307,7 +311,7 @@ public: (packed_path1.back() == packed_path2.back()) && phantom_node_pair.targetPhantom.isBidirected() ) { - NodeID last_node_id = packed_path2.back(); + const NodeID last_node_id = packed_path2.back(); search_from_1st_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode+1); search_from_2nd_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode); } From a9fdabf92668687827299968ca1da0592fbd69a6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 22 Sep 2013 22:18:54 +0200 Subject: [PATCH 048/127] moving common code into function --- RoutingAlgorithms/ShortestPathRouting.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index b5157fb1d..f3c4686b5 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -34,6 +34,10 @@ class ShortestPathRouting : public BasicRoutingInterface{ typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; + int ComputeEdgeOffset(const PhantomNode & phantom) { + return phantom.weight1 + (phantom.isBidirected() ? phantom.weight2 : 0); + } + public: ShortestPathRouting( DataFacadeT * facade, @@ -142,8 +146,12 @@ public: ); // INFO("rv2: " << phantom_node_pair.targetPhantom.edgeBasedNode+1 << ", w;" << phantom_node_pair.targetPhantom.weight2 ); } - const int forward_offset = phantom_node_pair.startPhantom.weight1 + (phantom_node_pair.startPhantom.isBidirected() ? phantom_node_pair.startPhantom.weight2 : 0); - const int reverse_offset = phantom_node_pair.targetPhantom.weight1 + (phantom_node_pair.targetPhantom.isBidirected() ? phantom_node_pair.targetPhantom.weight2 : 0); + const int forward_offset = ComputeEdgeOffset( + phantom_node_pair.startPhantom + ); + const int reverse_offset = ComputeEdgeOffset( + phantom_node_pair.targetPhantom + ); //run two-Target Dijkstra routing step. while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){ From 8afad5614a83909774b8562ea574b914d544478d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 22 Sep 2013 22:29:03 +0200 Subject: [PATCH 049/127] const'ing new function --- RoutingAlgorithms/ShortestPathRouting.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index f3c4686b5..80570b0fb 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -34,7 +34,7 @@ class ShortestPathRouting : public BasicRoutingInterface{ typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; - int ComputeEdgeOffset(const PhantomNode & phantom) { + int ComputeEdgeOffset(const PhantomNode & phantom) const { return phantom.weight1 + (phantom.isBidirected() ? phantom.weight2 : 0); } @@ -270,7 +270,10 @@ public: //Plug paths together, s.t. end of packed path is begin of temporary packed path if( !packed_path1.empty() && !packed_path2.empty() ) { - if( temporary_packed_path1.front() == temporary_packed_path2.front() ) { + if( + temporary_packed_path1.front() == + temporary_packed_path2.front() + ) { //both new route segments start with the same node //thus, one of the packedPath must go. BOOST_ASSERT_MSG( @@ -328,13 +331,12 @@ public: distance2 += local_upper_bound2; } - if( distance1 > distance2 ){ + if( distance1 > distance2 ) { std::swap( packed_path1, packed_path2 ); } remove_consecutive_duplicates_from_vector(packed_path1); super::UnpackPath(packed_path1, raw_route_data.computedShortestPath); raw_route_data.lengthOfShortestPath = std::min(distance1, distance2); - return; } }; From aaa9f89550be2a9bbcd7918a55f360205a838991 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 11:35:33 +0200 Subject: [PATCH 050/127] removing old data facade, good riddance --- DataStructures/NodeInformationHelpDesk.h | 211 ----------------------- 1 file changed, 211 deletions(-) delete mode 100644 DataStructures/NodeInformationHelpDesk.h diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h deleted file mode 100644 index bdaa21b35..000000000 --- a/DataStructures/NodeInformationHelpDesk.h +++ /dev/null @@ -1,211 +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. - */ - -//TODO: Umbauen in Private Data Facade - -#ifndef NODEINFORMATIONHELPDESK_H_ -#define NODEINFORMATIONHELPDESK_H_ - -#include "QueryNode.h" -#include "PhantomNodes.h" -#include "StaticRTree.h" -#include "../Contractor/EdgeBasedGraphFactory.h" -#include "../Util/OSRMException.h" -#include "../typedefs.h" - -#include -#include -#include -#include - -#include -#include -#include - -typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; - -class NodeInformationHelpDesk : boost::noncopyable { - -public: - NodeInformationHelpDesk( - const std::string & ram_index_filename, - const std::string & mem_index_filename, - const std::string & nodes_filename, - const std::string & edges_filename, - const unsigned m_number_of_nodes, - const unsigned m_check_sum - ) : - m_number_of_nodes(m_number_of_nodes), - m_check_sum(m_check_sum) - { - if ( ram_index_filename.empty() ) { - throw OSRMException("no ram index file name in server ini"); - } - if ( mem_index_filename.empty() ) { - throw OSRMException("no mem index file name in server ini"); - } - if ( nodes_filename.empty() ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( edges_filename.empty() ) { - throw OSRMException("no edges file name in server ini"); - } - - m_ro_rtree_ptr = new StaticRTree( - ram_index_filename, - mem_index_filename - ); - BOOST_ASSERT_MSG( - 0 == m_coordinate_list.size(), - "Coordinate vector not empty" - ); - - LoadNodesAndEdges(nodes_filename, edges_filename); - } - - ~NodeInformationHelpDesk() { - delete m_ro_rtree_ptr; - } - - inline FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const { - const NodeID node = m_via_node_list.at(id); - return m_coordinate_list.at(node); - } - - inline unsigned GetNameIndexFromEdgeID(const unsigned id) const { - return m_name_ID_list.at(id); - } - - inline TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const { - return m_turn_instruction_list.at(id); - } - - inline NodeID GetNumberOfNodes() const { - return m_number_of_nodes; - } - - inline bool LocateClosestEndPointForCoordinate( - const FixedPointCoordinate& input_coordinate, - FixedPointCoordinate& result, - const unsigned zoom_level = 18 - ) const { - bool found_node = m_ro_rtree_ptr->LocateClosestEndPointForCoordinate( - input_coordinate, - result, zoom_level - ); - return found_node; - } - - inline bool FindPhantomNodeForCoordinate( - const FixedPointCoordinate & input_coordinate, - PhantomNode & resulting_phantom_node, - const unsigned zoom_level - ) const { - return m_ro_rtree_ptr->FindPhantomNodeForCoordinate( - input_coordinate, - resulting_phantom_node, - zoom_level - ); - } - - inline unsigned GetCheckSum() const { - return m_check_sum; - } - -private: - void LoadNodesAndEdges( - const std::string & nodes_filename, - const std::string & edges_filename - ) { - boost::filesystem::path nodes_file(nodes_filename); - if ( !boost::filesystem::exists( nodes_file ) ) { - throw OSRMException("nodes file does not exist"); - } - if ( 0 == boost::filesystem::file_size( nodes_file ) ) { - throw OSRMException("nodes file is empty"); - } - - boost::filesystem::path edges_file(edges_filename); - if ( !boost::filesystem::exists( edges_file ) ) { - throw OSRMException("edges file does not exist"); - } - if ( 0 == boost::filesystem::file_size( edges_file ) ) { - throw OSRMException("edges file is empty"); - } - - boost::filesystem::ifstream nodes_input_stream( - nodes_file, - std::ios::binary - ); - - boost::filesystem::ifstream edges_input_stream( - edges_file, std::ios::binary - ); - - SimpleLogger().Write(logDEBUG) - << "Loading node data"; - NodeInfo current_node; - while(!nodes_input_stream.eof()) { - nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); - m_coordinate_list.push_back( - FixedPointCoordinate( - current_node.lat, - current_node.lon - ) - ); - } - std::vector(m_coordinate_list).swap(m_coordinate_list); - nodes_input_stream.close(); - - SimpleLogger().Write(logDEBUG) - << "Loading edge data"; - unsigned number_of_edges = 0; - edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); - m_via_node_list.resize(number_of_edges); - m_name_ID_list.resize(number_of_edges); - m_turn_instruction_list.resize(number_of_edges); - - OriginalEdgeData current_edge_data; - for(unsigned i = 0; i < number_of_edges; ++i) { - edges_input_stream.read( - (char*)&(current_edge_data), - sizeof(OriginalEdgeData) - ); - m_via_node_list[i] = current_edge_data.viaNode; - m_name_ID_list[i] = current_edge_data.nameID; - m_turn_instruction_list[i] = current_edge_data.turnInstruction; - } - edges_input_stream.close(); - SimpleLogger().Write(logDEBUG) - << "Loaded " << number_of_edges << " orig edges"; - SimpleLogger().Write(logDEBUG) << "Opening NN indices"; - } - - std::vector m_coordinate_list; - std::vector m_via_node_list; - std::vector m_name_ID_list; - std::vector m_turn_instruction_list; - - StaticRTree * m_ro_rtree_ptr; - const unsigned m_number_of_nodes; - const unsigned m_check_sum; -}; - -#endif /*NODEINFORMATIONHELPDESK_H_*/ From 973d115edf7cc9ff1c2d203ba690357c8dcf6107 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 13:30:21 +0200 Subject: [PATCH 051/127] further implementation of the vector interface for shared memory --- DataStructures/SharedMemoryVectorWrapper.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 0773466d9..76dbc4786 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -67,6 +67,10 @@ public: m_size(size) { } + DataT & at(const std::size_t index) { + return m_ptr[index]; + } + ShMemIterator begin() const { return ShMemIterator(m_ptr); } From 83655e9aefaeee1939aeadbf4357245ca9ffe371 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 13:41:53 +0200 Subject: [PATCH 052/127] Added list of all data types in shared memory --- Server/DataStructures/SharedDataType.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 83cc6da81..e9a9c948a 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -21,6 +21,26 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SHARED_DATA_TYPE_H_ #define SHARED_DATA_TYPE_H_ -enum SharedDataType { NAMES_INDEX, NAMES_LIST }; +enum SharedDataType { + NAMES_INDEX = 0, + NAME_INDEX_SIZE, + NAMES_LIST, + NAMES_LIST_SIZE, + VIA_NODE_LIST, + VIA_NODE_LIST_SIZE, + GRAPH_NODE_LIST, + GRAPH_NODE_LIST_SIZE, + GRAPH_EDGE_LIST, + GRAPH_EDGE_LIST_SIZE, + CHECK_SUM, + TIME_STAMP, + TIME_STAMP_SIZE, + COORDINATE_LIST, + COORDINATE_LIST_SIZE, + TURN_INSTRUCTION_LIST, + TURN_INSTRUCTION_LIST_SIZE, + R_SEARCH_TREE, + R_SEARCH_TREE_SIZE +}; #endif /* SHARED_DATA_TYPE_H_ */ From 248a239c7b05eb7242068f6dcf19d8671fd41227 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 13:42:35 +0200 Subject: [PATCH 053/127] Remove old facade from UUID generation --- Util/UUID.cpp.in | 16 ++++------------ Util/UUID.h | 1 - cmake/UUID-Config.cmake | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Util/UUID.cpp.in b/Util/UUID.cpp.in index cd3bc38b1..64be75b05 100644 --- a/Util/UUID.cpp.in +++ b/Util/UUID.cpp.in @@ -23,13 +23,14 @@ or see http://www.gnu.org/licenses/agpl.txt. #cmakedefine01 HAS64BITS #cmakedefine MD5PREPARE "${MD5PREPARE}" #cmakedefine MD5RTREE "${MD5RTREE}" -#cmakedefine MD5NODEINFO "${MD5NODEINFO}" #cmakedefine MD5GRAPH "${MD5GRAPH}" #cmakedefine MD5OBJECTS "${MD5OBJECTS}" UUID::UUID() : magic_number(1297240911) { - md5_prepare[32] = md5_tree[32] = md5_nodeinfo[32] = md5_graph[32] = - md5_objects[32] = '\0'; + md5_prepare[32] = + md5_tree[32] = + md5_graph[32] = + md5_objects[32] = '\0'; boost::uuids::name_generator gen(named_uuid); std::string temp_string(__DATE__); @@ -39,8 +40,6 @@ UUID::UUID() : magic_number(1297240911) { 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); @@ -83,13 +82,6 @@ bool UUID::TestRTree(const UUID & other) const { return std::equal(md5_tree, md5_tree+32, other.md5_tree); } -bool UUID::TestNodeInfo(const UUID & other) const { - if(!other.IsMagicNumberOK()) { - throw OSRMException("nodes file misses magic number. Check or reprocess the file"); - } - return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo); -} - bool UUID::TestQueryObjects(const UUID & other) const { if(!other.IsMagicNumberOK()) { throw OSRMException("missing magic number. Check or reprocess the file"); diff --git a/Util/UUID.h b/Util/UUID.h index d609d4592..20ae3a2da 100644 --- a/Util/UUID.h +++ b/Util/UUID.h @@ -51,7 +51,6 @@ private: const unsigned magic_number; char md5_prepare[33]; char md5_tree[33]; - char md5_nodeinfo[33]; char md5_graph[33]; char md5_objects[33]; diff --git a/cmake/UUID-Config.cmake b/cmake/UUID-Config.cmake index 3a4d819ef..5528d340f 100644 --- a/cmake/UUID-Config.cmake +++ b/cmake/UUID-Config.cmake @@ -4,7 +4,6 @@ if (EXISTS ${OLDFILE}) endif() file(MD5 ${SOURCE_DIR}/createHierarchy.cpp MD5PREPARE) file(MD5 ${SOURCE_DIR}/DataStructures/StaticRTree.h MD5RTREE) -file(MD5 ${SOURCE_DIR}/DataStructures/NodeInformationHelpDesk.h MD5NODEINFO) file(MD5 ${SOURCE_DIR}/Util/GraphLoader.h MD5GRAPH) file(MD5 ${SOURCE_DIR}/Server/DataStructures/InternalDataFacade.h MD5OBJECTS) From cce5d775ded0ca52853da11c3d3b9021a062ab26 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:01:30 +0200 Subject: [PATCH 054/127] Further stl interface implementation --- DataStructures/SharedMemoryVectorWrapper.h | 47 +++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 76dbc4786..6e44cb39c 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -21,10 +21,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SHARED_MEMORY_VECTOR_WRAPPER_H #define SHARED_MEMORY_VECTOR_WRAPPER_H +#include "../Util/SimpleLogger.h" + #include #include #include +#include #include #include @@ -60,17 +63,36 @@ private: boost::shared_ptr m_ptr; std::size_t m_size; - SharedMemoryWrapper() {}; public: - SharedMemoryWrapper(const DataT * ptr, std::size_t size) : + SharedMemoryWrapper() : + m_size(0) + { } + + SharedMemoryWrapper(DataT * ptr, std::size_t size) : m_ptr(ptr), m_size(size) { } + void swap(const SharedMemoryWrapper & other) { + std::swap( m_size, other.m_size); + std::swap( m_ptr , other.m_ptr ); + } + + // void SetData(const DataT * ptr, const std::size_t size) { + // BOOST_ASSERT_MSG( 0 == m_size, "vector not empty"); + // BOOST_ASSERT_MSG( 0 < size , "new vector empty"); + // m_ptr.reset(ptr); + // m_size = size; + // } + DataT & at(const std::size_t index) { return m_ptr[index]; } + const DataT & at(const std::size_t index) const { + return m_ptr[index]; + } + ShMemIterator begin() const { return ShMemIterator(m_ptr); } @@ -85,16 +107,21 @@ public: BOOST_ASSERT_MSG(index < m_size, "invalid size"); return m_ptr[index]; } + + const DataT & operator[](const int index) const { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + return m_ptr[index]; + } }; -template -class ShMemVector : public - boost::conditional< - SharedMemory, - SharedMemoryWrapper, - std::vector - >::type -{ }; +template +struct ShM { + typedef typename boost::conditional< + UseSharedMemory, + SharedMemoryWrapper, + std::vector + >::type vector; + }; #endif //SHARED_MEMORY_VECTOR_WRAPPER_H From 5e2b0ba46cc4fb0276fa3157a40dd37b762cb968 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:02:16 +0200 Subject: [PATCH 055/127] Use typedef instead of base class --- Server/DataStructures/InternalDataFacade.h | 18 +-- Server/DataStructures/SharedDataFacade.h | 175 ++++++++++++++++++--- 2 files changed, 163 insertions(+), 30 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index d62f789db..b62290a3c 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -28,6 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/Coordinate.h" #include "../../DataStructures/QueryNode.h" #include "../../DataStructures/QueryEdge.h" +#include "../../DataStructures/SharedMemoryVectorWrapper.h" #include "../../DataStructures/StaticGraph.h" #include "../../DataStructures/StaticRTree.h" #include "../../Util/BoostFileSystemFix.h" @@ -51,11 +52,11 @@ private: QueryGraph * m_query_graph; std::string m_timestamp; - std::vector m_coordinate_list; - std::vector m_via_node_list; - std::vector m_name_ID_list; - std::vector m_turn_instruction_list; - StaticRTree * m_static_rtree; + typename ShM::vector m_coordinate_list; + typename ShM::vector m_via_node_list; + typename ShM::vector m_name_ID_list; + typename ShM::vector m_turn_instruction_list; + StaticRTree * m_static_rtree; void LoadTimestamp(const boost::filesystem::path & timestamp_path) { @@ -77,8 +78,8 @@ private: } void LoadGraph(const boost::filesystem::path & hsgr_path) { - ShMemVector node_list; - ShMemVector< typename QueryGraph::_StrEdge> edge_list; + typename ShM::vector node_list; + typename ShM< typename QueryGraph::_StrEdge, false>::vector edge_list; m_number_of_nodes = readHSGRFromStream( hsgr_path, @@ -219,7 +220,6 @@ public: throw OSRMException("edges file is empty"); } - //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(hsgr_path); @@ -329,7 +329,7 @@ public: std::string GetTimestamp() const { return m_timestamp; - }; + } }; diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 1fdb3afa1..a67a02bf0 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -26,76 +26,210 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BaseDataFacade.h" #include "../../DataStructures/StaticGraph.h" +#include "../../DataStructures/StaticRTree.h" #include "../../Util/BoostFileSystemFix.h" #include "../../Util/IniFile.h" #include "../../Util/SimpleLogger.h" +#include + template class SharedDataFacade : public BaseDataFacade { private: + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename StaticGraph::_StrNode GraphNode; + typedef typename StaticGraph::_StrEdge GraphEdge; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + + unsigned m_check_sum; + unsigned m_number_of_nodes; + QueryGraph * m_query_graph; + std::string m_timestamp; + + ShM::vector m_coordinate_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + StaticRTree * m_static_rtree; + SharedDataFacade() { } + + void LoadTimestamp() { + uint32_t timestamp_size = *static_cast( + SharedMemoryFactory::Get(TIMESTAMP_SIZE)->Ptr() + ); + timestamp_size = std::min(timestamp_size, 25u); + SharedMemory * search_tree = SharedMemoryFactory::Get(TIMESTAMP); + char * tree_ptr = static_cast( search_tree->Ptr() ); + m_timestamp.resize(timestamp_size); + std::copy(tree_ptr, tree_ptr+timestamp_size, m_timestamp.begin()); + } + + void LoadRTree( + const boost::filesystem::path & file_index_path + ) { + uint32_t tree_size = *static_cast( + SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() + ); + SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); + typedef StaticRTree TreeNode; + TreeNode * tree_ptr = static_cast( search_tree->Ptr() ); + // m_static_rtree = new StaticRTree( + // tree_ptr, + // tree_size, + // file_index_path + // ); + } + + void LoadGraph() { + uint32_t number_of_nodes = *static_cast( + SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() + ); + SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); + GraphNode * graph_nodes_ptr = static_cast( graph_nodes->Ptr() ); + + uint32_t number_of_edges = *static_cast( + SharedMemoryFactory::Get(GRAPH_EDGE_LIST_SIZE)->Ptr() + ); + SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); + GraphEdge * graph_edges_ptr = static_cast( graph_edges->Ptr() ); + + typename ShM::vector node_list(graph_nodes_ptr, number_of_nodes); + typename ShM::vector edge_list(graph_edges_ptr, number_of_edges); + m_query_graph = new QueryGraph( + node_list , + edge_list + ); + + } + + void LoadNodeAndEdgeInformation() { + uint32_t number_of_coordinates = *static_cast( + SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() + ); + FixedPointCoordinate * graph_edges_ptr = static_cast( + SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr() + ); + + } public: SharedDataFacade( - const IniFile & configuration, + const IniFile & server_config, const boost::filesystem::path base_path ) { - //TODO: load data + //check contents of config file + if ( !server_config.Holds("ramIndex") ) { + throw OSRMException("no nodes file name in server ini"); + } + + //generate paths of data files + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + server_config.GetParameter("ramIndex"), + base_path + ); + + //load data + SimpleLogger().Write() << "loading graph data"; + LoadGraph(); + LoadNodeAndEdgeInformation(); + LoadRTree(ram_index_path); + LoadTimestamp(); } //search graph access - unsigned GetNumberOfNodes() const { return 0; } + unsigned GetNumberOfNodes() const { + return m_query_graph->GetNumberOfNodes(); + } - unsigned GetNumberOfEdges() const { return 0; } + unsigned GetNumberOfEdges() const { + return m_query_graph->GetNumberOfEdges(); + } - unsigned GetOutDegree( const NodeID n ) const { return 0; } + unsigned GetOutDegree( const NodeID n ) const { + return m_query_graph->GetOutDegree(n); + } - NodeID GetTarget( const EdgeID e ) const { return 0; } + NodeID GetTarget( const EdgeID e ) const { + return m_query_graph->GetTarget(e); } - EdgeDataT &GetEdgeData( const EdgeID e ) { return EdgeDataT(); } + EdgeDataT &GetEdgeData( const EdgeID e ) { + return m_query_graph->GetEdgeData(e); + } - const EdgeDataT &GetEdgeData( const EdgeID e ) const { return EdgeDataT(); } + const EdgeDataT &GetEdgeData( const EdgeID e ) const { + return m_query_graph->GetEdgeData(e); + } - EdgeID BeginEdges( const NodeID n ) const { return 0; } + EdgeID BeginEdges( const NodeID n ) const { + return m_query_graph->BeginEdges(n); + } - EdgeID EndEdges( const NodeID n ) const { return 0; } + EdgeID EndEdges( const NodeID n ) const { + return m_query_graph->EndEdges(n); + } //searches for a specific edge - EdgeID FindEdge( const NodeID from, const NodeID to ) const { return 0; } + EdgeID FindEdge( const NodeID from, const NodeID to ) const { + return m_query_graph->FindEdge(from, to); + } EdgeID FindEdgeInEitherDirection( const NodeID from, const NodeID to - ) const { return 0; } + ) const { + return m_query_graph->FindEdgeInEitherDirection(from, to); + } EdgeID FindEdgeIndicateIfReverse( const NodeID from, const NodeID to, bool & result - ) const { return 0; } + ) const { + return m_query_graph->FindEdgeIndicateIfReverse(from, to, result); + } //node and edge information access FixedPointCoordinate GetCoordinateOfNode( const unsigned id - ) const { return FixedPointCoordinate(); }; + ) const { + const NodeID node = m_via_node_list.at(id); + return m_coordinate_list.at(node); + }; TurnInstruction GetTurnInstructionForEdgeID( const unsigned id - ) const { return 0; } + ) const { + return m_turn_instruction_list.at(id); + } bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate& input_coordinate, FixedPointCoordinate& result, const unsigned zoom_level = 18 - ) const { return false; } + ) const { + return m_static_rtree->LocateClosestEndPointForCoordinate( + input_coordinate, + result, + zoom_level + ); + } bool FindPhantomNodeForCoordinate( const FixedPointCoordinate & input_coordinate, PhantomNode & resulting_phantom_node, const unsigned zoom_level - ) const { return false; } + ) const { + return m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, + zoom_level + ); + } - unsigned GetCheckSum() const { return 0; } + unsigned GetCheckSum() const { return m_check_sum; } unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; @@ -105,9 +239,8 @@ public: ) const { return; }; std::string GetTimestamp() const { - return ""; - }; - + return m_timestamp; + } }; #endif // SHARED_DATA_FACADE From 396dc219036474aa1fde5b56464b94030d5346b4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:02:45 +0200 Subject: [PATCH 056/127] Give all data types in shared memory --- Server/DataStructures/SharedDataType.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index e9a9c948a..0ca7e5771 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -33,8 +33,8 @@ enum SharedDataType { GRAPH_EDGE_LIST, GRAPH_EDGE_LIST_SIZE, CHECK_SUM, - TIME_STAMP, - TIME_STAMP_SIZE, + TIMESTAMP, + TIMESTAMP_SIZE, COORDINATE_LIST, COORDINATE_LIST_SIZE, TURN_INSTRUCTION_LIST, From 8521b5501f487aab57d5f6cff0f08b3f3bcf7e91 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:03:07 +0200 Subject: [PATCH 057/127] use flexible shared mem interfaces --- DataStructures/StaticGraph.h | 8 ++++---- DataStructures/StaticRTree.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 3558fad9a..c3e89408d 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -85,8 +85,8 @@ public: } StaticGraph( - ShMemVector<_StrNode, UseSharedMemory> & nodes, - ShMemVector<_StrEdge, UseSharedMemory> & edges + typename ShM<_StrNode, UseSharedMemory>::vector & nodes, + typename ShM<_StrEdge, UseSharedMemory>::vector & edges ) { _numNodes = nodes.size(); _numEdges = edges.size(); @@ -196,8 +196,8 @@ private: NodeIterator _numNodes; EdgeIterator _numEdges; - ShMemVector< _StrNode, UseSharedMemory > _nodes; - ShMemVector< _StrEdge, UseSharedMemory > _edges; + typename ShM< _StrNode, UseSharedMemory >::vector _nodes; + typename ShM< _StrEdge, UseSharedMemory >::vector _edges; }; #endif // STATICGRAPH_H_INCLUDED diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 82e4f726a..702022848 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -21,11 +21,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STATICRTREE_H_ #define STATICRTREE_H_ -#include "MercatorUtil.h" #include "Coordinate.h" -#include "PhantomNodes.h" #include "DeallocatingVector.h" #include "HilbertValue.h" +#include "MercatorUtil.h" +#include "PhantomNodes.h" +#include "SharedMemoryFactory.h" +#include "SharedMemoryVectorWrapper.h" + +#include "../Server/DataStructures/SharedDataType.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" @@ -41,6 +45,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include #include #include @@ -59,7 +64,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170; static boost::thread_specific_ptr thread_local_rtree_stream; -template +template class StaticRTree : boost::noncopyable { private: struct RectangleInt2D { @@ -276,7 +281,7 @@ private: } }; - std::vector m_search_tree; + typename ShM::vector m_search_tree; uint64_t m_element_count; const std::string m_leaf_node_filename; @@ -429,7 +434,30 @@ public: m_search_tree.resize(tree_size); tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size); tree_node_file.close(); + //open leaf node file and store thread specific pointer + if ( !boost::filesystem::exists( leaf_file ) ) { + throw OSRMException("mem index file does not exist"); + } + if ( 0 == boost::filesystem::file_size( leaf_file ) ) { + throw OSRMException("mem index file is empty"); + } + boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary ); + leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t)); + leaf_node_file.close(); + + //SimpleLogger().Write() << tree_size << " nodes in search tree"; + //SimpleLogger().Write() << m_element_count << " elements in leafs"; + } + + //Read-only operation for queries + explicit StaticRTree( + const TreeNode * tree_node_ptr, + const uint32_t number_of_nodes, + const boost::filesystem::path & leaf_file + ) : m_leaf_node_filename(leaf_file.string()), + m_search_tree(tree_node_ptr, number_of_nodes) + { //open leaf node file and store thread specific pointer if ( !boost::filesystem::exists( leaf_file ) ) { throw OSRMException("mem index file does not exist"); From 54551d9f37b5f7a4958959d838cf3ae738e7cabf Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:59:13 +0200 Subject: [PATCH 058/127] link against proper objects --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e222cbc..8f7c65c69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,9 +45,10 @@ add_executable(osrm-routed routed.cpp ) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) file(GLOB DescriptorGlob Descriptors/*.cpp) +file(GLOB DatastructureGlob Datastructures/*.cpp) file(GLOB LibOSRMGlob Library/*.cpp) -set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob}) +set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${DatastructureGlob}) add_library(OSRM SHARED ${OSRMSources}) add_library(UUID STATIC Util/UUID.cpp) add_dependencies( UUID UUIDConfigure ) From edce44df9760128c1bac8abfabcc52c70ede100f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:59:43 +0200 Subject: [PATCH 059/127] call facade where appropriate --- RoutingAlgorithms/AlternativePathRouting.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 167954739..3af05736d 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -34,7 +34,7 @@ const double VIAPATH_GAMMA = 0.75; //alternative shares at most 75% with the s template class AlternativeRouting : private BasicRoutingInterface { typedef BasicRoutingInterface super; - typedef SearchEngineData::QueryGraph SearchGraph; + // typedef SearchEngineData::QueryGraph SearchGraph; typedef SearchEngineData::QueryHeap QueryHeap; typedef std::pair SearchSpaceEdge; @@ -372,7 +372,7 @@ private: } for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); edge++ ) { - const typename SearchGraph::EdgeData & data = facade->GetEdgeData(edge); + const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { @@ -462,7 +462,7 @@ private: EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); + typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; @@ -503,7 +503,7 @@ private: EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename SearchGraph::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); + typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); const bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; From 6f71092aa4394d266119ea0d5cf1bce22237ea81 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 19:00:08 +0200 Subject: [PATCH 060/127] adjust facade to pass compilation --- DataStructures/SearchEngine.h | 12 ++++++------ DataStructures/SearchEngineData.h | 15 +++++++++------ DataStructures/SharedMemoryVectorWrapper.h | 9 ++++----- DataStructures/StaticGraph.h | 6 ------ Server/DataStructures/BaseDataFacade.h | 2 +- Server/DataStructures/SharedDataFacade.h | 6 +++--- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 34bbeb556..da8da9438 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -57,13 +57,13 @@ public: }; -SearchEngineHeapPtr SearchEngineData::forwardHeap; -SearchEngineHeapPtr SearchEngineData::backwardHeap; +// SearchEngineHeapPtr SearchEngineData::forwardHeap; +// SearchEngineHeapPtr SearchEngineData::backwardHeap; -SearchEngineHeapPtr SearchEngineData::forwardHeap2; -SearchEngineHeapPtr SearchEngineData::backwardHeap2; +// SearchEngineHeapPtr SearchEngineData::forwardHeap2; +// SearchEngineHeapPtr SearchEngineData::backwardHeap2; -SearchEngineHeapPtr SearchEngineData::forwardHeap3; -SearchEngineHeapPtr SearchEngineData::backwardHeap3; +// SearchEngineHeapPtr SearchEngineData::forwardHeap3; +// SearchEngineHeapPtr SearchEngineData::backwardHeap3; #endif // SEARCHENGINE_H diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h index 921140e6a..7833ad1b0 100644 --- a/DataStructures/SearchEngineData.h +++ b/DataStructures/SearchEngineData.h @@ -38,14 +38,10 @@ struct _HeapData { }; // typedef StaticGraph QueryGraph; -typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage > QueryHeapType; -typedef boost::thread_specific_ptr SearchEngineHeapPtr; struct SearchEngineData { - typedef StaticGraph QueryGraph; - typedef QueryHeapType QueryHeap; - - SearchEngineData() { } + typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage > QueryHeap; + typedef boost::thread_specific_ptr SearchEngineHeapPtr; static SearchEngineHeapPtr forwardHeap; static SearchEngineHeapPtr backwardHeap; @@ -61,4 +57,11 @@ struct SearchEngineData { void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes); }; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3; + #endif // SEARCH_ENGINE_DATA_H diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 6e44cb39c..906f3e34e 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -24,7 +24,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/SimpleLogger.h" #include -#include #include #include @@ -33,9 +32,9 @@ or see http://www.gnu.org/licenses/agpl.txt. template class ShMemIterator : public std::iterator { - boost::shared_ptr p; + DataT * p; public: - ShMemIterator(boost::shared_ptr & x) :p(x) {} + ShMemIterator(DataT * x) : p(x) {} ShMemIterator(const ShMemIterator & mit) : p(mit.p) {} ShMemIterator& operator++() { ++p; @@ -60,7 +59,7 @@ public: template class SharedMemoryWrapper { private: - boost::shared_ptr m_ptr; + DataT * m_ptr; std::size_t m_size; public: @@ -73,7 +72,7 @@ public: m_size(size) { } - void swap(const SharedMemoryWrapper & other) { + void swap( SharedMemoryWrapper & other ) { std::swap( m_size, other.m_size); std::swap( m_ptr , other.m_ptr ); } diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index c3e89408d..ccdb3a214 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -94,12 +94,6 @@ public: _nodes.swap(nodes); _edges.swap(edges); - if( !UseSharedMemory ) { - //Add dummy node to end of _nodes array; - _nodes.push_back(_nodes.back()); - } else { - //TODO: Move to graph array construction - } #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index d04a17b66..d74ef5cbc 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -52,7 +52,7 @@ public: virtual EdgeDataT &GetEdgeData( const EdgeID e ) = 0; - virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; + // virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; virtual EdgeID BeginEdges( const NodeID n ) const = 0; diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index a67a02bf0..305ca850c 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -159,9 +159,9 @@ public: return m_query_graph->GetEdgeData(e); } - const EdgeDataT &GetEdgeData( const EdgeID e ) const { - return m_query_graph->GetEdgeData(e); - } + // const EdgeDataT &GetEdgeData( const EdgeID e ) const { + // return m_query_graph->GetEdgeData(e); + // } EdgeID BeginEdges( const NodeID n ) const { return m_query_graph->BeginEdges(n); From e024ea5ee1e623d8ce5193ebf0e47db788e89854 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 09:39:12 +0200 Subject: [PATCH 061/127] demangling includes --- Descriptors/DescriptionFactory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 80b75a2a3..f7a3c5be0 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -24,7 +24,8 @@ #include "../Algorithms/DouglasPeucker.h" #include "../Algorithms/PolylineCompressor.h" #include "../DataStructures/Coordinate.h" -#include "../DataStructures/SearchEngine.h" +#include "../DataStructures/PhantomNodes.h" +#include "../DataStructures/RawRouteData.h" #include "../DataStructures/SegmentInformation.h" #include "../DataStructures/TurnInstructions.h" #include "../Util/SimpleLogger.h" From 0b5e8a086e642d828f8c23035b69705808043e35 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 09:45:33 +0200 Subject: [PATCH 062/127] remove superflous includes --- Descriptors/BaseDescriptor.h | 1 - Plugins/ViaRoutePlugin.h | 1 - 2 files changed, 2 deletions(-) diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index bf9138029..1120bc13c 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -24,7 +24,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/HashTable.h" #include "../DataStructures/PhantomNodes.h" #include "../DataStructures/RawRouteData.h" -#include "../DataStructures/SearchEngine.h" #include "../Server/BasicDatastructures.h" #include "../Util/StringUtil.h" #include "../typedefs.h" diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index dc9dd7918..0a3c439cd 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Algorithms/ObjectToBase64.h" #include "../DataStructures/QueryEdge.h" -#include "../DataStructures/StaticGraph.h" #include "../DataStructures/SearchEngine.h" #include "../Descriptors/BaseDescriptor.h" #include "../Descriptors/GPXDescriptor.h" From 0977cabc7957088b14046475635ac966524f65e2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 09:55:02 +0200 Subject: [PATCH 063/127] moving fwd decl of static members to root of include graph --- DataStructures/SearchEngineData.h | 7 ------- RoutingAlgorithms/BasicRoutingInterface.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h index 7833ad1b0..5f9e48ab6 100644 --- a/DataStructures/SearchEngineData.h +++ b/DataStructures/SearchEngineData.h @@ -57,11 +57,4 @@ struct SearchEngineData { void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes); }; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3; - #endif // SEARCH_ENGINE_DATA_H diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 8661e9747..ea40ae917 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -35,6 +35,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3; + template class BasicRoutingInterface : boost::noncopyable { protected: From 226dad651b046bd6e73d4b950a6bb87d57e5a8cb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 10:10:50 +0200 Subject: [PATCH 064/127] minor simplification of code --- RoutingAlgorithms/AlternativePathRouting.h | 6 +- RoutingAlgorithms/BasicRoutingInterface.h | 78 ++++++++++++++-------- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 3af05736d..44f3fc6cf 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -372,7 +372,7 @@ private: } for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); edge++ ) { - const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); + const EdgeData & data = facade->GetEdgeData(edge); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); if(forwardDirectionFlag) { @@ -462,7 +462,7 @@ private: EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); + EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; @@ -503,7 +503,7 @@ private: EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); if(UINT_MAX == edgeIDInViaPath) return false; - typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); + EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); const bool IsViaEdgeShortCut = currentEdgeData.shortcut; if (IsViaEdgeShortCut) { const NodeID middleOfViaPath = currentEdgeData.id; diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index ea40ae917..637b0d3cf 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -4,7 +4,7 @@ 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 +the Free Software Foundation; edge_idher version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, @@ -44,6 +44,8 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3; template class BasicRoutingInterface : boost::noncopyable { +private: + typedef typename DataFacadeT::EdgeData EdgeData; protected: DataFacadeT * facade; public: @@ -82,8 +84,8 @@ public: edge < facade->EndEdges(node); ++edge ) { - const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); - bool reverse_flag = (!forward_direction) ? data.forward : data.backward; + const EdgeData & data = facade->GetEdgeData(edge); + const bool reverse_flag = (!forward_direction) ? data.forward : data.backward; if( reverse_flag ) { const NodeID to = facade->GetTarget(edge); const int edge_weight = data.distance; @@ -98,8 +100,12 @@ public: } } - for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { - const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); + for( + EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); + edge < end_edge; + ++edge + ) { + const EdgeData & data = facade->GetEdgeData(edge); bool forward_directionFlag = (forward_direction ? data.forward : data.backward ); if( forward_directionFlag ) { @@ -144,34 +150,42 @@ public: EdgeID smaller_edge_id = SPECIAL_EDGEID; int edge_weight = INT_MAX; - for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ - const int weight = facade->GetEdgeData(eit).distance; + for( + EdgeID edge_id = facade->BeginEdges(edge.first); + edge_id < facade->EndEdges(edge.first); + ++edge_id + ){ + const int weight = facade->GetEdgeData(edge_id).distance; if( - (facade->GetTarget(eit) == edge.second) && - (weight < edge_weight) && - facade->GetEdgeData(eit).forward + (facade->GetTarget(edge_id) == edge.second) && + (weight < edge_weight) && + facade->GetEdgeData(edge_id).forward ){ - smaller_edge_id = eit; + smaller_edge_id = edge_id; edge_weight = weight; } } if( SPECIAL_EDGEID == smaller_edge_id ){ - for(EdgeID eit = facade->BeginEdges(edge.second); eit < facade->EndEdges(edge.second); ++eit){ - const int weight = facade->GetEdgeData(eit).distance; + for( + EdgeID edge_id = facade->BeginEdges(edge.second); + edge_id < facade->EndEdges(edge.second); + ++edge_id + ){ + const int weight = facade->GetEdgeData(edge_id).distance; if( - (facade->GetTarget(eit) == edge.first) && + (facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && - facade->GetEdgeData(eit).backward + facade->GetEdgeData(edge_id).backward ){ - smaller_edge_id = eit; + smaller_edge_id = edge_id; edge_weight = weight; } } } BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); - const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); + const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if( ed.shortcut ) {//unpack const NodeID middle_node_id = ed.id; //again, we need to this in reversed order @@ -206,34 +220,42 @@ public: EdgeID smaller_edge_id = SPECIAL_EDGEID; int edge_weight = INT_MAX; - for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ - const int weight = facade->GetEdgeData(eit).distance; + for( + EdgeID edge_id = facade->BeginEdges(edge.first); + edge_id < facade->EndEdges(edge.first); + ++edge_id + ){ + const int weight = facade->GetEdgeData(edge_id).distance; if( - (facade->GetTarget(eit) == edge.second) && + (facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) && - facade->GetEdgeData(eit).forward + facade->GetEdgeData(edge_id).forward ){ - smaller_edge_id = eit; + smaller_edge_id = edge_id; edge_weight = weight; } } if( SPECIAL_EDGEID == smaller_edge_id ){ - for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ - const int weight = facade->GetEdgeData(eit).distance; + for( + EdgeID edge_id = facade->BeginEdges(edge.second); + edge_id < facade->EndEdges(edge.second); + ++edge_id + ){ + const int weight = facade->GetEdgeData(edge_id).distance; if( - (facade->GetTarget(eit) == edge.first) && + (facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && - facade->GetEdgeData(eit).backward + facade->GetEdgeData(edge_id).backward ){ - smaller_edge_id = eit; + smaller_edge_id = edge_id; edge_weight = weight; } } } BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); - const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); + const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if(ed.shortcut) {//unpack const NodeID middle_node_id = ed.id; //again, we need to this in reversed order From 049c7ad1f09307bf3eef394d0b361956a8a8d0e8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 10:16:07 +0200 Subject: [PATCH 065/127] adding auxiliary typedef --- RoutingAlgorithms/AlternativePathRouting.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 44f3fc6cf..c970cff22 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasicRoutingInterface.h" #include "../DataStructures/SearchEngineData.h" + #include #include #include @@ -34,7 +35,7 @@ const double VIAPATH_GAMMA = 0.75; //alternative shares at most 75% with the s template class AlternativeRouting : private BasicRoutingInterface { typedef BasicRoutingInterface super; - // typedef SearchEngineData::QueryGraph SearchGraph; + typedef typename super::EdgeData EdgeData; typedef SearchEngineData::QueryHeap QueryHeap; typedef std::pair SearchSpaceEdge; From f2d9e4b2df184bfd4037f54912b45522700040a0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 10:16:57 +0200 Subject: [PATCH 066/127] removing dead code --- DataStructures/SearchEngine.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index da8da9438..eda254731 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -57,13 +57,4 @@ public: }; -// SearchEngineHeapPtr SearchEngineData::forwardHeap; -// SearchEngineHeapPtr SearchEngineData::backwardHeap; - -// SearchEngineHeapPtr SearchEngineData::forwardHeap2; -// SearchEngineHeapPtr SearchEngineData::backwardHeap2; - -// SearchEngineHeapPtr SearchEngineData::forwardHeap3; -// SearchEngineHeapPtr SearchEngineData::backwardHeap3; - #endif // SEARCHENGINE_H From cc48546f62dd016fdb1e50a5d9afffcf3919614f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 10:57:54 +0200 Subject: [PATCH 067/127] moving common code to parent class --- RoutingAlgorithms/BasicRoutingInterface.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 637b0d3cf..4290bc0c3 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -306,6 +306,11 @@ public: packed_path.push_back(current_node_id); } } + + int ComputeEdgeOffset(const PhantomNode & phantom) const { + return phantom.weight1 + (phantom.isBidirected() ? phantom.weight2 : 0); + } + }; #endif /* BASICROUTINGINTERFACE_H_ */ From 633060562f9b5241e329efb90964062c7a731fbb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 10:58:24 +0200 Subject: [PATCH 068/127] call function in parent class --- RoutingAlgorithms/AlternativePathRouting.h | 81 ++++++++++++++-------- RoutingAlgorithms/ShortestPathRouting.h | 8 +-- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index c970cff22..728833a8c 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -35,12 +35,17 @@ const double VIAPATH_GAMMA = 0.75; //alternative shares at most 75% with the s template class AlternativeRouting : private BasicRoutingInterface { typedef BasicRoutingInterface super; - typedef typename super::EdgeData EdgeData; + typedef typename DataFacadeT::EdgeData EdgeData; typedef SearchEngineData::QueryHeap QueryHeap; typedef std::pair SearchSpaceEdge; struct RankedCandidateNode { - RankedCandidateNode(const NodeID n, const int l, const int s) : node(n), length(l), sharing(s) {} + RankedCandidateNode(const NodeID n, const int l, const int s) : + node(n), + length(l), + sharing(s) + { } + NodeID node; int length; int sharing; @@ -63,18 +68,23 @@ public: ~AlternativeRouting() {} - void operator()(const PhantomNodes & phantomNodePair, RawRouteData & rawRouteData) { - if(!phantomNodePair.AtLeastOnePhantomNodeIsUINTMAX() || phantomNodePair.PhantomNodesHaveEqualLocation()) { - rawRouteData.lengthOfShortestPath = rawRouteData.lengthOfAlternativePath = INT_MAX; + void operator()( + const PhantomNodes & phantom_node_pair, + RawRouteData & raw_route_data) { + if( (!phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX()) || + phantom_node_pair.PhantomNodesHaveEqualLocation() + ) { + raw_route_data.lengthOfShortestPath = INT_MAX; + raw_route_data.lengthOfAlternativePath = INT_MAX; return; } - std::vector alternativePath; - std::vector viaNodeCandidates; + std::vector alternative_path; + std::vector via_node_candidate_list; std::vector forward_search_space; std::vector reverse_search_space; - //Initialize Queues, semi-expensive because access to TSS invokes a system call + //Init queues, semi-expensive because access to TSS invokes a sys-call engine_working_data.InitializeOrClearFirstThreadLocalStorage( super::facade->GetNumberOfNodes() ); @@ -92,28 +102,45 @@ public: int upper_bound_to_shortest_path_distance = INT_MAX; NodeID middle_node = UINT_MAX; - forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode); - if(phantomNodePair.startPhantom.isBidirected() ) { - forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1); - } - reverse_heap1.Insert(phantomNodePair.targetPhantom.edgeBasedNode, phantomNodePair.targetPhantom.weight1, phantomNodePair.targetPhantom.edgeBasedNode); - if(phantomNodePair.targetPhantom.isBidirected() ) { - reverse_heap1.Insert(phantomNodePair.targetPhantom.edgeBasedNode+1, phantomNodePair.targetPhantom.weight2, phantomNodePair.targetPhantom.edgeBasedNode+1); + forward_heap1.Insert( + phantom_node_pair.startPhantom.edgeBasedNode, + -phantom_node_pair.startPhantom.weight1, + phantom_node_pair.startPhantom.edgeBasedNode + ); + if(phantom_node_pair.startPhantom.isBidirected() ) { + forward_heap1.Insert( + phantom_node_pair.startPhantom.edgeBasedNode+1, + -phantom_node_pair.startPhantom.weight2, + phantom_node_pair.startPhantom.edgeBasedNode+1 + ); } - 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); + reverse_heap1.Insert( + phantom_node_pair.targetPhantom.edgeBasedNode, + phantom_node_pair.targetPhantom.weight1, + phantom_node_pair.targetPhantom.edgeBasedNode + ); + if(phantom_node_pair.targetPhantom.isBidirected() ) { + reverse_heap1.Insert( + phantom_node_pair.targetPhantom.edgeBasedNode+1, + phantom_node_pair.targetPhantom.weight2, + phantom_node_pair.targetPhantom.edgeBasedNode+1 + ); + } + + const int forward_offset = super::ComputeEdgeOffset(phantom_node_pair.startPhantom);// phantom_node_pair.startPhantom.weight1 + (phantom_node_pair.startPhantom.isBidirected() ? phantom_node_pair.startPhantom.weight2 : 0); + const int reverse_offset = super::ComputeEdgeOffset(phantom_node_pair.targetPhantom);//phantom_node_pair.targetPhantom.weight1 + (phantom_node_pair.targetPhantom.isBidirected() ? phantom_node_pair.targetPhantom.weight2 : 0); //exploration dijkstra from nodes s and t until deletemin/(1+epsilon) > _lengthOfShortestPath while(0 < (forward_heap1.Size() + reverse_heap1.Size())){ if(0 < forward_heap1.Size()){ - AlternativeRoutingStep(forward_heap1, reverse_heap1, &middle_node, &upper_bound_to_shortest_path_distance, viaNodeCandidates, forward_search_space, forward_offset); + AlternativeRoutingStep(forward_heap1, reverse_heap1, &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, forward_search_space, forward_offset); } if(0 < reverse_heap1.Size()){ - AlternativeRoutingStep(reverse_heap1, forward_heap1, &middle_node, &upper_bound_to_shortest_path_distance, viaNodeCandidates, reverse_search_space, reverse_offset); + AlternativeRoutingStep(reverse_heap1, forward_heap1, &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, reverse_search_space, reverse_offset); } } - sort_unique_resize(viaNodeCandidates); + sort_unique_resize(via_node_candidate_list); std::vector packed_forward_path; std::vector packed_reverse_path; @@ -153,7 +180,7 @@ public: } } std::vector nodes_that_passed_preselection; - BOOST_FOREACH(const NodeID node, viaNodeCandidates) { + BOOST_FOREACH(const NodeID node, via_node_candidate_list) { int approximated_sharing = approximated_forward_sharing[node] + approximated_reverse_sharing[node]; int approximated_length = forward_heap1.GetKey(node)+reverse_heap1.GetKey(node); bool lengthPassed = (approximated_length < upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)); @@ -194,17 +221,17 @@ public: //Unpack shortest path and alternative, if they exist if(INT_MAX != upper_bound_to_shortest_path_distance) { - super::UnpackPath(packedShortestPath, rawRouteData.computedShortestPath); - rawRouteData.lengthOfShortestPath = upper_bound_to_shortest_path_distance; + super::UnpackPath(packedShortestPath, raw_route_data.computedShortestPath); + raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; } else { - rawRouteData.lengthOfShortestPath = INT_MAX; + raw_route_data.lengthOfShortestPath = INT_MAX; } if(selectedViaNode != UINT_MAX) { - retrievePackedViaPath(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, s_v_middle, v_t_middle, rawRouteData.computedAlternativePath); - rawRouteData.lengthOfAlternativePath = lengthOfViaPath; + retrievePackedViaPath(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, s_v_middle, v_t_middle, raw_route_data.computedAlternativePath); + raw_route_data.lengthOfAlternativePath = lengthOfViaPath; } else { - rawRouteData.lengthOfAlternativePath = INT_MAX; + raw_route_data.lengthOfAlternativePath = INT_MAX; } } diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 80570b0fb..c1d231be8 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -34,10 +34,6 @@ class ShortestPathRouting : public BasicRoutingInterface{ typedef SearchEngineData::QueryHeap QueryHeap; SearchEngineData & engine_working_data; - int ComputeEdgeOffset(const PhantomNode & phantom) const { - return phantom.weight1 + (phantom.isBidirected() ? phantom.weight2 : 0); - } - public: ShortestPathRouting( DataFacadeT * facade, @@ -146,10 +142,10 @@ public: ); // INFO("rv2: " << phantom_node_pair.targetPhantom.edgeBasedNode+1 << ", w;" << phantom_node_pair.targetPhantom.weight2 ); } - const int forward_offset = ComputeEdgeOffset( + const int forward_offset = super::ComputeEdgeOffset( phantom_node_pair.startPhantom ); - const int reverse_offset = ComputeEdgeOffset( + const int reverse_offset = super::ComputeEdgeOffset( phantom_node_pair.targetPhantom ); From cc7caa9e16392fc69f9536b3318792b12ac4e45f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 11:02:24 +0200 Subject: [PATCH 069/127] some further refactoring of variable names and code formatting --- RoutingAlgorithms/AlternativePathRouting.h | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 728833a8c..322942f92 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -128,16 +128,36 @@ public: ); } - const int forward_offset = super::ComputeEdgeOffset(phantom_node_pair.startPhantom);// phantom_node_pair.startPhantom.weight1 + (phantom_node_pair.startPhantom.isBidirected() ? phantom_node_pair.startPhantom.weight2 : 0); - const int reverse_offset = super::ComputeEdgeOffset(phantom_node_pair.targetPhantom);//phantom_node_pair.targetPhantom.weight1 + (phantom_node_pair.targetPhantom.isBidirected() ? phantom_node_pair.targetPhantom.weight2 : 0); + const int forward_offset = super::ComputeEdgeOffset( + phantom_node_pair.startPhantom + ); + const int reverse_offset = super::ComputeEdgeOffset( + phantom_node_pair.targetPhantom + ); - //exploration dijkstra from nodes s and t until deletemin/(1+epsilon) > _lengthOfShortestPath + //search from s and t till new_min/(1+epsilon) > length_of_shortest_path while(0 < (forward_heap1.Size() + reverse_heap1.Size())){ if(0 < forward_heap1.Size()){ - AlternativeRoutingStep(forward_heap1, reverse_heap1, &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, forward_search_space, forward_offset); + AlternativeRoutingStep( + forward_heap1, + reverse_heap1, + &middle_node, + &upper_bound_to_shortest_path_distance, + via_node_candidate_list, + forward_search_space, + forward_offset + ); } if(0 < reverse_heap1.Size()){ - AlternativeRoutingStep(reverse_heap1, forward_heap1, &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, reverse_search_space, reverse_offset); + AlternativeRoutingStep( + reverse_heap1, + forward_heap1, + &middle_node, + &upper_bound_to_shortest_path_distance, + via_node_candidate_list, + reverse_search_space, + reverse_offset + ); } } sort_unique_resize(via_node_candidate_list); @@ -145,8 +165,17 @@ public: std::vector packed_forward_path; std::vector packed_reverse_path; - super::RetrievePackedPathFromSingleHeap(forward_heap1, middle_node, packed_forward_path); - super::RetrievePackedPathFromSingleHeap(reverse_heap1, middle_node, packed_reverse_path); + super::RetrievePackedPathFromSingleHeap( + forward_heap1, + middle_node, + packed_forward_path + ); + super::RetrievePackedPathFromSingleHeap( + reverse_heap1, + middle_node, + packed_reverse_path + ); + boost::unordered_map approximated_forward_sharing; boost::unordered_map approximated_reverse_sharing; From bf3cd37b49ce6fee3faa36e81e37d0cb6c9b19c9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 12:07:34 +0200 Subject: [PATCH 070/127] Load r-tree search data structure from shared memory --- DataStructures/StaticRTree.h | 30 +++++++------ Server/DataStructures/InternalDataFacade.h | 2 +- Server/DataStructures/SharedDataFacade.h | 52 +++++++++++++++------- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 702022848..67c2b116d 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -66,7 +66,7 @@ static boost::thread_specific_ptr thread_local_rtre template class StaticRTree : boost::noncopyable { -private: +public: struct RectangleInt2D { RectangleInt2D() : min_lon(INT_MAX), @@ -238,6 +238,16 @@ private: typedef RectangleInt2D RectangleT; + struct TreeNode { + TreeNode() : child_count(0), child_is_on_disk(false) {} + RectangleT minimum_bounding_rectangle; + uint32_t child_count:31; + bool child_is_on_disk:1; + uint32_t children[RTREE_BRANCHING_FACTOR]; + }; + +private: + struct WrappedInputElement { explicit WrappedInputElement( const uint32_t _array_index, @@ -260,14 +270,6 @@ private: DataT objects[RTREE_LEAF_NODE_SIZE]; }; - struct TreeNode { - TreeNode() : child_count(0), child_is_on_disk(false) {} - RectangleT minimum_bounding_rectangle; - uint32_t child_count:31; - bool child_is_on_disk:1; - uint32_t children[RTREE_BRANCHING_FACTOR]; - }; - struct QueryCandidate { explicit QueryCandidate( const uint32_t n_id, @@ -450,14 +452,13 @@ public: //SimpleLogger().Write() << m_element_count << " elements in leafs"; } - //Read-only operation for queries explicit StaticRTree( - const TreeNode * tree_node_ptr, + TreeNode * tree_node_ptr, const uint32_t number_of_nodes, const boost::filesystem::path & leaf_file - ) : m_leaf_node_filename(leaf_file.string()), - m_search_tree(tree_node_ptr, number_of_nodes) - { + ) : m_search_tree(tree_node_ptr, number_of_nodes), + m_leaf_node_filename(leaf_file.string()) + { //open leaf node file and store thread specific pointer if ( !boost::filesystem::exists( leaf_file ) ) { throw OSRMException("mem index file does not exist"); @@ -473,6 +474,7 @@ public: //SimpleLogger().Write() << tree_size << " nodes in search tree"; //SimpleLogger().Write() << m_element_count << " elements in leafs"; } + //Read-only operation for queries /* inline void FindKNearestPhantomNodesForCoordinate( const FixedPointCoordinate & location, diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index b62290a3c..f8eeac827 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -56,7 +56,7 @@ private: typename ShM::vector m_via_node_list; typename ShM::vector m_name_ID_list; typename ShM::vector m_turn_instruction_list; - StaticRTree * m_static_rtree; + StaticRTree * m_static_rtree; void LoadTimestamp(const boost::filesystem::path & timestamp_path) { diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 305ca850c..61f3e2bdf 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -37,12 +37,14 @@ template class SharedDataFacade : public BaseDataFacade { private: - typedef BaseDataFacade super; - typedef StaticGraph QueryGraph; - typedef typename StaticGraph::_StrNode GraphNode; - typedef typename StaticGraph::_StrEdge GraphEdge; - typedef typename QueryGraph::InputEdge InputEdge; - typedef typename super::RTreeLeaf RTreeLeaf; + typedef EdgeDataT EdgeData; + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename StaticGraph::_StrNode GraphNode; + typedef typename StaticGraph::_StrEdge GraphEdge; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + typedef typename StaticRTree::TreeNode RTreeNode; unsigned m_check_sum; unsigned m_number_of_nodes; @@ -75,17 +77,16 @@ private: SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() ); SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); - typedef StaticRTree TreeNode; - TreeNode * tree_ptr = static_cast( search_tree->Ptr() ); - // m_static_rtree = new StaticRTree( - // tree_ptr, - // tree_size, - // file_index_path - // ); + RTreeNode * tree_ptr = static_cast( search_tree->Ptr() ); + m_static_rtree = new StaticRTree( + tree_ptr, + tree_size, + file_index_path + ); } void LoadGraph() { - uint32_t number_of_nodes = *static_cast( + m_number_of_nodes = *static_cast( SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() ); SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); @@ -97,7 +98,7 @@ private: SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); GraphEdge * graph_edges_ptr = static_cast( graph_edges->Ptr() ); - typename ShM::vector node_list(graph_nodes_ptr, number_of_nodes); + typename ShM::vector node_list(graph_nodes_ptr, m_number_of_nodes); typename ShM::vector edge_list(graph_edges_ptr, number_of_edges); m_query_graph = new QueryGraph( node_list , @@ -110,10 +111,29 @@ private: uint32_t number_of_coordinates = *static_cast( SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() ); - FixedPointCoordinate * graph_edges_ptr = static_cast( + FixedPointCoordinate * coordinate_list_ptr = static_cast( SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr() ); + typename ShM::vector coordinate_list( + coordinate_list_ptr, + number_of_coordinates + ); + m_coordinate_list.swap( coordinate_list ); + uint32_t number_of_turn_instructions = *static_cast( + SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() + ); + + TurnInstruction * turn_instruction_list_ptr = static_cast( + SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST)->Ptr() + ); + + typename ShM::vector turn_instruction_list( + turn_instruction_list_ptr, + number_of_turn_instructions + ); + + m_turn_instruction_list.swap(turn_instruction_list); } public: SharedDataFacade( From 6756eea2099baffeb24bd3677c8b5e783ba31e9f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 13:33:38 +0200 Subject: [PATCH 071/127] load via node information from shared memory --- Server/DataStructures/SharedDataFacade.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 61f3e2bdf..9030dd5e4 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -124,7 +124,7 @@ private: SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() ); - TurnInstruction * turn_instruction_list_ptr = static_cast( + TurnInstruction * turn_instruction_list_ptr = static_cast( SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST)->Ptr() ); @@ -135,6 +135,21 @@ private: m_turn_instruction_list.swap(turn_instruction_list); } + + void LoadViaNodeList() { + uint32_t number_of_via_nodes = * static_cast ( + SharedMemoryFactory::Get(VIA_NODE_LIST_SIZE)->Ptr() + ); + NodeID * via_node_list_ptr = static_cast( + SharedMemoryFactory::Get(VIA_NODE_LIST)->Ptr() + ); + typename ShM::vector via_node_list( + via_node_list_ptr, + number_of_via_nodes + ); + m_via_node_list.swap(via_node_list); + } + public: SharedDataFacade( const IniFile & server_config, @@ -157,6 +172,8 @@ public: LoadNodeAndEdgeInformation(); LoadRTree(ram_index_path); LoadTimestamp(); + LoadViaNodeList(); + LoadNames(); } //search graph access From 6b4fa6a40db8673030e4f32030a3a229636167b2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 13:53:38 +0200 Subject: [PATCH 072/127] load street names into internal memory --- Server/DataStructures/InternalDataFacade.h | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index f8eeac827..b3ce85125 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -52,10 +52,13 @@ private: QueryGraph * m_query_graph; std::string m_timestamp; - typename ShM::vector m_coordinate_list; - typename ShM::vector m_via_node_list; - typename ShM::vector m_name_ID_list; - typename ShM::vector m_turn_instruction_list; + ShM::vector m_coordinate_list; + ShM::vector m_via_node_list; + ShM::vector m_name_ID_list; + ShM::vector m_turn_instruction_list; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; + StaticRTree * m_static_rtree; @@ -155,6 +158,25 @@ private: ); } + void LoadStreetNames( + const boost::filesystem::path & names_file + ) { + boost::filesystem::ifstream name_stream(names_file, std::ios::binary); + unsigned size = 0; + name_stream.read((char *)&size, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != size, "name file broken"); + + m_name_begin_indices.resize(size); + name_stream.read((char*)&m_name_begin_indices[0], size*sizeof(unsigned)); + name_stream.read((char *)&size, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != size, "name file broken"); + + m_names_char_list.resize(size+1); //+1 is sentinel/dummy element + name_stream.read((char *)&m_names_char_list[0], size*sizeof(char)); + BOOST_ASSERT_MSG(0 != m_names_char_list.size(), "could not load any names"); + + name_stream.close(); + } public: ~InternalDataFacade() { delete m_query_graph; @@ -226,6 +248,7 @@ public: LoadNodeAndEdgeInformation(node_data_path, edge_data_path); LoadRTree(ram_index_path, file_index_path); LoadTimestamp(hsgr_path); + LoadStreetNames(name_data_path); } //search graph access From fc4aef6d896723ba91ebf0543eab3b468cc02685 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 13:54:28 +0200 Subject: [PATCH 073/127] fetch ptr from shared memory to via node list --- Server/DataStructures/SharedDataFacade.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 9030dd5e4..0bc768ec5 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -55,6 +55,8 @@ private: ShM::vector m_via_node_list; ShM::vector m_name_ID_list; ShM::vector m_turn_instruction_list; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; StaticRTree * m_static_rtree; SharedDataFacade() { } @@ -150,6 +152,10 @@ private: m_via_node_list.swap(via_node_list); } + void LoadNames() { + + } + public: SharedDataFacade( const IniFile & server_config, From b25fe3d12744db38dab97c77a8205746b30c24f4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 14:44:25 +0200 Subject: [PATCH 074/127] implement GetName for internal memory --- Server/DataStructures/InternalDataFacade.h | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index b3ce85125..2482a5410 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -343,17 +343,43 @@ public: unsigned GetCheckSum() const { return m_check_sum; } - unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + unsigned GetNameIndexFromEdgeID(const unsigned id) const { + return m_name_ID_list.at(id); + }; - void GetName( - const unsigned name_id, - std::string & result - ) const { return; }; + void GetName( const unsigned name_id, std::string & result ) const { + if(UINT_MAX == name_id) { + result = ""; + return; + } + BOOST_ASSERT_MSG( + name_id < m_name_begin_indices.size(), + "name id too high" + ); + unsigned begin_index = m_name_begin_indices[name_id]; + unsigned end_index = m_name_begin_indices[name_id+1]; + BOOST_ASSERT_MSG( + begin_index < m_names_char_list.size(), + "begin index of name too high" + ); + BOOST_ASSERT_MSG( + end_index < m_names_char_list.size(), + "end index of name too high" + ); + + BOOST_ASSERT_MSG(begin_index <= end_index, "string ends before begin"); + result.clear(); + result.resize(end_index - begin_index); + std::copy( + m_names_char_list.begin() + begin_index, + m_names_char_list.begin() + end_index, + result.begin() + ); + } std::string GetTimestamp() const { return m_timestamp; } - }; #endif // INTERNAL_DATA_FACADE From 581c9c570baffbd181eac65a71d7191963766640 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 15:10:06 +0200 Subject: [PATCH 075/127] implement operator()+ for shared memory iterator --- DataStructures/SharedMemoryVectorWrapper.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 906f3e34e..1679efa99 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -45,6 +45,10 @@ public: operator++(); return tmp; } + ShMemIterator operator+(std::ptrdiff_t diff) { + ShMemIterator tmp(p+diff); + return tmp; + } bool operator==(const ShMemIterator& rhs) { return p==rhs.p; } From 71fe8ed80d3d88d2865cbd38e91c3fe520b53654 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 15:12:06 +0200 Subject: [PATCH 076/127] implement GetName() for shared memory (copy&paste) --- Server/DataStructures/SharedDataFacade.h | 69 ++++++++++++++++++++---- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 0bc768ec5..5d3003d5a 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -55,8 +55,8 @@ private: ShM::vector m_via_node_list; ShM::vector m_name_ID_list; ShM::vector m_turn_instruction_list; - ShM::vector m_names_char_list; - ShM::vector m_name_begin_indices; + ShM::vector m_names_char_list; + ShM::vector m_name_begin_indices; StaticRTree * m_static_rtree; SharedDataFacade() { } @@ -88,13 +88,13 @@ private: } void LoadGraph() { - m_number_of_nodes = *static_cast( + m_number_of_nodes = *static_cast( SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() ); SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); GraphNode * graph_nodes_ptr = static_cast( graph_nodes->Ptr() ); - uint32_t number_of_edges = *static_cast( + uint32_t number_of_edges = *static_cast( SharedMemoryFactory::Get(GRAPH_EDGE_LIST_SIZE)->Ptr() ); SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); @@ -110,7 +110,7 @@ private: } void LoadNodeAndEdgeInformation() { - uint32_t number_of_coordinates = *static_cast( + uint32_t number_of_coordinates = *static_cast( SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() ); FixedPointCoordinate * coordinate_list_ptr = static_cast( @@ -122,7 +122,7 @@ private: ); m_coordinate_list.swap( coordinate_list ); - uint32_t number_of_turn_instructions = *static_cast( + uint32_t number_of_turn_instructions = *static_cast( SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() ); @@ -139,7 +139,7 @@ private: } void LoadViaNodeList() { - uint32_t number_of_via_nodes = * static_cast ( + uint32_t number_of_via_nodes = * static_cast ( SharedMemoryFactory::Get(VIA_NODE_LIST_SIZE)->Ptr() ); NodeID * via_node_list_ptr = static_cast( @@ -153,7 +153,29 @@ private: } void LoadNames() { + uint32_t street_names_index_size = * static_cast ( + SharedMemoryFactory::Get(NAME_INDEX_SIZE)->Ptr() + ); + unsigned * street_names_index_ptr = static_cast( + SharedMemoryFactory::Get(NAMES_INDEX)->Ptr() + ); + typename ShM::vector name_begin_indices( + street_names_index_ptr, + street_names_index_size + ); + m_name_begin_indices.swap(m_name_begin_indices); + uint32_t names_list_size = * static_cast( + SharedMemoryFactory::Get(NAMES_LIST_SIZE)->Ptr() + ); + char * names_list_ptr = static_cast( + SharedMemoryFactory::Get(NAMES_LIST)->Ptr() + ); + typename ShM::vector names_char_list( + names_list_ptr, + names_list_size + ); + m_names_char_list.swap(names_char_list); } public: @@ -276,10 +298,35 @@ public: unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; - void GetName( - const unsigned name_id, - std::string & result - ) const { return; }; + void GetName( const unsigned name_id, std::string & result ) const { + if(UINT_MAX == name_id) { + result = ""; + return; + } + BOOST_ASSERT_MSG( + name_id < m_name_begin_indices.size(), + "name id too high" + ); + unsigned begin_index = m_name_begin_indices[name_id]; + unsigned end_index = m_name_begin_indices[name_id+1]; + BOOST_ASSERT_MSG( + begin_index < m_names_char_list.size(), + "begin index of name too high" + ); + BOOST_ASSERT_MSG( + end_index < m_names_char_list.size(), + "end index of name too high" + ); + + BOOST_ASSERT_MSG(begin_index <= end_index, "string ends before begin"); + result.clear(); + result.resize(end_index - begin_index); + std::copy( + m_names_char_list.begin() + begin_index, + m_names_char_list.begin() + end_index, + result.begin() + ); + } std::string GetTimestamp() const { return m_timestamp; From 6a0e90ef907810079087eaef196c744e46b90700 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 16:24:27 +0200 Subject: [PATCH 077/127] properly check for (non-)empty vectors --- Server/DataStructures/InternalDataFacade.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 2482a5410..5c6abc2c0 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -90,10 +90,13 @@ private: edge_list, &m_check_sum ); - BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); - BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed"); + BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); + BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty"); m_query_graph = new QueryGraph(node_list, edge_list); + + BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); + BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed"); SimpleLogger().Write() << "Data checksum is " << m_check_sum; } From 918e20b164f8f362cbdb27ca8a91e6290e1eaeff Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 16:45:34 +0200 Subject: [PATCH 078/127] inverting assertion --- RoutingAlgorithms/ShortestPathRouting.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index c1d231be8..d73a1352f 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -259,9 +259,9 @@ public: } BOOST_ASSERT_MSG( - temporary_packed_path1.empty() && - temporary_packed_path2.empty(), - "tempory packed paths not empty" + !temporary_packed_path1.empty() || + !temporary_packed_path2.empty(), + "tempory packed paths empty" ); //Plug paths together, s.t. end of packed path is begin of temporary packed path From 14bd1d01f2e197c5a0b652726b57ac547a28a711 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 18:48:02 +0200 Subject: [PATCH 079/127] create sentinel to adjancency array during preprocessing --- DataStructures/StaticGraph.h | 4 +++- Server/DataStructures/InternalDataFacade.h | 13 ++++++++++--- createHierarchy.cpp | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index ccdb3a214..8c086a664 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -88,7 +88,7 @@ public: typename ShM<_StrNode, UseSharedMemory>::vector & nodes, typename ShM<_StrEdge, UseSharedMemory>::vector & edges ) { - _numNodes = nodes.size(); + _numNodes = nodes.size()-1; _numEdges = edges.size(); _nodes.swap(nodes); @@ -97,8 +97,10 @@ public: #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { + SimpleLogger().Write() << "[" << u << "], 1st: " << BeginEdges(u) << ", last: " << EndEdges(u); for(unsigned eid = BeginEdges(u); eid < EndEdges(u); ++eid) { unsigned v = GetTarget(eid); + SimpleLogger().Write() << "Edge (" << u << "," << v << ")"; EdgeData & data = GetEdgeData(eid); if(data.shortcut) { unsigned eid2 = FindEdgeInEitherDirection(u, data.id); diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 5c6abc2c0..fa7ed927e 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -82,7 +82,9 @@ private: void LoadGraph(const boost::filesystem::path & hsgr_path) { typename ShM::vector node_list; - typename ShM< typename QueryGraph::_StrEdge, false>::vector edge_list; + typename ShM::vector edge_list; + + SimpleLogger().Write() << "loading graph from " << hsgr_path.string(); m_number_of_nodes = readHSGRFromStream( hsgr_path, @@ -90,9 +92,10 @@ private: edge_list, &m_check_sum ); + BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty"); - + SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size() << " edges"; m_query_graph = new QueryGraph(node_list, edge_list); BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); @@ -248,9 +251,13 @@ public: //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(hsgr_path); + SimpleLogger().Write() << "loading egde information"; LoadNodeAndEdgeInformation(node_data_path, edge_data_path); + SimpleLogger().Write() << "loading r-tree"; LoadRTree(ram_index_path, file_index_path); - LoadTimestamp(hsgr_path); + SimpleLogger().Write() << "loading timestamp"; + LoadTimestamp(timestamp_path); + SimpleLogger().Write() << "loading street names"; LoadStreetNames(name_data_path); } diff --git a/createHierarchy.cpp b/createHierarchy.cpp index a3c6ceb20..66706342e 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -269,6 +269,7 @@ int main (int argc, char *argv[]) { 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) { + SimpleLogger().Write() << "edge (" << edge.source << "," << edge.target << ")"; if(edge.source > numberOfNodes) { numberOfNodes = edge.source; } @@ -283,14 +284,26 @@ int main (int argc, char *argv[]) { StaticGraph::EdgeIterator edge = 0; StaticGraph::EdgeIterator position = 0; - for ( StaticGraph::NodeIterator node = 0; node <= numberOfNodes; ++node ) { + for ( StaticGraph::NodeIterator node = 0; node < numberOfNodes; ++node ) { StaticGraph::EdgeIterator lastEdge = edge; while ( edge < numberOfEdges && contractedEdgeList[edge].source == node ) ++edge; _nodes[node].firstEdge = position; //=edge position += edge - lastEdge; //remove + SimpleLogger().Write() << "_nodes[" << node << "].firstEdge = " << _nodes[node].firstEdge; } + _nodes[_nodes.size()-1].firstEdge = _nodes[_nodes.size()-2].firstEdge; + SimpleLogger().Write() << "position: " << position; ++numberOfNodes; + + SimpleLogger().Write() << "no. of nodes: " << numberOfNodes << ", edges: " << edge; + SimpleLogger().Write() << "_nodes.size(): " << _nodes.size(); + for(unsigned i = 0; i < _nodes.size(); ++i) { + SimpleLogger().Write() << _nodes[i].firstEdge; + } + + BOOST_ASSERT_MSG(_nodes.size() == numberOfNodes, "no. of nodes dont match"); + //Serialize numberOfNodes, nodes hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); hsgr_output_stream.write((char*) &numberOfNodes, sizeof(unsigned)); From f57e4c6c14b3f7381d9c38f06b07aa56c90f735a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 18:59:44 +0200 Subject: [PATCH 080/127] removing debug output and calling it a day --- DataStructures/StaticGraph.h | 2 -- createHierarchy.cpp | 9 --------- 2 files changed, 11 deletions(-) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 8c086a664..6a83e928c 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -97,10 +97,8 @@ public: #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { - SimpleLogger().Write() << "[" << u << "], 1st: " << BeginEdges(u) << ", last: " << EndEdges(u); for(unsigned eid = BeginEdges(u); eid < EndEdges(u); ++eid) { unsigned v = GetTarget(eid); - SimpleLogger().Write() << "Edge (" << u << "," << v << ")"; EdgeData & data = GetEdgeData(eid); if(data.shortcut) { unsigned eid2 = FindEdgeInEitherDirection(u, data.id); diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 66706342e..d0eadc14c 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -269,7 +269,6 @@ int main (int argc, char *argv[]) { 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) { - SimpleLogger().Write() << "edge (" << edge.source << "," << edge.target << ")"; if(edge.source > numberOfNodes) { numberOfNodes = edge.source; } @@ -290,18 +289,10 @@ int main (int argc, char *argv[]) { ++edge; _nodes[node].firstEdge = position; //=edge position += edge - lastEdge; //remove - SimpleLogger().Write() << "_nodes[" << node << "].firstEdge = " << _nodes[node].firstEdge; } _nodes[_nodes.size()-1].firstEdge = _nodes[_nodes.size()-2].firstEdge; - SimpleLogger().Write() << "position: " << position; ++numberOfNodes; - SimpleLogger().Write() << "no. of nodes: " << numberOfNodes << ", edges: " << edge; - SimpleLogger().Write() << "_nodes.size(): " << _nodes.size(); - for(unsigned i = 0; i < _nodes.size(); ++i) { - SimpleLogger().Write() << _nodes[i].firstEdge; - } - BOOST_ASSERT_MSG(_nodes.size() == numberOfNodes, "no. of nodes dont match"); //Serialize numberOfNodes, nodes From 0daf49a1da61e2f8c5e1e5b2ee98cdfc75f58d54 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 14:31:48 +0200 Subject: [PATCH 081/127] All tests are passing for internal memory\! --- createHierarchy.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index d0eadc14c..08eea1b3a 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -290,10 +290,14 @@ int main (int argc, char *argv[]) { _nodes[node].firstEdge = position; //=edge position += edge - lastEdge; //remove } - _nodes[_nodes.size()-1].firstEdge = _nodes[_nodes.size()-2].firstEdge; + + _nodes.back().firstEdge = numberOfEdges; //sentinel element ++numberOfNodes; - BOOST_ASSERT_MSG(_nodes.size() == numberOfNodes, "no. of nodes dont match"); + BOOST_ASSERT_MSG( + _nodes.size() == numberOfNodes, + "no. of nodes dont match" + ); //Serialize numberOfNodes, nodes hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); From 026da34ce902bf840712e1c2280f0559037ee2b3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 15:31:49 +0200 Subject: [PATCH 082/127] osrm-datastore handles manangement of shared memory --- CMakeLists.txt | 3 +++ datastore.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 datastore.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f7c65c69..055062bc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ add_executable(osrm-prepare ${PrepareSources} ) add_executable(osrm-routed routed.cpp ) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) +add_executable(osrm-datastore datastore.cpp) + file(GLOB DescriptorGlob Descriptors/*.cpp) file(GLOB DatastructureGlob Datastructures/*.cpp) file(GLOB LibOSRMGlob Library/*.cpp) @@ -100,6 +102,7 @@ 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 ) +target_link_libraries( osrm-datastore ${Boost_LIBRARIES} UUID ) find_package ( BZip2 REQUIRED ) include_directories(${BZIP_INCLUDE_DIRS}) diff --git a/datastore.cpp b/datastore.cpp new file mode 100644 index 000000000..944642a56 --- /dev/null +++ b/datastore.cpp @@ -0,0 +1,36 @@ +/* + 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 "DataStructures/SharedMemoryFactory.h" +#include "DataStructures/SharedMemoryVectorWrapper.h" +#include "Util/SimpleLogger.h" +#include "typedefs.h" + +int main(int argc, char * argv[]) { + try { + LogPolicy::GetInstance().Unmute(); + + } catch(const std::exception & e) { + SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); + + } + + return 0; +} From 4e589c2575089387671edac20725d8b6ee33f058 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 18:00:12 +0200 Subject: [PATCH 083/127] removing debug output --- Server/DataStructures/InternalDataFacade.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index fa7ed927e..24780b53d 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -149,9 +149,6 @@ private: m_turn_instruction_list[i] = current_edge_data.turnInstruction; } edges_input_stream.close(); - SimpleLogger().Write(logDEBUG) - << "Loaded " << number_of_edges << " orig edges"; - SimpleLogger().Write(logDEBUG) << "Opening NN indices"; } void LoadRTree( From 7579c41a35bb7944393fd4adf071f35cd4952432 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 18:26:10 +0200 Subject: [PATCH 084/127] Reordering resource aquisition --- Server/DataStructures/InternalDataFacade.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 24780b53d..8d28d8c69 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -111,10 +111,6 @@ private: nodes_file, std::ios::binary ); - boost::filesystem::ifstream edges_input_stream( - edges_file, - std::ios::binary - ); SimpleLogger().Write(logDEBUG) << "Loading node data"; NodeInfo current_node; @@ -130,8 +126,11 @@ private: std::vector(m_coordinate_list).swap(m_coordinate_list); nodes_input_stream.close(); - SimpleLogger().Write(logDEBUG) - << "Loading edge data"; + SimpleLogger().Write(logDEBUG) << "Loading edge data"; + boost::filesystem::ifstream edges_input_stream( + edges_file, + std::ios::binary + ); unsigned number_of_edges = 0; edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); m_via_node_list.resize(number_of_edges); From 572a9393aade3c2d224fb8802e8613aa6bb20c73 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 18:40:08 +0200 Subject: [PATCH 085/127] implementing loading of data into shared memory --- datastore.cpp | 268 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 267 insertions(+), 1 deletion(-) diff --git a/datastore.cpp b/datastore.cpp index 944642a56..f3629a653 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -18,19 +18,285 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ +#include "DataStructures/QueryEdge.h" #include "DataStructures/SharedMemoryFactory.h" #include "DataStructures/SharedMemoryVectorWrapper.h" +#include "DataStructures/StaticGraph.h" +#include "Server/DataStructures/SharedDataType.h" +#include "Util/BoostFilesystemFix.h" +#include "Util/GraphLoader.h" +#include "Util/IniFile.h" #include "Util/SimpleLogger.h" #include "typedefs.h" +#include +#include + +#include +#include + +typedef StaticGraph QueryGraph; + + +void StoreIntegerInSharedMemory( + const uint64_t value, + const SharedDataType data_type) +{ + SharedMemory * memory = SharedMemoryFactory::Get( + data_type, + sizeof(uint64_t) + ); + uint64_t * ptr = static_cast( memory->Ptr() ); + *ptr = value; +} + int main(int argc, char * argv[]) { try { LogPolicy::GetInstance().Unmute(); + SimpleLogger().Write() << "Checking input parameters"; + + boost::filesystem::path base_path = boost::filesystem::absolute( + (argc > 1 ? argv[1] : "server.ini") + ).parent_path(); + IniFile server_config((argc > 1 ? argv[1] : "server.ini")); + //check contents of config file + if ( !server_config.Holds("hsgrData")) { + throw OSRMException("no ram index file name in server ini"); + } + if ( !server_config.Holds("ramIndex") ) { + throw OSRMException("no mem index file name in server ini"); + } + if ( !server_config.Holds("nodesData") ) { + throw OSRMException("no nodes file name in server ini"); + } + if ( !server_config.Holds("edgesData") ) { + throw OSRMException("no edges file name in server ini"); + } + + //generate paths of data files + boost::filesystem::path hsgr_path = boost::filesystem::absolute( + server_config.GetParameter("hsgrData"), + base_path + ); + boost::filesystem::path ram_index_path = boost::filesystem::absolute( + server_config.GetParameter("ramIndex"), + base_path + ); + boost::filesystem::path node_data_path = boost::filesystem::absolute( + server_config.GetParameter("nodesData"), + base_path + ); + boost::filesystem::path edge_data_path = boost::filesystem::absolute( + server_config.GetParameter("edgesData"), + base_path + ); + boost::filesystem::path name_data_path = boost::filesystem::absolute( + server_config.GetParameter("namesData"), + base_path + ); + boost::filesystem::path timestamp_path = boost::filesystem::absolute( + server_config.GetParameter("timestamp"), + base_path + ); + + // check if data files empty + if ( 0 == boost::filesystem::file_size( node_data_path ) ) { + throw OSRMException("nodes file is empty"); + } + if ( 0 == boost::filesystem::file_size( edge_data_path ) ) { + throw OSRMException("edges file is empty"); + } + + //TODO: remove any previous data + + + // Loading street names + SimpleLogger().Write() << "Loading names index"; + uint64_t number_of_bytes = 0; + boost::filesystem::ifstream name_stream( + name_data_path, std::ios::binary + ); + unsigned number_of_elements = 0; + name_stream.read((char *)&number_of_elements, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != number_of_elements, "name file broken"); + StoreIntegerInSharedMemory(number_of_elements, NAME_INDEX_SIZE); + number_of_bytes = sizeof(unsigned)*number_of_elements; + + SharedMemory * index_memory = SharedMemoryFactory::Get( + NAMES_INDEX, + number_of_bytes + ); + unsigned * index_ptr = static_cast( index_memory->Ptr() ); + name_stream.read((char*)index_ptr, number_of_bytes); + + SimpleLogger().Write() << "Loading names list"; + name_stream.read((char *)&number_of_bytes, sizeof(unsigned)); + StoreIntegerInSharedMemory(number_of_bytes, NAME_INDEX_SIZE); + SharedMemory * char_memory = SharedMemoryFactory::Get( + NAMES_LIST, number_of_bytes+1 + ); + char * char_ptr = static_cast( char_memory->Ptr() ); + name_stream.read(char_ptr, number_of_bytes); + name_stream.close(); + + + std::vector node_list; + std::vector edge_list; + + + //TODO: Read directly into shared memory + unsigned m_check_sum = 0; + SimpleLogger().Write() << "Loading graph node list"; + uint64_t m_number_of_nodes = readHSGRFromStream( + hsgr_path, + node_list, + edge_list, + &m_check_sum + ); + + StoreIntegerInSharedMemory(node_list.size(), GRAPH_NODE_LIST_SIZE); + SharedMemory * graph_node_memory = SharedMemoryFactory::Get( + GRAPH_NODE_LIST, + sizeof(QueryGraph::_StrNode)*node_list.size() + ); + QueryGraph::_StrNode * graph_node_ptr = static_cast( + graph_node_memory->Ptr() + ); + + std::copy(node_list.begin(), node_list.end(), graph_node_ptr); + + SimpleLogger().Write() << "Loading graph edge list"; + StoreIntegerInSharedMemory(edge_list.size(), GRAPH_EDGE_LIST_SIZE); + SharedMemory * graph_edge_memory = SharedMemoryFactory::Get( + GRAPH_EDGE_LIST, + sizeof(QueryGraph::_StrEdge)*edge_list.size() + ); + QueryGraph::_StrEdge * graph_edge_ptr = static_cast( + graph_edge_memory->Ptr() + ); + std::copy(edge_list.begin(), edge_list.end(), graph_edge_ptr); + + // load checksum + SimpleLogger().Write() << "Loading check sum"; + StoreIntegerInSharedMemory(m_check_sum, CHECK_SUM); + + SimpleLogger().Write() << "Loading timestamp"; + std::string m_timestamp; + if( boost::filesystem::exists(timestamp_path) ) { + boost::filesystem::ifstream timestampInStream( timestamp_path ); + if(!timestampInStream) { + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + } + getline(timestampInStream, m_timestamp); + timestampInStream.close(); + } + if(m_timestamp.empty()) { + m_timestamp = "n/a"; + } + if(25 < m_timestamp.length()) { + m_timestamp.resize(25); + } + StoreIntegerInSharedMemory(m_timestamp.length(), TIMESTAMP_SIZE); + SharedMemory * timestamp_memory = SharedMemoryFactory::Get( + TIMESTAMP, m_timestamp.length() + ); + char * timestamp_ptr = static_cast( timestamp_memory->Ptr() ); + std::copy( + m_timestamp.c_str(), + m_timestamp.c_str()+m_timestamp.length(), + timestamp_ptr + ); + + //Loading information for original edges + boost::filesystem::ifstream edges_input_stream( + edge_data_path, + std::ios::binary + ); + unsigned number_of_edges = 0; + edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); + SimpleLogger().Write() << "Loading via node, coordinates and turn instruction list"; + StoreIntegerInSharedMemory(number_of_edges, NAME_ID_LIST_SIZE); + StoreIntegerInSharedMemory(number_of_edges, TURN_INSTRUCTION_LIST_SIZE); + StoreIntegerInSharedMemory(number_of_edges, VIA_NODE_LIST_SIZE); + + SharedMemory * name_id_memory = SharedMemoryFactory::Get( + NAME_ID_LIST, + number_of_edges*sizeof(unsigned) + ); + unsigned * name_id_ptr = static_cast( name_id_memory->Ptr() ); + + SharedMemory *via_node_memory = SharedMemoryFactory::Get( + VIA_NODE_LIST, + number_of_edges*sizeof(unsigned) + ); + unsigned * via_node_ptr = static_cast( via_node_memory->Ptr() ); + + SharedMemory *turn_instruction_memory = SharedMemoryFactory::Get( + TURN_INSTRUCTION_LIST, + number_of_edges*sizeof(TurnInstruction) + ); + unsigned * turn_instructions_ptr = static_cast( turn_instruction_memory->Ptr() ); + + OriginalEdgeData current_edge_data; + for(unsigned i = 0; i < number_of_edges; ++i) { + edges_input_stream.read( + (char*)&(current_edge_data), + sizeof(OriginalEdgeData) + ); + via_node_ptr[i] = current_edge_data.viaNode; + name_id_ptr[i] = current_edge_data.nameID; + turn_instructions_ptr[i] = current_edge_data.turnInstruction; + } + edges_input_stream.close(); + + // Loading list of coordinates + SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; + boost::filesystem::ifstream nodes_input_stream( + node_data_path, + std::ios::binary + ); + unsigned number_of_nodes = 0; + nodes_input_stream.read((char *)&number_of_nodes, sizeof(unsigned)); + StoreIntegerInSharedMemory(number_of_nodes, COORDINATE_LIST_SIZE); + + SharedMemory *coordinates_memory = SharedMemoryFactory::Get( + COORDINATE_LIST, + number_of_nodes*sizeof(FixedPointCoordinate) + ); + FixedPointCoordinate * coordinates_ptr = static_cast( coordinates_memory->Ptr() ); + + NodeInfo current_node; + for(unsigned i = 0; i < number_of_nodes; ++i) { + nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon); + } + nodes_input_stream.close(); + + // Loading r-tree search data structure + SimpleLogger().Write() << "loading r-tree search list"; + boost::filesystem::ifstream tree_node_file( + ram_index_path, + std::ios::binary + ); + + uint32_t tree_size = 0; + tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); + StoreIntegerInSharedMemory(tree_size, R_SEARCH_TREE_SIZE); + //SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"; + SharedMemory * rtree_memory = SharedMemoryFactory::Get( + R_SEARCH_TREE, + tree_size*sizeof(TreeNode); + ); + char * rtree_ptr = static_cast( rtree_memory->Ptr() ); + + tree_node_file.read(rtree_ptr, sizeof(TreeNode)*tree_size); + tree_node_file.close(); } catch(const std::exception & e) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); - } + // + return 0; } From ae45eed2b18c708adf48d454312dbb86d01909c7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 18:58:39 +0200 Subject: [PATCH 086/127] move shmem stored sizes to 64 bits --- Server/DataStructures/SharedDataType.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 0ca7e5771..abecdefcf 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -26,6 +26,8 @@ enum SharedDataType { NAME_INDEX_SIZE, NAMES_LIST, NAMES_LIST_SIZE, + NAME_ID_LIST, + NAME_ID_LIST_SIZE, VIA_NODE_LIST, VIA_NODE_LIST_SIZE, GRAPH_NODE_LIST, From 4bf1987bb7c77a108dc5e39be222489cf7584a6b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 18:59:07 +0200 Subject: [PATCH 087/127] store name id of edges in shmem, too --- Server/DataStructures/SharedDataFacade.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 5d3003d5a..2084eeca6 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -62,10 +62,10 @@ private: SharedDataFacade() { } void LoadTimestamp() { - uint32_t timestamp_size = *static_cast( + uint64_t timestamp_size = *static_cast( SharedMemoryFactory::Get(TIMESTAMP_SIZE)->Ptr() ); - timestamp_size = std::min(timestamp_size, 25u); + timestamp_size = std::min(timestamp_size, (uint64_t)25); SharedMemory * search_tree = SharedMemoryFactory::Get(TIMESTAMP); char * tree_ptr = static_cast( search_tree->Ptr() ); m_timestamp.resize(timestamp_size); @@ -75,7 +75,7 @@ private: void LoadRTree( const boost::filesystem::path & file_index_path ) { - uint32_t tree_size = *static_cast( + uint64_t tree_size = *static_cast( SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() ); SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); @@ -88,13 +88,13 @@ private: } void LoadGraph() { - m_number_of_nodes = *static_cast( + m_number_of_nodes = *static_cast( SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() ); SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); GraphNode * graph_nodes_ptr = static_cast( graph_nodes->Ptr() ); - uint32_t number_of_edges = *static_cast( + uint64_t number_of_edges = *static_cast( SharedMemoryFactory::Get(GRAPH_EDGE_LIST_SIZE)->Ptr() ); SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); @@ -110,7 +110,7 @@ private: } void LoadNodeAndEdgeInformation() { - uint32_t number_of_coordinates = *static_cast( + uint64_t number_of_coordinates = *static_cast( SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() ); FixedPointCoordinate * coordinate_list_ptr = static_cast( @@ -122,7 +122,7 @@ private: ); m_coordinate_list.swap( coordinate_list ); - uint32_t number_of_turn_instructions = *static_cast( + uint64_t number_of_turn_instructions = *static_cast( SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() ); @@ -139,7 +139,7 @@ private: } void LoadViaNodeList() { - uint32_t number_of_via_nodes = * static_cast ( + uint64_t number_of_via_nodes = * static_cast ( SharedMemoryFactory::Get(VIA_NODE_LIST_SIZE)->Ptr() ); NodeID * via_node_list_ptr = static_cast( @@ -153,7 +153,7 @@ private: } void LoadNames() { - uint32_t street_names_index_size = * static_cast ( + uint64_t street_names_index_size = * static_cast ( SharedMemoryFactory::Get(NAME_INDEX_SIZE)->Ptr() ); unsigned * street_names_index_ptr = static_cast( @@ -165,7 +165,7 @@ private: ); m_name_begin_indices.swap(m_name_begin_indices); - uint32_t names_list_size = * static_cast( + uint64_t names_list_size = * static_cast( SharedMemoryFactory::Get(NAMES_LIST_SIZE)->Ptr() ); char * names_list_ptr = static_cast( From 1be67518df8a4d8e12c60f1e7bf0797436567378 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 25 Sep 2013 19:06:50 +0200 Subject: [PATCH 088/127] adding proper typedefs s.t. all used types are known --- datastore.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index f3629a653..540e3da4f 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -22,6 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "DataStructures/SharedMemoryFactory.h" #include "DataStructures/SharedMemoryVectorWrapper.h" #include "DataStructures/StaticGraph.h" +#include "DataStructures/StaticRTree.h" +#include "Server/DataStructures/BaseDataFacade.h" #include "Server/DataStructures/SharedDataType.h" #include "Util/BoostFilesystemFix.h" #include "Util/GraphLoader.h" @@ -36,6 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include typedef StaticGraph QueryGraph; +typedef StaticRTree::RTreeLeaf, true>::TreeNode RTreeNode; void StoreIntegerInSharedMemory( @@ -144,7 +147,8 @@ int main(int argc, char * argv[]) { std::vector edge_list; - //TODO: Read directly into shared memory + //TODO BEGIN: + //Read directly into shared memory unsigned m_check_sum = 0; SimpleLogger().Write() << "Loading graph node list"; uint64_t m_number_of_nodes = readHSGRFromStream( @@ -153,6 +157,7 @@ int main(int argc, char * argv[]) { edge_list, &m_check_sum ); + //TODO END StoreIntegerInSharedMemory(node_list.size(), GRAPH_NODE_LIST_SIZE); SharedMemory * graph_node_memory = SharedMemoryFactory::Get( @@ -285,11 +290,11 @@ int main(int argc, char * argv[]) { //SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"; SharedMemory * rtree_memory = SharedMemoryFactory::Get( R_SEARCH_TREE, - tree_size*sizeof(TreeNode); + tree_size*sizeof(RTreeNode) ); char * rtree_ptr = static_cast( rtree_memory->Ptr() ); - tree_node_file.read(rtree_ptr, sizeof(TreeNode)*tree_size); + tree_node_file.read(rtree_ptr, sizeof(RTreeNode)*tree_size); tree_node_file.close(); } catch(const std::exception & e) { From 043c8be7476381232f0c37bdff5a331ec52f945d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 26 Sep 2013 11:28:51 +0200 Subject: [PATCH 089/127] create lock file if it does not exist --- DataStructures/SharedMemoryFactory.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index 9c908a187..4218250c7 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include #include #include @@ -36,9 +37,9 @@ struct OSRMLockFile { boost::filesystem::path operator()() { boost::filesystem::path temp_dir = boost::filesystem::temp_directory_path(); - SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; + // SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; boost::filesystem::path lock_file = temp_dir / "osrm.lock"; - SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; + // SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; return lock_file; } }; @@ -144,8 +145,13 @@ public: ) { try { LockFileT lock_file; - if(0 == size && !boost::filesystem::exists(lock_file()) ) { - throw OSRMException("lock file does not exist, exiting"); + if(!boost::filesystem::exists(lock_file()) ) { + if( 0 == size ) { + throw OSRMException("lock file does not exist, exiting"); + } else { + boost::filesystem::ofstream ofs(lock_file()); + ofs.close(); + } } return new SharedMemory(lock_file(), id, size); } catch(const boost::interprocess::interprocess_exception &e){ From e9d93ae210b4ee595e47bfcc34ee1c77248cfe39 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 26 Sep 2013 11:52:15 +0200 Subject: [PATCH 090/127] changing file format for coordinates to be canonical --- Server/DataStructures/InternalDataFacade.h | 12 ++++++++---- createHierarchy.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 8d28d8c69..33f251bd7 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -114,13 +114,17 @@ private: SimpleLogger().Write(logDEBUG) << "Loading node data"; NodeInfo current_node; - while(!nodes_input_stream.eof()) { + unsigned number_of_coordinates = 0; + nodes_input_stream.read( + (char *)&number_of_coordinates, + sizeof(unsigned) + ); + m_coordinate_list.resize(number_of_coordinates); + for(unsigned i = 0; i < number_of_coordinates; ++i) { nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); - m_coordinate_list.push_back( - FixedPointCoordinate( + m_coordinate_list[i] = FixedPointCoordinate( current_node.lat, current_node.lon - ) ); } std::vector(m_coordinate_list).swap(m_coordinate_list); diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 08eea1b3a..e771b6980 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -212,7 +212,12 @@ int main (int argc, char *argv[]) { SimpleLogger().Write() << "writing node map ..."; std::ofstream mapOutFile(nodeOut.c_str(), std::ios::binary); - mapOutFile.write((char *)&(internalToExternalNodeMapping[0]), internalToExternalNodeMapping.size()*sizeof(NodeInfo)); + const unsigned size_of_mapping = internalToExternalNodeMapping.size(); + mapOutFile.write((char *)&size_of_mapping, sizeof(unsigned)); + mapOutFile.write( + (char *)&(internalToExternalNodeMapping[0]), + size_of_mapping*sizeof(NodeInfo) + ); mapOutFile.close(); std::vector().swap(internalToExternalNodeMapping); From 333aba8be66cbbad6be253afb9e1ac371bc1dbec Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 26 Sep 2013 18:19:51 +0200 Subject: [PATCH 091/127] street name file is now more canonical --- DataStructures/SharedMemoryFactory.h | 3 - DataStructures/SharedMemoryVectorWrapper.h | 4 +- DataStructures/StaticRTree.h | 1 - Extractor/ExtractionContainers.cpp | 22 ++- Server/DataStructures/InternalDataFacade.h | 41 ++-- Server/DataStructures/SharedDataFacade.h | 114 +++++------ Server/DataStructures/SharedDataType.h | 211 +++++++++++++++++++-- 7 files changed, 294 insertions(+), 102 deletions(-) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index 4218250c7..3f71279c6 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -37,9 +37,7 @@ struct OSRMLockFile { boost::filesystem::path operator()() { boost::filesystem::path temp_dir = boost::filesystem::temp_directory_path(); - // SimpleLogger().Write(logDEBUG) << "creating lock file in " << temp_dir; boost::filesystem::path lock_file = temp_dir / "osrm.lock"; - // SimpleLogger().Write(logDEBUG) << "locking at " << lock_file; return lock_file; } }; @@ -66,7 +64,6 @@ class SharedMemory : boost::noncopyable { boost::interprocess::xsi_shared_memory::remove(m_shmid); } } - }; public: diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 1679efa99..89d549c05 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -106,12 +106,12 @@ public: std::size_t size() const { return m_size; } - DataT & operator[](const int index) { + DataT & operator[](const unsigned index) { BOOST_ASSERT_MSG(index < m_size, "invalid size"); return m_ptr[index]; } - const DataT & operator[](const int index) const { + const DataT & operator[](const unsigned index) const { BOOST_ASSERT_MSG(index < m_size, "invalid size"); return m_ptr[index]; } diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 67c2b116d..d4d615d85 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -29,7 +29,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "SharedMemoryFactory.h" #include "SharedMemoryVectorWrapper.h" -#include "../Server/DataStructures/SharedDataType.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index a21b45163..cd5576b71 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -290,8 +290,21 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con std::ios::binary ); - const unsigned number_of_ways = name_list.size()+1; - name_file_stream.write((char *)&(number_of_ways), sizeof(unsigned)); + //write number of names + const unsigned number_of_names = name_list.size()+1; + name_file_stream.write((char *)&(number_of_names), sizeof(unsigned)); + + //compute total number of chars + unsigned total_number_of_chars = 0; + BOOST_FOREACH(const std::string & str, name_list) { + total_number_of_chars += strlen(str.c_str()); + } + //write total number of chars + name_file_stream.write( + (char *)&(total_number_of_chars), + sizeof(unsigned) + ); + //write prefixe sums unsigned name_lengths_prefix_sum = 0; BOOST_FOREACH(const std::string & str, name_list) { name_file_stream.write( @@ -300,12 +313,13 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con ); name_lengths_prefix_sum += strlen(str.c_str()); } + //duplicate on purpose! name_file_stream.write( (char *)&(name_lengths_prefix_sum), sizeof(unsigned) ); - //duplicate on purpose! - name_file_stream.write((char *)&(name_lengths_prefix_sum), sizeof(unsigned)); + + //write all chars consecutively BOOST_FOREACH(const std::string & str, name_list) { const unsigned lengthOfRawString = strlen(str.c_str()); name_file_stream.write(str.c_str(), lengthOfRawString); diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 33f251bd7..efba74fdd 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -47,10 +47,10 @@ private: InternalDataFacade() { } - unsigned m_check_sum; - unsigned m_number_of_nodes; - QueryGraph * m_query_graph; - std::string m_timestamp; + unsigned m_check_sum; + unsigned m_number_of_nodes; + QueryGraph * m_query_graph; + std::string m_timestamp; ShM::vector m_coordinate_list; ShM::vector m_via_node_list; @@ -59,7 +59,7 @@ private: ShM::vector m_names_char_list; ShM::vector m_name_begin_indices; - StaticRTree * m_static_rtree; + StaticRTree * m_static_rtree; void LoadTimestamp(const boost::filesystem::path & timestamp_path) { @@ -168,19 +168,28 @@ private: const boost::filesystem::path & names_file ) { boost::filesystem::ifstream name_stream(names_file, std::ios::binary); - unsigned size = 0; - name_stream.read((char *)&size, sizeof(unsigned)); - BOOST_ASSERT_MSG(0 != size, "name file broken"); + unsigned number_of_names = 0; + unsigned number_of_chars = 0; + name_stream.read((char *)&number_of_names, sizeof(unsigned)); + name_stream.read((char *)&number_of_chars, sizeof(unsigned)); + BOOST_ASSERT_MSG(0 != number_of_names, "name file broken"); + BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken"); - m_name_begin_indices.resize(size); - name_stream.read((char*)&m_name_begin_indices[0], size*sizeof(unsigned)); - name_stream.read((char *)&size, sizeof(unsigned)); - BOOST_ASSERT_MSG(0 != size, "name file broken"); - - m_names_char_list.resize(size+1); //+1 is sentinel/dummy element - name_stream.read((char *)&m_names_char_list[0], size*sizeof(char)); - BOOST_ASSERT_MSG(0 != m_names_char_list.size(), "could not load any names"); + m_name_begin_indices.resize(number_of_names); + name_stream.read( + (char*)&m_name_begin_indices[0], + number_of_names*sizeof(unsigned) + ); + m_names_char_list.resize(number_of_chars+1); //+1 gives sentinel element + name_stream.read( + (char *)&m_names_char_list[0], + number_of_chars*sizeof(char) + ); + BOOST_ASSERT_MSG( + 0 != m_names_char_list.size(), + "could not load any names" + ); name_stream.close(); } public: diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 2084eeca6..aefb2fc64 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -24,6 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt. //implements all data storage when shared memory is _NOT_ used #include "BaseDataFacade.h" +#include "SharedDataType.h" #include "../../DataStructures/StaticGraph.h" #include "../../DataStructures/StaticRTree.h" @@ -46,6 +47,9 @@ private: typedef typename super::RTreeLeaf RTreeLeaf; typedef typename StaticRTree::TreeNode RTreeNode; + SharedDataLayout * data_layout; + char * shared_memory; + unsigned m_check_sum; unsigned m_number_of_nodes; QueryGraph * m_query_graph; @@ -62,46 +66,46 @@ private: SharedDataFacade() { } void LoadTimestamp() { - uint64_t timestamp_size = *static_cast( - SharedMemoryFactory::Get(TIMESTAMP_SIZE)->Ptr() + char * timestamp_ptr = shared_memory + data_layout->GetTimeStampOffset(); + m_timestamp.resize(data_layout->timestamp_length); + std::copy( + timestamp_ptr, + timestamp_ptr+data_layout->timestamp_length, + m_timestamp.begin() ); - timestamp_size = std::min(timestamp_size, (uint64_t)25); - SharedMemory * search_tree = SharedMemoryFactory::Get(TIMESTAMP); - char * tree_ptr = static_cast( search_tree->Ptr() ); - m_timestamp.resize(timestamp_size); - std::copy(tree_ptr, tree_ptr+timestamp_size, m_timestamp.begin()); } void LoadRTree( const boost::filesystem::path & file_index_path ) { - uint64_t tree_size = *static_cast( - SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() + RTreeNode * tree_ptr = (RTreeNode *)( + shared_memory + data_layout->GetRSearchTreeOffset() ); - SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); - RTreeNode * tree_ptr = static_cast( search_tree->Ptr() ); m_static_rtree = new StaticRTree( tree_ptr, - tree_size, + data_layout->r_search_tree_size, file_index_path ); } void LoadGraph() { - m_number_of_nodes = *static_cast( - SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() + m_number_of_nodes = data_layout->graph_node_list_size; + GraphNode * graph_nodes_ptr = (GraphNode *)( + shared_memory + data_layout->GetGraphNodeListOffset() ); - SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); - GraphNode * graph_nodes_ptr = static_cast( graph_nodes->Ptr() ); - uint64_t number_of_edges = *static_cast( - SharedMemoryFactory::Get(GRAPH_EDGE_LIST_SIZE)->Ptr() + GraphEdge * graph_edges_ptr = (GraphEdge *)( + shared_memory + data_layout->GetGraphEdgeListOffsett() ); - SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); - GraphEdge * graph_edges_ptr = static_cast( graph_edges->Ptr() ); - typename ShM::vector node_list(graph_nodes_ptr, m_number_of_nodes); - typename ShM::vector edge_list(graph_edges_ptr, number_of_edges); + typename ShM::vector node_list( + graph_nodes_ptr, + data_layout->graph_node_list_size + ); + typename ShM::vector edge_list( + graph_edges_ptr, + data_layout->graph_edge_list_size + ); m_query_graph = new QueryGraph( node_list , edge_list @@ -110,70 +114,62 @@ private: } void LoadNodeAndEdgeInformation() { - uint64_t number_of_coordinates = *static_cast( - SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() - ); - FixedPointCoordinate * coordinate_list_ptr = static_cast( - SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr() + + FixedPointCoordinate * coordinate_list_ptr = (FixedPointCoordinate *)( + shared_memory + data_layout->GetCoordinateListOffset() ); typename ShM::vector coordinate_list( coordinate_list_ptr, - number_of_coordinates + data_layout->coordinate_list_size ); m_coordinate_list.swap( coordinate_list ); - uint64_t number_of_turn_instructions = *static_cast( - SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() + TurnInstruction * turn_instruction_list_ptr = (TurnInstruction *)( + shared_memory + data_layout->GetTurnInstructionListOffset() ); - - TurnInstruction * turn_instruction_list_ptr = static_cast( - SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST)->Ptr() - ); - typename ShM::vector turn_instruction_list( turn_instruction_list_ptr, - number_of_turn_instructions + data_layout->turn_instruction_list_size ); - m_turn_instruction_list.swap(turn_instruction_list); + + unsigned * name_id_list_ptr = (unsigned *)( + shared_memory + data_layout->GetNameIDListOffset() + ); + typename ShM::vector name_id_list( + name_id_list_ptr, + data_layout->name_id_list_size + ); + m_name_ID_list.swap(name_id_list); } void LoadViaNodeList() { - uint64_t number_of_via_nodes = * static_cast ( - SharedMemoryFactory::Get(VIA_NODE_LIST_SIZE)->Ptr() - ); - NodeID * via_node_list_ptr = static_cast( - SharedMemoryFactory::Get(VIA_NODE_LIST)->Ptr() + NodeID * via_node_list_ptr = (NodeID *)( + shared_memory + data_layout->GetViaNodeListOffset() ); typename ShM::vector via_node_list( via_node_list_ptr, - number_of_via_nodes + data_layout->via_node_list_size ); m_via_node_list.swap(via_node_list); } void LoadNames() { - uint64_t street_names_index_size = * static_cast ( - SharedMemoryFactory::Get(NAME_INDEX_SIZE)->Ptr() - ); - unsigned * street_names_index_ptr = static_cast( - SharedMemoryFactory::Get(NAMES_INDEX)->Ptr() + unsigned * street_names_index_ptr = (unsigned *)( + shared_memory + data_layout->GetNameIndexOffset() ); typename ShM::vector name_begin_indices( street_names_index_ptr, - street_names_index_size + data_layout->names_index_size ); m_name_begin_indices.swap(m_name_begin_indices); - uint64_t names_list_size = * static_cast( - SharedMemoryFactory::Get(NAMES_LIST_SIZE)->Ptr() - ); - char * names_list_ptr = static_cast( - SharedMemoryFactory::Get(NAMES_LIST)->Ptr() + char * names_list_ptr = (char *)( + shared_memory + data_layout->GetNameListOffset() ); typename ShM::vector names_char_list( names_list_ptr, - names_list_size + data_layout->names_list_size ); m_names_char_list.swap(names_char_list); } @@ -194,6 +190,14 @@ public: base_path ); + data_layout = (SharedDataLayout *)( + SharedMemoryFactory::Get(LAYOUT_1)->Ptr() + ); + + shared_memory = (char *)( + SharedMemoryFactory::Get(DATA_1)->Ptr() + ); + //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(); diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index abecdefcf..ec20acc3e 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -21,28 +21,197 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef SHARED_DATA_TYPE_H_ #define SHARED_DATA_TYPE_H_ +#include "BaseDataFacade.h" + +#include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/QueryEdge.h" +#include "../../DataStructures/StaticGraph.h" +#include "../../DataStructures/StaticRTree.h" +#include "../../DataStructures/TurnInstructions.h" + +#include "../../typedefs.h" + +#include + +typedef BaseDataFacade::RTreeLeaf RTreeLeaf; +typedef StaticRTree::TreeNode RTreeNode; +typedef StaticGraph QueryGraph; + +struct SharedDataLayout { + uint64_t names_index_size; + uint64_t names_list_size; + uint64_t name_id_list_size; + uint64_t via_node_list_size; + uint64_t graph_node_list_size; + uint64_t graph_edge_list_size; + uint64_t coordinate_list_size; + uint64_t turn_instruction_list_size; + uint64_t r_search_tree_size; + + unsigned checksum; + unsigned timestamp_length; + + SharedDataLayout() : + names_index_size(0), + names_list_size(0), + name_id_list_size(0), + via_node_list_size(0), + graph_node_list_size(0), + graph_edge_list_size(0), + coordinate_list_size(0), + turn_instruction_list_size(0), + r_search_tree_size(0), + checksum(0), + timestamp_length(0) + { } + + uint64_t GetSizeOfLayout() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + + (turn_instruction_list_size * sizeof(TurnInstructions) ) + + (r_search_tree_size * sizeof(RTreeNode) ) + + sizeof(checksum); + return result; + } + + uint64_t GetNameIndexOffset() const { + return 0; + } + uint64_t GetNameListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ); + return result; + } + uint64_t GetNameIDListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ); + return result; + } + uint64_t GetViaNodeListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ); + return result; + } + uint64_t GetGraphNodeListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ); + return result; + } + uint64_t GetGraphEdgeListOffsett() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) ; + return result; + } + uint64_t GetTimeStampOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)); + return result; + } + uint64_t GetCoordinateListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + + (timestamp_length * sizeof(char) ); + return result; + } + uint64_t GetTurnInstructionListOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate)); + return result; + } + uint64_t GetRSearchTreeOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + + (turn_instruction_list_size * sizeof(TurnInstructions) ); + return result; + } + uint64_t GetChecksumOffset() const { + uint64_t result = + (names_index_size * sizeof(unsigned) ) + + (names_list_size * sizeof(char) ) + + (name_id_list_size * sizeof(unsigned) ) + + (via_node_list_size * sizeof(NodeID) ) + + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate)) + + (turn_instruction_list_size * sizeof(TurnInstructions) ) + + (r_search_tree_size * sizeof(RTreeNode) ); + return result; + } +}; + enum SharedDataType { - NAMES_INDEX = 0, - NAME_INDEX_SIZE, - NAMES_LIST, - NAMES_LIST_SIZE, - NAME_ID_LIST, - NAME_ID_LIST_SIZE, - VIA_NODE_LIST, - VIA_NODE_LIST_SIZE, - GRAPH_NODE_LIST, - GRAPH_NODE_LIST_SIZE, - GRAPH_EDGE_LIST, - GRAPH_EDGE_LIST_SIZE, - CHECK_SUM, - TIMESTAMP, - TIMESTAMP_SIZE, - COORDINATE_LIST, - COORDINATE_LIST_SIZE, - TURN_INSTRUCTION_LIST, - TURN_INSTRUCTION_LIST_SIZE, - R_SEARCH_TREE, - R_SEARCH_TREE_SIZE + // NAMES_INDEX = 0, + // NAME_INDEX_SIZE, + // NAMES_LIST, + // NAMES_LIST_SIZE, + // NAME_ID_LIST, + // NAME_ID_LIST_SIZE, + // VIA_NODE_LIST, + // VIA_NODE_LIST_SIZE, + // GRAPH_NODE_LIST, + // GRAPH_NODE_LIST_SIZE, + // GRAPH_EDGE_LIST, + // GRAPH_EDGE_LIST_SIZE, + // CHECK_SUM, + // TIMESTAMP, + // TIMESTAMP_SIZE, + // COORDINATE_LIST, + // COORDINATE_LIST_SIZE, + // TURN_INSTRUCTION_LIST, + // TURN_INSTRUCTION_LIST_SIZE, + // R_SEARCH_TREE, + // R_SEARCH_TREE_SIZE + + LAYOUT_1, + DATA_1, + LAYOUT_2, + DATA_2, + LAYOUT_3, + DATA_3, + LAYOUT_4, + DATA_5 }; #endif /* SHARED_DATA_TYPE_H_ */ From e894ce00c925918b28296c6a84130bdb381fd315 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 11:48:25 +0200 Subject: [PATCH 092/127] add all binaries to ignore list --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index d87653237..74c4e9068 100644 --- a/.gitignore +++ b/.gitignore @@ -72,7 +72,10 @@ stxxl.errlog /win/bin/ /win/bin-debug/ /osrm-extract +/osrm-io-benchmark +/osrm-components /osrm-routed +/osrm-datastore /osrm-prepare /osrm-cli /nohup.out From f965b7129b69ee39db46e383829391ea8817aee7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 12:00:58 +0200 Subject: [PATCH 093/127] Renaming variables to properly reflect its content --- Server/DataStructures/SharedDataFacade.h | 4 +- Server/DataStructures/SharedDataType.h | 52 ++++++++++++------------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index aefb2fc64..f13e0332f 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -160,7 +160,7 @@ private: ); typename ShM::vector name_begin_indices( street_names_index_ptr, - data_layout->names_index_size + data_layout->name_index_list_size ); m_name_begin_indices.swap(m_name_begin_indices); @@ -169,7 +169,7 @@ private: ); typename ShM::vector names_char_list( names_list_ptr, - data_layout->names_list_size + data_layout->name_char_list_size ); m_names_char_list.swap(names_char_list); } diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index ec20acc3e..d064a695f 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -38,8 +38,8 @@ typedef StaticRTree::TreeNode RTreeNode; typedef StaticGraph QueryGraph; struct SharedDataLayout { - uint64_t names_index_size; - uint64_t names_list_size; + uint64_t name_index_list_size; + uint64_t name_char_list_size; uint64_t name_id_list_size; uint64_t via_node_list_size; uint64_t graph_node_list_size; @@ -52,8 +52,8 @@ struct SharedDataLayout { unsigned timestamp_length; SharedDataLayout() : - names_index_size(0), - names_list_size(0), + name_index_list_size(0), + name_char_list_size(0), name_id_list_size(0), via_node_list_size(0), graph_node_list_size(0), @@ -67,8 +67,8 @@ struct SharedDataLayout { uint64_t GetSizeOfLayout() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -86,34 +86,34 @@ struct SharedDataLayout { } uint64_t GetNameListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ); + (name_index_list_size * sizeof(unsigned) ); return result; } uint64_t GetNameIDListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ); + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ); return result; } uint64_t GetViaNodeListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ); return result; } uint64_t GetGraphNodeListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ); return result; } uint64_t GetGraphEdgeListOffsett() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) ; @@ -121,8 +121,8 @@ struct SharedDataLayout { } uint64_t GetTimeStampOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -131,8 +131,8 @@ struct SharedDataLayout { } uint64_t GetCoordinateListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -142,8 +142,8 @@ struct SharedDataLayout { } uint64_t GetTurnInstructionListOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -154,8 +154,8 @@ struct SharedDataLayout { } uint64_t GetRSearchTreeOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -167,8 +167,8 @@ struct SharedDataLayout { } uint64_t GetChecksumOffset() const { uint64_t result = - (names_index_size * sizeof(unsigned) ) + - (names_list_size * sizeof(char) ) + + (name_index_list_size * sizeof(unsigned) ) + + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + @@ -185,7 +185,7 @@ enum SharedDataType { // NAMES_INDEX = 0, // NAME_INDEX_SIZE, // NAMES_LIST, - // NAMES_LIST_SIZE, + // name_char_list_size, // NAME_ID_LIST, // NAME_ID_LIST_SIZE, // VIA_NODE_LIST, From a45b887c5bbb6c570f9cf7fabd88b7caf4b86ab8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 12:59:33 +0200 Subject: [PATCH 094/127] load orig edge information --- datastore.cpp | 189 +++++++++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 79 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 540e3da4f..631ef071a 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -37,22 +37,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -typedef StaticGraph QueryGraph; -typedef StaticRTree::RTreeLeaf, true>::TreeNode RTreeNode; - - -void StoreIntegerInSharedMemory( - const uint64_t value, - const SharedDataType data_type) -{ - SharedMemory * memory = SharedMemoryFactory::Get( - data_type, - sizeof(uint64_t) - ); - uint64_t * ptr = static_cast( memory->Ptr() ); - *ptr = value; -} - int main(int argc, char * argv[]) { try { LogPolicy::GetInstance().Unmute(); @@ -110,38 +94,123 @@ int main(int argc, char * argv[]) { throw OSRMException("edges file is empty"); } - //TODO: remove any previous data + // Allocate a memory layout in shared memory // + SharedMemory * layout_memory = SharedMemoryFactory::Get( + LAYOUT_1, + sizeof(SharedDataLayout) + ); + SharedDataLayout * shared_layout_ptr = static_cast( + layout_memory->Ptr() + ); - - // Loading street names - SimpleLogger().Write() << "Loading names index"; - uint64_t number_of_bytes = 0; + // // + // collect number of elements to store in shared memory object // + // // + SimpleLogger().Write() << "Collecting files sizes"; + // number of entries in name index boost::filesystem::ifstream name_stream( name_data_path, std::ios::binary ); - unsigned number_of_elements = 0; - name_stream.read((char *)&number_of_elements, sizeof(unsigned)); - BOOST_ASSERT_MSG(0 != number_of_elements, "name file broken"); - StoreIntegerInSharedMemory(number_of_elements, NAME_INDEX_SIZE); - number_of_bytes = sizeof(unsigned)*number_of_elements; + unsigned name_index_size = 0; + name_stream.read((char *)&name_index_size, sizeof(unsigned)); + shared_layout_ptr->name_index_list_size = name_index_size; + BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken"); - SharedMemory * index_memory = SharedMemoryFactory::Get( - NAMES_INDEX, - number_of_bytes - ); - unsigned * index_ptr = static_cast( index_memory->Ptr() ); - name_stream.read((char*)index_ptr, number_of_bytes); + unsigned number_of_chars = 0; + name_stream.read((char *)&number_of_chars, sizeof(unsigned)); + shared_layout_ptr->name_char_list_size = number_of_chars; - SimpleLogger().Write() << "Loading names list"; - name_stream.read((char *)&number_of_bytes, sizeof(unsigned)); - StoreIntegerInSharedMemory(number_of_bytes, NAME_INDEX_SIZE); - SharedMemory * char_memory = SharedMemoryFactory::Get( - NAMES_LIST, number_of_bytes+1 + //Loading information for original edges + boost::filesystem::ifstream edges_input_stream( + edge_data_path, + std::ios::binary + ); + unsigned number_of_edges = 0; + edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); + SimpleLogger().Write() << "number of edges: " << number_of_edges; + + shared_layout_ptr->via_node_list_size = number_of_edges; + shared_layout_ptr->name_id_list_size = number_of_edges; + shared_layout_ptr->turn_instruction_list_size = number_of_edges; + + //TODO load graph node size + //TODO load graph edge size + //TODO load search tree size + + // allocate shared memory block + SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; + SharedMemory * shared_memory = SharedMemoryFactory::Get( + DATA_1, + shared_layout_ptr->GetSizeOfLayout() + ); + char * shared_memory_ptr = static_cast(shared_memory->Ptr()); + + // read actual data into shared memory object // + // Loading street names + SimpleLogger().Write() << "Loading names index and chars from: " << name_data_path.string(); + unsigned * name_index_ptr = (unsigned*)( + shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset() + ); + SimpleLogger().Write(logDEBUG) << "Bytes: " << shared_layout_ptr->name_index_list_size*sizeof(unsigned); + + name_stream.read( + (char*)name_index_ptr, + shared_layout_ptr->name_index_list_size*sizeof(unsigned) + ); + + SimpleLogger().Write() << "Loading names char list"; + SimpleLogger().Write(logDEBUG) << "Bytes: " << shared_layout_ptr->name_char_list_size*sizeof(char); + char * name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset(); + name_stream.read( + name_char_ptr, + shared_layout_ptr->name_char_list_size*sizeof(char) ); - char * char_ptr = static_cast( char_memory->Ptr() ); - name_stream.read(char_ptr, number_of_bytes); name_stream.close(); + //load original edge information + SimpleLogger().Write() << "Loading via node, coordinates and turn instruction list"; + + NodeID * via_node_ptr = (NodeID *)( + shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset() + ); + + unsigned * name_id_ptr = (unsigned *)( + shared_memory_ptr + shared_layout_ptr->GetNameIDListOffset() + ); + + TurnInstruction * turn_instructions_ptr = (TurnInstruction *)( + shared_memory_ptr + shared_layout_ptr->GetTurnInstructionListOffset() + ); + + OriginalEdgeData current_edge_data; + for(unsigned i = 0; i < number_of_edges; ++i) { + SimpleLogger().Write() << i << "/" << number_of_edges; + edges_input_stream.read( + (char*)&(current_edge_data), + sizeof(OriginalEdgeData) + ); + via_node_ptr[i] = current_edge_data.viaNode; + name_id_ptr[i] = current_edge_data.nameID; + turn_instructions_ptr[i] = current_edge_data.turnInstruction; + } + edges_input_stream.close(); + + + + + + + + + + + + + + + + + std::vector node_list; std::vector edge_list; @@ -157,9 +226,9 @@ int main(int argc, char * argv[]) { edge_list, &m_check_sum ); + SimpleLogger().Write() << "number of nodes: " << m_number_of_nodes; //TODO END - StoreIntegerInSharedMemory(node_list.size(), GRAPH_NODE_LIST_SIZE); SharedMemory * graph_node_memory = SharedMemoryFactory::Get( GRAPH_NODE_LIST, sizeof(QueryGraph::_StrNode)*node_list.size() @@ -171,7 +240,6 @@ int main(int argc, char * argv[]) { std::copy(node_list.begin(), node_list.end(), graph_node_ptr); SimpleLogger().Write() << "Loading graph edge list"; - StoreIntegerInSharedMemory(edge_list.size(), GRAPH_EDGE_LIST_SIZE); SharedMemory * graph_edge_memory = SharedMemoryFactory::Get( GRAPH_EDGE_LIST, sizeof(QueryGraph::_StrEdge)*edge_list.size() @@ -183,7 +251,6 @@ int main(int argc, char * argv[]) { // load checksum SimpleLogger().Write() << "Loading check sum"; - StoreIntegerInSharedMemory(m_check_sum, CHECK_SUM); SimpleLogger().Write() << "Loading timestamp"; std::string m_timestamp; @@ -201,7 +268,6 @@ int main(int argc, char * argv[]) { if(25 < m_timestamp.length()) { m_timestamp.resize(25); } - StoreIntegerInSharedMemory(m_timestamp.length(), TIMESTAMP_SIZE); SharedMemory * timestamp_memory = SharedMemoryFactory::Get( TIMESTAMP, m_timestamp.length() ); @@ -219,40 +285,7 @@ int main(int argc, char * argv[]) { ); unsigned number_of_edges = 0; edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); - SimpleLogger().Write() << "Loading via node, coordinates and turn instruction list"; - StoreIntegerInSharedMemory(number_of_edges, NAME_ID_LIST_SIZE); - StoreIntegerInSharedMemory(number_of_edges, TURN_INSTRUCTION_LIST_SIZE); - StoreIntegerInSharedMemory(number_of_edges, VIA_NODE_LIST_SIZE); - - SharedMemory * name_id_memory = SharedMemoryFactory::Get( - NAME_ID_LIST, - number_of_edges*sizeof(unsigned) - ); - unsigned * name_id_ptr = static_cast( name_id_memory->Ptr() ); - - SharedMemory *via_node_memory = SharedMemoryFactory::Get( - VIA_NODE_LIST, - number_of_edges*sizeof(unsigned) - ); - unsigned * via_node_ptr = static_cast( via_node_memory->Ptr() ); - - SharedMemory *turn_instruction_memory = SharedMemoryFactory::Get( - TURN_INSTRUCTION_LIST, - number_of_edges*sizeof(TurnInstruction) - ); - unsigned * turn_instructions_ptr = static_cast( turn_instruction_memory->Ptr() ); - - OriginalEdgeData current_edge_data; - for(unsigned i = 0; i < number_of_edges; ++i) { - edges_input_stream.read( - (char*)&(current_edge_data), - sizeof(OriginalEdgeData) - ); - via_node_ptr[i] = current_edge_data.viaNode; - name_id_ptr[i] = current_edge_data.nameID; - turn_instructions_ptr[i] = current_edge_data.turnInstruction; - } - edges_input_stream.close(); + SimpleLogger().Write() << "number of edges: " << number_of_edges; // Loading list of coordinates SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; @@ -301,7 +334,5 @@ int main(int argc, char * argv[]) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); } - // - return 0; } From cd0cab465d9cc0d267b76f1fdbe7124b16a904bf Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 13:14:30 +0200 Subject: [PATCH 095/127] load coordinate list into shared memory --- datastore.cpp | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 631ef071a..b6b32d1e8 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -136,6 +136,20 @@ int main(int argc, char * argv[]) { //TODO load graph node size //TODO load graph edge size //TODO load search tree size + //TODO load checksum + //TODO load rsearch tree size + //TODO load timestamp size + + //load coordinate size + SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; + boost::filesystem::ifstream nodes_input_stream( + node_data_path, + std::ios::binary + ); + unsigned coordinate_list_size = 0; + nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned)); + shared_layout_ptr->coordinate_list_size = coordinate_list_size; + // allocate shared memory block SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; @@ -195,6 +209,17 @@ int main(int argc, char * argv[]) { } edges_input_stream.close(); + // Loading list of coordinates + FixedPointCoordinate * coordinates_ptr = (FixedPointCoordinate *)( + shared_memory_ptr + shared_layout_ptr->GetCoordinateListOffset() + ); + + NodeInfo current_node; + for(unsigned i = 0; i < coordinate_list_size; ++i) { + nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon); + } + nodes_input_stream.close(); @@ -287,29 +312,6 @@ int main(int argc, char * argv[]) { edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); SimpleLogger().Write() << "number of edges: " << number_of_edges; - // Loading list of coordinates - SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; - boost::filesystem::ifstream nodes_input_stream( - node_data_path, - std::ios::binary - ); - unsigned number_of_nodes = 0; - nodes_input_stream.read((char *)&number_of_nodes, sizeof(unsigned)); - StoreIntegerInSharedMemory(number_of_nodes, COORDINATE_LIST_SIZE); - - SharedMemory *coordinates_memory = SharedMemoryFactory::Get( - COORDINATE_LIST, - number_of_nodes*sizeof(FixedPointCoordinate) - ); - FixedPointCoordinate * coordinates_ptr = static_cast( coordinates_memory->Ptr() ); - - NodeInfo current_node; - for(unsigned i = 0; i < number_of_nodes; ++i) { - nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); - coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon); - } - nodes_input_stream.close(); - // Loading r-tree search data structure SimpleLogger().Write() << "loading r-tree search list"; boost::filesystem::ifstream tree_node_file( From d91d911051273e6134d178ed72c31183e2fede00 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 13:53:49 +0200 Subject: [PATCH 096/127] load timestamp into shared memory --- datastore.cpp | 57 ++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index b6b32d1e8..6a8f9928c 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -138,7 +138,24 @@ int main(int argc, char * argv[]) { //TODO load search tree size //TODO load checksum //TODO load rsearch tree size - //TODO load timestamp size + //load timestamp size + SimpleLogger().Write() << "Loading timestamp"; + std::string m_timestamp; + if( boost::filesystem::exists(timestamp_path) ) { + boost::filesystem::ifstream timestampInStream( timestamp_path ); + if(!timestampInStream) { + SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; + } + getline(timestampInStream, m_timestamp); + timestampInStream.close(); + } + if(m_timestamp.empty()) { + m_timestamp = "n/a"; + } + if(25 < m_timestamp.length()) { + m_timestamp.resize(25); + } + shared_layout_ptr->timestamp_length = m_timestamp.length(); //load coordinate size SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; @@ -221,6 +238,15 @@ int main(int argc, char * argv[]) { } nodes_input_stream.close(); + //store timestamp + char * timestamp_ptr = static_cast( + shared_memory_ptr + shared_layout_ptr->GetTimeStampOffset() + ); + std::copy( + m_timestamp.c_str(), + m_timestamp.c_str()+m_timestamp.length(), + timestamp_ptr + ); @@ -274,35 +300,6 @@ int main(int argc, char * argv[]) { ); std::copy(edge_list.begin(), edge_list.end(), graph_edge_ptr); - // load checksum - SimpleLogger().Write() << "Loading check sum"; - - SimpleLogger().Write() << "Loading timestamp"; - std::string m_timestamp; - if( boost::filesystem::exists(timestamp_path) ) { - boost::filesystem::ifstream timestampInStream( timestamp_path ); - if(!timestampInStream) { - SimpleLogger().Write(logWARNING) << timestamp_path << " not found"; - } - getline(timestampInStream, m_timestamp); - timestampInStream.close(); - } - if(m_timestamp.empty()) { - m_timestamp = "n/a"; - } - if(25 < m_timestamp.length()) { - m_timestamp.resize(25); - } - SharedMemory * timestamp_memory = SharedMemoryFactory::Get( - TIMESTAMP, m_timestamp.length() - ); - char * timestamp_ptr = static_cast( timestamp_memory->Ptr() ); - std::copy( - m_timestamp.c_str(), - m_timestamp.c_str()+m_timestamp.length(), - timestamp_ptr - ); - //Loading information for original edges boost::filesystem::ifstream edges_input_stream( edge_data_path, From 5d7c23c62ad7a82eb19e05de6e6245fe93d1f735 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 15:01:25 +0200 Subject: [PATCH 097/127] graph format now canonical --- Util/GraphLoader.h | 13 +++++-------- createHierarchy.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 23fd40236..58e59e2c4 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -426,20 +426,17 @@ unsigned readHSGRFromStream( } unsigned number_of_nodes = 0; - hsgr_input_stream.read((char*) check_sum, sizeof(unsigned)); - hsgr_input_stream.read((char*) & number_of_nodes, sizeof(unsigned)); + unsigned number_of_edges = 0; + hsgr_input_stream.read( (char*) check_sum, sizeof(unsigned) ); + hsgr_input_stream.read( (char*) &number_of_nodes, sizeof(unsigned) ); BOOST_ASSERT_MSG( 0 != number_of_nodes, "number of nodes is zero"); + hsgr_input_stream.read( (char*) &number_of_edges, sizeof(unsigned) ); + BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); node_list.resize(number_of_nodes + 1); hsgr_input_stream.read( (char*) &(node_list[0]), number_of_nodes*sizeof(NodeT) ); - unsigned number_of_edges = 0; - hsgr_input_stream.read( - (char*) &number_of_edges, - sizeof(unsigned) - ); - BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); edge_list.resize(number_of_edges); hsgr_input_stream.read( diff --git a/createHierarchy.cpp b/createHierarchy.cpp index e771b6980..74ce9a4d7 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -304,12 +304,15 @@ int main (int argc, char *argv[]) { "no. of nodes dont match" ); - //Serialize numberOfNodes, nodes + //serialize crc32, aka checksum hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); + //serialize number f nodes hsgr_output_stream.write((char*) &numberOfNodes, sizeof(unsigned)); - hsgr_output_stream.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes)); - //Serialize number of Edges + //serialize number of edges hsgr_output_stream.write((char*) &position, sizeof(unsigned)); + //serialize all nodes + hsgr_output_stream.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes)); + //serialize all edges --numberOfNodes; edge = 0; int usedEdgeCounter = 0; From 7a1bd4d53ae04aede5cb913d0b4ccde982f01e21 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 27 Sep 2013 17:45:23 +0200 Subject: [PATCH 098/127] load graph into shared memory --- datastore.cpp | 154 +++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 82 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 6a8f9928c..6b657c306 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -26,9 +26,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Server/DataStructures/BaseDataFacade.h" #include "Server/DataStructures/SharedDataType.h" #include "Util/BoostFilesystemFix.h" -#include "Util/GraphLoader.h" #include "Util/IniFile.h" #include "Util/SimpleLogger.h" +#include "Util/UUID.h" #include "typedefs.h" #include @@ -133,11 +133,46 @@ int main(int argc, char * argv[]) { shared_layout_ptr->name_id_list_size = number_of_edges; shared_layout_ptr->turn_instruction_list_size = number_of_edges; - //TODO load graph node size - //TODO load graph edge size - //TODO load search tree size - //TODO load checksum - //TODO load rsearch tree size + + boost::filesystem::ifstream hsgr_input_stream( + hsgr_path, + std::ios::binary + ); + + // load checksum + unsigned checksum = 0; + hsgr_input_stream.read((char*) checksum, sizeof(unsigned) ); + shared_layout_ptr->checksum = checksum; + + // load graph node size + unsigned number_of_graph_nodes = 0; + hsgr_input_stream.read( + (char*) &number_of_graph_nodes, + sizeof(unsigned) + ); + BOOST_ASSERT_MSG( + (0 != number_of_graph_nodes), + "number of nodes is zero" + ); + shared_layout_ptr->graph_node_list_size = number_of_graph_nodes; + + // load graph edge size + unsigned number_of_graph_edges = 0; + hsgr_input_stream.read( (char*) &number_of_edges, sizeof(unsigned) ); + BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); + shared_layout_ptr->graph_edge_list_size = number_of_graph_edges; + + // load rsearch tree size + SimpleLogger().Write() << "loading r-tree search list size"; + boost::filesystem::ifstream tree_node_file( + ram_index_path, + std::ios::binary + ); + + uint32_t tree_size = 0; + tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); + shared_layout_ptr->r_search_tree_size = tree_size; + //load timestamp size SimpleLogger().Write() << "Loading timestamp"; std::string m_timestamp; @@ -248,87 +283,42 @@ int main(int argc, char * argv[]) { timestamp_ptr ); - - - - - - - - - - - - - - - - std::vector node_list; - std::vector edge_list; - - - //TODO BEGIN: - //Read directly into shared memory - unsigned m_check_sum = 0; - SimpleLogger().Write() << "Loading graph node list"; - uint64_t m_number_of_nodes = readHSGRFromStream( - hsgr_path, - node_list, - edge_list, - &m_check_sum + // store search tree portion of rtree + char * rtree_ptr = static_cast( + shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset() ); - SimpleLogger().Write() << "number of nodes: " << m_number_of_nodes; - //TODO END - - SharedMemory * graph_node_memory = SharedMemoryFactory::Get( - GRAPH_NODE_LIST, - sizeof(QueryGraph::_StrNode)*node_list.size() - ); - QueryGraph::_StrNode * graph_node_ptr = static_cast( - graph_node_memory->Ptr() - ); - - std::copy(node_list.begin(), node_list.end(), graph_node_ptr); - - SimpleLogger().Write() << "Loading graph edge list"; - SharedMemory * graph_edge_memory = SharedMemoryFactory::Get( - GRAPH_EDGE_LIST, - sizeof(QueryGraph::_StrEdge)*edge_list.size() - ); - QueryGraph::_StrEdge * graph_edge_ptr = static_cast( - graph_edge_memory->Ptr() - ); - std::copy(edge_list.begin(), edge_list.end(), graph_edge_ptr); - - //Loading information for original edges - boost::filesystem::ifstream edges_input_stream( - edge_data_path, - std::ios::binary - ); - unsigned number_of_edges = 0; - edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); - SimpleLogger().Write() << "number of edges: " << number_of_edges; - - // Loading r-tree search data structure - SimpleLogger().Write() << "loading r-tree search list"; - boost::filesystem::ifstream tree_node_file( - ram_index_path, - std::ios::binary - ); - - uint32_t tree_size = 0; - tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); - StoreIntegerInSharedMemory(tree_size, R_SEARCH_TREE_SIZE); - //SimpleLogger().Write() << "reading " << tree_size << " tree nodes in " << (sizeof(TreeNode)*tree_size) << " bytes"; - SharedMemory * rtree_memory = SharedMemoryFactory::Get( - R_SEARCH_TREE, - tree_size*sizeof(RTreeNode) - ); - char * rtree_ptr = static_cast( rtree_memory->Ptr() ); tree_node_file.read(rtree_ptr, sizeof(RTreeNode)*tree_size); tree_node_file.close(); + UUID uuid_loaded, uuid_orig; + hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); + if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { + SimpleLogger().Write(logWARNING) << + ".hsgr was prepared with different build. " + "Reprocess to get rid of this warning."; + } + + // load the nodes of the search graph + QueryGraph::_StrNode * graph_node_list_ptr = (QueryGraph::_StrNode*)( + shared_memory_ptr + shared_layout_ptr->GetGraphNodeListOffset() + ); + hsgr_input_stream.read( + (char*) graph_node_list_ptr, + shared_layout_ptr->graph_node_list_size*sizeof(QueryGraph::_StrNode) + ); + + + // load the edges of the search graph + QueryGraph::_StrEdge * graph_edge_list_ptr = (QueryGraph::_StrEdge *)( + shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffsett() + ); + hsgr_input_stream.read( + (char*) graph_edge_list_ptr, + shared_layout_ptr->graph_edge_list_size*sizeof(QueryGraph::_StrEdge) + ); + hsgr_input_stream.close(); + } catch(const std::exception & e) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); } From 58c94159b1784165974e222eabc12b33f44667fd Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 11:28:53 +0200 Subject: [PATCH 099/127] use only one pointer for shared layout --- datastore.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datastore.cpp b/datastore.cpp index 6b657c306..341ff9191 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -102,6 +102,7 @@ int main(int argc, char * argv[]) { SharedDataLayout * shared_layout_ptr = static_cast( layout_memory->Ptr() ); + shared_layout_ptr = new SharedDataLayout(); // // // collect number of elements to store in shared memory object // @@ -114,11 +115,13 @@ int main(int argc, char * argv[]) { unsigned name_index_size = 0; name_stream.read((char *)&name_index_size, sizeof(unsigned)); shared_layout_ptr->name_index_list_size = name_index_size; + SimpleLogger().Write() << "name index size: " << shared_layout_ptr->name_index_list_size; BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken"); unsigned number_of_chars = 0; name_stream.read((char *)&number_of_chars, sizeof(unsigned)); shared_layout_ptr->name_char_list_size = number_of_chars; + SimpleLogger().Write() << "name char size: " << shared_layout_ptr->name_char_list_size; //Loading information for original edges boost::filesystem::ifstream edges_input_stream( @@ -308,7 +311,6 @@ int main(int argc, char * argv[]) { shared_layout_ptr->graph_node_list_size*sizeof(QueryGraph::_StrNode) ); - // load the edges of the search graph QueryGraph::_StrEdge * graph_edge_list_ptr = (QueryGraph::_StrEdge *)( shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffsett() From ff9a216990741ac48d4c67392574ad5de1950214 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 14:21:00 +0200 Subject: [PATCH 100/127] properly loading all data into shared memory --- datastore.cpp | 58 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 341ff9191..2992eada8 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -102,7 +102,7 @@ int main(int argc, char * argv[]) { SharedDataLayout * shared_layout_ptr = static_cast( layout_memory->Ptr() ); - shared_layout_ptr = new SharedDataLayout(); + shared_layout_ptr = new(layout_memory->Ptr()) SharedDataLayout(); // // // collect number of elements to store in shared memory object // @@ -115,44 +115,60 @@ int main(int argc, char * argv[]) { unsigned name_index_size = 0; name_stream.read((char *)&name_index_size, sizeof(unsigned)); shared_layout_ptr->name_index_list_size = name_index_size; - SimpleLogger().Write() << "name index size: " << shared_layout_ptr->name_index_list_size; + // SimpleLogger().Write() << "name index size: " << shared_layout_ptr->name_index_list_size; BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken"); unsigned number_of_chars = 0; name_stream.read((char *)&number_of_chars, sizeof(unsigned)); shared_layout_ptr->name_char_list_size = number_of_chars; - SimpleLogger().Write() << "name char size: " << shared_layout_ptr->name_char_list_size; + // SimpleLogger().Write() << "name char size: " << shared_layout_ptr->name_char_list_size; //Loading information for original edges boost::filesystem::ifstream edges_input_stream( edge_data_path, std::ios::binary ); - unsigned number_of_edges = 0; - edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned)); - SimpleLogger().Write() << "number of edges: " << number_of_edges; + unsigned number_of_original_edges = 0; + edges_input_stream.read((char*)&number_of_original_edges, sizeof(unsigned)); + SimpleLogger().Write() << "number of edges: " << number_of_original_edges; - shared_layout_ptr->via_node_list_size = number_of_edges; - shared_layout_ptr->name_id_list_size = number_of_edges; - shared_layout_ptr->turn_instruction_list_size = number_of_edges; + shared_layout_ptr->via_node_list_size = number_of_original_edges; + shared_layout_ptr->name_id_list_size = number_of_original_edges; + shared_layout_ptr->turn_instruction_list_size = number_of_original_edges; + SimpleLogger().Write() << "noted number of edges"; + + SimpleLogger().Write() << "loading hsgr from " << hsgr_path.string(); boost::filesystem::ifstream hsgr_input_stream( hsgr_path, std::ios::binary ); + UUID uuid_loaded, uuid_orig; + hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); + if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { + SimpleLogger().Write(logWARNING) << + ".hsgr was prepared with different build. " + "Reprocess to get rid of this warning."; + } else { + SimpleLogger().Write() << "UUID checked out ok"; + } + + SimpleLogger().Write() << "loaded file"; // load checksum unsigned checksum = 0; - hsgr_input_stream.read((char*) checksum, sizeof(unsigned) ); + hsgr_input_stream.read((char*)&checksum, sizeof(unsigned) ); + SimpleLogger().Write() << "checksum: " << checksum; shared_layout_ptr->checksum = checksum; - + SimpleLogger().Write() << "noted checksum"; // load graph node size unsigned number_of_graph_nodes = 0; hsgr_input_stream.read( (char*) &number_of_graph_nodes, sizeof(unsigned) ); + SimpleLogger().Write() << "number of nodes: " << number_of_graph_nodes; BOOST_ASSERT_MSG( (0 != number_of_graph_nodes), "number of nodes is zero" @@ -161,8 +177,9 @@ int main(int argc, char * argv[]) { // load graph edge size unsigned number_of_graph_edges = 0; - hsgr_input_stream.read( (char*) &number_of_edges, sizeof(unsigned) ); - BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); + hsgr_input_stream.read( (char*) &number_of_graph_edges, sizeof(unsigned) ); + SimpleLogger().Write() << "number of graph edges: " << number_of_graph_edges; + BOOST_ASSERT_MSG( 0 != number_of_graph_edges, "number of graph edges is zero"); shared_layout_ptr->graph_edge_list_size = number_of_graph_edges; // load rsearch tree size @@ -252,8 +269,8 @@ int main(int argc, char * argv[]) { ); OriginalEdgeData current_edge_data; - for(unsigned i = 0; i < number_of_edges; ++i) { - SimpleLogger().Write() << i << "/" << number_of_edges; + for(unsigned i = 0; i < number_of_original_edges; ++i) { + // SimpleLogger().Write() << i << "/" << number_of_edges; edges_input_stream.read( (char*)&(current_edge_data), sizeof(OriginalEdgeData) @@ -294,14 +311,6 @@ int main(int argc, char * argv[]) { tree_node_file.read(rtree_ptr, sizeof(RTreeNode)*tree_size); tree_node_file.close(); - UUID uuid_loaded, uuid_orig; - hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); - if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { - SimpleLogger().Write(logWARNING) << - ".hsgr was prepared with different build. " - "Reprocess to get rid of this warning."; - } - // load the nodes of the search graph QueryGraph::_StrNode * graph_node_list_ptr = (QueryGraph::_StrNode*)( shared_memory_ptr + shared_layout_ptr->GetGraphNodeListOffset() @@ -324,6 +333,7 @@ int main(int argc, char * argv[]) { } catch(const std::exception & e) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); } - + SimpleLogger().Write() << "all done. pressing a key deallocates memory"; + std::cin.get(); return 0; } From ed7b478ee088554b3853370cb7dabea49f9188d2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 15:50:26 +0200 Subject: [PATCH 101/127] swapping correct vectors --- DataStructures/SharedMemoryVectorWrapper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 89d549c05..2b1c283ec 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -77,6 +77,7 @@ public: { } void swap( SharedMemoryWrapper & other ) { + BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid"); std::swap( m_size, other.m_size); std::swap( m_ptr , other.m_ptr ); } From de8d28ea5f3fb2c850dfd5163fbb552190f95bc9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 15:54:32 +0200 Subject: [PATCH 102/127] printing debug output --- Server/DataStructures/SharedDataType.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index d064a695f..90e09498f 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -65,6 +65,21 @@ struct SharedDataLayout { timestamp_length(0) { } + void PrintInformation() const { + SimpleLogger().Write(logDEBUG) << "-"; + SimpleLogger().Write(logDEBUG) << "name_index_list_size: " << name_index_list_size; + SimpleLogger().Write(logDEBUG) << "name_char_list_size: " << name_char_list_size; + SimpleLogger().Write(logDEBUG) << "name_id_list_size: " << name_id_list_size; + SimpleLogger().Write(logDEBUG) << "via_node_list_size: " << via_node_list_size; + SimpleLogger().Write(logDEBUG) << "graph_node_list_size: " << graph_node_list_size; + SimpleLogger().Write(logDEBUG) << "graph_edge_list_size: " << graph_edge_list_size; + SimpleLogger().Write(logDEBUG) << "timestamp_length: " << timestamp_length; + SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << coordinate_list_size; + SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << turn_instruction_list_size; + SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << r_search_tree_size; + SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); + } + uint64_t GetSizeOfLayout() const { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + From 73234e778225a282b23230fa61a9b8d5c890cb77 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 15:55:29 +0200 Subject: [PATCH 103/127] loading correct file with rtree leafs and not inner nodes --- Server/DataStructures/SharedDataFacade.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index f13e0332f..a3882868c 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -162,7 +162,7 @@ private: street_names_index_ptr, data_layout->name_index_list_size ); - m_name_begin_indices.swap(m_name_begin_indices); + m_name_begin_indices.swap(name_begin_indices); char * names_list_ptr = (char *)( shared_memory + data_layout->GetNameListOffset() @@ -180,13 +180,13 @@ public: const boost::filesystem::path base_path ) { //check contents of config file - if ( !server_config.Holds("ramIndex") ) { + if ( !server_config.Holds("fileIndex") ) { throw OSRMException("no nodes file name in server ini"); } //generate paths of data files boost::filesystem::path ram_index_path = boost::filesystem::absolute( - server_config.GetParameter("ramIndex"), + server_config.GetParameter("fileIndex"), base_path ); @@ -198,6 +198,8 @@ public: SharedMemoryFactory::Get(DATA_1)->Ptr() ); + data_layout->PrintInformation(); + //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(); From 08d861e87cd514750e5f3634b0f3ff439d1e1b4c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 16:01:51 +0200 Subject: [PATCH 104/127] removing extra ; --- DataStructures/SharedMemoryFactory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index 3f71279c6..d4d9770d1 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -157,7 +157,7 @@ public: ", code " << e.get_error_code(); throw OSRMException(e.what()); } - }; + } private: SharedMemoryFactory_tmpl() {} From cfab0fa24517586f1908d6e5d316bda96238c6e8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 16:03:46 +0200 Subject: [PATCH 105/127] fixing include typo --- datastore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datastore.cpp b/datastore.cpp index 2992eada8..fe9782a3b 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -25,7 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "DataStructures/StaticRTree.h" #include "Server/DataStructures/BaseDataFacade.h" #include "Server/DataStructures/SharedDataType.h" -#include "Util/BoostFilesystemFix.h" +#include "Util/BoostFileSystemFix.h" #include "Util/IniFile.h" #include "Util/SimpleLogger.h" #include "Util/UUID.h" From e4c6e98099e58ecacb5b64acf6020bc92226ec81 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 30 Sep 2013 16:12:19 +0200 Subject: [PATCH 106/127] fixing typo in build configuration --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 055062bc3..375af49fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) add_executable(osrm-datastore datastore.cpp) file(GLOB DescriptorGlob Descriptors/*.cpp) -file(GLOB DatastructureGlob Datastructures/*.cpp) +file(GLOB DatastructureGlob DataStructures/*.cpp) file(GLOB LibOSRMGlob Library/*.cpp) set(OSRMSources ${LibOSRMGlob} ${DescriptorGlob} ${DatastructureGlob}) From f59cb6417f0e9dafd96ecd46e764c94adcf54290 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 13:24:25 +0200 Subject: [PATCH 107/127] commenting unneeded variables --- Descriptors/DescriptionFactory.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index f7a3c5be0..17ce86efc 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -97,8 +97,8 @@ public: unsigned durationOfSegment = 0; unsigned indexOfSegmentBegin = 0; - std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].nameID); - std::string string1; + // std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].nameID); + // std::string string1; /*Simplify turn instructions @@ -152,7 +152,7 @@ public: if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { - //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; + //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << pathDescription[i].nameID; assert(pathDescription[i].necessary); lengthOfSegment = 0; durationOfSegment = 0; From ca3464512d563f28079c53742474a375229586f6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 13:25:11 +0200 Subject: [PATCH 108/127] implementing the fetch of name ids in shared memory --- Server/DataStructures/SharedDataFacade.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index a3882868c..b8daa1041 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -302,7 +302,9 @@ public: unsigned GetCheckSum() const { return m_check_sum; } - unsigned GetNameIndexFromEdgeID(const unsigned id) const { return 0; }; + unsigned GetNameIndexFromEdgeID(const unsigned id) const { + return m_name_ID_list.at(id); + }; void GetName( const unsigned name_id, std::string & result ) const { if(UINT_MAX == name_id) { From fd7b22f639bf883d8bc3b97fe18983935087b5b9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 16:48:40 +0200 Subject: [PATCH 109/127] deciding which memory subsystem to use depending on server.ini --- routed.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/routed.cpp b/routed.cpp index de6ad1472..6c25de855 100644 --- a/routed.cpp +++ b/routed.cpp @@ -65,13 +65,11 @@ int main (int argc, char * argv[]) { try { LogPolicy::GetInstance().Unmute(); #ifdef __linux__ - if(!mlockall(MCL_CURRENT | MCL_FUTURE)) { - SimpleLogger().Write(logWARNING) << "Process " << argv[0] << "could not be locked to RAM"; + if( !mlockall(MCL_CURRENT | MCL_FUTURE) ) { + SimpleLogger().Write(logWARNING) << + "Process " << argv[0] << "could not be locked to RAM"; } -#endif -#ifdef __linux__ - - installCrashHandler(argv[0]); + installCrashHandler(argv[0]); #endif SimpleLogger().Write() << "starting up engines, compiled at " << __DATE__ << ", " __TIME__; @@ -84,10 +82,23 @@ int main (int argc, char * argv[]) { pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - IniFile serverConfig((argc > 1 ? argv[1] : "server.ini")); - OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); + IniFile server_config((argc > 1 ? argv[1] : "server.ini")); - Server * s = ServerFactory::CreateServer(serverConfig); + bool use_shared_memory = false; + if( + server_config.Holds("SharedMemory") && + "yes" == server_config.GetParameter("SharedMemory") + ) { + use_shared_memory = true; + SimpleLogger().Write() << "Using data stored in shared memory"; + } + + OSRM routing_machine( + (argc > 1 ? argv[1] : "server.ini"), + use_shared_memory + ); + + Server * s = ServerFactory::CreateServer(server_config); s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine); boost::thread t(boost::bind(&Server::Run, s)); @@ -115,7 +126,8 @@ int main (int argc, char * argv[]) { std::cout << "[server] stopping threads" << std::endl; if(!t.timed_join(boost::posix_time::seconds(2))) { - SimpleLogger().Write(logDEBUG) << "Threads did not finish within 2 seconds. Hard abort!"; + SimpleLogger().Write(logDEBUG) << + "Threads did not finish within 2 seconds. Hard abort!"; } std::cout << "[server] freeing objects" << std::endl; From 0f258f94a84cbf1b99201e94d60550e7c82f6f62 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 16:53:15 +0200 Subject: [PATCH 110/127] removing completed todo markers --- Plugins/LocatePlugin.h | 8 ++++++-- Plugins/TimestampPlugin.h | 1 - Plugins/ViaRoutePlugin.h | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index ed2a89a4e..443694067 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/StringUtil.h" //locates the nearest node in the road network for a given coordinate. -//TODO: Rework data access to go through facade template class LocatePlugin : public BasePlugin { @@ -63,7 +62,12 @@ public: reply.status = http::Reply::ok; reply.content += ("{"); reply.content += ("\"version\":0.3,"); - if(!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates[0], result)) { + if( + !facade->LocateClosestEndPointForCoordinate( + routeParameters.coordinates[0], + result + ) + ) { reply.content += ("\"status\":207,"); reply.content += ("\"mapped_coordinate\":[]"); } else { diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index b6a9b6b4f..6ee77ef84 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #define TIMESTAMPPLUGIN_H_ #include "BasePlugin.h" -//TODO: Rework data access to go through facade template class TimestampPlugin : public BasePlugin { diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 0a3c439cd..f1b7231e4 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -39,7 +39,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -//TODO: Rework data access to go through facade template class ViaRoutePlugin : public BasePlugin { private: From 940b740b24c3e97fc9d35b750b2e08bfa12446c2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 17:37:52 +0200 Subject: [PATCH 111/127] checking if data files actually exist --- Server/DataStructures/InternalDataFacade.h | 19 +++++++++++++++++++ datastore.cpp | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index efba74fdd..f1b5d3005 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -249,6 +249,25 @@ public: base_path ); + if ( !boost::filesystem::exists(hsgr_path) ) { + throw(".hsgr not found"); + } + if ( !boost::filesystem::exists(ram_index_path) ) { + throw(".ramIndex not found"); + } + if ( !boost::filesystem::exists(file_index_path) ) { + throw(".fileIndex not found"); + } + if ( !boost::filesystem::exists(node_data_path) ) { + throw(".nodes not found"); + } + if ( !boost::filesystem::exists(edge_data_path) ) { + throw(".edges not found"); + } + if ( !boost::filesystem::exists(name_data_path) ) { + throw(".names not found"); + } + // check if data files empty if ( 0 == boost::filesystem::file_size( node_data_path ) ) { throw OSRMException("nodes file is empty"); diff --git a/datastore.cpp b/datastore.cpp index fe9782a3b..2d1bf8947 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -86,6 +86,24 @@ int main(int argc, char * argv[]) { base_path ); + //check if data files actually exist + if ( !boost::filesystem::exists(hsgr_path) ) { + throw(".hsgr not found"); + } + if ( !boost::filesystem::exists(ram_index_path) ) { + throw(".ramIndex not found"); + } + if ( !boost::filesystem::exists(node_data_path) ) { + throw(".nodes not found"); + } + if ( !boost::filesystem::exists(edge_data_path) ) { + throw(".edges not found"); + } + if ( !boost::filesystem::exists(name_data_path) ) { + throw(".names not found"); + } + + // check if data files empty if ( 0 == boost::filesystem::file_size( node_data_path ) ) { throw OSRMException("nodes file is empty"); From 0f58ff83562a642bc7964cf223e41eed7bd7c352 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Oct 2013 18:01:19 +0200 Subject: [PATCH 112/127] mild refactoring of debug outputs --- datastore.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 2d1bf8947..88904a4e5 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -148,16 +148,17 @@ int main(int argc, char * argv[]) { ); unsigned number_of_original_edges = 0; edges_input_stream.read((char*)&number_of_original_edges, sizeof(unsigned)); - SimpleLogger().Write() << "number of edges: " << number_of_original_edges; + SimpleLogger().Write(logDEBUG) << + "number of edges: " << number_of_original_edges; shared_layout_ptr->via_node_list_size = number_of_original_edges; shared_layout_ptr->name_id_list_size = number_of_original_edges; shared_layout_ptr->turn_instruction_list_size = number_of_original_edges; - SimpleLogger().Write() << "noted number of edges"; + SimpleLogger().Write(logDEBUG) << "noted number of edges"; - SimpleLogger().Write() << "loading hsgr from " << hsgr_path.string(); + SimpleLogger().Write(logDEBUG) << "loading hsgr from " << hsgr_path.string(); boost::filesystem::ifstream hsgr_input_stream( hsgr_path, std::ios::binary @@ -173,20 +174,19 @@ int main(int argc, char * argv[]) { SimpleLogger().Write() << "UUID checked out ok"; } - SimpleLogger().Write() << "loaded file"; // load checksum unsigned checksum = 0; hsgr_input_stream.read((char*)&checksum, sizeof(unsigned) ); SimpleLogger().Write() << "checksum: " << checksum; shared_layout_ptr->checksum = checksum; - SimpleLogger().Write() << "noted checksum"; + SimpleLogger().Write(logDEBUG) << "noted checksum"; // load graph node size unsigned number_of_graph_nodes = 0; hsgr_input_stream.read( (char*) &number_of_graph_nodes, sizeof(unsigned) ); - SimpleLogger().Write() << "number of nodes: " << number_of_graph_nodes; + SimpleLogger().Write(logDEBUG) << "number of nodes: " << number_of_graph_nodes; BOOST_ASSERT_MSG( (0 != number_of_graph_nodes), "number of nodes is zero" @@ -201,7 +201,7 @@ int main(int argc, char * argv[]) { shared_layout_ptr->graph_edge_list_size = number_of_graph_edges; // load rsearch tree size - SimpleLogger().Write() << "loading r-tree search list size"; + SimpleLogger().Write(logDEBUG) << "loading r-tree search list size"; boost::filesystem::ifstream tree_node_file( ram_index_path, std::ios::binary @@ -212,7 +212,7 @@ int main(int argc, char * argv[]) { shared_layout_ptr->r_search_tree_size = tree_size; //load timestamp size - SimpleLogger().Write() << "Loading timestamp"; + SimpleLogger().Write(logDEBUG) << "Loading timestamp"; std::string m_timestamp; if( boost::filesystem::exists(timestamp_path) ) { boost::filesystem::ifstream timestampInStream( timestamp_path ); @@ -231,7 +231,8 @@ int main(int argc, char * argv[]) { shared_layout_ptr->timestamp_length = m_timestamp.length(); //load coordinate size - SimpleLogger().Write(logDEBUG) << "Loading coordinates list"; + SimpleLogger().Write() << + "Loading coordinates list from " << node_data_path.string(); boost::filesystem::ifstream nodes_input_stream( node_data_path, std::ios::binary @@ -262,7 +263,7 @@ int main(int argc, char * argv[]) { shared_layout_ptr->name_index_list_size*sizeof(unsigned) ); - SimpleLogger().Write() << "Loading names char list"; + SimpleLogger().Write(logDEBUG) << "Loading names char list"; SimpleLogger().Write(logDEBUG) << "Bytes: " << shared_layout_ptr->name_char_list_size*sizeof(char); char * name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset(); name_stream.read( @@ -272,7 +273,9 @@ int main(int argc, char * argv[]) { name_stream.close(); //load original edge information - SimpleLogger().Write() << "Loading via node, coordinates and turn instruction list"; + SimpleLogger().Write() << + "Loading via node, coordinates and turn instruction lists from: " << + edge_data_path.string(); NodeID * via_node_ptr = (NodeID *)( shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset() @@ -348,10 +351,12 @@ int main(int argc, char * argv[]) { ); hsgr_input_stream.close(); + SimpleLogger().Write() << "all data loaded. pressing a key deallocates memory"; + std::cin.get(); + } catch(const std::exception & e) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); } - SimpleLogger().Write() << "all done. pressing a key deallocates memory"; - std::cin.get(); + return 0; } From 843348338a38defa96bd633342ece4ef17c7bbc4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 14:40:49 +0200 Subject: [PATCH 113/127] check if shmem segment exists --- DataStructures/SharedMemoryFactory.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index d4d9770d1..a0de8e47e 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -108,7 +108,29 @@ public: } } + template + static bool RegionExists( + const boost::filesystem::path & lock_file, + const IdentifierT id + ) { + boost::interprocess::xsi_key key( lock_file.string().c_str(), id ); + return RegionExists(key); + } + private: + static bool RegionExists( const boost::interprocess::xsi_key &key ) { + bool result = true; + try { + boost::interprocess::xsi_shared_memory shm( + boost::interprocess::open_only, + key + ); + } catch(...) { + result = false; + } + return result; + } + static void RemoveSharedMemory( const boost::interprocess::xsi_key &key ) { From 5afed2d396231513ca43a3cbde515c2df6142daa Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 15:26:19 +0200 Subject: [PATCH 114/127] make shmem swappable by ref and ptr --- DataStructures/SharedMemoryFactory.h | 100 ++++++++++++++++----------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index a0de8e47e..f3d829681 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -67,53 +67,73 @@ class SharedMemory : boost::noncopyable { }; public: - void * Ptr() const { - return region.get_address(); - } + void * Ptr() const { + return region.get_address(); + } - template - SharedMemory( - const boost::filesystem::path & lock_file, - const IdentifierT id, - const unsigned size = 0 - ) : key( - lock_file.string().c_str(), - id - ) { - if( 0 == size ){ //read_only - shm = boost::interprocess::xsi_shared_memory ( - boost::interprocess::open_only, - key - ); - region = boost::interprocess::mapped_region ( - shm, - boost::interprocess::read_only - ); - } else { //writeable pointer - //remove previously allocated mem - RemoveSharedMemory(key); - shm = boost::interprocess::xsi_shared_memory ( - boost::interprocess::create_only, - key, - size - ); - region = boost::interprocess::mapped_region ( - shm, - boost::interprocess::read_write - ); + template + SharedMemory( + const boost::filesystem::path & lock_file, + const IdentifierT id, + const unsigned size = 0 + ) : key( + lock_file.string().c_str(), + id + ) { + if( 0 == size ){ //read_only + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::open_only, + key + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_only + ); + } else { //writeable pointer + //remove previously allocated mem + RemoveSharedMemory(key); + shm = boost::interprocess::xsi_shared_memory ( + boost::interprocess::create_only, + key, + size + ); + region = boost::interprocess::mapped_region ( + shm, + boost::interprocess::read_write + ); - remover.SetID( shm.get_shmid() ); - SimpleLogger().Write(logDEBUG) << - "writeable memory allocated " << size << " bytes"; - } - } + remover.SetID( shm.get_shmid() ); + SimpleLogger().Write(logDEBUG) << + "writeable memory allocated " << size << " bytes"; + } + } + + void Swap(SharedMemory & other) { + SimpleLogger().Write() << "prev: " << shm.get_shmid(); + shm.swap(other.shm); + region.swap(other.region); + boost::interprocess::xsi_key temp_key = other.key; + other.key = key; + key = temp_key; + SimpleLogger().Write() << "after: " << shm.get_shmid(); + } + + void Swap(SharedMemory * other) { + SimpleLogger().Write() << "prev: " << shm.get_shmid(); + shm.swap(other->shm); + region.swap(other->region); + boost::interprocess::xsi_key temp_key = other->key; + other->key = key; + key = temp_key; + SimpleLogger().Write() << "after: " << shm.get_shmid(); + } template static bool RegionExists( - const boost::filesystem::path & lock_file, const IdentifierT id ) { - boost::interprocess::xsi_key key( lock_file.string().c_str(), id ); + OSRMLockFile lock_file; + boost::interprocess::xsi_key key( lock_file().string().c_str(), id ); return RegionExists(key); } From aaec0e641b78e430ffeda26afeb2ca5f7924ef65 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 15:47:43 +0200 Subject: [PATCH 115/127] add static function to remove shared memory --- DataStructures/SharedMemoryFactory.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index f3d829681..b61a48b84 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -137,6 +137,15 @@ public: return RegionExists(key); } + template + static void RemoveSharedMemory( + const IdentifierT id + ) { + OSRMLockFile lock_file; + boost::interprocess::xsi_key key( lock_file().string().c_str(), id ); + RemoveSharedMemory(key); + } + private: static bool RegionExists( const boost::interprocess::xsi_key &key ) { bool result = true; From a7449c913cb3cf3dc5b38e6c142af34d3328675c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 16:25:02 +0200 Subject: [PATCH 116/127] fail gracefully when lock file is not present --- DataStructures/SharedMemoryFactory.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index b61a48b84..e05f54dc4 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -132,9 +132,15 @@ public: static bool RegionExists( const IdentifierT id ) { - OSRMLockFile lock_file; - boost::interprocess::xsi_key key( lock_file().string().c_str(), id ); - return RegionExists(key); + bool result = true; + try { + OSRMLockFile lock_file; + boost::interprocess::xsi_key key( lock_file().string().c_str(), id ); + result = RegionExists(key); + } catch(...) { + result = false; + } + return result; } template From 2211c6945550ef3eb4d2ff1e344aa9567de4d8b7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 18:10:31 +0200 Subject: [PATCH 117/127] Add explicit shmem id for data loading --- Server/DataStructures/SharedDataType.h | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 90e09498f..020477ae5 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -197,36 +197,14 @@ struct SharedDataLayout { }; enum SharedDataType { - // NAMES_INDEX = 0, - // NAME_INDEX_SIZE, - // NAMES_LIST, - // name_char_list_size, - // NAME_ID_LIST, - // NAME_ID_LIST_SIZE, - // VIA_NODE_LIST, - // VIA_NODE_LIST_SIZE, - // GRAPH_NODE_LIST, - // GRAPH_NODE_LIST_SIZE, - // GRAPH_EDGE_LIST, - // GRAPH_EDGE_LIST_SIZE, - // CHECK_SUM, - // TIMESTAMP, - // TIMESTAMP_SIZE, - // COORDINATE_LIST, - // COORDINATE_LIST_SIZE, - // TURN_INSTRUCTION_LIST, - // TURN_INSTRUCTION_LIST_SIZE, - // R_SEARCH_TREE, - // R_SEARCH_TREE_SIZE - LAYOUT_1, DATA_1, LAYOUT_2, DATA_2, LAYOUT_3, DATA_3, - LAYOUT_4, - DATA_5 + LAYOUT_LOAD, + DATA_LOAD }; #endif /* SHARED_DATA_TYPE_H_ */ From 87e0f074e848a96112b3a6b02a600dd1b1c37169 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 9 Oct 2013 17:34:48 +0200 Subject: [PATCH 118/127] remove unneeded member --- Library/OSRM.cpp | 4 +--- Library/OSRM.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 3e4509362..491bb7007 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -20,9 +20,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "OSRM.h" -OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) : - use_shared_memory(use_shared_memory) -{ +OSRM::OSRM(const char * server_ini_path, const bool use_shared_memory) { if( !testDataFile(server_ini_path) ){ std::string error_message(server_ini_path); diff --git a/Library/OSRM.h b/Library/OSRM.h index df2c8ad93..4713565e5 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -62,7 +62,6 @@ private: BaseDataFacade * query_data_facade; PluginMap plugin_map; - const bool use_shared_memory; }; #endif //OSRM_H From 75f77783ff56e4bdca03aad2f03a304bfe00d65d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 9 Oct 2013 18:58:37 +0200 Subject: [PATCH 119/127] further compile fixes for clang 3.3 (OS X 10.9) --- DataStructures/DeallocatingVector.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/DataStructures/DeallocatingVector.h b/DataStructures/DeallocatingVector.h index 89d8e2ce7..c3bce4dd8 100644 --- a/DataStructures/DeallocatingVector.h +++ b/DataStructures/DeallocatingVector.h @@ -75,10 +75,18 @@ protected: return (mData == other.mData) && (mIndex == other.mIndex) && (mBucketList == other.mBucketList); } - inline bool operator<(const DeallocatingVectorIteratorState &other) { + bool operator<(const DeallocatingVectorIteratorState &other) const { return mIndex < other.mIndex; } + bool operator>(const DeallocatingVectorIteratorState &other) const { + return mIndex > other.mIndex; + } + + bool operator>=(const DeallocatingVectorIteratorState &other) const { + return mIndex >= other.mIndex; + } + //This is a hack to make assignment operator possible with reference member inline DeallocatingVectorIteratorState& operator= (const DeallocatingVectorIteratorState &a) { if (this != &a) { @@ -128,7 +136,7 @@ public: mState.mIndex++; mState.setPointerForIndex(); return DeallocatingVectorIterator(_myState); } - inline DeallocatingVectorIterator operator --(int) { //postfix + inline DeallocatingVectorIterator operator--(int) { //postfix if(DeallocateC) assert(false); DeallocatingVectorIteratorState _myState(mState); mState.mIndex--; mState.setPointerForIndex(); @@ -141,7 +149,7 @@ public: return DeallocatingVectorIterator(_myState); } - inline DeallocatingVectorIterator& operator+=(const difference_type& n) const { + inline DeallocatingVectorIterator& operator+=(const difference_type& n) { mState.mIndex+=n; return *this; } @@ -174,10 +182,18 @@ public: return mState == other.mState; } - bool operator<(const DeallocatingVectorIterator & other) { + inline bool operator<(const DeallocatingVectorIterator & other) const { return mState < other.mState; } + inline bool operator>(const DeallocatingVectorIterator & other) const { + return mState > other.mState; + } + + inline bool operator>=(const DeallocatingVectorIterator & other) const { + return mState >= other.mState; + } + difference_type operator-(const DeallocatingVectorIterator & other) { if(DeallocateC) assert(false); return mState.mIndex-other.mState.mIndex; From acbba950322afbf002e01c3bc258ec9e511b39e2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Oct 2013 14:31:28 +0200 Subject: [PATCH 120/127] remove problematic luabind code --- Extractor/ScriptingEnvironment.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index fba59f89d..c3fe7db2f 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -87,10 +87,11 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { ] ]; - luabind::module(myLuaState) [ - luabind::class_ >("vector") - .def("Add", &std::vector::push_back) - ]; + // fails on c++11/OS X 10.9 + // luabind::module(myLuaState) [ + // luabind::class_ >("vector") + // .def("Add", &std::vector::push_back) + // ]; if(0 != luaL_dofile(myLuaState, fileName) ) { throw OSRMException("ERROR occured in scripting block"); From 076944da5db2861206fe0194f479f0a61c6ee9b7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Oct 2013 14:32:10 +0200 Subject: [PATCH 121/127] always compile with C++11 on OS X (Linux to follow) --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 375af49fd..951ac4343 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ add_executable(osrm-prepare ${PrepareSources} ) add_executable(osrm-routed routed.cpp ) set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED) - add_executable(osrm-datastore datastore.cpp) file(GLOB DescriptorGlob Descriptors/*.cpp) @@ -69,7 +68,7 @@ endif(CMAKE_BUILD_TYPE MATCHES Release) #Configuring compilers if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # using Clang - set(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration") + set(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -std=c++11") message(STATUS "OpenMP parallelization not available using clang++") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC From 18f438a52851fcd6af3f2f629f8b1878b33c41e9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Oct 2013 15:34:10 +0200 Subject: [PATCH 122/127] make C++11 default on OS X --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951ac4343..ceed8fd1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,10 @@ endif(CMAKE_BUILD_TYPE MATCHES Release) #Configuring compilers if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # using Clang - set(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -std=c++11") + set(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration") + if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif(APPLE) message(STATUS "OpenMP parallelization not available using clang++") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC From 352bf8839b4650269115066edcdffea57e388171 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Oct 2013 17:25:02 +0200 Subject: [PATCH 123/127] state type of template class member function explicitly --- Extractor/ScriptingEnvironment.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index c3fe7db2f..5572adad6 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -88,10 +88,11 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { ]; // fails on c++11/OS X 10.9 - // luabind::module(myLuaState) [ - // luabind::class_ >("vector") - // .def("Add", &std::vector::push_back) - // ]; + luabind::module(myLuaState) [ + luabind::class_ >("vector") + .def("Add", static_cast::*)(const std::string&)>(&std::vector::push_back) + ) + ]; if(0 != luaL_dofile(myLuaState, fileName) ) { throw OSRMException("ERROR occured in scripting block"); From dee7c339b35678f5eff965da6750a40b1dc4de3f Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 11 Oct 2013 16:14:59 +0200 Subject: [PATCH 124/127] Move edge-based node out ouf surrounding class --- Contractor/EdgeBasedGraphFactory.h | 46 +---------------------- DataStructures/EdgeBasedNode.h | 51 ++++++++++++++++++++++++++ Server/DataStructures/BaseDataFacade.h | 5 ++- 3 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 DataStructures/EdgeBasedNode.h diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 5f4df157b..6b2fe5cc4 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -26,6 +26,7 @@ #include "../typedefs.h" #include "../DataStructures/DeallocatingVector.h" #include "../DataStructures/DynamicGraph.h" +#include "../DataStructures/EdgeBasedNode.h" #include "../Extractor/ExtractorStructs.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportEdge.h" @@ -49,51 +50,6 @@ 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; - } - - bool operator==(const EdgeBasedNode & other) const { - return id == other.id; - } - - inline FixedPointCoordinate Centroid() const { - FixedPointCoordinate centroid; - //The coordinates of the midpoint are given by: - //x = (x1 + x2) /2 and y = (y1 + y2) /2. - centroid.lon = (std::min(lon1, lon2) + std::max(lon1, lon2))/2; - centroid.lat = (std::min(lat1, lat2) + std::max(lat1, lat2))/2; - return centroid; - } - - inline bool isIgnored() const { - return ignoreInGrid; - } - - NodeID id; - int lat1; - int lat2; - int lon1; - int lon2:31; - bool belongsToTinyComponent:1; - NodeID nameID; - unsigned weight:31; - bool ignoreInGrid:1; - }; - struct SpeedProfileProperties{ SpeedProfileProperties() : trafficSignalPenalty(0), diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h new file mode 100644 index 000000000..542eda451 --- /dev/null +++ b/DataStructures/EdgeBasedNode.h @@ -0,0 +1,51 @@ +#ifndef EDGE_BASED_NODE_H +#define EDGE_BASED_NODE_H + +#include "Coordinate.h" + +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; + } + + bool operator==(const EdgeBasedNode & other) const { + return id == other.id; + } + + inline FixedPointCoordinate Centroid() const { + FixedPointCoordinate centroid; + //The coordinates of the midpoint are given by: + //x = (x1 + x2) /2 and y = (y1 + y2) /2. + centroid.lon = (std::min(lon1, lon2) + std::max(lon1, lon2))/2; + centroid.lat = (std::min(lat1, lat2) + std::max(lat1, lat2))/2; + return centroid; + } + + inline bool isIgnored() const { + return ignoreInGrid; + } + + NodeID id; + int lat1; + int lat2; + int lon1; + int lon2:31; + bool belongsToTinyComponent:1; + NodeID nameID; + unsigned weight:31; + bool ignoreInGrid:1; +}; + +#endif //EDGE_BASED_NODE_H \ No newline at end of file diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index d74ef5cbc..55c0a8f84 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -23,8 +23,9 @@ or see http://www.gnu.org/licenses/agpl.txt. //Exposes all data access interfaces to the algorithms via base class ptr -#include "../../Contractor/EdgeBasedGraphFactory.h" #include "../../DataStructures/Coordinate.h" +#include "../../DataStructures/EdgeBasedNode.h" +#include "../../DataStructures/ImportNode.h" #include "../../DataStructures/PhantomNodes.h" #include "../../DataStructures/TurnInstructions.h" #include "../../Util/OSRMException.h" @@ -36,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. template class BaseDataFacade { public: - typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf; + typedef EdgeBasedNode RTreeLeaf; typedef EdgeDataT EdgeData; BaseDataFacade( ) { } virtual ~BaseDataFacade() { } From 8d98316a892936167415677e61d21b1e8b2f6a11 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 15 Oct 2013 11:52:41 +0200 Subject: [PATCH 125/127] change EdgeBasedNode namespace --- createHierarchy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 74ce9a4d7..612919d0e 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -202,7 +202,7 @@ int main (int argc, char *argv[]) { NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); DeallocatingVector edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); - std::vector nodeBasedEdgeList; + std::vector nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); delete edgeBasedGraphFactory; @@ -228,14 +228,14 @@ int main (int argc, char *argv[]) { */ SimpleLogger().Write() << "building r-tree ..."; - StaticRTree * rtree = - new StaticRTree( + StaticRTree * rtree = + new StaticRTree( nodeBasedEdgeList, rtree_nodes_path.c_str(), rtree_leafs_path.c_str() ); delete rtree; - IteratorbasedCRC32 > crc32; + IteratorbasedCRC32 > crc32; unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); nodeBasedEdgeList.clear(); SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList; From 748df0b21a38c41bbcbd75c77bd10441f680274d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 15 Oct 2013 11:56:27 +0200 Subject: [PATCH 126/127] fix iterator concept implementation --- DataStructures/DeallocatingVector.h | 65 +++++++++++------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/DataStructures/DeallocatingVector.h b/DataStructures/DeallocatingVector.h index c3bce4dd8..6acec9b27 100644 --- a/DataStructures/DeallocatingVector.h +++ b/DataStructures/DeallocatingVector.h @@ -40,39 +40,18 @@ protected: //make constructors explicit, so we do not mix random access and deallocation iterators. DeallocatingVectorIteratorState(); public: - explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r) : mData(r.mData), mIndex(r.mIndex), mBucketList(r.mBucketList) {} - //explicit DeallocatingVectorIteratorState(const ElementT * ptr, const std::size_t idx, const std::vector & input_list) : mData(ptr), mIndex(idx), mBucketList(input_list) {} - explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector & input_list) : mData(DEALLOCATION_VECTOR_NULL_PTR), mIndex(idx), mBucketList(input_list) { - setPointerForIndex(); + explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r) : /*mData(r.mData),*/ mIndex(r.mIndex), mBucketList(r.mBucketList) {} + explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector & input_list) : /*mData(DEALLOCATION_VECTOR_NULL_PTR),*/ mIndex(idx), mBucketList(input_list) { } - ElementT * mData; std::size_t mIndex; std::vector & mBucketList; - inline void setPointerForIndex() { - if(bucketSizeC*mBucketList.size() <= mIndex) { - mData = DEALLOCATION_VECTOR_NULL_PTR; - return; - } - std::size_t _bucket = mIndex/bucketSizeC; - std::size_t _index = mIndex%bucketSizeC; - mData = &(mBucketList[_bucket][_index]); - - if(DeallocateC) { - //if we hopped over the border of the previous bucket, then delete that bucket. - if(0 == _index && _bucket) { - delete[] mBucketList[_bucket-1]; - mBucketList[_bucket-1] = DEALLOCATION_VECTOR_NULL_PTR; - } - } - - } inline bool operator!=(const DeallocatingVectorIteratorState &other) { - return (mData != other.mData) || (mIndex != other.mIndex) || (mBucketList != other.mBucketList); + return mIndex != other.mIndex; } inline bool operator==(const DeallocatingVectorIteratorState &other) { - return (mData == other.mData) && (mIndex == other.mIndex) && (mBucketList == other.mBucketList); + return mIndex == other.mIndex; } bool operator<(const DeallocatingVectorIteratorState &other) const { @@ -112,7 +91,6 @@ public: DeallocatingVectorIterator(const DeallocatingVectorIterator & r) : mState(r.mState) {} DeallocatingVectorIterator(std::size_t idx, std::vector & input_list) : mState(idx, input_list) {} - //DeallocatingVectorIterator(std::size_t idx, const std::vector & input_list) : mState(idx, input_list) {} DeallocatingVectorIterator(const DeallocatingVectorIteratorState & r) : mState(r) {} template @@ -122,30 +100,32 @@ public: } inline DeallocatingVectorIterator& operator++() { //prefix -// if(DeallocateC) assert(false); - ++mState.mIndex; mState.setPointerForIndex(); return *this; + if(DeallocateC) assert(false); + ++mState.mIndex; + return *this; } inline DeallocatingVectorIterator& operator--() { //prefix if(DeallocateC) assert(false); - --mState.mIndex; mState.setPointerForIndex(); return *this; + --mState.mIndex; + return *this; } inline DeallocatingVectorIterator operator++(int) { //postfix DeallocatingVectorIteratorState _myState(mState); - mState.mIndex++; mState.setPointerForIndex(); + mState.mIndex++; return DeallocatingVectorIterator(_myState); } inline DeallocatingVectorIterator operator--(int) { //postfix if(DeallocateC) assert(false); DeallocatingVectorIteratorState _myState(mState); - mState.mIndex--; mState.setPointerForIndex(); + mState.mIndex--; return DeallocatingVectorIterator(_myState); } inline DeallocatingVectorIterator operator+(const difference_type& n) const { DeallocatingVectorIteratorState _myState(mState); - _myState.mIndex+=n; _myState.setPointerForIndex(); + _myState.mIndex+=n; return DeallocatingVectorIterator(_myState); } @@ -156,7 +136,7 @@ public: inline DeallocatingVectorIterator operator-(const difference_type& n) const { if(DeallocateC) assert(false); DeallocatingVectorIteratorState _myState(mState); - _myState.mIndex-=n; _myState.setPointerForIndex(); + _myState.mIndex-=n; return DeallocatingVectorIterator(_myState); } @@ -164,14 +144,17 @@ public: if(DeallocateC) assert(false); mState.mIndex-=n; return *this; } - inline reference operator*() const { return *mState.mData; } - inline pointer operator->() const { return mState.mData; } - inline reference operator[](const difference_type &n) const { - if(DeallocateC) assert(false); - DeallocatingVectorIteratorState _myState(mState); - _myState.mIndex += n; - _myState.setPointerForIndex; - return _myState.mData; + + inline reference operator*() const { + std::size_t _bucket = mState.mIndex/bucketSizeC; + std::size_t _index = mState.mIndex%bucketSizeC; + return (mState.mBucketList[_bucket][_index]); + } + + inline pointer operator->() const { + std::size_t _bucket = mState.mIndex/bucketSizeC; + std::size_t _index = mState.mIndex%bucketSizeC; + return &(mState.mBucketList[_bucket][_index]); } inline bool operator!=(const DeallocatingVectorIterator & other) { From 411d8d4d98b2ee5be5205fe0bbd06c19f038dabe Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 15 Oct 2013 12:00:20 +0200 Subject: [PATCH 127/127] fix iterator concept implementation --- DataStructures/DeallocatingVector.h | 1 - 1 file changed, 1 deletion(-) diff --git a/DataStructures/DeallocatingVector.h b/DataStructures/DeallocatingVector.h index 6acec9b27..576ce9092 100644 --- a/DataStructures/DeallocatingVector.h +++ b/DataStructures/DeallocatingVector.h @@ -100,7 +100,6 @@ public: } inline DeallocatingVectorIterator& operator++() { //prefix - if(DeallocateC) assert(false); ++mState.mIndex; return *this; }