From 5bde545ce3ef9932d8e1fcd0c6180ad70212ec32 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Feb 2014 16:55:41 +0100 Subject: [PATCH] All good, but needs unpacking of start and end --- Contractor/EdgeBasedGraphFactory.cpp | 8 ++-- DataStructures/Coordinate.cpp | 19 ++++++++- DataStructures/EdgeBasedNode.h | 12 +++--- DataStructures/PhantomNodes.h | 45 ++++++++++++++++------ DataStructures/SharedMemoryVectorWrapper.h | 2 + DataStructures/StaticGraph.h | 4 +- DataStructures/StaticRTree.h | 20 +++++++--- Descriptors/DescriptionFactory.cpp | 4 ++ Include/osrm/Coordinate.h | 12 +++--- RoutingAlgorithms/AlternativePathRouting.h | 8 ++-- RoutingAlgorithms/BasicRoutingInterface.h | 18 +++++++-- RoutingAlgorithms/ShortestPathRouting.h | 12 +++--- Server/DataStructures/InternalDataFacade.h | 38 +++++++++++++----- Server/DataStructures/SharedDataFacade.h | 35 +++++++++++------ Server/DataStructures/SharedDataType.h | 2 +- 15 files changed, 169 insertions(+), 70 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index f8487aab5..279edf797 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -306,7 +306,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; } BOOST_ASSERT( forward_data.edgeBasedNodeID != std::numeric_limits::max() ); - SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v; + // SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v; if( forward_data.ignore_in_grid ) { // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << @@ -324,7 +324,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( if ( e2 == m_node_based_graph->EndEdges(v) ) { SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")"; } -#endif NDEBUG +#endif BOOST_ASSERT( e2 != std::numeric_limits::max() ); BOOST_ASSERT( e2 < m_node_based_graph->EndEdges(v) ); const EdgeData & reverse_data = m_node_based_graph->GetEdgeData(e2); @@ -470,6 +470,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( reverse_dist_prefix_sum[geometry_size-1-i] ) ); + BOOST_ASSERT( m_edge_based_node_list.back().IsCompressed() ); first_node_of_edge = last_coordinate_id; } //TODO: Manually reconstruct last edge. @@ -518,6 +519,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( 0 ) ); + BOOST_ASSERT( !m_edge_based_node_list.back().IsCompressed() ); } } @@ -742,7 +744,7 @@ void EdgeBasedGraphFactory::Run( if( u > v ) { continue; } - BOOST_ASSERT( u < v ); + // BOOST_ASSERT( u < v ); BOOST_ASSERT( edge_data.type != SHRT_MAX ); //Note: edges that end on barrier nodes or on a turn restriction diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index e45931adf..90e44eac0 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -26,9 +26,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include + +#include +#include #include FixedPointCoordinate::FixedPointCoordinate() @@ -39,7 +43,16 @@ FixedPointCoordinate::FixedPointCoordinate() FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon) -{ } +{ + if(0 != (lat >> 30)) { + std::bitset<32> y(lat); + SimpleLogger().Write(logDEBUG) << "broken lat: " << lat << ", bits: " << y; + } + if(0 != (lon >> 30)) { + std::bitset<32> x(lon); + SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x; + } +} void FixedPointCoordinate::Reset() { lat = std::numeric_limits::min(); @@ -159,3 +172,7 @@ void FixedPointCoordinate::convertInternalReversedCoordinateToString( convertInternalLatLonToString(coord.lon, tmp); output += tmp; } + +void FixedPointCoordinate::Output(std::ostream & out) const {//, FixedPointCoordinate & c) { + out << "(" << lat << "," << lon << ")"; +} diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index 6b562ba4b..b8744edd3 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -23,8 +23,8 @@ struct EdgeBasedNode { name_id(std::numeric_limits::max()), forward_weight(std::numeric_limits::max() >> 1), reverse_weight(std::numeric_limits::max() >> 1), - forward_offset_to_edge_based_node(0), - reverse_offset_to_edge_based_node(0) + forward_offset(0), + reverse_offset(0) { } EdgeBasedNode( @@ -38,8 +38,8 @@ struct EdgeBasedNode { NodeID name_id, int forward_weight, int reverse_weight, - int forward_offset_to_edge_based_node, - int reverse_offset_to_edge_based_node + int forward_offset, + int reverse_offset ) : forward_edge_based_node_id(forward_edge_based_node_id), reverse_edge_based_node_id(reverse_edge_based_node_id), @@ -51,8 +51,8 @@ struct EdgeBasedNode { name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight), - forward_offset_to_edge_based_node(forward_offset_to_edge_based_node), - reverse_offset_to_edge_based_node(reverse_offset_to_edge_based_node) + forward_offset(forward_offset), + reverse_offset(reverse_offset) { } // Computes: diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 03ffb92f6..e01774691 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -33,11 +33,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct PhantomNode { PhantomNode() : - forward_node_id(std::numeric_limits::max()), - reverse_node_id(std::numeric_limits::max()), - name_id(std::numeric_limits::max()), - forward_weight(INT_MAX), - reverse_weight(INT_MAX), + forward_node_id( SPECIAL_NODEID ), + reverse_node_id( SPECIAL_NODEID ), + name_id( std::numeric_limits::max() ), + forward_weight(INVALID_EDGE_WEIGHT), + reverse_weight(INVALID_EDGE_WEIGHT), + forward_offset(0), + reverse_offset(0), ratio(0.) { } @@ -46,25 +48,44 @@ struct PhantomNode { unsigned name_id; int forward_weight; int reverse_weight; + int forward_offset; + int reverse_offset; double ratio; FixedPointCoordinate location; + int GetForwardWeightPlusOffset() const { + return forward_weight + forward_offset; + } + + int GetReverseWeightPlusOffset() const { + return reverse_weight + reverse_offset; + } + void Reset() { - forward_node_id = std::numeric_limits::max(); - name_id = std::numeric_limits::max(); - forward_weight = INT_MAX; - reverse_weight = INT_MAX; + forward_node_id = SPECIAL_NODEID; + name_id = SPECIAL_NODEID; + forward_weight = INVALID_EDGE_WEIGHT; + reverse_weight = INVALID_EDGE_WEIGHT; + forward_offset = 0; + reverse_offset = 0; ratio = 0.; location.Reset(); } + bool isBidirected() const { - return forward_node_id != UINT_MAX && reverse_node_id != UINT_MAX; + return ( forward_node_id != SPECIAL_NODEID ) && + ( reverse_node_id != SPECIAL_NODEID ); } + + bool IsCompressed() const { + return (forward_offset != 0) || (reverse_offset != 0); + } + bool isValid(const unsigned numberOfNodes) const { return location.isValid() && ( (forward_node_id < numberOfNodes) || (reverse_node_id < numberOfNodes) ) && - ( (forward_weight != INT_MAX) || (reverse_weight != INT_MAX) ) && + ( (forward_weight != INVALID_EDGE_WEIGHT) || (reverse_weight != INVALID_EDGE_WEIGHT) ) && (ratio >= 0.) && (ratio <= 1.) && (name_id != std::numeric_limits::max()); @@ -88,7 +109,7 @@ struct PhantomNodes { } bool AtLeastOnePhantomNodeIsUINTMAX() const { - return !(startPhantom.forward_node_id == std::numeric_limits::max() || targetPhantom.forward_node_id == std::numeric_limits::max()); + return !(startPhantom.forward_node_id == SPECIAL_NODEID || targetPhantom.forward_node_id == SPECIAL_NODEID); } bool PhantomNodesHaveEqualLocation() const { diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 8ceff2489..22337188e 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -115,6 +115,8 @@ public: std::size_t size() const { return m_size; } + bool empty() const { return 0 == size(); } + DataT & operator[](const unsigned index) { BOOST_ASSERT_MSG(index < m_size, "invalid size"); return m_ptr[index]; diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index b572d7f2e..41e5e61ec 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -115,6 +115,7 @@ public: u << "," << data.id << "," << v << ")"; data.shortcut = false; + BOOST_ASSERT(false); } eid2 = FindEdgeInEitherDirection(data.id, v); if(eid2 == UINT_MAX) { @@ -122,6 +123,7 @@ public: "cannot find second segment of edge (" << u << "," << data.id << "," << v << ")"; data.shortcut = false; + BOOST_ASSERT(false); } } } @@ -165,7 +167,7 @@ public: //searches for a specific edge EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const { EdgeIterator smallestEdge = SPECIAL_EDGEID; - EdgeWeight smallestWeight = UINT_MAX; + EdgeWeight smallestWeight = INVALID_EDGE_WEIGHT; for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) { const NodeID target = GetTarget(edge); const EdgeWeight weight = GetEdgeData(edge).distance; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 7821ce0dc..aef5544b1 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -51,6 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -68,7 +69,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170; static boost::thread_specific_ptr thread_local_rtree_stream; -template +template, bool UseSharedMemory = false> class StaticRTree : boost::noncopyable { public: struct RectangleInt2D { @@ -289,8 +290,9 @@ private: typename ShM::vector m_search_tree; uint64_t m_element_count; - const std::string m_leaf_node_filename; + boost::shared_ptr m_coordinate_list; + public: //Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1] explicit StaticRTree( @@ -426,9 +428,11 @@ public: //Read-only operation for queries explicit StaticRTree( const boost::filesystem::path & node_file, - const boost::filesystem::path & leaf_file - ) : m_leaf_node_filename(leaf_file.string()) { + const boost::filesystem::path & leaf_file, + const boost::shared_ptr coordinate_list + ) : m_leaf_node_filename( leaf_file.string() ) { //open tree node file and load into RAM. + m_coordinate_list = coordinate_list; if ( !boost::filesystem::exists( node_file ) ) { throw OSRMException("ram index file does not exist"); @@ -463,9 +467,11 @@ public: explicit StaticRTree( TreeNode * tree_node_ptr, const uint32_t number_of_nodes, - const boost::filesystem::path & leaf_file + const boost::filesystem::path & leaf_file, + boost::shared_ptr coordinate_list ) : m_search_tree(tree_node_ptr, number_of_nodes), - m_leaf_node_filename(leaf_file.string()) + m_leaf_node_filename(leaf_file.string()), + m_coordinate_list(coordinate_list) { //open leaf node file and store thread specific pointer if ( !boost::filesystem::exists( leaf_file ) ) { @@ -659,6 +665,8 @@ public: result_phantom_node.name_id = current_edge.name_id; result_phantom_node.forward_weight = current_edge.forward_weight; result_phantom_node.reverse_weight = current_edge.reverse_weight; + result_phantom_node.forward_offset = current_edge.forward_offset; + result_phantom_node.reverse_offset = current_edge.reverse_offset; result_phantom_node.location = nearest; current_start_coordinate.lat = current_edge.lat1; current_start_coordinate.lon = current_edge.lon1; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index dacb60a60..11dfc1164 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -139,5 +139,9 @@ void DescriptionFactory::BuildRouteSummary( ) { summary.startName = start_phantom.name_id; summary.destName = target_phantom.name_id; + + SimpleLogger().Write(logDEBUG) << "phantom start name: " << start_phantom.name_id << ", path: " << pathDescription.front().name_id; + SimpleLogger().Write(logDEBUG) << "phantom target name: " << target_phantom.name_id << ", path: " << pathDescription.back().name_id; + summary.BuildDurationAndLengthStrings(distance, time); } diff --git a/Include/osrm/Coordinate.h b/Include/osrm/Coordinate.h index 1f7a27a28..76d158a34 100644 --- a/Include/osrm/Coordinate.h +++ b/Include/osrm/Coordinate.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef FIXED_POINT_COORDINATE_H_ #define FIXED_POINT_COORDINATE_H_ -#include +#include //for std::ostream static const double COORDINATE_PRECISION = 1000000.; @@ -37,7 +37,7 @@ struct FixedPointCoordinate { int lon; FixedPointCoordinate(); - explicit FixedPointCoordinate (int lat, int lon); + explicit FixedPointCoordinate( int lat, int lon); void Reset(); bool isSet() const; bool isValid() const; @@ -74,11 +74,13 @@ struct FixedPointCoordinate { const FixedPointCoordinate & coord, std::string & output ); + + void Output(std::ostream & out) const; }; -inline std::ostream & operator<<(std::ostream & out, const FixedPointCoordinate & c){ - out << "(" << c.lat << "," << c.lon << ")"; - return out; +inline std::ostream& operator<<(std::ostream& o, FixedPointCoordinate const & c){ + c.Output(o); + return o; } #endif /* FIXED_POINT_COORDINATE_H_ */ diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 1f5389727..e9e771ea8 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -113,26 +113,26 @@ public: NodeID middle_node = UINT_MAX; forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, - -phantom_node_pair.startPhantom.forward_weight, + -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.startPhantom.forward_node_id ); if(phantom_node_pair.startPhantom.isBidirected() ) { forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, - -phantom_node_pair.startPhantom.reverse_weight, + -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.startPhantom.reverse_node_id ); } reverse_heap1.Insert( phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.forward_weight, + phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.targetPhantom.forward_node_id ); if(phantom_node_pair.targetPhantom.isBidirected() ) { reverse_heap1.Insert( phantom_node_pair.targetPhantom.reverse_node_id, - phantom_node_pair.targetPhantom.reverse_weight, + phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.targetPhantom.reverse_node_id ); } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index fa495d583..66db0409e 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -202,7 +202,8 @@ public: BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut"); unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id); TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); - //TODO: reorder to always iterate over a result vector + + //TODO: refactor to iterate over a result vector in both cases if ( !facade->EdgeIsCompressed(ed.id) ){ SimpleLogger().Write() << "Edge " << ed.id << " is not compressed, smaller_edge_id: " << smaller_edge_id; BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) ); @@ -218,10 +219,17 @@ public: SimpleLogger().Write() << "Edge " << ed.id << " is compressed"; std::vector id_vector; facade->GetUncompressedGeometry(ed.id, id_vector); - BOOST_FOREACH(const unsigned coordinate_id, id_vector){ - //TODO: unpack entire geometry - //TODO: set distance to 0, see if works + if( unpacked_path.empty() ) { + SimpleLogger().Write(logDEBUG) << "first segment(" << facade->GetEscapedNameForNameID(ed.id) << ") is packed"; + } + + // if( recursion_stack.empty() ) { + // SimpleLogger().Write(logDEBUG) << "last segment is packed"; + // } + + BOOST_FOREACH(const unsigned coordinate_id, id_vector){ + //TODO: skip if first edge is compressed until start point is reached unpacked_path.push_back( PathData( coordinate_id, @@ -238,6 +246,8 @@ public: } } + + } inline void UnpackEdge( diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 4cd7f9bab..5e90af97b 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -109,12 +109,12 @@ public: forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, - distance1-phantom_node_pair.startPhantom.forward_weight, + distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.startPhantom.forward_node_id ); forward_heap2.Insert( phantom_node_pair.startPhantom.forward_node_id, - distance1-phantom_node_pair.startPhantom.forward_weight, + distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.startPhantom.forward_node_id ); } @@ -122,12 +122,12 @@ public: BOOST_ASSERT(phantom_node_pair.startPhantom.reverse_node_id != UINT_MAX); forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, - distance2-phantom_node_pair.startPhantom.reverse_weight, + distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.startPhantom.reverse_node_id ); forward_heap2.Insert( phantom_node_pair.startPhantom.reverse_node_id, - distance2-phantom_node_pair.startPhantom.reverse_weight, + distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.startPhantom.reverse_node_id ); } @@ -135,7 +135,7 @@ public: //insert new backward nodes into backward heap, unadjusted. reverse_heap1.Insert( phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.forward_weight, + phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.targetPhantom.forward_node_id ); BOOST_ASSERT(phantom_node_pair.targetPhantom.forward_node_id != UINT_MAX); @@ -144,7 +144,7 @@ public: BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); reverse_heap2.Insert( phantom_node_pair.targetPhantom.reverse_node_id, - phantom_node_pair.targetPhantom.reverse_weight, + phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.targetPhantom.reverse_node_id ); } diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 93cf39811..a10517cfd 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -45,6 +45,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include +#include + template class InternalDataFacade : public BaseDataFacade { @@ -61,7 +64,7 @@ private: QueryGraph * m_query_graph; std::string m_timestamp; - ShM::vector m_coordinate_list; + boost::shared_ptr::vector> m_coordinate_list; ShM::vector m_via_node_list; ShM::vector m_name_ID_list; ShM::vector m_turn_instruction_list; @@ -71,7 +74,13 @@ private: ShM::vector m_compressed_geometry_indices; ShM::vector m_compressed_geometries; - StaticRTree * m_static_rtree; + boost::shared_ptr< + StaticRTree< + RTreeLeaf, + ShM::vector, + false + > + > m_static_rtree; void LoadTimestamp(const boost::filesystem::path & timestamp_path) { @@ -131,15 +140,16 @@ private: (char *)&number_of_coordinates, sizeof(unsigned) ); - m_coordinate_list.resize(number_of_coordinates); + m_coordinate_list = boost::make_shared >(number_of_coordinates); for(unsigned i = 0; i < number_of_coordinates; ++i) { nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); - m_coordinate_list[i] = FixedPointCoordinate( + m_coordinate_list->at(i) = FixedPointCoordinate( current_node.lat, current_node.lon ); + BOOST_ASSERT( ( m_coordinate_list->at(i).lat >> 30) == 0 ); + BOOST_ASSERT( ( m_coordinate_list->at(i).lon >> 30) == 0 ); } - std::vector(m_coordinate_list).swap(m_coordinate_list); nodes_input_stream.close(); SimpleLogger().Write(logDEBUG) << "Loading edge data"; @@ -221,9 +231,15 @@ private: const boost::filesystem::path & ram_index_path, const boost::filesystem::path & file_index_path ) { - m_static_rtree = new StaticRTree( + BOOST_ASSERT_MSG( + !m_coordinate_list->empty(), + "coordinates must be loaded before r-tree" + ); + + m_static_rtree = boost::make_shared >( ram_index_path, - file_index_path + file_index_path, + m_coordinate_list ); } @@ -238,6 +254,8 @@ private: BOOST_ASSERT_MSG(0 != number_of_names, "name file broken"); BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken"); + SimpleLogger().Write(logDEBUG) << "no. of names: " << number_of_names; + m_name_begin_indices.resize(number_of_names); name_stream.read( (char*)&m_name_begin_indices[0], @@ -258,7 +276,7 @@ private: public: ~InternalDataFacade() { delete m_query_graph; - delete m_static_rtree; + m_static_rtree.reset(); } explicit InternalDataFacade( const ServerPaths & server_paths ) { @@ -379,7 +397,7 @@ public: const unsigned id ) const { // const unsigned coordinate_index = m_via_node_list.at(id); - return m_coordinate_list.at(id); + return m_coordinate_list->at(id); }; bool EdgeIsCompressed( const unsigned id ) const { @@ -471,7 +489,7 @@ public: unsigned coordinate_id = m_compressed_geometries[geometry_index]; // uncomment to use compressed geometry result_nodes.push_back( coordinate_id ); - SimpleLogger().Write() << "coordinate " << coordinate_id << " at " << m_coordinate_list.at(coordinate_id); + SimpleLogger().Write() << "coordinate " << coordinate_id << " at " << m_coordinate_list->at(coordinate_id); } } diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 461220d08..be86d4221 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -30,9 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //implements all data storage when shared memory _IS_ used -#include -#include - #include "BaseDataFacade.h" #include "SharedDataType.h" @@ -42,6 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../Util/ProgramOptions.h" #include "../../Util/SimpleLogger.h" +#include +#include + #include template @@ -55,7 +55,7 @@ private: typedef typename StaticGraph::_StrEdge GraphEdge; typedef typename QueryGraph::InputEdge InputEdge; typedef typename super::RTreeLeaf RTreeLeaf; - typedef typename StaticRTree::TreeNode RTreeNode; + typedef typename StaticRTree::vector, true>::TreeNode RTreeNode; SharedDataLayout * data_layout; char * shared_memory; @@ -72,13 +72,21 @@ private: boost::shared_ptr m_large_memory; std::string m_timestamp; - ShM::vector m_coordinate_list; + boost::shared_ptr< + 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; - boost::shared_ptr > m_static_rtree; + boost::shared_ptr< + StaticRTree< + RTreeLeaf, + ShM::vector, + true + > + > m_static_rtree; // SharedDataFacade() { } @@ -95,13 +103,19 @@ private: void LoadRTree( const boost::filesystem::path & file_index_path ) { + BOOST_ASSERT_MSG( + !m_coordinate_list->empty(), + "coordinates must be loaded before r-tree" + ); + RTreeNode * tree_ptr = (RTreeNode *)( shared_memory + data_layout->GetRSearchTreeOffset() ); - m_static_rtree = boost::make_shared >( + m_static_rtree = boost::make_shared::vector, true> >( tree_ptr, data_layout->r_search_tree_size, - file_index_path + file_index_path, + m_coordinate_list ); } @@ -134,11 +148,10 @@ private: FixedPointCoordinate * coordinate_list_ptr = (FixedPointCoordinate *)( shared_memory + data_layout->GetCoordinateListOffset() ); - typename ShM::vector coordinate_list( + m_coordinate_list = boost::make_shared::vector> ( coordinate_list_ptr, data_layout->coordinate_list_size ); - m_coordinate_list.swap( coordinate_list ); TurnInstruction * turn_instruction_list_ptr = (TurnInstruction *)( shared_memory + data_layout->GetTurnInstructionListOffset() @@ -309,7 +322,7 @@ public: const unsigned id ) const { // const NodeID node = m_via_node_list.at(id); - return m_coordinate_list.at(id); + return m_coordinate_list->at(id); }; virtual bool EdgeIsCompressed( const unsigned id ) const { diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 902eea986..b7154094f 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include typedef BaseDataFacade::RTreeLeaf RTreeLeaf; -typedef StaticRTree::TreeNode RTreeNode; +typedef StaticRTree::vector, true>::TreeNode RTreeNode; typedef StaticGraph QueryGraph; struct SharedDataLayout {